16
18
* specific language governing permissions and limitations
17
19
* under the License.
19
package org.apache.maven.plugins.enforcer;
21
22
import java.util.HashSet;
22
23
import java.util.Iterator;
24
import java.util.List;
23
25
import java.util.Set;
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;
32
// TODO: Auto-generated Javadoc
34
38
* This rule checks that no snapshots are included.
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 $
39
43
public class RequireReleaseDeps
40
44
extends AbstractBanDependencies
44
48
* Allows this rule to execute only when this project is a release.
48
52
public boolean onlyWhenRelease = false;
51
55
* Allows this rule to fail when the parent is defined as a snapshot.
55
59
public boolean failWhenParentIsSnapshot = true;
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.
65
public List excludes = null;
68
* Dependencies to include when checking for release versions. If any of the included dependencies
69
* have snapshot versions, the rule will fail.
71
public List includes = null;
58
74
* Override parent to allow optional ignore of this rule.
60
76
public void execute( EnforcerRuleHelper helper )
121
137
protected Set checkDependencies( Set dependencies, Log log )
122
138
throws EnforcerRuleException
124
Set foundExcludes = new HashSet();
140
Set foundSnapshots = new HashSet();
126
Iterator DependencyIter = dependencies.iterator();
142
Set filteredDependencies = this.filterArtifacts( dependencies );
144
Iterator DependencyIter = filteredDependencies.iterator();
127
145
while ( DependencyIter.hasNext() )
129
147
Artifact artifact = (Artifact) DependencyIter.next();
131
149
if ( artifact.isSnapshot() )
133
foundExcludes.add( artifact );
151
foundSnapshots.add( artifact );
137
return foundExcludes;
155
return foundSnapshots;
159
* Filter the dependency artifacts according to the includes and excludes
160
* If includes and excludes are both null, the original set is returned.
162
* @param dependencies the list of dependencies to filter
163
* @return the resulting set of dependencies
165
public Set filterArtifacts( Set dependencies )
167
if ( includes == null && excludes == null )
172
AndArtifactFilter filter = new AndArtifactFilter( );
173
if ( includes != null )
175
filter.add( new StrictPatternIncludesArtifactFilter( includes ) );
177
if ( excludes != null )
179
filter.add( new StrictPatternExcludesArtifactFilter( excludes ) );
182
Set result = new HashSet();
183
Iterator iter = dependencies.iterator();
184
while ( iter.hasNext() )
186
Artifact artifact = (Artifact) iter.next();
187
if ( filter.include( artifact ) )
189
result.add( artifact );
140
195
public boolean isOnlyWhenRelease()
142
197
return onlyWhenRelease;