]> source.dussan.org Git - archiva.git/commitdiff
more legacy discoverer tests
authorBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 04:56:46 +0000 (04:56 +0000)
committerBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 04:56:46 +0000 (04:56 +0000)
PR: MRM-9

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

maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
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/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java
maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar [new file with mode: 0644]
maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar [new file with mode: 0644]
maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/maven-test-1.0-20050611.112233-1.jar [deleted file]
maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar [new file with mode: 0644]
maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar [new file with mode: 0644]

index 82d2ecea42cd9cc5857e65bd01529225adf0e3dc..f7c94612b21ccbc05d5e314b19269f5de689dd84 100644 (file)
@@ -80,6 +80,7 @@ public abstract class AbstractArtifactDiscoverer
      * Add a path to the list of files that were kicked out due to being invalid.
      *
      * @param path the path to add
+     * @todo add a reason
      */
     protected void addKickedOutPath( String path )
     {
index b7883e54d61964400bcf49258dc3612d9b7d4d24..24ee9ce015eaaa7271321455b96c4fb939db8e42 100644 (file)
@@ -81,21 +81,26 @@ public class DefaultArtifactDiscoverer
             return null;
         }
 
-        //discard the actual artifact filename.
-        pathParts.remove( 0 );
+        // the actual artifact filename.
+        String filename = (String) pathParts.remove( 0 );
 
         // the next one is the version.
-        String version = (String) pathParts.get( 0 );
-        pathParts.remove( 0 );
+        String version = (String) pathParts.remove( 0 );
 
         // the next one is the artifactId.
-        String artifactId = (String) pathParts.get( 0 );
-        pathParts.remove( 0 );
+        String artifactId = (String) pathParts.remove( 0 );
 
         // the remaining are the groupId.
         Collections.reverse( pathParts );
         String groupId = StringUtils.join( pathParts.iterator(), "." );
 
+        if ( !filename.startsWith( artifactId + "-" ) )
+        {
+            addKickedOutPath( path );
+
+            return null;
+        }
+
         result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
 
         result.setFile( new File( path ) );
index 0c3cd3e87459b21131d0f8d5276d5d2febb7bee0..1a9f6fb07e13bdb4a498e21b5f15bd392d9613cc 100644 (file)
@@ -303,7 +303,10 @@ public class LegacyArtifactDiscoverer
             }
         }
 
-        result.setFile( new File( path ) );
+        if ( result != null )
+        {
+            result.setFile( new File( path ) );
+        }
 
         return result;
     }
index 6bd0afb6cd62deda3bdad1038b6b403e0692b7d7..1ea6c2a09e030129a13d53f25a21366523e8a5a7 100644 (file)
@@ -29,6 +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
  */
 public class DefaultArtifactDiscovererTest
     extends PlexusTestCase
@@ -118,7 +119,7 @@ public class DefaultArtifactDiscovererTest
 
             found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" );
         }
-        assertTrue( "Check exclusion was found", found );
+        assertTrue( "Check kickout was found", found );
 
         for ( Iterator i = artifacts.iterator(); i.hasNext(); )
         {
@@ -127,6 +128,28 @@ public class DefaultArtifactDiscovererTest
         }
     }
 
+    public void testKickoutWithWrongArtifactId()
+    {
+        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(
+                "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
+        }
+        assertTrue( "Check kickout was found", found );
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+            assertFalse( "Check not wrong jar",
+                         a.getFile().getName().equals( "wrong-artifactId-1.0-20050611.112233-1.jar" ) );
+        }
+    }
+
     public void testSnapshotInclusion()
     {
         List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
index 50d1dd783b31d0fc5a8f46405be3ed6e8327d856..db9b046a2aa165956d1a230e2e349927b20bce88 100644 (file)
@@ -107,7 +107,6 @@ public class LegacyArtifactDiscovererTest
         assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
     }
 
-/*
     public void testKickoutWithShortPath()
     {
         List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
@@ -128,6 +127,26 @@ public class LegacyArtifactDiscovererTest
         }
     }
 
+    public void testKickoutWithLongPath()
+    {
+        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/jars/1.0/invalid-1.0.jar" );
+        }
+        assertTrue( "Check exclusion was found", found );
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+            assertFalse( "Check not invalid-1.0.jar", a.getFile().getName().equals( "invalid-1.0.jar" ) );
+        }
+    }
+
     public void testSnapshotInclusion()
     {
         List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
@@ -135,7 +154,7 @@ public class LegacyArtifactDiscovererTest
 
         assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
         assertTrue( "Check snapshot included",
-                    artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
+                    artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
     }
 
     public void testSnapshotExclusion()
@@ -145,9 +164,8 @@ public class LegacyArtifactDiscovererTest
 
         assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
         assertFalse( "Check snapshot included",
-                     artifacts.contains( createArtifact( "org.apache.maven", "test", "1.0-SNAPSHOT" ) ) );
+                     artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
     }
-*/
 
     private Artifact createArtifact( String groupId, String artifactId, String version )
     {
diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/invalid/invalid-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar b/maven-repository-discovery/src/test/legacy-repository/invalid/jars/1.0/invalid-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/legacy-repository/org.apache.maven/jars/testing-1.0-20050611.112233-1.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/maven-test-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/maven-test-1.0-20050611.112233-1.jar
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar b/maven-repository-discovery/src/test/repository/org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar
new file mode 100644 (file)
index 0000000..e69de29