~ubuntu-branches/ubuntu/utopic/maven-enforcer/utopic

« back to all changes in this revision

Viewing changes to enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireReleaseDeps.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-12 22:30:16 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: package-import@ubuntu.com-20110912223016-hrf239vjs4g4pik3
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.apache.maven.plugins.enforcer;
 
2
 
1
3
/*
2
4
 * Licensed to the Apache Software Foundation (ASF) under one
3
5
 * or more contributor license agreements.  See the NOTICE file
16
18
 * specific language governing permissions and limitations
17
19
 * under the License.
18
20
 */
19
 
package org.apache.maven.plugins.enforcer;
20
21
 
21
22
import java.util.HashSet;
22
23
import java.util.Iterator;
 
24
import java.util.List;
23
25
import java.util.Set;
24
26
 
25
27
import org.apache.maven.artifact.Artifact;
 
28
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
26
29
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
27
30
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
28
31
import org.apache.maven.plugin.logging.Log;
29
32
import org.apache.maven.project.MavenProject;
 
33
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
 
34
import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter;
30
35
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
31
36
 
32
 
// TODO: Auto-generated Javadoc
33
37
/**
34
38
 * This rule checks that no snapshots are included.
35
 
 * 
 
39
 *
36
40
 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
37
 
 * @version $Id: RequireReleaseDeps.java 683054 2008-08-06 00:13:22Z brianf $
 
41
 * @version $Id: RequireReleaseDeps.java 989820 2010-08-26 16:52:46Z pgier $
38
42
 */
39
43
public class RequireReleaseDeps
40
44
    extends AbstractBanDependencies
42
46
 
43
47
    /**
44
48
     * Allows this rule to execute only when this project is a release.
45
 
     * 
 
49
     *
46
50
     * @parameter
47
51
     */
48
52
    public boolean onlyWhenRelease = false;
49
53
 
50
54
    /**
51
55
     * Allows this rule to fail when the parent is defined as a snapshot.
52
 
     * 
 
56
     *
53
57
     * @parameter
54
58
     */
55
59
    public boolean failWhenParentIsSnapshot = true;
56
60
 
57
61
    /**
 
62
     * Dependencies to ignore when checking for release versions.  For example, inter-module dependencies 
 
63
     * can be excluded from the check and therefore allowed to contain snapshot versions.
 
64
     */
 
65
    public List excludes = null;
 
66
 
 
67
    /**
 
68
     * Dependencies to include when checking for release versions.  If any of the included dependencies
 
69
     * have snapshot versions, the rule will fail.
 
70
     */
 
71
    public List includes = null;
 
72
 
 
73
    /**
58
74
     * Override parent to allow optional ignore of this rule.
59
75
     */
60
76
    public void execute( EnforcerRuleHelper helper )
112
128
 
113
129
    /**
114
130
     * Checks the set of dependencies to see if any snapshots are included
115
 
     * 
 
131
     *
116
132
     * @param dependencies the dependencies
117
133
     * @param log the log
118
134
     * @return the sets the
121
137
    protected Set checkDependencies( Set dependencies, Log log )
122
138
        throws EnforcerRuleException
123
139
    {
124
 
        Set foundExcludes = new HashSet();
 
140
        Set foundSnapshots = new HashSet();
125
141
 
126
 
        Iterator DependencyIter = dependencies.iterator();
 
142
        Set filteredDependencies = this.filterArtifacts( dependencies );
 
143
        
 
144
        Iterator DependencyIter = filteredDependencies.iterator();
127
145
        while ( DependencyIter.hasNext() )
128
146
        {
129
147
            Artifact artifact = (Artifact) DependencyIter.next();
130
148
 
131
149
            if ( artifact.isSnapshot() )
132
150
            {
133
 
                foundExcludes.add( artifact );
 
151
                foundSnapshots.add( artifact );
134
152
            }
135
153
        }
136
154
 
137
 
        return foundExcludes;
 
155
        return foundSnapshots;
138
156
    }
139
157
    
 
158
    /*
 
159
     * Filter the dependency artifacts according to the includes and excludes
 
160
     * If includes and excludes are both null, the original set is returned.
 
161
     * 
 
162
     * @param dependencies the list of dependencies to filter
 
163
     * @return the resulting set of dependencies
 
164
     */
 
165
    public Set filterArtifacts( Set dependencies )
 
166
    {
 
167
        if ( includes == null && excludes == null )
 
168
        {
 
169
            return dependencies;
 
170
        }
 
171
        
 
172
        AndArtifactFilter filter = new AndArtifactFilter( );
 
173
        if ( includes != null )
 
174
        {
 
175
            filter.add( new StrictPatternIncludesArtifactFilter( includes ) );
 
176
        }
 
177
        if ( excludes != null )
 
178
        {
 
179
            filter.add( new StrictPatternExcludesArtifactFilter( excludes ) );
 
180
        }
 
181
        
 
182
        Set result = new HashSet();
 
183
        Iterator iter = dependencies.iterator();
 
184
        while ( iter.hasNext() )
 
185
        {
 
186
            Artifact artifact = (Artifact) iter.next();
 
187
            if ( filter.include( artifact ) )
 
188
            {
 
189
                result.add( artifact );
 
190
            }
 
191
        }
 
192
        return result;
 
193
    }
 
194
 
140
195
    public boolean isOnlyWhenRelease()
141
196
    {
142
197
        return onlyWhenRelease;