]> source.dussan.org Git - archiva.git/commitdiff
test classifiers and custom types
authorBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 10:38:58 +0000 (10:38 +0000)
committerBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 10:38:58 +0000 (10:38 +0000)
PR: MRM-9

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@349700 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0-sources.jar [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.jar [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.tar.gz [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/testing/1.0/testing-1.0.zip [new file with mode: 0644]

index ee5c9bd8196a452d8b72f73882a43e4ffb01e20b..00fe863d441e1a56fae217e687cbfbbcc2f1afae 100644 (file)
@@ -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 ) );
 
index 85329511782b3c09a2f470efd6c971dcc7409cc2..a9e0eb82e3513ad29297e8de5c70e984f66be1e2 100644 (file)
@@ -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";
index df3caac38f168a77e9ae22119a3006f06553d0c5..01931061a712b8d6e43a2e7154f19acc41af71ef 100644 (file)
@@ -29,7 +29,7 @@ import java.util.List;
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @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 (file)
index 0000000..e69de29
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..e69de29
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 (file)
index 0000000..e69de29