]> source.dussan.org Git - archiva.git/commitdiff
add some more tests
authorBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 03:11:23 +0000 (03:11 +0000)
committerBrett Porter <brett@apache.org>
Tue, 29 Nov 2005 03:11:23 +0000 (03:11 +0000)
PR: MRM-9

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@349600 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/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java
maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.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 [new file with mode: 0644]

index 676f38bb2bb65b90afaf24df6ef0bcc7c58318bd..f28ca0c0f68d8218d2682f6af48d4e689cab6964 100644 (file)
@@ -18,6 +18,7 @@ package org.apache.maven.repository.discovery;
 
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -55,24 +56,18 @@ public abstract class AbstractArtifactDiscoverer
      */
     protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
     {
-        String[] blacklisted;
+        List allExcludes = new ArrayList();
+        allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
+        allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
+
         if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
         {
-            blacklisted = blacklistedPatterns.split( "," );
-        }
-        else
-        {
-            blacklisted = EMPTY_STRING_ARRAY;
+            allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
         }
 
-        String[] allExcludes = new String[STANDARD_DISCOVERY_EXCLUDES.length + blacklisted.length];
-
-        System.arraycopy( STANDARD_DISCOVERY_EXCLUDES, 0, allExcludes, 0, STANDARD_DISCOVERY_EXCLUDES.length );
-        System.arraycopy( blacklisted, 0, allExcludes, STANDARD_DISCOVERY_EXCLUDES.length, blacklisted.length );
-
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir( repositoryBase );
-        scanner.setExcludes( allExcludes );
+        scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
 
         scanner.scan();
 
index 410434d3f028ee414c2d2af5aaede0d7cb61086b..b7883e54d61964400bcf49258dc3612d9b7d4d24 100644 (file)
@@ -18,11 +18,11 @@ package org.apache.maven.repository.discovery;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
@@ -93,27 +93,12 @@ public class DefaultArtifactDiscoverer
         pathParts.remove( 0 );
 
         // the remaining are the groupId.
-        StringBuffer groupBuffer = new StringBuffer();
-
-        boolean firstPart = true;
-        for ( Iterator it = pathParts.iterator(); it.hasNext(); )
-        {
-            String part = (String) it.next();
-
-            groupBuffer.append( part );
+        Collections.reverse( pathParts );
+        String groupId = StringUtils.join( pathParts.iterator(), "." );
 
-            if ( firstPart )
-            {
-                firstPart = false;
-            }
-            else if ( it.hasNext() )
-            {
-                groupBuffer.append( "." );
-            }
-        }
+        result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" );
 
-        result = artifactFactory.createArtifact( groupBuffer.toString(), artifactId, version, Artifact.SCOPE_RUNTIME,
-                                                 "jar" );
+        result.setFile( new File( path ) );
 
         return result;
     }
index ce2d1abd5ffbbb83b90056858edd914ff8fa445b..5a279e04dd02842caf0ed27ff39c58d46528e096 100644 (file)
@@ -16,6 +16,8 @@ package org.apache.maven.repository.discovery;
  * limitations under the License.
  */
 
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.codehaus.plexus.PlexusTestCase;
 
 import java.io.File;
@@ -33,6 +35,8 @@ public class DefaultArtifactDiscovererTest
 {
     private ArtifactDiscoverer discoverer;
 
+    private ArtifactFactory factory;
+
     private File repositoryLocation;
 
     protected void setUp()
@@ -42,29 +46,90 @@ public class DefaultArtifactDiscovererTest
 
         discoverer = (ArtifactDiscoverer) lookup( ArtifactDiscoverer.ROLE, "default" );
 
+        factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+
         repositoryLocation = getTestFile( "src/test/repository" );
     }
 
     public void testDefaultExcludes()
     {
         List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
-        assertNotNull( "Check artifacts returned", artifacts );
-        assertTrue( "Check no artifacts returned", artifacts.isEmpty() );
+        assertNotNull( "Check artifacts not null", artifacts );
         boolean found = false;
-        for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext(); )
+        for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
         {
             String path = (String) i.next();
 
-            if ( !path.startsWith( ".svn" ) )
-            {
-                assertEquals( "Check the excluded path", "KEYS", path );
-                if ( found )
-                {
-                    fail( "KEYS entry found twice" );
-                }
-                found = true;
-            }
+            found = path.indexOf( ".svn" ) >= 0;
         }
         assertTrue( "Check exclusion was found", found );
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+            assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
+        }
     }
+
+    public void testStandardExcludes()
+    {
+        List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
+        assertNotNull( "Check artifacts not null", artifacts );
+        boolean found = false;
+        for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
+        {
+            String path = (String) i.next();
+
+            found = path.equals( "KEYS" );
+        }
+        assertTrue( "Check exclusion was found", found );
+
+        for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+            assertFalse( "Check not KEYS", a.getFile().getName().equals( "KEYS" ) );
+        }
+    }
+
+    public void testBlacklistedExclude()
+    {
+        List artifacts = discoverer.discoverArtifacts( repositoryLocation, "javax/**", false );
+        assertNotNull( "Check artifacts not null", artifacts );
+        boolean found = false;
+        for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
+        {
+            String path = (String) i.next();
+
+            found = path.replace( '\\', '/' ).equals( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
+        }
+        assertTrue( "Check exclusion was found", found );
+
+        assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
+    }
+
+    public void testSnapshotInclusion()
+    {
+        List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
+        assertNotNull( "Check artifacts not null", artifacts );
+
+        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" ) ) );
+    }
+
+    public void testSnapshotExclusion()
+    {
+        List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
+        assertNotNull( "Check artifacts not null", artifacts );
+
+        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" ) ) );
+    }
+
+    private Artifact createArtifact( String groupId, String artifactId, String version )
+    {
+        return factory.createArtifact( groupId, artifactId, version, null, "jar" );
+    }
+
 }
diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.jar b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/jdbc-2.0.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
new file mode 100644 (file)
index 0000000..e69de29