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 2009/02/22 04:13:03 UTC

svn commit: r746626 - in /maven/enforcer/trunk/enforcer-rules/src: main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java site/apt/requirePluginVersions.apt test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java

Author: brianf
Date: Sun Feb 22 03:13:03 2009
New Revision: 746626

URL: http://svn.apache.org/viewvc?rev=746626&view=rev
Log:
MENFORCER-62, convert the uncheckedPlugins from a list to comma separated string

Modified:
    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/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=746626&r1=746625&r2=746626&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 Sun Feb 22 03:13:03 2009
@@ -21,6 +21,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -66,6 +67,7 @@
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.util.CollectionUtils;
 import org.codehaus.plexus.util.ReflectionUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -108,9 +110,16 @@
 
     /**
      * Plugins to skip for version enforcement. The plugins should be specified in the form:
-     * <code>group:artifactId</code>.
+     * <code>group:artifactId</code>. NOTE: This is deprecated, use unCheckedPluginList instead.
+     * @deprecated
      */
     public List unCheckedPlugins;
+    
+    /**
+     * Same as unCheckedPlugins but as a comma list to better support properties. Sample form:
+     * <code>group:artifactId,group2:artifactId2</code>
+     */
+    public String unCheckedPluginList;
 
     /** The plugin manager. */
     private PluginManager pluginManager;
@@ -191,8 +200,9 @@
             allPlugins = addAdditionalPlugins( allPlugins, additionalPlugins );
             allPlugins.addAll( getProfilePlugins( project ) );
 
+            
             // pull out any we should skip
-            allPlugins = (Set) removeUncheckedPlugins( unCheckedPlugins, allPlugins );
+            allPlugins = (Set) removeUncheckedPlugins( combineUncheckedPlugins( unCheckedPlugins, unCheckedPluginList ), allPlugins );
 
             // there's nothing to do here
             if ( allPlugins.isEmpty() )
