]> source.dussan.org Git - archiva.git/commitdiff
refactor to share code
authorBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 04:52:59 +0000 (04:52 +0000)
committerBrett Porter <brett@apache.org>
Fri, 30 Dec 2005 04:52:59 +0000 (04:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@359987 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/DefaultMetadataDiscoverer.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/DefaultMetadataDiscovererTest.java

index f55154c1733ac1ecea36531f856834f5314ca991..2ac660b7bd7ce5141cbc4c476013bbae8dff7d8d 100644 (file)
@@ -34,7 +34,6 @@ import java.util.List;
  */
 public abstract class AbstractArtifactDiscoverer
     extends AbstractLogEnabled
-    implements ArtifactDiscoverer
 {
     /**
      * Standard patterns to exclude from discovery as they are not artifacts.
@@ -55,10 +54,24 @@ public abstract class AbstractArtifactDiscoverer
      * @todo replace blacklisted patterns by an artifact filter
      */
     protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
+    {
+        return scanForArtifactPaths( repositoryBase, blacklistedPatterns, null, STANDARD_DISCOVERY_EXCLUDES );
+    }
+
+    /**
+     * Scan the repository for artifact paths.
+     *
+     * @todo replace blacklisted patterns by an artifact filter
+     */
+    protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns, String[] includes,
+                                             String[] excludes )
     {
         List allExcludes = new ArrayList();
         allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
-        allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
+        if ( excludes != null )
+        {
+            allExcludes.addAll( Arrays.asList( excludes ) );
+        }
 
         if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
         {
@@ -67,6 +80,10 @@ public abstract class AbstractArtifactDiscoverer
 
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir( repositoryBase );
+        if ( includes != null )
+        {
+            scanner.setIncludes( includes );
+        }
         scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
 
         scanner.scan();
index d88ed4f5294e0179e96329a1133ccdc864649d02..80cf5899d9ca6188b5e82a53248a8cacc5deccb5 100644 (file)
@@ -34,6 +34,7 @@ import java.util.StringTokenizer;
  */
 public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
+    implements ArtifactDiscoverer
 {
     private ArtifactFactory artifactFactory;
 
index e7948f2268c790d3c5b77bf1557f69fb1e47bed7..14f4d6d1dd3b21bd8bc43d9e4d19f61e23581112 100644 (file)
@@ -27,8 +27,6 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.apache.maven.artifact.versioning.VersionRange;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
@@ -39,7 +37,6 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
@@ -49,28 +46,15 @@ import java.util.StringTokenizer;
  * This class gets all the paths that contain the metadata files.
  */
 public class DefaultMetadataDiscoverer
+    extends AbstractArtifactDiscoverer
     implements MetadataDiscoverer
 {
-
-    /**
-     * Standard patterns to exclude from discovery as they are not artifacts.
-     */
-    private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5",
-        "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
-        "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
-
     /**
      * Standard patterns to include in discovery of metadata files.
      */
     private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml", "**/*/*-metadata.xml",
         "**/*/*/*-metadata.xml", "**/*-metadata-*.xml", "**/*/*-metadata-*.xml", "**/*/*/*-metadata-*.xml"};
 
-    private static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-    private List excludedPaths = new ArrayList();
-
-    private List kickedOutPaths = new ArrayList();
-
     /**
      * Search the repository for metadata files.
      *
@@ -80,7 +64,8 @@ public class DefaultMetadataDiscoverer
     public List discoverMetadata( File repositoryBase, String blacklistedPatterns )
     {
         List metadataFiles = new ArrayList();
-        String[] metadataPaths = scanForMetadataPaths( repositoryBase, blacklistedPatterns );
+        String[] metadataPaths =
+            scanForArtifactPaths( repositoryBase, blacklistedPatterns, STANDARD_DISCOVERY_INCLUDES, null );
 
         for ( int i = 0; i < metadataPaths.length; i++ )
         {
@@ -93,7 +78,7 @@ public class DefaultMetadataDiscoverer
             }
             else
             {
-                kickedOutPaths.add( metadataPaths[i] );
+                addKickedOutPath( metadataPaths[i] );
             }
         }
 
@@ -105,11 +90,10 @@ public class DefaultMetadataDiscoverer
      *
      * @param repo         The path to the repository.
      * @param metadataPath The path to the metadata file.
-     * @return
+     * @return the metadata
      */
     private RepositoryMetadata buildMetadata( String repo, String metadataPath )
     {
-
         RepositoryMetadata metadata = null;
 
         try
@@ -183,59 +167,17 @@ public class DefaultMetadataDiscoverer
         }
         catch ( FileNotFoundException fe )
         {
-            return null;
+            // TODO: log ignored metadata
         }
         catch ( XmlPullParserException xe )
         {
-            return null;
+            // TODO: log ignored metadata
         }
         catch ( IOException ie )
         {
-            return null;
+            // TODO: log ignored metadata
         }
 
         return metadata;
     }
-
-    /**
-     * Scan or search for metadata files.
-     *
-     * @param repositoryBase      The repository directory.
-     * @param blacklistedPatterns The patterns to be exluded from the search.
-     * @return
-     */
-    private String[] scanForMetadataPaths( File repositoryBase, String blacklistedPatterns )
-    {
-
-        List allExcludes = new ArrayList();
-        allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
-        allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
-
-        if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
-        {
-            allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
-        }
-
-        DirectoryScanner scanner = new DirectoryScanner();
-        scanner.setBasedir( repositoryBase );
-        scanner.setIncludes( STANDARD_DISCOVERY_INCLUDES );
-        scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
-        scanner.scan();
-
-        excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
-
-        return scanner.getIncludedFiles();
-
-    }
-
-    public Iterator getExcludedPathsIterator()
-    {
-        return excludedPaths.iterator();
-    }
-
-    public Iterator getKickedOutPathsIterator()
-    {
-        return kickedOutPaths.iterator();
-    }
-
 }
index b41cef5538c757269f91e740048e19b64818e9b9..4cac9168d2cb670afbf095d58239e9887b71cfc3 100644 (file)
@@ -35,6 +35,7 @@ import java.util.StringTokenizer;
  */
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
+    implements ArtifactDiscoverer
 {
     private ArtifactFactory artifactFactory;
 
index fa19654172c147ca04144b8940a64fefaf6818f8..f9138e7733f8331b7378f8baa0007154442d5ade 100644 (file)
@@ -61,7 +61,7 @@ public class DefaultMetadataDiscovererTest
     {
         List metadataPaths = discoverer.discoverMetadata( repositoryLocation, null );
         assertNotNull( "Check metadata not null", metadataPaths );
-        assertTrue( metadataPaths.size() == 3 );
+        assertEquals( 3, metadataPaths.size() );
     }
 
     /**