From: Brett Porter Date: Fri, 30 Dec 2005 04:52:59 +0000 (+0000) Subject: refactor to share code X-Git-Tag: archiva-0.9-alpha-1~1035 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=15da6122ee2120df43e46d7b7fbaf82ea3561919;p=archiva.git refactor to share code git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@359987 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java index f55154c17..2ac660b7b 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java @@ -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(); diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java index d88ed4f52..80cf5899d 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java @@ -34,6 +34,7 @@ import java.util.StringTokenizer; */ public class DefaultArtifactDiscoverer extends AbstractArtifactDiscoverer + implements ArtifactDiscoverer { private ArtifactFactory artifactFactory; diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java index e7948f226..14f4d6d1d 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java @@ -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(); - } - } diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java index b41cef553..4cac9168d 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java @@ -35,6 +35,7 @@ import java.util.StringTokenizer; */ public class LegacyArtifactDiscoverer extends AbstractArtifactDiscoverer + implements ArtifactDiscoverer { private ArtifactFactory artifactFactory; diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java index fa1965417..f9138e773 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java @@ -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() ); } /**