Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EAAA31013C for ; Sat, 18 Jan 2014 19:00:28 +0000 (UTC) Received: (qmail 46889 invoked by uid 500); 18 Jan 2014 19:00:27 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 46836 invoked by uid 500); 18 Jan 2014 19:00:27 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 46825 invoked by uid 99); 18 Jan 2014 19:00:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Jan 2014 19:00:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Jan 2014 19:00:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3804D23888A6; Sat, 18 Jan 2014 18:59:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@maven.apache.org From: khmarbaise@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140118185959.3804D23888A6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 checkDependencies( Set 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 Brian Fox * @version $Id$ */ @@ -42,36 +41,36 @@ public class BannedDependencies { /** - * Specify the banned dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. - * Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
+ * Specify the banned dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
* 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 excludes = null; /** - * Specify the allowed dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. - * Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
+ * Specify the allowed dependencies. This can be a list of artifacts in the format + * groupId[:artifactId][:version]. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
* Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a * smaller set of includes.
* 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 includes = null; - /** * {@inheritDoc} */ protected Set checkDependencies( Set theDependencies, Log log ) throws EnforcerRuleException { + Set excluded = checkDependencies( theDependencies, excludes ); // anything specifically included should be removed @@ -79,6 +78,7 @@ public class BannedDependencies if ( excluded != null ) { Set 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 null @@ -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 + * groupId:artifactId:version:type:scope:classifier. + * + * @param pattern The pattern to compare the artifact with. * @param artifact the artifact * @return true 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 getExcludes() @@ -208,7 +166,7 @@ public class BannedDependencies /** * Sets the excludes. - * + * * @param theExcludes the excludes to set */ public void setExcludes( List theExcludes ) @@ -218,7 +176,7 @@ public class BannedDependencies /** * Gets the includes. - * + * * @return the includes */ public List getIncludes() @@ -228,7 +186,7 @@ public class BannedDependencies /** * Sets the includes. - * + * * @param theIncludes the includes to set */ public void setIncludes( List 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 Brian Fox */ +@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 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(); + 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 excludes = new ArrayList(); - rule.setSearchTransitive( false ); + private List 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(); + 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 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(); + 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 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(); + 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 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(); + 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 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);