maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khmarba...@apache.org
Subject svn commit: r1559391 - in /maven/enforcer/trunk/enforcer-rules/src: main/java/org/apache/maven/plugins/enforcer/ main/java/org/apache/maven/plugins/enforcer/utils/ test/java/org/apache/maven/plugins/enforcer/ test/java/org/apache/maven/plugins/enforcer...
Date Sat, 18 Jan 2014 18:59:58 GMT
Author: khmarbaise
Date: Sat Jan 18 18:59:58 2014
New Revision: 1559391

URL: http://svn.apache.org/r1559391
Log:
[MENFORCER-167]
  - Fixed the code to work in accordance with the documented
    behaviour.

Modified:
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java
    maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
    maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java?rev=1559391&r1=1559390&r2=1559391&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java
Sat Jan 18 18:59:58 2014
@@ -19,9 +19,6 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.util.HashSet;
-import java.util.Set;
-
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
@@ -32,6 +29,8 @@ import org.apache.maven.shared.dependenc
 import org.apache.maven.shared.dependency.graph.DependencyNode;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * Abstract Rule for banning dependencies.
@@ -173,7 +172,7 @@ public abstract class AbstractBanDepende
      * @throws EnforcerRuleException the enforcer rule exception
      */
     protected abstract Set<Artifact> checkDependencies( Set<Artifact> dependencies,
Log log )
-        throws EnforcerRuleException;
+            throws EnforcerRuleException;
 
     /**
      * Checks if is search transitive.

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java?rev=1559391&r1=1559390&r2=1559391&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BannedDependencies.java
Sat Jan 18 18:59:58 2014
@@ -19,21 +19,20 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.plugin.logging.Log;
-import org.codehaus.plexus.util.StringUtils;
+import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher;
+import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher.Pattern;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 /**
  * This rule checks that lists of dependencies are not included.
- *
+ * 
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
  * @version $Id$
  */
