maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1489638 - in /maven/enforcer/trunk/enforcer-rules/src: main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java site/apt/bannedDependencies.apt.vm test/java/org/apache/maven/plugins/enforcer/utils/TestArtifactMatcher.java
Date Tue, 04 Jun 2013 21:45:36 GMT
Author: rfscholte
Date: Tue Jun  4 21:45:03 2013
New Revision: 1489638

URL: http://svn.apache.org/r1489638
Log:
[MENFORCER-83] Banned dependencies should support regular expressions

Modified:
    maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/ArtifactMatcher.java
    maven/enforcer/trunk/enforcer-rules/src/site/apt/bannedDependencies.apt.vm
    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/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=1489638&r1=1489637&r2=1489638&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
Tue Jun  4 21:45:03 2013
@@ -47,19 +47,25 @@ public final class ArtifactMatcher
         public Pattern( String pattern )
         {
             if ( pattern == null )
+            {
                 throw new NullPointerException( "pattern" );
+            }
 
             this.pattern = pattern;
 
             parts = pattern.split( ":", 6 );
 
             if ( parts.length == 6 )
+            {
                 throw new IllegalArgumentException( "Pattern contains too many delimiters."
);
+            }
 
             for ( String part : parts )
             {
                 if ( "".equals( part ) )
+                {
                     throw new IllegalArgumentException( "Pattern or its part is empty." );
+                }
             }
         }
 
@@ -67,7 +73,9 @@ public final class ArtifactMatcher
             throws InvalidVersionSpecificationException
         {
             if ( artifact == null )
+            {
                 throw new NullPointerException( "artifact" );
+            }
 
             switch ( parts.length )
             {
@@ -78,9 +86,10 @@ public final class ArtifactMatcher
                         scope = "compile";
                     }
 
-                    if ( !"*".equals( parts[4] ) && !parts[4].equals( scope ) )
+                    if ( !matches( parts[4], scope ) )
+                    {
                         return false;
-
+                    }
                 case 4:
                     String type = artifact.getType();
                     if ( type == null || type.equals( "" ) )
@@ -88,11 +97,13 @@ public final class ArtifactMatcher
                         type = "jar";
                     }
 
-                    if ( !"*".equals( parts[3] ) && !parts[3].equals( type ) )
+                    if ( !matches( parts[3], type ) )
+                    {
                         return false;
+                    }
 
                 case 3:
-                    if ( !"*".equals( parts[2] ) && !parts[2].equals( artifact.getVersion()
) )
+                    if ( !matches( parts[2], artifact.getVersion() ) )
                     {
                         if ( !AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec(
parts[2] ),
                                                                        new DefaultArtifactVersion(
@@ -103,18 +114,30 @@ public final class ArtifactMatcher
                     }
 
                 case 2:
-                    if ( !"*".equals( parts[1] ) && !parts[1].equals( artifact.getArtifactId()
) )
+                    if ( !matches( parts[1],artifact.getArtifactId() ) )
+                    {
                         return false;
-
+                    }
                 case 1:
-                    if ( !"*".equals( parts[0] ) && !parts[0].equals( artifact.getGroupId()
) )
+                    if ( !matches( parts[0], artifact.getGroupId() ) )
+                    {
                         return false;
+                    }
                     else
+                    {
                         return true;
+                    }
                 default:
                     throw new AssertionError();
             }
         }
+        
+        private boolean matches( String expression, String input )
+        {
+            String regex = expression.replace( ".", "\\." ).replace( "*", ".*" ).replace(
":", "\\:" ).replace( '?', '.' );
+
+            return java.util.regex.Pattern.matches( regex , input );
+        }
 
         @Override
         public String toString()
@@ -135,10 +158,13 @@ public final class ArtifactMatcher
     public ArtifactMatcher( final Collection<String> patterns, final Collection<String>
ignorePatterns )
     {
         if ( patterns == null )
+        {
             throw new NullPointerException( "patterns" );
+        }
         if ( ignorePatterns == null )
+        {
             throw new NullPointerException( "ignorePatterns" );
-
+        }
         for ( String pattern : patterns )
         {
             if ( pattern != null && !"".equals( pattern ) )

Modified: maven/enforcer/trunk/enforcer-rules/src/site/apt/bannedDependencies.apt.vm
URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/bannedDependencies.apt.vm?rev=1489638&r1=1489637&r2=1489638&view=diff
==============================================================================
--- maven/enforcer/trunk/enforcer-rules/src/site/apt/bannedDependencies.apt.vm (original)
+++ maven/enforcer/trunk/enforcer-rules/src/site/apt/bannedDependencies.apt.vm Tue Jun  4
21:45:03 2013
@@ -32,7 +32,7 @@ Banned Dependencies
    
    * searchTransitive - if transitive dependencies should be checked.
    
-   * excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version][:type][:scope]
where artifactId, version, type, and scope are optional. Wildcards may be used to replace
an entire section.
+   * excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version][:type][:scope]
where artifactId, version, type, and scope are optional. Wildcards may be used to replace
an entire or just parts of a section.
       Examples:
        
         * org.apache.maven
@@ -44,6 +44,8 @@ Banned Dependencies
         * org.apache.maven:*:1.2
         
         * org.apache.maven:*:*:jar:test
+
+        * org.apache.*:maven-*:*
         
         []
 

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=1489638&r1=1489637&r2=1489638&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
Tue Jun  4 21:45:03 2013
@@ -92,6 +92,13 @@ public class TestArtifactMatcher extends
 		executePatternMatch("*:artifactId:*", "groupId", "artifactId", "1.0", "", "", true);
 		
 		executePatternMatch("*", "groupId", "artifactId", "1.0", "", "", true);
+		
+		// MENFORCER-83
+        executePatternMatch("*upId", "groupId", "artifactId", "1.0", "", "", true);
+        
+        executePatternMatch("gr*pId:?rt?f?ct?d:1.0", "groupId", "artifactId", "1.0", "",
"", true);
+        
+        executePatternMatch("org.apache.*:maven-*:*", "org.apache.maven", "maven-core", "3.0",
"", "", true);
 	}
 	
 	public void testMatch() throws InvalidVersionSpecificationException



Mime
View raw message