You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2010/09/15 23:57:47 UTC
svn commit: r997521 - in
/maven/shared/trunk/maven-common-artifact-filters/src:
main/java/org/apache/maven/shared/artifact/filter/
test/java/org/apache/maven/shared/artifact/filter/
Author: jdcasey
Date: Wed Sep 15 21:57:47 2010
New Revision: 997521
URL: http://svn.apache.org/viewvc?rev=997521&view=rev
Log:
[MSHARED-162] Consider dependency trail items separately for pattern matching.
Modified:
maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java
maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternArtifactFilterTCK.java
maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternExcludesArtifactFilterTest.java
maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilterTest.java
Modified: maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java?rev=997521&r1=997520&r2=997521&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java (original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilter.java Wed Sep 15 21:57:47 2010
@@ -18,12 +18,6 @@
*/
package org.apache.maven.shared.artifact.filter;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
@@ -31,16 +25,20 @@ import org.apache.maven.artifact.version
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
/**
* TODO: include in maven-artifact in future
- *
+ *
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @see StrictPatternIncludesArtifactFilter
*/
-public class PatternIncludesArtifactFilter
- implements ArtifactFilter, StatisticsReportingArtifactFilter
+public class PatternIncludesArtifactFilter implements ArtifactFilter, StatisticsReportingArtifactFilter
{
private final List positivePatterns;
@@ -48,25 +46,25 @@ public class PatternIncludesArtifactFilt
private final boolean actTransitively;
- private Set patternsTriggered = new HashSet();
+ private final Set patternsTriggered = new HashSet();
- private List filteredArtifactIds = new ArrayList();
+ private final List filteredArtifactIds = new ArrayList();
- public PatternIncludesArtifactFilter( List patterns )
+ public PatternIncludesArtifactFilter( final List patterns )
{
this( patterns, false );
}
- public PatternIncludesArtifactFilter( List patterns, boolean actTransitively )
+ public PatternIncludesArtifactFilter( final List patterns, final boolean actTransitively )
{
this.actTransitively = actTransitively;
- List pos = new ArrayList();
- List neg = new ArrayList();
+ final List pos = new ArrayList();
+ final List neg = new ArrayList();
if ( ( patterns != null ) && !patterns.isEmpty() )
{
- for ( Iterator it = patterns.iterator(); it.hasNext(); )
+ for ( final Iterator it = patterns.iterator(); it.hasNext(); )
{
- String pattern = (String) it.next();
+ final String pattern = (String) it.next();
if ( pattern.startsWith( "!" ) )
{
@@ -83,9 +81,9 @@ public class PatternIncludesArtifactFilt
negativePatterns = neg;
}
- public boolean include( Artifact artifact )
+ public boolean include( final Artifact artifact )
{
- boolean shouldInclude = patternMatches( artifact );
+ final boolean shouldInclude = patternMatches( artifact );
if ( !shouldInclude )
{
@@ -95,17 +93,17 @@ public class PatternIncludesArtifactFilt
return shouldInclude;
}
- protected boolean patternMatches( Artifact artifact )
+ protected boolean patternMatches( final Artifact artifact )
{
return ( positiveMatch( artifact ) == Boolean.TRUE ) || ( negativeMatch( artifact ) == Boolean.FALSE );
}
- protected void addFilteredArtifactId( String artifactId )
+ protected void addFilteredArtifactId( final String artifactId )
{
filteredArtifactIds.add( artifactId );
}
- private Boolean negativeMatch( Artifact artifact )
+ private Boolean negativeMatch( final Artifact artifact )
{
if ( ( negativePatterns == null ) || negativePatterns.isEmpty() )
{
@@ -117,7 +115,7 @@ public class PatternIncludesArtifactFilt
}
}
- protected Boolean positiveMatch( Artifact artifact )
+ protected Boolean positiveMatch( final Artifact artifact )
{
if ( ( positivePatterns == null ) || positivePatterns.isEmpty() )
{
@@ -129,11 +127,11 @@ public class PatternIncludesArtifactFilt
}
}
- private boolean match( Artifact artifact, List patterns )
+ private boolean match( final Artifact artifact, final List patterns )
{
- String shortId = ArtifactUtils.versionlessKey( artifact );
- String id = artifact.getDependencyConflictId();
- String wholeId = artifact.getId();
+ final String shortId = ArtifactUtils.versionlessKey( artifact );
+ final String id = artifact.getDependencyConflictId();
+ final String wholeId = artifact.getId();
if ( matchAgainst( wholeId, patterns, false ) )
{
@@ -152,58 +150,67 @@ public class PatternIncludesArtifactFilt
if ( actTransitively )
{
- List depTrail = artifact.getDependencyTrail();
+ final List depTrail = artifact.getDependencyTrail();
- if ( ( depTrail != null ) && !depTrail.isEmpty() )
+ if ( ( depTrail != null ) && depTrail.size() > 1 )
{
- String trailStr = "," + StringUtils.join( depTrail.iterator(), "," );
-
- return matchAgainst( trailStr, patterns, true );
+ for ( final Iterator iterator = depTrail.iterator(); iterator.hasNext(); )
+ {
+ final String trailItem = (String) iterator.next();
+ if ( matchAgainst( trailItem, patterns, true ) )
+ {
+ return true;
+ }
+ }
}
}
return false;
}
- private boolean matchAgainst( String value, List patterns, boolean regionMatch ) {
- for (Iterator iterator = patterns.iterator(); iterator.hasNext();) {
- String pattern = (String) iterator.next();
-
- String[] patternTokens = pattern.split( ":" );
- String[] tokens = value.split( ":" );
-
- // fail immediately if pattern tokens outnumber tokens to match
- boolean matched = ( patternTokens.length <= tokens.length );
-
- for ( int i = 0; matched && i < patternTokens.length; i++ )
- {
- matched = matches( tokens[i], patternTokens[i] );
- }
-
-// // case of starting '*' like '*:jar:*'
- if (!matched && patternTokens.length < tokens.length && patternTokens.length>0 && "*".equals(patternTokens[0]))
- {
- matched=true;
- for ( int i = 0; matched && i < patternTokens.length; i++ )
- {
- matched = matches( tokens[i+(tokens.length-patternTokens.length)], patternTokens[i] );
- }
- }
+ private boolean matchAgainst( final String value, final List patterns, final boolean regionMatch )
+ {
+ for ( final Iterator iterator = patterns.iterator(); iterator.hasNext(); )
+ {
+ final String pattern = (String) iterator.next();
+
+ final String[] patternTokens = pattern.split( ":" );
+ final String[] tokens = value.split( ":" );
+
+ // fail immediately if pattern tokens outnumber tokens to match
+ boolean matched = ( patternTokens.length <= tokens.length );
+
+ for ( int i = 0; matched && i < patternTokens.length; i++ )
+ {
+ matched = matches( tokens[i], patternTokens[i] );
+ }
+
+ // // case of starting '*' like '*:jar:*'
+ if ( !matched && patternTokens.length < tokens.length && patternTokens.length > 0
+ && "*".equals( patternTokens[0] ) )
+ {
+ matched = true;
+ for ( int i = 0; matched && i < patternTokens.length; i++ )
+ {
+ matched = matches( tokens[i + ( tokens.length - patternTokens.length )], patternTokens[i] );
+ }
+ }
- if (matched) {
- patternsTriggered.add( pattern );
+ if ( matched )
+ {
+ patternsTriggered.add( pattern );
return true;
- }
-
- if ( regionMatch && value.indexOf( pattern ) > -1 )
+ }
+
+ if ( regionMatch && value.indexOf( pattern ) > -1 )
{
patternsTriggered.add( pattern );
return true;
}
-
- }
- return false;
-
+
+ }
+ return false;
+
}
/**
@@ -215,9 +222,9 @@ public class PatternIncludesArtifactFilt
* the pattern segment to match, as defined above
* @return <code>true</code> if the specified token is matched by the specified pattern segment
*/
- private boolean matches( String token, final String pattern )
+ private boolean matches( final String token, final String pattern )
{
- boolean matches;
+ boolean matches;
// support full wildcard and implied wildcard
if ( "*".equals( pattern ) || pattern.length() == 0 )
@@ -227,28 +234,28 @@ public class PatternIncludesArtifactFilt
// support contains wildcard
else if ( pattern.startsWith( "*" ) && pattern.endsWith( "*" ) )
{
- String contains = pattern.substring( 1, pattern.length() - 1 );
+ final String contains = pattern.substring( 1, pattern.length() - 1 );
matches = ( token.indexOf( contains ) != -1 );
}
// support leading wildcard
else if ( pattern.startsWith( "*" ) )
{
- String suffix = pattern.substring( 1, pattern.length() );
+ final String suffix = pattern.substring( 1, pattern.length() );
matches = token.endsWith( suffix );
}
// support trailing wildcard
else if ( pattern.endsWith( "*" ) )
{
- String prefix = pattern.substring( 0, pattern.length() - 1 );
+ final String prefix = pattern.substring( 0, pattern.length() - 1 );
matches = token.startsWith( prefix );
}
- // support versions range
- else if ( pattern.startsWith( "[" ) || pattern.startsWith( "(" ))
+ // support versions range
+ else if ( pattern.startsWith( "[" ) || pattern.startsWith( "(" ) )
{
- matches = isVersionIncludedInRange(token, pattern);
+ matches = isVersionIncludedInRange( token, pattern );
}
// support exact match
else
@@ -258,21 +265,25 @@ public class PatternIncludesArtifactFilt
return matches;
}
-
- private boolean isVersionIncludedInRange(final String version, final String range) {
- try {
- return VersionRange.createFromVersionSpec(range).containsVersion(new DefaultArtifactVersion(version));
- } catch (InvalidVersionSpecificationException e) {
- return false;
- }
- }
- public void reportMissedCriteria( Logger logger )
+ private boolean isVersionIncludedInRange( final String version, final String range )
+ {
+ try
+ {
+ return VersionRange.createFromVersionSpec( range ).containsVersion( new DefaultArtifactVersion( version ) );
+ }
+ catch ( final InvalidVersionSpecificationException e )
+ {
+ return false;
+ }
+ }
+
+ public void reportMissedCriteria( final Logger logger )
{
// if there are no patterns, there is nothing to report.
if ( !positivePatterns.isEmpty() || !negativePatterns.isEmpty() )
{
- List missed = new ArrayList();
+ final List missed = new ArrayList();
missed.addAll( positivePatterns );
missed.addAll( negativePatterns );
@@ -280,15 +291,15 @@ public class PatternIncludesArtifactFilt
if ( !missed.isEmpty() && logger.isWarnEnabled() )
{
- StringBuffer buffer = new StringBuffer();
+ final StringBuffer buffer = new StringBuffer();
buffer.append( "The following patterns were never triggered in this " );
buffer.append( getFilterDescription() );
buffer.append( ':' );
- for ( Iterator it = missed.iterator(); it.hasNext(); )
+ for ( final Iterator it = missed.iterator(); it.hasNext(); )
{
- String pattern = (String) it.next();
+ final String pattern = (String) it.next();
buffer.append( "\no \'" ).append( pattern ).append( "\'" );
}
@@ -307,10 +318,10 @@ public class PatternIncludesArtifactFilt
protected String getPatternsAsString()
{
- StringBuffer buffer = new StringBuffer();
- for ( Iterator it = positivePatterns.iterator(); it.hasNext(); )
+ final StringBuffer buffer = new StringBuffer();
+ for ( final Iterator it = positivePatterns.iterator(); it.hasNext(); )
{
- String pattern = (String) it.next();
+ final String pattern = (String) it.next();
buffer.append( "\no \'" ).append( pattern ).append( "\'" );
}
@@ -323,16 +334,16 @@ public class PatternIncludesArtifactFilt
return "artifact inclusion filter";
}
- public void reportFilteredArtifacts( Logger logger )
+ public void reportFilteredArtifacts( final Logger logger )
{
if ( !filteredArtifactIds.isEmpty() && logger.isDebugEnabled() )
{
- StringBuffer buffer = new StringBuffer( "The following artifacts were removed by this "
- + getFilterDescription() + ": " );
+ final StringBuffer buffer =
+ new StringBuffer( "The following artifacts were removed by this " + getFilterDescription() + ": " );
- for ( Iterator it = filteredArtifactIds.iterator(); it.hasNext(); )
+ for ( final Iterator it = filteredArtifactIds.iterator(); it.hasNext(); )
{
- String artifactId = (String) it.next();
+ final String artifactId = (String) it.next();
buffer.append( '\n' ).append( artifactId );
}
@@ -346,7 +357,7 @@ public class PatternIncludesArtifactFilt
// if there are no patterns, there is nothing to report.
if ( !positivePatterns.isEmpty() || !negativePatterns.isEmpty() )
{
- List missed = new ArrayList();
+ final List missed = new ArrayList();
missed.addAll( positivePatterns );
missed.addAll( negativePatterns );
Modified: maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternArtifactFilterTCK.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternArtifactFilterTCK.java?rev=997521&r1=997520&r2=997521&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternArtifactFilterTCK.java (original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternArtifactFilterTCK.java Wed Sep 15 21:57:47 2010
@@ -18,45 +18,45 @@
*/
package org.apache.maven.shared.artifact.filter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.shared.tools.easymock.MockManager;
+import org.easymock.MockControl;
+
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.shared.tools.easymock.MockManager;
-import org.easymock.MockControl;
-
-public abstract class PatternArtifactFilterTCK
- extends TestCase
+public abstract class PatternArtifactFilterTCK extends TestCase
{
- private MockManager mockManager = new MockManager();
+ private final MockManager mockManager = new MockManager();
protected abstract ArtifactFilter createFilter( List patterns );
protected abstract ArtifactFilter createFilter( List patterns, boolean actTransitively );
- public void testShouldTriggerBothPatternsWithWildcards( boolean reverse )
+ public void testShouldTriggerBothPatternsWithWildcards( final boolean reverse )
{
- String groupId1 = "group";
- String artifactId1 = "artifact";
+ final String groupId1 = "group";
+ final String artifactId1 = "artifact";
- String groupId2 = "group2";
- String artifactId2 = "artifact2";
+ final String groupId2 = "group2";
+ final String artifactId2 = "artifact2";
- ArtifactMockAndControl mac1 = new ArtifactMockAndControl( groupId1, artifactId1 );
- ArtifactMockAndControl mac2 = new ArtifactMockAndControl( groupId2, artifactId2 );
+ final ArtifactMockAndControl mac1 = new ArtifactMockAndControl( groupId1, artifactId1 );
+ final ArtifactMockAndControl mac2 = new ArtifactMockAndControl( groupId2, artifactId2 );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( groupId1 + ":" + artifactId1 + ":*" );
patterns.add( groupId2 + ":" + artifactId2 + ":*" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -72,16 +72,49 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeDirectlyMatchedArtifactByGroupIdArtifactId( boolean reverse )
+ public void testShouldTriggerBothPatternsWithNonColonWildcards( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId1 = "group";
+ final String artifactId1 = "artifact";
+
+ final String groupId2 = "group2";
+ final String artifactId2 = "artifact2";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac1 = new ArtifactMockAndControl( groupId1, artifactId1 );
+ final ArtifactMockAndControl mac2 = new ArtifactMockAndControl( groupId2, artifactId2 );
mockManager.replayAll();
- ArtifactFilter filter = createFilter( Collections.singletonList( groupId + ":" + artifactId ) );
+ final List patterns = new ArrayList();
+ patterns.add( groupId1 + "*" );
+ patterns.add( groupId2 + "*" );
+
+ final ArtifactFilter filter = createFilter( patterns );
+
+ if ( reverse )
+ {
+ assertFalse( filter.include( mac1.artifact ) );
+ assertFalse( filter.include( mac2.artifact ) );
+ }
+ else
+ {
+ assertTrue( filter.include( mac1.artifact ) );
+ assertTrue( filter.include( mac2.artifact ) );
+ }
+
+ mockManager.verifyAll();
+ }
+
+ public void testShouldIncludeDirectlyMatchedArtifactByGroupIdArtifactId( final boolean reverse )
+ {
+ final String groupId = "group";
+ final String artifactId = "artifact";
+
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+
+ mockManager.replayAll();
+
+ final ArtifactFilter filter = createFilter( Collections.singletonList( groupId + ":" + artifactId ) );
if ( reverse )
{
@@ -95,16 +128,16 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeDirectlyMatchedArtifactByDependencyConflictId( boolean reverse )
+ public void testShouldIncludeDirectlyMatchedArtifactByDependencyConflictId( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- ArtifactFilter filter = createFilter( Collections.singletonList( groupId + ":" + artifactId + ":jar" ) );
+ final ArtifactFilter filter = createFilter( Collections.singletonList( groupId + ":" + artifactId + ":jar" ) );
if ( reverse )
{
@@ -118,20 +151,20 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldNotIncludeWhenGroupIdDiffers( boolean reverse )
+ public void testShouldNotIncludeWhenGroupIdDiffers( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( "otherGroup:" + artifactId + ":jar" );
patterns.add( "otherGroup:" + artifactId );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -145,21 +178,21 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldNotIncludeWhenArtifactIdDiffers( boolean reverse )
+ public void testShouldNotIncludeWhenArtifactIdDiffers( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( groupId + "otherArtifact:jar" );
patterns.add( groupId + "otherArtifact" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -173,21 +206,21 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldNotIncludeWhenBothIdElementsDiffer( boolean reverse )
+ public void testShouldNotIncludeWhenBothIdElementsDiffer( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( "otherGroup:otherArtifact:jar" );
patterns.add( "otherGroup:otherArtifact" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -201,20 +234,22 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsEnabled( boolean reverse )
+ public void testShouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsEnabled( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- String depTrailItem = "otherGroup:otherArtifact";
- List depTrail = Collections.singletonList( depTrailItem + ":jar:1.0" );
- List patterns = Collections.singletonList( depTrailItem );
+ final String rootDepTrailItem = "current:project:jar:1.0";
+ final String depTrailItem = "otherGroup:otherArtifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, depTrail );
+ final List depTrail = Arrays.asList( new String[] { rootDepTrailItem, depTrailItem + ":jar:1.0" } );
+ final List patterns = Collections.singletonList( depTrailItem );
+
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, depTrail );
mockManager.replayAll();
- ArtifactFilter filter = createFilter( patterns, true );
+ final ArtifactFilter filter = createFilter( patterns, true );
if ( reverse )
{
@@ -228,20 +263,49 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldNotIncludeWhenNegativeMatch( boolean reverse )
+ public void testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
+
+ final String rootDepTrailItem = "current:project:jar:1.0";
+ final String depTrailItem = "otherGroup:otherArtifact";
+
+ final List depTrail = Arrays.asList( new String[] { rootDepTrailItem, depTrailItem + ":jar:1.0" } );
+ final List patterns = Collections.singletonList( "otherGroup*" );
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, depTrail );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final ArtifactFilter filter = createFilter( patterns, true );
+
+ if ( reverse )
+ {
+ assertFalse( filter.include( mac.artifact ) );
+ }
+ else
+ {
+ assertTrue( filter.include( mac.artifact ) );
+ }
+
+ mockManager.verifyAll();
+ }
+
+ public void testShouldNotIncludeWhenNegativeMatch( final boolean reverse )
+ {
+ final String groupId = "group";
+ final String artifactId = "artifact";
+
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+
+ mockManager.replayAll();
+
+ final List patterns = new ArrayList();
patterns.add( "!group:artifact:jar" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -255,20 +319,20 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeWhenWildcardMatchesInsideSequence( boolean reverse )
+ public void testShouldIncludeWhenWildcardMatchesInsideSequence( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( "group:*:jar" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -282,20 +346,20 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeWhenWildcardMatchesOutsideSequence( boolean reverse )
+ public void testShouldIncludeWhenWildcardMatchesOutsideSequence( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId );
mockManager.replayAll();
- List patterns = new ArrayList();
+ final List patterns = new ArrayList();
patterns.add( "*:artifact:*" );
- ArtifactFilter filter = createFilter( patterns );
+ final ArtifactFilter filter = createFilter( patterns );
if ( reverse )
{
@@ -309,26 +373,26 @@ public abstract class PatternArtifactFil
mockManager.verifyAll();
}
- public void testShouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMatchParent( boolean reverse )
+ public void testShouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMatchParent( final boolean reverse )
{
- String groupId = "group";
- String artifactId = "artifact";
+ final String groupId = "group";
+ final String artifactId = "artifact";
- String otherGroup = "otherGroup";
- String otherArtifact = "otherArtifact";
- String otherType = "ejb";
+ final String otherGroup = "otherGroup";
+ final String otherArtifact = "otherArtifact";
+ final String otherType = "ejb";
- String depTrailItem = otherGroup + ":" + otherArtifact + ":" + otherType + ":version";
- List depTrail = Collections.singletonList( depTrailItem );
- List patterns = Collections.singletonList( "*:jar:*" );
+ final String depTrailItem = otherGroup + ":" + otherArtifact + ":" + otherType + ":version";
+ final List depTrail = Collections.singletonList( depTrailItem );
+ final List patterns = Collections.singletonList( "*:jar:*" );
- ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, "jar", depTrail );
- ArtifactMockAndControl otherMac = new ArtifactMockAndControl( otherGroup, otherArtifact, otherType,
- Collections.EMPTY_LIST );
+ final ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, "jar", depTrail );
+ final ArtifactMockAndControl otherMac =
+ new ArtifactMockAndControl( otherGroup, otherArtifact, otherType, Collections.EMPTY_LIST );
mockManager.replayAll();
- ArtifactFilter filter = createFilter( patterns, true );
+ final ArtifactFilter filter = createFilter( patterns, true );
if ( reverse )
{
@@ -345,40 +409,40 @@ public abstract class PatternArtifactFil
}
// FIXME: Not sure what this is even trying to test.
-// public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild(
-// boolean reverse )
-// {
-// String groupId = "group";
-// String artifactId = "artifact";
-//
-// String otherGroup = "otherGroup";
-// String otherArtifact = "otherArtifact";
-// String otherType = "ejb";
-//
-// String depTrailItem = otherGroup + ":" + otherArtifact + ":" + otherType + ":version";
-// List depTrail = Collections.singletonList( depTrailItem );
-// List patterns = Collections.singletonList( "!*:ejb:*" );
-//
-// ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, "jar", depTrail );
-// ArtifactMockAndControl otherMac = new ArtifactMockAndControl( otherGroup, otherArtifact, otherType, null );
-//
-// mockManager.replayAll();
-//
-// ArtifactFilter filter = createFilter( patterns, true );
-//
-// if ( reverse )
-// {
-// assertTrue( filter.include( otherMac.artifact ) );
-// assertFalse( filter.include( mac.artifact ) );
-// }
-// else
-// {
-// assertFalse( filter.include( otherMac.artifact ) );
-// assertFalse( filter.include( mac.artifact ) );
-// }
-//
-// mockManager.verifyAll();
-// }
+ // public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild(
+ // boolean reverse )
+ // {
+ // String groupId = "group";
+ // String artifactId = "artifact";
+ //
+ // String otherGroup = "otherGroup";
+ // String otherArtifact = "otherArtifact";
+ // String otherType = "ejb";
+ //
+ // String depTrailItem = otherGroup + ":" + otherArtifact + ":" + otherType + ":version";
+ // List depTrail = Collections.singletonList( depTrailItem );
+ // List patterns = Collections.singletonList( "!*:ejb:*" );
+ //
+ // ArtifactMockAndControl mac = new ArtifactMockAndControl( groupId, artifactId, "jar", depTrail );
+ // ArtifactMockAndControl otherMac = new ArtifactMockAndControl( otherGroup, otherArtifact, otherType, null );
+ //
+ // mockManager.replayAll();
+ //
+ // ArtifactFilter filter = createFilter( patterns, true );
+ //
+ // if ( reverse )
+ // {
+ // assertTrue( filter.include( otherMac.artifact ) );
+ // assertFalse( filter.include( mac.artifact ) );
+ // }
+ // else
+ // {
+ // assertFalse( filter.include( otherMac.artifact ) );
+ // assertFalse( filter.include( mac.artifact ) );
+ // }
+ //
+ // mockManager.verifyAll();
+ // }
private final class ArtifactMockAndControl
{
@@ -391,17 +455,18 @@ public abstract class PatternArtifactFil
String artifactId;
String version;
-
+
List dependencyTrail;
String type;
- ArtifactMockAndControl( String groupId, String artifactId, List depTrail )
+ ArtifactMockAndControl( final String groupId, final String artifactId, final List depTrail )
{
this( groupId, artifactId, "jar", depTrail );
}
- ArtifactMockAndControl( String groupId, String artifactId, String type, List dependencyTrail )
+ ArtifactMockAndControl( final String groupId, final String artifactId, final String type,
+ final List dependencyTrail )
{
this.groupId = groupId;
this.artifactId = artifactId;
@@ -423,12 +488,12 @@ public abstract class PatternArtifactFil
}
}
- public ArtifactMockAndControl( String groupId, String artifactId )
+ public ArtifactMockAndControl( final String groupId, final String artifactId )
{
this( groupId, artifactId, "jar", null );
}
- public ArtifactMockAndControl( String groupId, String artifactId, String type )
+ public ArtifactMockAndControl( final String groupId, final String artifactId, final String type )
{
this( groupId, artifactId, type, null );
}
@@ -451,7 +516,7 @@ public abstract class PatternArtifactFil
control.setReturnValue( groupId + ":" + artifactId + ":" + type, MockControl.ONE_OR_MORE );
}
- void enableGetGroupIdArtifactIdAndVersion()
+ void enableGetGroupIdArtifactIdAndVersion()
{
artifact.getGroupId();
control.setReturnValue( groupId, MockControl.ONE_OR_MORE );
@@ -460,8 +525,8 @@ public abstract class PatternArtifactFil
control.setReturnValue( artifactId, MockControl.ONE_OR_MORE );
artifact.getVersion();
- control.setReturnValue( version , MockControl.ZERO_OR_MORE );
-
+ control.setReturnValue( version, MockControl.ZERO_OR_MORE );
+
}
}
Modified: maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternExcludesArtifactFilterTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternExcludesArtifactFilterTest.java?rev=997521&r1=997520&r2=997521&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternExcludesArtifactFilterTest.java (original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternExcludesArtifactFilterTest.java Wed Sep 15 21:57:47 2010
@@ -18,31 +18,40 @@
*/
package org.apache.maven.shared.artifact.filter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
import java.util.List;
import junit.framework.TestCase;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-
-public class PatternExcludesArtifactFilterTest
- extends TestCase
+public class PatternExcludesArtifactFilterTest extends TestCase
{
- private PatternArtifactFilterTCK tck = new PatternArtifactFilterTCK()
+ private final PatternArtifactFilterTCK tck = new PatternArtifactFilterTCK()
{
- protected ArtifactFilter createFilter( List patterns )
+ protected ArtifactFilter createFilter( final List patterns )
{
return new PatternExcludesArtifactFilter( patterns );
}
- protected ArtifactFilter createFilter( List patterns, boolean actTransitively )
+ protected ArtifactFilter createFilter( final List patterns, final boolean actTransitively )
{
return new PatternExcludesArtifactFilter( patterns, actTransitively );
}
};
+ public void testShouldTriggerBothPatternsWithNonColonWildcards()
+ {
+ tck.testShouldTriggerBothPatternsWithNonColonWildcards( true );
+ }
+
+ public void testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard()
+ {
+ tck.testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard( true );
+ }
+
public void testShouldTriggerBothPatternsWithWildcards()
{
tck.testShouldTriggerBothPatternsWithWildcards( true );
@@ -99,8 +108,8 @@ public class PatternExcludesArtifactFilt
}
// See comment in TCK.
-// public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild()
-// {
-// tck.testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild( true );
-// }
+ // public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild()
+ // {
+ // tck.testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild( true );
+ // }
}
Modified: maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilterTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilterTest.java?rev=997521&r1=997520&r2=997521&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilterTest.java (original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/PatternIncludesArtifactFilterTest.java Wed Sep 15 21:57:47 2010
@@ -18,30 +18,34 @@
*/
package org.apache.maven.shared.artifact.filter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
import java.util.List;
import junit.framework.TestCase;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-
-public class PatternIncludesArtifactFilterTest
- extends TestCase
+public class PatternIncludesArtifactFilterTest extends TestCase
{
- private PatternArtifactFilterTCK tck = new PatternArtifactFilterTCK()
+ private final PatternArtifactFilterTCK tck = new PatternArtifactFilterTCK()
{
- protected ArtifactFilter createFilter( List patterns )
+ protected ArtifactFilter createFilter( final List patterns )
{
return new PatternIncludesArtifactFilter( patterns );
}
- protected ArtifactFilter createFilter( List patterns, boolean actTransitively )
+ protected ArtifactFilter createFilter( final List patterns, final boolean actTransitively )
{
return new PatternIncludesArtifactFilter( patterns, actTransitively );
}
};
+ public void testShouldTriggerBothPatternsWithNonColonWildcards()
+ {
+ tck.testShouldTriggerBothPatternsWithNonColonWildcards( false );
+ }
+
public void testShouldTriggerBothPatternsWithWildcards()
{
tck.testShouldTriggerBothPatternsWithWildcards( false );
@@ -62,6 +66,11 @@ public class PatternIncludesArtifactFilt
tck.testShouldIncludeWhenPatternMatchesDependencyTrailAndTransitivityIsEnabled( false );
}
+ public void testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard()
+ {
+ tck.testIncludeWhenPatternMatchesDepTrailWithTransitivityUsingNonColonWildcard( false );
+ }
+
public void testShouldNotIncludeWhenArtifactIdDiffers()
{
tck.testShouldNotIncludeWhenArtifactIdDiffers( false );
@@ -98,8 +107,8 @@ public class PatternIncludesArtifactFilt
}
// See comment in TCK.
-// public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild()
-// {
-// tck.testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild( false );
-// }
+ // public void testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild()
+ // {
+ // tck.testShouldIncludeDirectDependencyWhenInvertedWildcardMatchesButDoesntMatchTransitiveChild( false );
+ // }
}