ensure failed artifact path is passed through to all resolution exceptions

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-22 14:27:35 +00:00
parent 75ff0f8d73
commit 777cbc968c
12 changed files with 78 additions and 117 deletions

View File

@ -17,7 +17,6 @@ package org.apache.maven.artifact.ant;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.DependencyManagement;
@ -91,7 +90,7 @@ public class Pom
}
return instance;
}
public void setMavenProject( MavenProject mavenProject )
{
getInstance().mavenProject = mavenProject;
@ -121,10 +120,6 @@ public class Pom
{
throw new BuildException( "Unable to build project: " + file, e );
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Unable to build project: " + file, e );
}
}
else if ( refid != null )
{

View File

@ -101,4 +101,8 @@ public interface Artifact
void setDependencyFilter( ArtifactFilter artifactFilter );
ArtifactHandler getArtifactHandler();
List getDependencyTrail();
void setDependencyTrail( List dependencyTrail );
}

View File

@ -62,14 +62,11 @@ public class DefaultArtifact
private final ArtifactHandler artifactHandler;
private List dependencyTrail;
// TODO: direct all through the artifact factory
public DefaultArtifact( String groupId,
String artifactId,
String version,
String scope,
String type,
String classifier,
ArtifactHandler artifactHandler )
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type,
String classifier, ArtifactHandler artifactHandler )
{
this.groupId = groupId;
@ -90,14 +87,15 @@ public class DefaultArtifact
private void validateIdentity()
{
if( empty( groupId ) )
if ( empty( groupId ) )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The groupId cannot be empty." );
}
if( artifactId == null )
if ( artifactId == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The artifactId cannot be empty." );
throw new InvalidArtifactRTException( groupId, artifactId, version, type,
"The artifactId cannot be empty." );
}
if ( type == null )
@ -105,7 +103,7 @@ public class DefaultArtifact
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The type cannot be empty." );
}
if( version == null )
if ( version == null )
{
throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The version cannot be empty." );
}
@ -182,7 +180,8 @@ public class DefaultArtifact
public String getId()
{
return getDependencyConflictId() + ( hasClassifier() ? ( ":" + getClassifier() ) : "" ) + ":" + getBaseVersion();
return getDependencyConflictId() + ( hasClassifier() ? ( ":" + getClassifier() ) : "" ) + ":" +
getBaseVersion();
}
public String getDependencyConflictId()
@ -351,4 +350,14 @@ public class DefaultArtifact
{
return artifactHandler;
}
public List getDependencyTrail()
{
return dependencyTrail;
}
public void setDependencyTrail( List dependencyTrail )
{
this.dependencyTrail = dependencyTrail;
}
}

View File

@ -18,7 +18,6 @@ package org.apache.maven.artifact.metadata;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import java.util.List;
import java.util.Set;
@ -30,5 +29,5 @@ import java.util.Set;
public interface ArtifactMetadataSource
{
Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException, ArtifactResolutionException;
throws ArtifactMetadataRetrievalException;
}

View File

@ -144,24 +144,16 @@ public class ArtifactResolutionException
return sb.toString();
}
public ArtifactResolutionException( String message, Artifact artifact, List path, List remoteRepositories,
Throwable t )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
remoteRepositories, artifact.getDownloadUrl(), path, t );
}
public ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
{
// TODO: path
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
remoteRepositories, artifact.getDownloadUrl(), null, t );
remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), t );
}
public ArtifactResolutionException( String message, Artifact artifact, List path )
public ArtifactResolutionException( String message, Artifact artifact )
{
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), null,
artifact.getDownloadUrl(), path );
artifact.getDownloadUrl(), artifact.getDependencyTrail() );
}
public ArtifactResolutionException( String message, Throwable cause )

View File

