Added a new class "DiscovererPath" for use to represent paths processed by the Discoverer. Currently used to fill KickedOutPaths and ExcludedPaths

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@413827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-06-13 07:57:20 +00:00
parent 18f031c774
commit 30602fb39f
5 changed files with 130 additions and 28 deletions

View File

@ -20,14 +20,13 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
/**
* Base class for the artifact and metadata discoverers.
@ -38,7 +37,7 @@ public abstract class AbstractDiscoverer
extends AbstractLogEnabled
implements Discoverer
{
private Map kickedOutPaths = new HashMap();
private List kickedOutPaths = new ArrayList();
/**
* @plexus.requirement
@ -57,12 +56,12 @@ public abstract class AbstractDiscoverer
*/
protected void addKickedOutPath( String path, String reason )
{
kickedOutPaths.put( path, reason );
kickedOutPaths.add( new DiscovererPath( path, reason ) );
}
public Iterator getKickedOutPathsIterator()
{
return kickedOutPaths.keySet().iterator();
return kickedOutPaths.iterator();
}
/**
@ -78,7 +77,7 @@ public abstract class AbstractDiscoverer
allExcludes.addAll( Arrays.asList( excludes ) );
}
if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
if ( !StringUtils.isEmpty( blacklistedPatterns ) )
{
allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
}
@ -93,7 +92,12 @@ public abstract class AbstractDiscoverer
scanner.scan();
excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
for ( Iterator files = Arrays.asList( scanner.getExcludedFiles() ).iterator(); files.hasNext(); )
{
String path = files.next().toString();
excludedPaths.add( new DiscovererPath( path, "Excluded by DirectoryScanner" ) );
}
return scanner.getIncludedFiles();
}

View File

@ -0,0 +1,56 @@
package org.apache.maven.repository.discovery;
/*
* Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Edwin Punzalan
*/
public class DiscovererPath
{
private String path;
private String comment;
public DiscovererPath()
{
}
public DiscovererPath( String path, String comment )
{
setPath( path );
setComment( comment );
}
public String getPath()
{
return path;
}
public void setPath( String path )
{
this.path = path;
}
public String getComment()
{
return comment;
}
public void setComment( String comment )
{
this.comment = comment;
}
}

View File

@ -71,7 +71,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = path.indexOf( ".svn" ) >= 0;
}
@ -91,7 +93,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "KEYS".equals( path );
}
@ -111,7 +115,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "javax/sql/jdbc/2.0/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -127,7 +133,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -147,7 +155,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar".equals(
path.replace( '\\', '/' ) );
@ -169,7 +179,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid/1/invalid-1".equals( path.replace( '\\', '/' ) );
}
@ -189,7 +201,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid/1.0/invalid-2.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -209,7 +223,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid/1.0/invalid-1.0b.jar".equals( path.replace( '\\', '/' ) );
}
@ -229,7 +245,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -249,7 +267,9 @@ public class DefaultArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar".equals(
path.replace( '\\', '/' ) );

View File

@ -75,7 +75,9 @@ public class DefaultMetadataDiscovererTest
boolean found = false;
while ( iter.hasNext() && !found )
{
String dir = (String) iter.next();
DiscovererPath dPath = (DiscovererPath) iter.next();
String dir = dPath.getPath();
String normalizedDir = dir.replace( '\\', '/' );
if ( "javax/maven-metadata-repository.xml".equals( normalizedDir ) )
{
@ -95,7 +97,9 @@ public class DefaultMetadataDiscovererTest
boolean found = false;
while ( iter.hasNext() && !found )
{
String dir = (String) iter.next();
DiscovererPath dPath = (DiscovererPath) iter.next();
String dir = dPath.getPath();
String normalizedDir = dir.replace( '\\', '/' );
if ( "org/apache/maven/some-ejb/1.0/maven-metadata-repository.xml".equals( normalizedDir ) )
{

View File

@ -69,7 +69,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = path.indexOf( ".svn" ) >= 0;
}
@ -89,7 +91,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "KEYS".equals( path );
}
@ -109,7 +113,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -125,7 +131,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -145,7 +153,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) );
}
@ -165,7 +175,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) );
}
@ -185,7 +197,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) );
}
@ -205,7 +219,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) );
}
@ -225,7 +241,9 @@ public class LegacyArtifactDiscovererTest
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
DiscovererPath dPath = (DiscovererPath) i.next();
String path = dPath.getPath();
found = "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) );
}