diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java index 1a9f6fb07..b13040c41 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java @@ -79,10 +79,13 @@ public class LegacyArtifactDiscoverer String type = tokens.nextToken(); - if ( type.endsWith( "s" ) ) + if ( !type.endsWith( "s" ) ) { - type = type.substring( 0, type.length() - 1 ); + addKickedOutPath( path ); + + return null; } + type = type.substring( 0, type.length() - 1 ); // contains artifactId, version, classifier, and extension. String avceGlob = tokens.nextToken(); diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java index db9b046a2..d23a7aa61 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java @@ -25,10 +25,11 @@ import java.util.Iterator; import java.util.List; /** - * Test the default artifact discoverer. + * Test the legacy artifact discoverer. * * @author Brett Porter * @version $Id$ + * @todo share as much as possible with default via abstract test case */ public class LegacyArtifactDiscovererTest extends PlexusTestCase @@ -147,6 +148,44 @@ public class LegacyArtifactDiscovererTest } } + public void testKickoutWithInvalidType() + { + List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false ); + assertNotNull( "Check artifacts not null", artifacts ); + boolean found = false; + for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; ) + { + String path = (String) i.next(); + + found = path.replace( '\\', '/' ).equals( "invalid/foo/invalid-1.0.foo" ); + } + assertTrue( "Check exclusion was found", found ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + assertFalse( "Check not invalid-1.0.foo", a.getFile().getName().equals( "invalid-1.0.foo" ) ); + } + } + + public void testInclusion() + { + List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) ); + } + + public void testJavaSourcesInclusion() + { + List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createSourceArtifact( "org.apache.maven", "testing", "1.0" ) ) ); + } + public void testSnapshotInclusion() { List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); @@ -172,4 +211,9 @@ public class LegacyArtifactDiscovererTest return factory.createArtifact( groupId, artifactId, version, null, "jar" ); } + private Artifact createSourceArtifact( String groupId, String artifactId, String version ) + { + return factory.createArtifact( groupId, artifactId, version, null, "java-source" ); + } + } diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/foo/invalid-1.0.foo b/maven-repository-discovery/src/test/legacy-repository/invalid/foo/invalid-1.0.foo new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-sources.jar new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0.jar new file mode 100644 index 000000000..e69de29bb