@@ -42,36 +41,36 @@ public class BannedDependencies
 {
 
     /**
-     * Specify the banned dependencies. This can be a list of artifacts in the format <code>groupId[:artifactId][:version]</code>.
-     * Any of the sections can be a wildcard by using '*' (ie group:*:1.0) <br>
+     * Specify the banned dependencies. This can be a list of artifacts in the format
+     * <code>groupId[:artifactId][:version]</code>. Any of the sections can be
a wildcard by using '*' (ie group:*:1.0) <br>
      * The rule will fail if any dependency matches any exclude, unless it also matches an
include rule.
      * 
-     * @deprecated the visibility will be reduced to private with the next major version
      * @see {@link #setExcludes(List)}
      * @see {@link #getExcludes()}
+     * @deprecated the visibility will be reduced to private with the next major version
      */
     public List<String> excludes = null;
 
     /**
-     * Specify the allowed dependencies. This can be a list of artifacts in the format <code>groupId[:artifactId][:version]</code>.
-     * Any of the sections can be a wildcard by using '*' (ie group:*:1.0) <br>
+     * Specify the allowed dependencies. This can be a list of artifacts in the format
+     * <code>groupId[:artifactId][:version]</code>. Any of the sections can be
a wildcard by using '*' (ie group:*:1.0) <br>
      * Includes override the exclude rules. It is meant to allow wide exclusion rules with
wildcards and still allow a
      * smaller set of includes. <br>
      * For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api"
      * 
-     * @deprecated the visibility will be reduced to private with the next major version
      * @see {@link #setIncludes(List)}
      * @see {@link #getIncludes()}
+     * @deprecated the visibility will be reduced to private with the next major version
      */
     public List<String> includes = null;
 
-
     /**
      * {@inheritDoc}
      */
     protected Set<Artifact> checkDependencies( Set<Artifact> theDependencies,
Log log )
         throws EnforcerRuleException
     {
+
         Set<Artifact> excluded = checkDependencies( theDependencies, excludes );
 
         // anything specifically included should be removed
@@ -79,6 +78,7 @@ public class BannedDependencies
         if ( excluded != null )
         {
             Set<Artifact> included = checkDependencies( theDependencies, includes );
+
             if ( included != null )
             {
                 excluded.removeAll( included );
@@ -90,7 +90,7 @@ public class BannedDependencies
 
     /**
      * Checks the set of dependencies against the list of patterns.
-     *
+     * 
      * @param thePatterns the patterns
      * @param dependencies the dependencies
      * @return a set containing artifacts matching one of the patterns or <code>null</code>
@@ -106,13 +106,13 @@ public class BannedDependencies
 
             for ( String pattern : thePatterns )
             {
-
                 String[] subStrings = pattern.split( ":" );
                 subStrings = StringUtils.stripAll( subStrings );
+                String resultPattern = StringUtils.join( subStrings, ":" );
 
                 for ( Artifact artifact : dependencies )
                 {
-                    if ( compareDependency( subStrings, artifact ) )
+                    if ( compareDependency( resultPattern, artifact ) )
                     {
                         // only create if needed
                         if ( foundMatches == null )
@@ -128,69 +128,27 @@ public class BannedDependencies
     }
 
     /**
-     * Compares the parsed array of substrings against the artifact.
-     * The pattern should follow the format "groupId:artifactId:version:type:scope"
-     *
-     * @param pattern the array of patterns
+     * Compares the given pattern against the given artifact. The pattern should follow the
format
+     * <code>groupId:artifactId:version:type:scope:classifier</code>.
+     * 
+     * @param pattern The pattern to compare the artifact with.
      * @param artifact the artifact
      * @return <code>true</code> if the artifact matches one of the patterns
      * @throws EnforcerRuleException the enforcer rule exception
      */
-    protected boolean compareDependency( String[] pattern, Artifact artifact )
+    protected boolean compareDependency( String pattern, Artifact artifact )
         throws EnforcerRuleException
     {
 
-        boolean result = false;
-        if ( pattern.length > 0 )
+        ArtifactMatcher.Pattern am = new Pattern( pattern );
+        boolean result;
+        try
         {
-            result = pattern[0].equals( "*" ) || artifact.getGroupId().equals( pattern[0]
);
+            result = am.match( artifact );
         }
-
-        if ( result && pattern.length > 1 )
+        catch ( InvalidVersionSpecificationException e )
         {
-            result = pattern[1].equals( "*" ) || artifact.getArtifactId().equals( pattern[1]
);
-        }
-
-        if ( result && pattern.length > 2 )
-        {
-            // short circuit if the versions are exactly the same
-            if ( pattern[2].equals( "*" ) || artifact.getVersion().equals( pattern[2] ) )
-            {
-                result = true;
-            }
-            else
-            {
-                try
-                {
-                    result =
-                        AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec(
pattern[2] ),
-                                                                 new DefaultArtifactVersion(
artifact.getBaseVersion() ) );
-                }
-                catch ( InvalidVersionSpecificationException e )
-                {
-                    throw new EnforcerRuleException( "Invalid Version Range: ", e );
-                }
-            }
-        }
-
-        if ( result && pattern.length > 3 )
-        {
-            String type = artifact.getType();
-            if ( type == null || type.equals( "" ) )
-            {
-                type = "jar";
-            }
-            result = pattern[3].equals( "*" ) || type.equals( pattern[3] );
-        }
-
-        if ( result && pattern.length > 4 )
-        {
-            String scope = artifact.getScope();
-            if ( scope == null || scope.equals( "" ) )
-            {
-                scope = "compile";
-            }
-            result = pattern[4].equals( "*" ) || scope.equals( pattern[4] );
+            throw new EnforcerRuleException( "Invalid Version Range: ", e );
         }
 
         return result;
@@ -198,7 +156,7 @@ public class BannedDependencies
 
     /**
      * Gets the excludes.
-     *
+     * 
      * @return the excludes
      */
     public List<String> getExcludes()
@@ -208,7 +166,7 @@ public class BannedDependencies
 
     /**
      * Sets the excludes.
-     *
+     * 
      * @param theExcludes the excludes to set
      */
     public void setExcludes( List<String> theExcludes )
@@ -218,7 +176,7 @@ public class BannedDependencies
 
     /**
      * Gets the includes.
-     *
+     * 
      * @return the includes
      */
     public List<String> getIncludes()
@@ -228,7 +186,7 @@ public class BannedDependencies
 
     /**
      * Sets the includes.
-     *
+     * 
      * @param theIncludes the includes to set
      */
     public void setIncludes( List<String> theIncludes )

Modified: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java?rev=1559391&r1=1559390&r2=1559391&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java
Sat Jan 18 18:59:58 2014
@@ -19,14 +19,13 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.util.Collection;
-import java.util.LinkedList;
-
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.plugins.enforcer.AbstractVersionEnforcer;
+import java.util.Collection;
+import java.util.LinkedList;
 
 /**
  * This class is used for matching Artifacts against a list of patterns.
@@ -136,11 +135,16 @@ public final class ArtifactMatcher
                     throw new AssertionError();
             }
         }
-        
+
         private boolean matches( String expression, String input )
         {
             String regex = expression.replace( ".", "\\." ).replace( "*", ".*" ).replace(
":", "\\:" ).replace( '?', '.' );
 
+            //TODO: Check if this can be done better or prevented earlier.
+            if (input == null) {
+                input = "";
+            }
+
             return java.util.regex.Pattern.matches( regex , input );
         }
 

Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java?rev=1559391&r1=1559390&r2=1559391&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedDependencies.java
Sat Jan 18 18:59:58 2014
@@ -19,126 +19,354 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.plugin.testing.ArtifactStubFactory;
 import org.apache.maven.project.MavenProject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.runners.Enclosed;
+import org.junit.runner.RunWith;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import static org.junit.Assert.fail;
 
 // TODO: Auto-generated Javadoc
 /**
  * The Class TestBannedDependencies.
- *
+ * 
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
  */
+@RunWith( Enclosed.class )
 public class TestBannedDependencies
-    extends TestCase
 {
+    public static class ExcludesDoNotUseTransitiveDependencies
+    {
 
-    /**
-     * Test rule.
-     *
-     * @throws IOException Signals that an I/O exception has occurred.
-     */
-    public void testRule()
-        throws IOException
+        private List<String> excludes;
+
+        private BannedDependencies rule;
+
+        private EnforcerRuleHelper helper;
+
+        @Before
+        public void beforeMethod()
+            throws IOException
+        {
+            ArtifactStubFactory factory = new ArtifactStubFactory();
+
+            MockProject project = new MockProject();
+            project.setArtifacts( factory.getMixedArtifacts() );
+            project.setDependencyArtifacts( factory.getScopedArtifacts() );
+
+            helper = EnforcerTestUtils.getHelper( project );
+            rule = newBannedDependenciesRule();
+
+            excludes = new ArrayList<String>();
+            rule.setExcludes( excludes );
+            rule.setMessage( null );
+
+            rule.setSearchTransitive( false );
+        }
+
+        private void addExcludeAndRunRule( String toAdd )
+            throws EnforcerRuleException
+        {
+            excludes.add( toAdd );
+            rule.execute( helper );
+        }
+
+        @Test
+        public void testGroupIdArtifactIdVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId:release:1.0" );
+        }
+
+        @Test
+        public void testGroupIdArtifactId()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId:release" );
+        }
+
+        @Test
+        public void testGroupId()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId" );
+        }
+
+    }
+
+    public static class ExcludesUsingTransitiveDependencies
     {
-        ArtifactStubFactory factory = new ArtifactStubFactory();
-        MockProject project = new MockProject();
-        EnforcerRuleHelper helper = EnforcerTestUtils.getHelper( project );
-        project.setArtifacts( factory.getMixedArtifacts() );
-        project.setDependencyArtifacts( factory.getScopedArtifacts() );
-        
-        BannedDependencies rule = newBannedDependenciesRule();
 
-        List<String> excludes = new ArrayList<String>();
-        rule.setSearchTransitive( false );
+        private List<String> excludes;
 
-        // test whole name
-        excludes.add( "testGroupId:release:1.0" );
-        rule.setExcludes( excludes );
+        private BannedDependencies rule;
 
-        execute( rule, helper, false );
+        private EnforcerRuleHelper helper;
 
-        // test group:artifact
-        excludes.clear();
-        excludes.add( "testGroupId:release" );
-        execute( rule, helper, false );
+        @Before
+        public void beforeMethod()
+            throws IOException
+        {
+            ArtifactStubFactory factory = new ArtifactStubFactory();
 
-        // test group
-        excludes.clear();
-        excludes.add( "testGroupId" );
-        execute( rule, helper, false );
+            MockProject project = new MockProject();
+            project.setArtifacts( factory.getMixedArtifacts() );
+            project.setDependencyArtifacts( factory.getScopedArtifacts() );
 
-        // now check one that should be found in direct
-        // dependencies
-        excludes.clear();
-        excludes.add( "g:compile:1.0" );
-        execute( rule, helper, true );
-        rule.setSearchTransitive( true );
+            helper = EnforcerTestUtils.getHelper( project );
+            rule = newBannedDependenciesRule();
 
-        // whole name
-        excludes.clear();
-        excludes.add( "testGroupId:release:1.0" );
-        execute( rule, helper, true );
+            excludes = new ArrayList<String>();
+            rule.setExcludes( excludes );
+            rule.setMessage( null );
+            rule.setSearchTransitive( true );
+        }
 
-        // group:artifact
-        excludes.clear();
-        excludes.add( "testGroupId:release" );
-        execute( rule, helper, true );
+        private void addExcludeAndRunRule( String toAdd )
+            throws EnforcerRuleException
+        {
+            excludes.add( toAdd );
+            rule.execute( helper );
+        }
 
-        // group
-        excludes.clear();
-        excludes.add( "testGroupId" );
-        execute( rule, helper, true );
+        @Test( expected = EnforcerRuleException.class )
+        public void testGroupIdArtifactIdVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId:release:1.0" );
+        }
 
-        // now check wildcards
-        excludes.clear();
-        excludes.add( "*:release" );
-        execute( rule, helper, true );
+        @Test( expected = EnforcerRuleException.class )
+        public void testGroupIdArtifactId()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId:release" );
+        }
 
-        // now check wildcards
-        excludes.clear();
-        excludes.add( "*:*:1.0" );
-        execute( rule, helper, true );
+        @Test( expected = EnforcerRuleException.class )
+        public void testGroupId()
+            throws Exception
+        {
+            addExcludeAndRunRule( "testGroupId" );
+        }
 
-        // now check wildcards
-        excludes.clear();
-        excludes.add( "*:release:*" );
-        execute( rule, helper, true );
+        @Test( expected = EnforcerRuleException.class )
+        public void testSpaceTrimmingGroupIdArtifactIdVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "  testGroupId  :  release   :   1.0    " );
+        }
 
