Added reason parameter in kickedOutPaths. Also, added an interface with the kickedOutPaths which two other interfaces extends

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@413818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-06-13 06:53:38 +00:00
parent b6dd4adbe6
commit 18f031c774
12 changed files with 351 additions and 248 deletions

View File

@ -73,17 +73,19 @@ public abstract class AbstractArtifactDiscoverer
{
String path = artifactPaths[i];
Artifact artifact = buildArtifactFromPath( path, repository );
if ( artifact != null )
Artifact artifact = null;
try
{
artifact = buildArtifactFromPath( path, repository );
if ( includeSnapshots || !artifact.isSnapshot() )
{
artifacts.add( artifact );
}
}
else
catch ( DiscovererException e )
{
addKickedOutPath( path );
addKickedOutPath( path, e.getMessage() );
}
}
@ -103,14 +105,16 @@ public abstract class AbstractArtifactDiscoverer
{
String path = artifactPaths[i];
String filename = repositoryBase.getAbsolutePath() + "/" + path;
if ( path.toLowerCase().endsWith( POM ) )
{
try
{
Artifact pomArtifact = buildArtifactFromPath( path, repository );
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
String filename = repositoryBase.getAbsolutePath() + "/" + path;
try
{
Model model = mavenReader.read( new FileReader( filename ) );
if ( pomArtifact != null && "pom".equals( model.getPackaging() ) )
{
@ -134,6 +138,10 @@ public abstract class AbstractArtifactDiscoverer
getLogger().error(
"Parse error reading file during POM discovery: " + filename + ": " + e.getMessage() );
}
catch ( DiscovererException e )
{
getLogger().error( e.getMessage() );
}
}
}
@ -141,6 +149,7 @@ public abstract class AbstractArtifactDiscoverer
}
public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
throws DiscovererException
{
Artifact artifact = buildArtifact( path );

View File

@ -26,6 +26,8 @@ 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.
@ -34,8 +36,9 @@ import java.util.List;
*/
public abstract class AbstractDiscoverer
extends AbstractLogEnabled
implements Discoverer
{
private List kickedOutPaths = new ArrayList();
private Map kickedOutPaths = new HashMap();
/**
* @plexus.requirement
@ -50,16 +53,16 @@ public abstract class AbstractDiscoverer
* Add a path to the list of files that were kicked out due to being invalid.
*
* @param path the path to add
* @todo add a reason
* @param reason the reason why the path is being kicked out
*/
protected void addKickedOutPath( String path )
protected void addKickedOutPath( String path, String reason )
{
kickedOutPaths.add( path );
kickedOutPaths.put( path, reason );
}
public Iterator getKickedOutPathsIterator()
{
return kickedOutPaths.iterator();
return kickedOutPaths.keySet().iterator();
}
/**

View File

@ -19,7 +19,6 @@ package org.apache.maven.repository.discovery;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.Iterator;
import java.util.List;
/**
@ -29,6 +28,7 @@ import java.util.List;
* @author Brett Porter
*/
public interface ArtifactDiscoverer
extends Discoverer
{
String ROLE = ArtifactDiscoverer.class.getName();
@ -58,20 +58,6 @@ public interface ArtifactDiscoverer
*/
List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots );
/**
* Get the list of paths kicked out during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getKickedOutPathsIterator();
/**
* Get the list of paths excluded during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getExcludedPathsIterator();
/**
* Build an artifact from a path in the repository
*
@ -79,5 +65,6 @@ public interface ArtifactDiscoverer
* @return the artifact
* @todo this should be in maven-artifact
*/
Artifact buildArtifact( String path );
Artifact buildArtifact( String path )
throws DiscovererException;
}

View File

@ -35,6 +35,7 @@ public class DefaultArtifactDiscoverer
extends AbstractArtifactDiscoverer
{
public Artifact buildArtifact( String path )
throws DiscovererException
{
List pathParts = new ArrayList();
StringTokenizer st = new StringTokenizer( path, "/\\" );
@ -64,11 +65,7 @@ public class DefaultArtifactDiscoverer
String groupId = StringUtils.join( pathParts.iterator(), "." );
String remainingFilename = filename;
if ( !remainingFilename.startsWith( artifactId + "-" ) )
{
return null;
}
else
if ( remainingFilename.startsWith( artifactId + "-" ) )
{
remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
@ -97,21 +94,18 @@ public class DefaultArtifactDiscoverer
else
{
int index = remainingFilename.lastIndexOf( "." );
if ( index < 0 )
{
return null;
}
else
if ( index >= 0 )
{
type = remainingFilename.substring( index + 1 );
remainingFilename = remainingFilename.substring( 0, index );
}
else
{
throw new DiscovererException( "Path filename does not have an extension" );
}
}
if ( type != null )
{
Artifact result;
if ( classifier == null )
{
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
@ -144,11 +138,12 @@ public class DefaultArtifactDiscoverer
// poor encapsulation requires we do this to populate base version
if ( !result.isSnapshot() )
{
return null;
throw new DiscovererException( "Failed to create a snapshot artifact" );
}
else if ( !result.getBaseVersion().equals( version ) )
{
return null;
throw new DiscovererException( "Built snapshot artifact base version does not match " +
"path version" );
}
else
{
@ -157,28 +152,35 @@ public class DefaultArtifactDiscoverer
}
else if ( !remainingFilename.startsWith( version ) )
{
return null;
throw new DiscovererException( "Built artifact version does not match path version" );
}
else if ( !remainingFilename.equals( version ) )
{
if ( remainingFilename.charAt( version.length() ) != '-' )
{
return null;
}
else
if ( remainingFilename.charAt( version.length() ) == '-' )
{
classifier = remainingFilename.substring( version.length() + 1 );
artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
classifier );
}
else
{
throw new DiscovererException( "Path version does not corresspond to an artifact version" );
}
}
else
{
artifact = result;
}
}
else
{
throw new DiscovererException( "Path filename does not correspond to an artifact" );
}
}
else
{
throw new DiscovererException( "Path is too short to build an artifact from" );
}
return artifact;
}

View File

@ -24,6 +24,7 @@ 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.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
@ -67,15 +68,14 @@ public class DefaultMetadataDiscoverer
for ( int i = 0; i < metadataPaths.length; i++ )
{
RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
if ( metadata != null )
try
{
RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
metadataFiles.add( metadata );
}
else
catch ( DiscovererException e )
{
addKickedOutPath( metadataPaths[i] );
addKickedOutPath( metadataPaths[i], e.getMessage() );
}
}
@ -90,6 +90,7 @@ public class DefaultMetadataDiscoverer
* @return the metadata
*/
private RepositoryMetadata buildMetadata( String repo, String metadataPath )
throws DiscovererException
{
Metadata m = null;
String repoPath = repo + "/" + metadataPath;
@ -104,23 +105,26 @@ public class DefaultMetadataDiscoverer
}
catch ( XmlPullParserException e )
{
getLogger().error( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e );
throw new DiscovererException( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e );
}
catch ( MalformedURLException e )
{
// shouldn't happen
getLogger().error( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), e );
throw new DiscovererException( "Error constructing metadata file '" + repoPath + "': " +
e.getMessage(), e );
}
catch ( IOException e )
{
getLogger().error( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e );
throw new DiscovererException( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e );
}
RepositoryMetadata repositoryMetadata = null;
if ( m != null )
RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath );
if ( repositoryMetadata == null )
{
repositoryMetadata = buildMetadata( m, metadataPath );
throw new DiscovererException( "Unable to build a repository metadata from path" );
}
return repositoryMetadata;
}
@ -146,14 +150,8 @@ public class DefaultMetadataDiscoverer
Iterator it = pathParts.iterator();
String tmpDir = (String) it.next();
//ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
//if( metaVersion != null && !metaVersion.equals( "" ) )
//{
// VersionRange version = VersionRange.createFromVersion( metaVersion );
//}
Artifact artifact = null;
if ( metaVersion != null && !"".equals( metaVersion ) )
if ( !StringUtils.isEmpty( metaVersion ) )
{
artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
}

