diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java index ee5c9bd81..00fe863d4 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java @@ -94,8 +94,6 @@ public class DefaultArtifactDiscoverer Collections.reverse( pathParts ); String groupId = StringUtils.join( pathParts.iterator(), "." ); - result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); - String remainingFilename = filename; if ( !remainingFilename.startsWith( artifactId + "-" ) ) { @@ -105,11 +103,67 @@ public class DefaultArtifactDiscoverer } remainingFilename = remainingFilename.substring( artifactId.length() + 1 ); + + String classifier = null; + + // TODO: use artifact handler, share with legacy discoverer + String type; + if ( remainingFilename.endsWith( ".tar.gz" ) ) + { + type = "distribution-tgz"; + remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 7 ); + } + else if ( remainingFilename.endsWith( ".zip" ) ) + { + type = "distribution-zip"; + remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 4 ); + } + else if ( remainingFilename.endsWith( "-sources.jar" ) ) + { + type = "java-source"; + classifier = "sources"; + remainingFilename = remainingFilename.substring( 0, remainingFilename.length() - 12 ); + } + else + { + int index = remainingFilename.lastIndexOf( "." ); + if ( index < 0 ) + { + addKickedOutPath( path ); + + return null; + } + + type = remainingFilename.substring( index + 1 ); + remainingFilename = remainingFilename.substring( 0, index ); + } + + if ( classifier == null ) + { + result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type ); + } + else + { + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + } + if ( result.isSnapshot() ) { - result = artifactFactory.createArtifact( groupId, artifactId, - remainingFilename.substring( 0, remainingFilename.length() - 4 ), - Artifact.SCOPE_RUNTIME, "jar" ); + // version is XXX-SNAPSHOT, filename is XXX-yyyyMMdd.hhmmss-b + int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 ); + if ( classifierIndex >= 0 ) + { + classifier = remainingFilename.substring( classifierIndex + 1 ); + remainingFilename = remainingFilename.substring( 0, classifierIndex ); + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, remainingFilename, type, + classifier ); + } + else + { + result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, Artifact.SCOPE_RUNTIME, + type ); + } + // poor encapsulation requires we do this to populate base version if ( !result.isSnapshot() ) { @@ -130,6 +184,17 @@ public class DefaultArtifactDiscoverer return null; } + else if ( !remainingFilename.equals( version ) ) + { + if ( remainingFilename.charAt( version.length() ) != '-' ) + { + addKickedOutPath( path ); + + return null; + } + classifier = remainingFilename.substring( version.length() + 1 ); + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + } result.setFile( new File( path ) ); 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 853295117..a9e0eb82e 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 @@ -99,6 +99,7 @@ public class LegacyArtifactDiscoverer String lastAvceToken = (String) avceTokenList.removeLast(); + // TODO: share with other discoverer, use artifact handlers instead if ( lastAvceToken.endsWith( ".tar.gz" ) ) { type = "distribution-tgz"; diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java index df3caac38..01931061a 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java @@ -29,7 +29,7 @@ import java.util.List; * * @author Brett Porter * @version $Id$ - * @todo other tests for kickouts to do here, along the lines of wrong artifactId, parse classifiers, locate poms + * @todo test location of poms, checksums */ public class DefaultArtifactDiscovererTest extends PlexusTestCase @@ -212,6 +212,45 @@ public class DefaultArtifactDiscovererTest } } + 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 testArtifactWithClassifier() + { + List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check normal included", + artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) ); + } + + public void testJavaSourcesInclusion() + { + 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", "java-source" ) ) ); + } + + public void testDistributionInclusion() + { + List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); + assertNotNull( "Check artifacts not null", artifacts ); + + assertTrue( "Check zip included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) ); + + assertTrue( "Check tar.gz included", + artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) ); + } + public void testSnapshotInclusion() { List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); @@ -237,4 +276,14 @@ public class DefaultArtifactDiscovererTest return factory.createArtifact( groupId, artifactId, version, null, "jar" ); } + private Artifact createArtifact( String groupId, String artifactId, String version, String type ) + { + return factory.createArtifact( groupId, artifactId, version, null, type ); + } + + private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier ) + { + return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier ); + } + } diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz new file mode 100644 index 000000000..e69de29bb diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip b/maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip new file mode 100644 index 000000000..e69de29bb