@ -18,8 +18,6 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact;
import java.util.List;
/**
* Indiciates a cycle in the dependency graph.
*
@ -29,8 +27,8 @@ import java.util.List;
public class CyclicDependencyException
extends ArtifactResolutionException
{
public CyclicDependencyException( String message, Artifact artifact, List path )
public CyclicDependencyException( String message, Artifact artifact )
{
super( message, artifact, path );
super( message, artifact );
}
}

View File

@ -72,7 +72,11 @@ public class DefaultArtifactCollector
ResolutionNode node = (ResolutionNode) i.next();
if ( node != root )
{
set.add( node.getArtifact() );
Artifact artifact = node.getArtifact();
artifact.setDependencyTrail( node.getDependencyTrail() );
set.add( artifact );
}
}
@ -86,7 +90,7 @@ public class DefaultArtifactCollector
private void recurse( ResolutionNode node, Map resolvedArtifacts, Map managedVersions,
ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source,
ArtifactFilter filter, ArtifactFactory artifactFactory )
throws ArtifactResolutionException
throws CyclicDependencyException, TransitiveArtifactResolutionException
{
// TODO: conflict resolvers, shouldn't be munging original artifact perhaps?
Object key = node.getKey();
@ -185,6 +189,7 @@ public class DefaultArtifactCollector
}
catch ( ArtifactMetadataRetrievalException e )
{
child.getArtifact().setDependencyTrail( node.getDependencyTrail() );
throw new TransitiveArtifactResolutionException( e.getMessage(), child.getArtifact(),
remoteRepositories, e );
}
@ -195,13 +200,10 @@ public class DefaultArtifactCollector
}
}
private static class ResolutionNode
{
private Artifact artifact;
private final ResolutionNode parent;
private List children = null;
private final List parents;
@ -211,7 +213,6 @@ public class DefaultArtifactCollector
public ResolutionNode( Artifact artifact )
{
this.artifact = artifact;
this.parent = null;
this.depth = 0;
this.parents = Collections.EMPTY_LIST;
}
@ -219,7 +220,6 @@ public class DefaultArtifactCollector
public ResolutionNode( Artifact artifact, ResolutionNode parent )
{
this.artifact = artifact;
this.parent = parent;
this.depth = parent.depth + 1;
this.parents = new ArrayList();
this.parents.addAll( parent.parents );
@ -249,9 +249,9 @@ public class DefaultArtifactCollector
{
if ( parents.contains( a.getDependencyConflictId() ) )
{
List path = new ArrayList( parents );
path.add( getKey() );
throw new CyclicDependencyException( "The dependency is present in a cycle", a, path );
a.setDependencyTrail( getDependencyTrail() );
throw new CyclicDependencyException( "The dependency is present in a cycle", a );
}
children.add( new ResolutionNode( a, this ) );
@ -259,6 +259,13 @@ public class DefaultArtifactCollector
}
}
public List getDependencyTrail()
{
List path = new ArrayList( parents );
path.add( getKey() );
return path;
}
public boolean isResolved()
{
return children != null;

View File

@ -27,7 +27,8 @@ import java.util.List;
public class TransitiveArtifactResolutionException
extends ArtifactResolutionException
{
public TransitiveArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
public TransitiveArtifactResolutionException( String message, Artifact artifact, List remoteRepositories,
Throwable t )
{
super( message, artifact, remoteRepositories, t );
}

View File

@ -337,7 +337,7 @@ public class DefaultArtifactCollectorTest
Map artifacts = new HashMap();
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException, ArtifactResolutionException
throws ArtifactMetadataRetrievalException
{
ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() );
return createArtifacts( artifactFactory, a.dependencies, artifact.getScope(),

View File

@ -181,14 +181,14 @@ public class DefaultMavenProjectBuilder
}
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
return buildFromSourceFile( projectDescriptor, localRepository, externalProfiles );
}
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
Model model = readModel( projectDescriptor );
@ -213,7 +213,7 @@ public class DefaultMavenProjectBuilder
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
@ -222,13 +222,21 @@ public class DefaultMavenProjectBuilder
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
Model model = getCachedModel( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
if ( model == null )
{
// TODO: can't assume artifact is a POM
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
try
{
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
// TODO: a not found would be better vs other errors
throw new ProjectBuildingException( "Unable to find the POM in the repository", e );
}
// String path = localRepository.pathOfMetadata( new ProjectArtifactMetadata( artifact, null ) );
// File file = new File( localRepository.getBasedir(), path );
@ -257,7 +265,7 @@ public class DefaultMavenProjectBuilder
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository,
List externalProfiles )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
Model superModel = getSuperModel();
@ -438,7 +446,7 @@ public class DefaultMavenProjectBuilder
private MavenProject assembleLineage( Model model, LinkedList lineage, List aggregatedRemoteWagonRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException, ArtifactResolutionException
throws ProjectBuildingException
{
if ( !model.getRepositories().isEmpty() )
{

View File

@ -35,7 +35,7 @@ public interface MavenProjectBuilder
static final String STANDALONE_SUPERPOM_VERSION = "2.0";
MavenProject build( File project, ArtifactRepository localRepository, List profiles )
throws ProjectBuildingException, ArtifactResolutionException;
throws ProjectBuildingException;
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
ArtifactMetadataSource artifactMetadataSource, List externalProfiles )
@ -55,7 +55,7 @@ public interface MavenProjectBuilder
*/
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException, ArtifactResolutionException;
throws ProjectBuildingException;
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository, List externalProfiles )
throws ProjectBuildingException;

View File

@ -21,25 +21,17 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@ -64,13 +56,6 @@ public class MavenMetadataSource
*/
private MavenXpp3Reader reader = new MavenXpp3Reader();
public MavenMetadataSource( ArtifactResolver artifactResolver, ArtifactFactory artifactFactory )
{
this.artifactResolver = artifactResolver;
this.mavenProjectBuilder = null;
this.artifactFactory = artifactFactory;
}
public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuilder projectBuilder,
ArtifactFactory artifactFactory )
{
@ -80,64 +65,27 @@ public class MavenMetadataSource
}
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException, ArtifactResolutionException
throws ArtifactMetadataRetrievalException
{
// TODO: only metadata is really needed - resolve as metadata
Artifact pomArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), artifact.getScope(), "pom" );
// TODO: this a very thin wrapper around a project builder - is it needed?
List dependencies = null;
// Use the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the
// associated artifacts.
if ( mavenProjectBuilder != null )
try
{
try
{
MavenProject p = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories,
localRepository );
dependencies = p.getDependencies();
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
}
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
MavenProject p = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories,
localRepository );
dependencies = p.getDependencies();
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
}
else
catch ( ProjectBuildingException e )
{
// there is code in plexus that uses this (though it shouldn't) so we
// need to be able to not have a project builder
// TODO: remove - which then makes this a very thin wrapper around a project builder - is it needed?
artifactResolver.resolve( pomArtifact, remoteRepositories, localRepository );
FileReader reader = null;
try
{
// String path = localRepository.pathOfMetadata( new ProjectArtifactMetadata( artifact, null ) );
// File file = new File( localRepository.getBasedir(), path );
File file = pomArtifact.getFile();
reader = new FileReader( file );
Model model = this.reader.read( reader );
dependencies = model.getDependencies();
}
catch ( FileNotFoundException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to find the metadata file", e );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to parse the metadata file", e );
}
finally
{
IOUtil.close( reader );
}
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
return createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() );
}