View File

@ -0,0 +1,39 @@
package org.apache.maven.repository.discovery;
import java.util.Iterator;
/*
* 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 interface Discoverer
{
/**
* Get the list of paths kicked out during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getKickedOutPathsIterator();
/**
* Get the list of paths excluded during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getExcludedPathsIterator();
}

View File

@ -0,0 +1,39 @@
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 DiscovererException
extends Exception
{
public DiscovererException( Throwable cause )
{
super( cause );
}
public DiscovererException( String message )
{
super( message );
}
public DiscovererException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -38,10 +38,11 @@ public class LegacyArtifactDiscoverer
extends AbstractArtifactDiscoverer
{
public Artifact buildArtifact( String path )
throws DiscovererException
{
StringTokenizer tokens = new StringTokenizer( path, "/\\" );
Artifact result = null;
Artifact result;
int numberOfTokens = tokens.countTokens();
@ -69,8 +70,6 @@ public class LegacyArtifactDiscoverer
String lastAvceToken = (String) avceTokenList.removeLast();
boolean valid = true;
// TODO: share with other discoverer, use artifact handlers instead
if ( lastAvceToken.endsWith( ".tar.gz" ) )
{
@ -111,19 +110,15 @@ public class LegacyArtifactDiscoverer
}
else
{
//type does not match extension
valid = false;
throw new DiscovererException( "Path type does not match the extension" );
}
}
else
{
// no extension
valid = false;
throw new DiscovererException( "Path filename does not have an extension" );
}
}
if ( valid )
{
// let's discover the version, and whatever's leftover will be either
// a classifier, or part of the artifactId, depending on position.
// Since version is at the end, we have to move in from the back.
@ -245,7 +240,7 @@ public class LegacyArtifactDiscoverer
String version = versionBuffer.toString();
if ( version.length() >= 1 )
if ( version.length() > 0 )
{
if ( classifierBuffer.length() > 0 )
{
@ -259,10 +254,25 @@ public class LegacyArtifactDiscoverer
Artifact.SCOPE_RUNTIME, type );
}
}
else
{
throw new DiscovererException( "Path filename version is empty" );
}
}
else
{
throw new DiscovererException( "Path filename artifactId is empty" );
}
}
else
{
throw new DiscovererException( "Path artifact type does not corresspond to an artifact type" );
}
}
else
{
throw new DiscovererException( "Path does not match a legacy repository path for an artifact" );
}
return result;
}

View File

@ -17,13 +17,13 @@ package org.apache.maven.repository.discovery;
*/
import java.io.File;
import java.util.Iterator;
import java.util.List;
/**
* Interface for discovering metadata files.
*/
public interface MetadataDiscoverer
extends Discoverer
{
String ROLE = MetadataDiscoverer.class.getName();
@ -34,18 +34,4 @@ public interface MetadataDiscoverer
* @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
*/
List discoverMetadata( File repositoryBase, String blacklistedPatterns );
/**
* Get the list of paths kicked out during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getKickedOutPathsIterator();
/**
* Get the list of paths excluded during the discovery process.
*
* @return the paths as Strings.
*/
Iterator getExcludedPathsIterator();
}

