You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2008/07/17 05:25:55 UTC
svn commit: r677494 - in /maven/enforcer/trunk/enforcer-rules/src:
it/requirePlugins1/ it/requirePluginsUnchecked/
main/java/org/apache/maven/plugins/enforcer/ site/apt/
test/java/org/apache/maven/plugins/enforcer/
Author: brianf
Date: Wed Jul 16 20:25:54 2008
New Revision: 677494
URL: http://svn.apache.org/viewvc?rev=677494&view=rev
Log:
allow some plugins to be skipped in the check (make it easier to use an snapshot of the enforcer)
Added:
maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/
- copied from r677480, maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/
Modified:
maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/pom.xml
maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/pom.xml
maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt
maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
Modified: maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/pom.xml?rev=677494&r1=677493&r2=677494&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/pom.xml (original)
+++ maven/enforcer/trunk/enforcer-rules/src/it/requirePlugins1/pom.xml Wed Jul 16 20:25:54 2008
@@ -24,6 +24,7 @@
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
+ <id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
Modified: maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/pom.xml
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/pom.xml?rev=677494&r1=677480&r2=677494&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/pom.xml (original)
+++ maven/enforcer/trunk/enforcer-rules/src/it/requirePluginsUnchecked/pom.xml Wed Jul 16 20:25:54 2008
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.enforcer.its</groupId>
- <artifactId>requirePlugins1</artifactId>
+ <artifactId>requirePluginsUnchecked</artifactId>
<packaging>jar</packaging>
<version>testing</version>
@@ -29,7 +29,12 @@
</goals>
<configuration>
<rules>
- <requirePluginVersions><phases>site</phases></requirePluginVersions>
+ <requirePluginVersions>
+ <phases>site</phases>
+ <unCheckedPlugins>
+ <unCheckedPlugin>org.apache.maven.plugins:maven-enforcer-plugin</unCheckedPlugin>
+ </unCheckedPlugins>
+ </requirePluginVersions>
</rules>
</configuration>
<!-- <dependencies>
Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java?rev=677494&r1=677493&r2=677494&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java (original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java Wed Jul 16 20:25:54 2008
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -70,7 +71,7 @@
// TODO: Auto-generated Javadoc
/**
- * This rule will enforce that all plugins specified in the poms have a version declared.
+ * This rule will enforce that all plugins specified in the poms have a version declared.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
@@ -104,6 +105,12 @@
*/
public List additionalPlugins;
+ /**
+ * Plugins to skip for version enforcement. The plugins should be specified in the form:
+ * <code>group:artifactId</code>.
+ */
+ public List unCheckedPlugins;
+
/** The plugin manager. */
private PluginManager pluginManager;
@@ -167,6 +174,9 @@
allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins );
allPlugins.addAll( getProfilePlugins( project ) );
+ // pull out any we should skip
+ allPlugins = (Set) removeUncheckedPlugins( unCheckedPlugins, allPlugins );
+
// there's nothing to do here
if ( allPlugins.isEmpty() )
{
@@ -299,6 +309,28 @@
}
/**
+ * Remove the plugins that the user doesn't want to check.
+ *
+ * @param uncheckedPlugins
+ * @param plugins
+ * @return
+ * @throws MojoExecutionException
+ */
+ public Collection removeUncheckedPlugins( Collection uncheckedPlugins, Collection plugins ) throws MojoExecutionException
+ {
+ if ( uncheckedPlugins != null && !uncheckedPlugins.isEmpty() )
+ {
+ Iterator iter = uncheckedPlugins.iterator();
+ while ( iter.hasNext() )
+ {
+ Plugin plugin = parsePluginString( (String) iter.next() );
+ plugins.remove( plugin );
+ }
+ }
+ return plugins;
+ }
+
+ /**
* Add the additional plugins if they don't exist yet.
*
* @param existing the existing
@@ -315,35 +347,56 @@
while ( iter.hasNext() )
{
String pluginString = (String) iter.next();
- String[] pluginStrings = pluginString.split( ":" );
- if ( pluginStrings.length == 2 )
- {
- Plugin plugin = new Plugin();
- plugin.setGroupId( pluginStrings[0] );
- plugin.setArtifactId( pluginStrings[1] );
+ Plugin plugin = parsePluginString( pluginString );
- // only add this if it's not already there.
- if ( existing == null )
- {
- existing = new HashSet();
- existing.add( plugin );
- }
- else if ( !existing.contains( plugin ) )
- {
- existing.add( plugin );
- }
+ if ( existing == null )
+ {
+ existing = new HashSet();
+ existing.add( plugin );
}
- else
+ else if ( !existing.contains( plugin ) )
{
- throw new MojoExecutionException( "Invalid AdditionalPlugin string: " + pluginString );
+ existing.add( plugin );
}
}
-
}
return existing;
}
/**
+ * Helper method to parse and inject a Plugin.
+ *
+ * @param pluginString
+ * @return
+ * @throws MojoExecutionException
+ */
+ protected Plugin parsePluginString( String pluginString )
+ throws MojoExecutionException
+ {
+ if ( pluginString != null )
+ {
+ String[] pluginStrings = pluginString.split( ":" );
+ if ( pluginStrings.length == 2 )
+ {
+ Plugin plugin = new Plugin();
+ plugin.setGroupId( pluginStrings[0] );
+ plugin.setArtifactId( pluginStrings[1] );
+
+ return plugin;
+ }
+ else
+ {
+ throw new MojoExecutionException( "Invalid AdditionalPlugin string: " + pluginString );
+ }
+ }
+ else
+ {
+ throw new MojoExecutionException( "Invalid AdditionalPlugin string: " + pluginString );
+ }
+
+ }
+
+ /**
* Finds the plugins that are listed in active profiles.
*
* @param project the project
@@ -1071,4 +1124,14 @@
{
this.banTimestamps = theBanTimestamps;
}
+
+ public List getUnCheckedPlugins()
+ {
+ return unCheckedPlugins;
+ }
+
+ public void setUnCheckedPlugins( List unCheckedPlugins )
+ {
+ this.unCheckedPlugins = unCheckedPlugins;
+ }
}
\ No newline at end of file
Modified: maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt?rev=677494&r1=677493&r2=677494&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt (original)
+++ maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt Wed Jul 16 20:25:54 2008
@@ -46,6 +46,8 @@
are plugins that may not be in the poms but are used anyway, like help, eclipse etc.
The plugins should be specified in the form: group:artifactId.
+ * uncheckedPlugins - A list of plugins to skip version checking. Ie allow no version, or snapshots, etc. The plugins should be specified in the form: group:artifactId
+
[]
Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java?rev=677494&r1=677493&r2=677494&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java (original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java Wed Jul 16 20:25:54 2008
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -319,13 +320,43 @@
}
/**
+ * Test remove Unchecked plugins.
+ *
+ * @throws MojoExecutionException the mojo execution exception
+ */
+ public void testGetUncheckedPlugins()
+ throws MojoExecutionException
+ {
+ RequirePluginVersions rule = new RequirePluginVersions();
+
+ Set plugins = new HashSet();
+ plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) );
+ plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) );
+ plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) );
+
+ List unchecked = new ArrayList();
+ unchecked.add( "group:a-artifact" );
+
+ Collection results = rule.removeUncheckedPlugins( unchecked, plugins );
+
+
+ // make sure only one new plugin has been added
+ assertNotNull( results );
+ assertEquals( 2, results.size() );
+ assertContainsPlugin( "group", "foo", results );
+ assertContainsPlugin( "group", "foo2", results );
+ assertNotContainPlugin( "group", "a-artifact", plugins );
+
+ }
+
+ /**
* Assert contains plugin.
*
* @param group the group
* @param artifact the artifact
* @param theSet the the set
*/
- private void assertContainsPlugin( String group, String artifact, Set theSet )
+ private void assertContainsPlugin( String group, String artifact, Collection theSet )
{
Plugin p = new Plugin();
p.setGroupId( group );
@@ -334,6 +365,21 @@
}
/**
+ * Assert doesn't contain plugin.
+ *
+ * @param group the group
+ * @param artifact the artifact
+ * @param theSet the the set
+ */
+ private void assertNotContainPlugin( String group, String artifact, Collection theSet )
+ {
+ Plugin p = new Plugin();
+ p.setGroupId( group );
+ p.setArtifactId( artifact );
+ assertFalse( theSet.contains( p ) );
+ }
+
+ /**
* Test id.
*/
public void testId()