@@ -351,6 +361,32 @@
     }
 
     /**
+     * Combines the old Collection with the new comma separated list.
+     * @param uncheckedPlugins
+     * @param uncheckedPluginsList
+     * @return
+     */
+    public Collection combineUncheckedPlugins( Collection uncheckedPlugins, String uncheckedPluginsList )
+    {
+        //if the comma list is empty, then there's nothing to do here.
+        if ( StringUtils.isNotEmpty( uncheckedPluginsList ) )
+        {
+            //make sure there is a collection to add to.
+            if ( uncheckedPlugins == null )
+            {
+                uncheckedPlugins = new HashSet();
+            }
+            else if (!uncheckedPlugins.isEmpty() && log != null)
+            {
+                log.warn( "The parameter 'unCheckedPlugins' is deprecated. Use 'unCheckedPluginList' instead" );
+            }
+
+            uncheckedPlugins.addAll( Arrays.asList( uncheckedPluginsList.split( "," ) ) );
+        }
+        return uncheckedPlugins;
+    }
+    
+    /**
      * Add the additional plugins if they don't exist yet.
      * 
      * @param existing the existing
@@ -399,8 +435,8 @@
             if ( pluginStrings.length == 2 )
             {
                 Plugin plugin = new Plugin();
-                plugin.setGroupId( pluginStrings[0] );
-                plugin.setArtifactId( pluginStrings[1] );
+                plugin.setGroupId( StringUtils.strip( pluginStrings[0] ) );
+                plugin.setArtifactId( StringUtils.strip( pluginStrings[1] ) );
 
                 return plugin;
             }

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=746626&r1=746625&r2=746626&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt (original)
+++ maven/enforcer/trunk/enforcer-rules/src/site/apt/requirePluginVersions.apt Sun Feb 22 03:13:03 2009
@@ -46,7 +46,7 @@
      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.
+   * unCheckedPluginsList - A comma separated list of plugins to skip version checking. Ie allow no version, or snapshots, etc. The plugins should be specified in the form: group:artifactId.
 
 
    []
@@ -78,9 +78,10 @@
                    <phases>clean,deploy,site</phases>
                    <additionalPlugins>
                      <additionalPlugin>org.apache.maven.plugins:maven-eclipse-plugin</additionalPlugin>
-                     <additionalPlugin>org.apache.maven.plugins:maven-ide-plugin</additionalPlugin>
+                     <additionalPlugin>org.apache.maven.plugins:maven-reactor-plugin</additionalPlugin>
                    </additionalPlugins>
                 </requirePluginVersions>
+                <unCheckedPluginsList>org.apache.maven.plugins:maven-enforcer-plugin,org.apache.maven.plugins:maven-idea-plugin</unCheckedPluginsList>
               </rules>
             </configuration>
           </execution>

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=746626&r1=746625&r2=746626&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 Sun Feb 22 03:13:03 2009
@@ -341,7 +341,8 @@
         plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) );
 
         List unchecked = new ArrayList();
-        unchecked.add( "group:a-artifact" );
+        //intentionally inserting spaces to make sure they are handled correctly.
+        unchecked.add( "group : a-artifact" );
 
         Collection results = rule.removeUncheckedPlugins( unchecked, plugins );
         
@@ -351,11 +352,132 @@
         assertEquals( 2, results.size() );
         assertContainsPlugin( "group", "foo", results );
         assertContainsPlugin( "group", "foo2", results );
-        assertNotContainPlugin( "group", "a-artifact", plugins );
+        assertNotContainPlugin( "group", "a-artifact", results );
 
     }
     
     /**
+     * Test combining values from both lists
+     */
+    public void testCombinePlugins()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Set plugins = new HashSet();
+        plugins.add( "group:a-artifact" );
+        plugins.add( "group:foo" );
+        plugins.add( "group:foo2" );
+
+        Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); 
+
+        // make sure only one new plugin has been added
+        assertNotNull( results );
+        assertEquals( 5, results.size() );
+        assertTrue( results.contains( "group:foo") );
+        assertTrue( results.contains( "group:foo2") );
+        assertTrue( results.contains( "group:a-artifact") );
+        assertTrue( results.contains( "group2:a") );
+        assertTrue( results.contains( "group3:b") );
+    }
+    
+    /**
+     * Test combining with an empty list
+     */
+    public void testCombinePlugins1()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Set plugins = new HashSet();
+        Collection results = rule.combineUncheckedPlugins( plugins, "group2:a,group3:b" ); 
+        
+
+        // make sure only one new plugin has been added
+        assertNotNull( results );
+        assertEquals( 2, results.size() );
+        assertTrue( results.contains( "group2:a") );
+        assertTrue( results.contains( "group3:b") );
+    }
+
+    /**
+     * Test combining with a null list
+     */
+    public void testCombinePlugins2()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Collection results = rule.combineUncheckedPlugins( null, "group2:a,group3:b" ); 
+        
+
+        // make sure only one new plugin has been added
+        assertNotNull( results );
+        assertEquals( 2, results.size() );
+        assertTrue( results.contains( "group2:a") );
+        assertTrue( results.contains( "group3:b") );
+    }
+
+    /**
+     * Test combining with an empty string
+     */
+    public void testCombinePlugins3()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Set plugins = new HashSet();
+        plugins.add( "group:a-artifact" );
+        plugins.add( "group:foo" );
+        plugins.add( "group:foo2" );
+                     
+        Collection results = rule.combineUncheckedPlugins( plugins, "" ); 
+        assertNotNull( results );
+        assertEquals( 3, results.size() );
+        assertTrue( results.contains( "group:foo") );
+        assertTrue( results.contains( "group:foo2") );
+        assertTrue( results.contains( "group:a-artifact") );
+    }
+
+    /**
+     * Test combining with a null string
+     */
+    public void testCombinePlugins4()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Set plugins = new HashSet();
+        plugins.add( "group:a-artifact" );
+        plugins.add( "group:foo" );
+        plugins.add( "group:foo2" );
+                     
+        Collection results = rule.combineUncheckedPlugins( plugins, null ); 
+        assertNotNull( results );
+        assertEquals( 3, results.size() );   
+        assertTrue( results.contains( "group:foo") );
+        assertTrue( results.contains( "group:foo2") );
+        assertTrue( results.contains( "group:a-artifact") );
+    } 
+
+    /**
+     * Test combining with an invalid plugin string
+     */
+    public void testCombinePlugins5()
+    {
+        RequirePluginVersions rule = new RequirePluginVersions();
+
+        Set plugins = new HashSet();
+        plugins.add( "group:a-artifact" );
+        plugins.add( "group:foo" );
+        plugins.add( "group:foo2" );
+        
+        Collection results = rule.combineUncheckedPlugins( plugins, "a" ); 
+        assertNotNull( results );
+        assertEquals( 4, results.size() ); 
+        assertTrue( results.contains( "group:foo") );
+        assertTrue( results.contains( "group:foo2") );
+        //this should be here, the checking of a valid plugin string happens in another method.
+        assertTrue( results.contains( "a") );
+    }
+
+    
+    /**
      * Assert contains plugin.
      * 
      * @param group the group