Author: rfscholte Date: Wed Jun 5 18:49:55 2013 New Revision: 1489999 URL: http://svn.apache.org/r1489999 Log: [MENFORCER-74] The bannedDependencies rule should support classifier [MENFORCER-75] The bannedDependencies rule should support scope condition
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/banTransitiveDependencies.apt.vm 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=1489999&r1=1489998&r2=1489999&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 Wed Jun 5 18:49:55 2013 @@ -53,9 +53,9 @@ public final class ArtifactMatcher this.pattern = pattern; - parts = pattern.split( ":", 6 ); + parts = pattern.split( ":", 7 ); - if ( parts.length == 6 ) + if ( parts.length == 7 ) { throw new IllegalArgumentException( "Pattern contains too many delimiters." ); } @@ -79,6 +79,12 @@ public final class ArtifactMatcher switch ( parts.length ) { + case 6: + String classifier = artifact.getClassifier(); + if ( !matches( parts[5], classifier ) ) + { + return false; + } case 5: String scope = artifact.getScope(); if ( scope == null || scope.equals( "" ) ) Modified: maven/enforcer/trunk/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm?rev=1489999&r1=1489998&r2=1489999&view=diff ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm (original) +++ maven/enforcer/trunk/enforcer-rules/src/site/apt/banTransitiveDependencies.apt.vm Wed Jun 5 18:49:55 2013 @@ -31,13 +31,13 @@ Ban Transitive Dependencies * excludes - specify the dependencies that will be ignored.\ This can be a list of artifacts in the format - groupId[:artifactId[:version[:type[:scope]]]] . + groupId[:artifactId[:version[:type[:scope[:classifier]]]]] . Wildcard '*' can be used to in place of specific section (e.g. group:*:1.0 will match both 'group:artifact:1.0' and 'group:anotherArtifact:1.0') Version is a string representing standard maven version range. Empty patterns will be ignored. * includes - specify the dependencies that will be checked.\ These are exceptions to excludes intended for more convenient configuration. This can be a list of artifacts in the format - groupId[:artifactId[:version[:type[:scope]]]] as above. + groupId[:artifactId[:version[:type[:scope[:classifier]]]]] as above. * message - an optional message to the user if the rule fails. Will replace generated report message. 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=1489999&r1=1489998&r2=1489999&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 Wed Jun 5 18:49:55 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 or just parts of a section. + * excludes - a list of artifacts to ban. The format is groupId[:artifactId][:version][:type][:scope][:classifier] where artifactId, version, type, scope and classifier 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 + + * *:*:*:jar:compile:tests * 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=1489999&r1=1489998&r2=1489999&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 Wed Jun 5 18:49:55 2013 @@ -52,7 +52,7 @@ public class TestArtifactMatcher extends try { - new Pattern("a:b:c:d:e:f"); + new Pattern("a:b:c:d:e:f:g"); fail("IllegalArgumentException expected."); } catch(IllegalArgumentException e){} @@ -93,6 +93,9 @@ public class TestArtifactMatcher extends executePatternMatch("*", "groupId", "artifactId", "1.0", "", "", true); + // MENFORCER-74/75 + executePatternMatch("*:*:*:jar:compile:tests", "groupId", "artifactId", "1.0", "", "", "tests", true); + // MENFORCER-83 executePatternMatch("*upId", "groupId", "artifactId", "1.0", "", "", true); @@ -122,27 +125,42 @@ public class TestArtifactMatcher extends executeMatch(matcher, "groupId", "anotherArtifact", "1.1", "", "", false); } - private void executePatternMatch(final String pattern, final String groupId, final String artifactId, - final String versionRange, final String scope, final String type, boolean expectedResult) - throws InvalidVersionSpecificationException - { - assertEquals(expectedResult, new ArtifactMatcher.Pattern(pattern).match(createMockArtifact(groupId, artifactId, versionRange, scope, type))); - } - - - private void executeMatch(final ArtifactMatcher matcher, final String groupId, final String artifactId, - final String versionRange, final String scope, final String type, final boolean expectedResult) throws InvalidVersionSpecificationException - { - assertEquals(expectedResult, matcher.match(createMockArtifact(groupId, artifactId, versionRange, scope, type))); - } - - - private static Artifact createMockArtifact(final String groupId, final String artifactId, - final String versionRange, final String scope, final String type) - { - ArtifactHandler artifactHandler = new DefaultArtifactHandler(); - - VersionRange version = VersionRange.createFromVersion(versionRange); - return new DefaultArtifact(groupId, artifactId, version, scope, type, "", artifactHandler); - } + private void executePatternMatch( final String pattern, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + boolean expectedResult ) + throws InvalidVersionSpecificationException + { + executePatternMatch( pattern, groupId, artifactId, versionRange, scope, type, "", expectedResult ); + } + + private void executePatternMatch( final String pattern, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final String classifier, boolean expectedResult ) + throws InvalidVersionSpecificationException + { + assertEquals( expectedResult, new ArtifactMatcher.Pattern( pattern ).match( createMockArtifact( groupId, + artifactId, + versionRange, + scope, type, + classifier ) ) ); + } + + private void executeMatch( final ArtifactMatcher matcher, final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final boolean expectedResult ) + throws InvalidVersionSpecificationException + { + assertEquals( expectedResult, + matcher.match( createMockArtifact( groupId, artifactId, versionRange, scope, type, "" ) ) ); + } + + private static Artifact createMockArtifact( final String groupId, final String artifactId, + final String versionRange, final String scope, final String type, + final String classifier ) + { + ArtifactHandler artifactHandler = new DefaultArtifactHandler(); + + VersionRange version = VersionRange.createFromVersion( versionRange ); + return new DefaultArtifact( groupId, artifactId, version, scope, type, classifier, artifactHandler ); + } }