[MNG-6760] ExclusionArtifactFilter result invalid when wildcard exclusion is followed by other exclusions

This commit is contained in:
rfscholte 2019-09-07 14:24:21 +02:00
parent 71eafc4d68
commit 3eb242c571
2 changed files with 41 additions and 6 deletions

View File

@ -47,16 +47,18 @@ public boolean include( Artifact artifact )
{
return false;
}
if ( WILDCARD.equals( exclusion.getGroupId() ) )
if ( WILDCARD.equals( exclusion.getGroupId() )
&& exclusion.getArtifactId().equals( artifact.getArtifactId() ) )
{
return !exclusion.getArtifactId().equals( artifact.getArtifactId() );
return false;
}
if ( WILDCARD.equals( exclusion.getArtifactId() ) )
if ( WILDCARD.equals( exclusion.getArtifactId() )
&& exclusion.getGroupId().equals( artifact.getGroupId() ) )
{
return !exclusion.getGroupId().equals( artifact.getGroupId() );
return false;
}
if ( exclusion.getGroupId().equals( artifact.getGroupId() ) && exclusion.getArtifactId().equals(
artifact.getArtifactId() ) )
if ( exclusion.getGroupId().equals( artifact.getGroupId() )
&& exclusion.getArtifactId().equals( artifact.getArtifactId() ) )
{
return false;
}

View File

@ -24,6 +24,7 @@
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
@ -120,4 +121,36 @@ public void testExcludeAllWildcard()
assertThat( filter.include( artifact ), is( false ) );
}
@Test
public void testMultipleExclusionsExcludeArtifactIdWildcard()
{
Exclusion exclusion1 = new Exclusion();
exclusion1.setGroupId( "org.apache.groovy" );
exclusion1.setArtifactId( "*" );
Exclusion exclusion2 = new Exclusion();
exclusion2.setGroupId( "org.apache.maven" );
exclusion2.setArtifactId( "maven-core" );
ExclusionArtifactFilter filter = new ExclusionArtifactFilter( Arrays.asList( exclusion1, exclusion2 ) );
assertThat( filter.include( artifact ), is( false ) );
}
@Test
public void testMultipleExclusionsExcludeGroupIdWildcard()
{
Exclusion exclusion1 = new Exclusion();
exclusion1.setGroupId( "*" );
exclusion1.setArtifactId( "maven-model" );
Exclusion exclusion2 = new Exclusion();
exclusion2.setGroupId( "org.apache.maven" );
exclusion2.setArtifactId( "maven-core" );
ExclusionArtifactFilter filter = new ExclusionArtifactFilter( Arrays.asList( exclusion1, exclusion2 ) );
assertThat( filter.include( artifact ), is( false ) );
}
}