maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r359987 - in /maven/repository-manager/trunk/maven-repository-discovery/src: main/java/org/apache/maven/repository/discovery/ test/java/org/apache/maven/repository/discovery/
Date Fri, 30 Dec 2005 04:53:08 GMT
Author: brett
Date: Thu Dec 29 20:52:59 2005
New Revision: 359987

URL: http://svn.apache.org/viewcvs?rev=359987&view=rev
Log:
refactor to share code

Modified:
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
    maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
    maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java?rev=359987&r1=359986&r2=359987&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java
Thu Dec 29 20:52:59 2005
@@ -34,7 +34,6 @@
  */
 public abstract class AbstractArtifactDiscoverer
     extends AbstractLogEnabled
-    implements ArtifactDiscoverer
 {
     /**
      * Standard patterns to exclude from discovery as they are not artifacts.
@@ -56,9 +55,23 @@
      */
     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 @@
 
         DirectoryScanner scanner = new DirectoryScanner();
         scanner.setBasedir( repositoryBase );
+        if ( includes != null )
+        {
+            scanner.setIncludes( includes );
+        }
         scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
 
         scanner.scan();

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java?rev=359987&r1=359986&r2=359987&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java
Thu Dec 29 20:52:59 2005
@@ -34,6 +34,7 @@
  */
 public class DefaultArtifactDiscoverer
     extends AbstractArtifactDiscoverer
+    implements ArtifactDiscoverer
 {
     private ArtifactFactory artifactFactory;
 

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java?rev=359987&r1=359986&r2=359987&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java
Thu Dec 29 20:52:59 2005
@@ -27,8 +27,6 @@
 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.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 @@
  * 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 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 @@
             }
             else
             {
-                kickedOutPaths.add( metadataPaths[i] );
+                addKickedOutPath( metadataPaths[i] );
             }
         }
 
@@ -105,11 +90,10 @@
      *
      * @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 @@
         }
         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();
-    }
-
 }

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java?rev=359987&r1=359986&r2=359987&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java
Thu Dec 29 20:52:59 2005
@@ -35,6 +35,7 @@
  */
 public class LegacyArtifactDiscoverer
     extends AbstractArtifactDiscoverer
+    implements ArtifactDiscoverer
 {
     private ArtifactFactory artifactFactory;
 

Modified: maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java?rev=359987&r1=359986&r2=359987&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java
(original)
+++ maven/repository-manager/trunk/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java
Thu Dec 29 20:52:59 2005
@@ -61,7 +61,7 @@
     {
         List metadataPaths = discoverer.discoverMetadata( repositoryLocation, null );
         assertNotNull( "Check metadata not null", metadataPaths );
-        assertTrue( metadataPaths.size() == 3 );
+        assertEquals( 3, metadataPaths.size() );
     }
 
     /**



Mime
View raw message