avoid failure when there is a bad path in the repository

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-20 05:43:03 +00:00
parent 27aa17cb32
commit 2b44ccee57
3 changed files with 16 additions and 9 deletions

View File

@ -17,6 +17,7 @@ package org.apache.maven.tools.repoclean.discover;
*/ */
import org.apache.maven.tools.repoclean.report.PathLister; import org.apache.maven.tools.repoclean.report.PathLister;
import org.apache.maven.tools.repoclean.report.ReportWriteException;
import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.report.Reporter;
import java.io.File; import java.io.File;
@ -35,6 +36,6 @@ public interface ArtifactDiscoverer
List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns, List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns,
PathLister excludeLister, PathLister kickoutLister, boolean includeSnapshots ) PathLister excludeLister, PathLister kickoutLister, boolean includeSnapshots )
throws Exception; throws ReportWriteException;
} }

View File

@ -19,6 +19,7 @@ package org.apache.maven.tools.repoclean.discover;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.tools.repoclean.report.PathLister; import org.apache.maven.tools.repoclean.report.PathLister;
import org.apache.maven.tools.repoclean.report.ReportWriteException;
import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.report.Reporter;
import java.io.File; import java.io.File;
@ -39,7 +40,7 @@ public class DefaultArtifactDiscoverer
public List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns, public List discoverArtifacts( File repositoryBase, Reporter reporter, String blacklistedPatterns,
PathLister excludeLister, PathLister kickoutLister, boolean convertSnapshots ) PathLister excludeLister, PathLister kickoutLister, boolean convertSnapshots )
throws Exception throws ReportWriteException
{ {
List artifacts = new ArrayList(); List artifacts = new ArrayList();
@ -49,7 +50,7 @@ public class DefaultArtifactDiscoverer
{ {
String path = artifactPaths[i]; String path = artifactPaths[i];
Artifact artifact = buildArtifact( path ); Artifact artifact = buildArtifact( path, reporter );
if ( artifact != null ) if ( artifact != null )
{ {
@ -63,8 +64,8 @@ public class DefaultArtifactDiscoverer
return artifacts; return artifacts;
} }
private Artifact buildArtifact( String path ) private Artifact buildArtifact( String path, Reporter reporter )
throws Exception throws ReportWriteException
{ {
Artifact result; Artifact result;
@ -77,7 +78,11 @@ public class DefaultArtifactDiscoverer
Collections.reverse( pathParts ); Collections.reverse( pathParts );
int currentPart = 0; if ( pathParts.size() < 4 )
{
reporter.error( "Not enough parts (4) in path " + path );
return null;
}
//discard the actual artifact filename. //discard the actual artifact filename.
pathParts.remove( 0 ); pathParts.remove( 0 );

View File

@ -19,6 +19,7 @@ package org.apache.maven.tools.repoclean.phase;
import org.apache.maven.tools.repoclean.RepositoryCleanerConfiguration; import org.apache.maven.tools.repoclean.RepositoryCleanerConfiguration;
import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer; import org.apache.maven.tools.repoclean.discover.ArtifactDiscoverer;
import org.apache.maven.tools.repoclean.report.PathLister; import org.apache.maven.tools.repoclean.report.PathLister;
import org.apache.maven.tools.repoclean.report.ReportWriteException;
import org.apache.maven.tools.repoclean.report.Reporter; import org.apache.maven.tools.repoclean.report.Reporter;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
@ -54,8 +55,8 @@ public class DiscoveryPhase
try try
{ {
artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE, configuration artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE,
.getSourceRepositoryLayout() ); configuration.getSourceRepositoryLayout() );
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
{ {
@ -74,7 +75,7 @@ public class DiscoveryPhase
configuration.getBlacklistedPatterns(), excludeLister, configuration.getBlacklistedPatterns(), excludeLister,
kickoutLister, configuration.isConvertSnapshots() ); kickoutLister, configuration.isConvertSnapshots() );
} }
catch ( Exception e ) catch ( ReportWriteException e )
{ {
repoReporter.error( "Error discovering artifacts in source repository.", e ); repoReporter.error( "Error discovering artifacts in source repository.", e );