-        // now check wildcards
-        excludes.clear();
-        excludes.add( "*:release:1.2" );
-        execute( rule, helper, false );
+        @Test( expected = EnforcerRuleException.class )
+        public void groupIdArtifactIdVersionType()
+            throws Exception
+        {
+            addExcludeAndRunRule( "g:a:1.0:war" );
+        }
 
-        // now check multiple excludes
-        excludes.add( "*:release:*" );
-        execute( rule, helper, true );
+        @Test( expected = EnforcerRuleException.class )
+        public void groupIdArtifactIdVersionTypeScope()
+            throws Exception
+        {
+            addExcludeAndRunRule( "g:a:1.0:war:compile" );
+        }
 
-        // now check space trimming
-        excludes.clear();
-        excludes.add( "  testGroupId  :  release   :   1.0    " );
-        execute( rule, helper, true );
+        // @Test(expected = EnforcerRuleException.class)
+        // public void groupIdArtifactIdVersionTypeScopeClassifier() throws Exception {
+        // addExcludeAndRunRule("g:compile:1.0:jar:compile:one");
+        // }
+        //
+    }
+
+    public static class WildcardExcludesUsingTransitiveDependencies
+    {
+
+        private List<String> excludes;
+
+        private BannedDependencies rule;
+
+        private EnforcerRuleHelper helper;
+
+        @Before
+        public void beforeMethod()
+            throws IOException
+        {
+            ArtifactStubFactory factory = new ArtifactStubFactory();
+
+            MockProject project = new MockProject();
+            project.setArtifacts( factory.getMixedArtifacts() );
+            project.setDependencyArtifacts( factory.getScopedArtifacts() );
+
+            helper = EnforcerTestUtils.getHelper( project );
+            rule = newBannedDependenciesRule();
+
+            rule.setMessage( null );
+
+            excludes = new ArrayList<String>();
+            rule.setExcludes( excludes );
+            rule.setSearchTransitive( true );
+        }
+
+        private void addExcludeAndRunRule( String toAdd )
+            throws EnforcerRuleException
+        {
+            excludes.add( toAdd );
+            rule.execute( helper );
+        }
+
+        @Test
+        public void testWildcardForGroupIdArtifactIdVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "*:release:1.2" );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void testWildCardForGroupIdArtifactId()
+            throws Exception
+        {
+            addExcludeAndRunRule( "*:release" );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void testWildcardForGroupIdWildcardForArtifactIdVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "*:*:1.0" );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void testWildcardForGroupIdArtifactIdWildcardForVersion()
+            throws Exception
+        {
+            addExcludeAndRunRule( "*:release:*" );
+        }
+
+    }
+
+    public static class PartialWildcardExcludesUsingTransitiveDependencies
+    {
+
+        private List<String> excludes;
+
+        private BannedDependencies rule;
+
+        private EnforcerRuleHelper helper;
+
+        @Before
+        public void beforeMethod()
+            throws IOException
+        {
+            ArtifactStubFactory factory = new ArtifactStubFactory();
+
+            MockProject project = new MockProject();
+            project.setArtifacts( factory.getMixedArtifacts() );
+            project.setDependencyArtifacts( factory.getScopedArtifacts() );
+
+            helper = EnforcerTestUtils.getHelper( project );
+            rule = newBannedDependenciesRule();
+
+            rule.setMessage( null );
+
+            excludes = new ArrayList<String>();
+            rule.setExcludes( excludes );
+            rule.setSearchTransitive( true );
+        }
+
+        private void addExcludeAndRunRule( String toAdd )
+            throws EnforcerRuleException
+        {
+            excludes.add( toAdd );
+            rule.execute( helper );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void groupIdArtifactIdWithWildcard()
+            throws EnforcerRuleException
+        {
+            addExcludeAndRunRule( "testGroupId:re*" );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void groupIdArtifactIdVersionTypeWildcardScope()
+            throws EnforcerRuleException
+        {
+            addExcludeAndRunRule( "g:a:1.0:war:co*" );
+        }
+
+        @Test( expected = EnforcerRuleException.class )
+        public void groupIdArtifactIdVersionWildcardTypeScope()
+            throws EnforcerRuleException
+        {
+            addExcludeAndRunRule( "g:a:1.0:w*:compile" );
+        }
+    }
+
+    public static class IllegalFormatsTests
+    {
+        private List<String> excludes;
+
+        private BannedDependencies rule;
+
+        private EnforcerRuleHelper helper;
+
+        @Before
+        public void beforeMethod()
+            throws IOException
+        {
+            ArtifactStubFactory factory = new ArtifactStubFactory();
+
+            MockProject project = new MockProject();
+            project.setArtifacts( factory.getMixedArtifacts() );
+            project.setDependencyArtifacts( factory.getScopedArtifacts() );
+
+            helper = EnforcerTestUtils.getHelper( project );
+            rule = newBannedDependenciesRule();
+
+            rule.setMessage( null );
+
+            excludes = new ArrayList<String>();
+            rule.setExcludes( excludes );
+            rule.setSearchTransitive( true );
+        }
+
+        private void addExcludeAndRunRule( String toAdd )
+            throws EnforcerRuleException
+        {
+            excludes.add( toAdd );
+            rule.execute( helper );
+        }
+
+        @Test( expected = IllegalArgumentException.class )
+        public void onlyThreeColonsWithoutAnythingElse()
+            throws EnforcerRuleException
+        {
+            addExcludeAndRunRule( ":::" );
+        }
+
+        @Test( expected = IllegalArgumentException.class )
+        public void onlySevenColonsWithoutAnythingElse()
+            throws EnforcerRuleException
+        {
+            addExcludeAndRunRule( ":::::::" );
+        }
 
-        // now check weirdness
-        excludes.clear();
-        excludes.add( ":::" ); // null entry, won't match anything
-        execute( rule, helper, false );
     }
 
     /**
      * Test includes.
-     *
+     * 
      * @throws IOException Signals that an I/O exception has occurred.
      */
+    @Test
     public void testIncludes()
         throws IOException
     {
@@ -172,9 +400,10 @@ public class TestBannedDependencies
         includes.add( "*:test" );
         rule.setIncludes( includes );
         execute( rule, helper, true );
+
     }
 
-    private BannedDependencies newBannedDependenciesRule()
+    private static BannedDependencies newBannedDependenciesRule()
     {
         BannedDependencies rule = new BannedDependencies()
         {
@@ -182,7 +411,7 @@ public class TestBannedDependencies
             protected Set<Artifact> getDependenciesToCheck( MavenProject project )
             {
                 // the integration with dependencyGraphTree is verified with the integration
tests
-                // for unit-testing 
+                // for unit-testing
                 return isSearchTransitive() ? project.getArtifacts() : project.getDependencyArtifacts();
             }
         };
@@ -191,7 +420,7 @@ public class TestBannedDependencies
 
     /**
      * Simpler wrapper to execute and deal with the expected result.
-     *
+     * 
      * @param rule the rule
      * @param helper the helper
      * @param shouldFail the should fail

Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java?rev=1559391&r1=1559390&r2=1559391&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java
(original)
+++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java
Sat Jan 18 18:59:58 2014
@@ -19,19 +19,16 @@ package org.apache.maven.plugins.enforce
  * under the License.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-
+import junit.framework.TestCase;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
-
 import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher.Pattern;
-
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Collection;
 
 public class TestArtifactMatcher extends TestCase
 {
@@ -72,7 +69,7 @@ public class TestArtifactMatcher extends
 		}
 		catch(NullPointerException e){}
 	}
-	
+
 	public void testPattern() throws InvalidVersionSpecificationException
 	{
 		executePatternMatch("groupId:artifactId:1.0:jar:compile", "groupId", "artifactId", "1.0",
"compile", "jar", true);



Mime
View raw message