View File

@ -564,9 +564,16 @@ public class DefaultArtifactDiscovererTest
}
private Artifact getArtifactFromPath( String path )
{
try
{
return discoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
return null;
}
}
private Artifact createArtifact( String groupId, String artifactId, String version )
{

View File

@ -405,9 +405,16 @@ public class LegacyArtifactDiscovererTest
}
private Artifact getArtifactFromPath( String path )
{
try
{
return discoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
return null;
}
}
private Artifact createArtifact( String groupId, String artifactId, String version )
{

View File

@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.discovery.ArtifactDiscoverer;
import org.apache.maven.repository.discovery.DiscovererException;
import org.apache.maven.repository.proxy.configuration.ProxyConfiguration;
import org.apache.maven.repository.proxy.repository.ProxyRepository;
import org.apache.maven.wagon.ConnectionException;
@ -150,12 +151,27 @@ public class DefaultProxyManager
}
else
{
Artifact artifact = defaultArtifactDiscoverer.buildArtifact( path );
Artifact artifact = null;
try
{
artifact = defaultArtifactDiscoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() );
}
if ( artifact == null )
{
try
{
artifact = legacyArtifactDiscoverer.buildArtifact( path );
}
catch ( DiscovererException e )
{
getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() );
}
}
if ( artifact != null )
{