mirror of https://github.com/apache/maven.git
propogate more ArtifactResolutionExceptions directly
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169557 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b10ed41fca
commit
d64970af4d
|
@ -17,6 +17,7 @@ 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;
|
||||
|
@ -90,6 +91,10 @@ 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 )
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.artifact.metadata;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -29,5 +30,5 @@ import java.util.Set;
|
|||
public interface ArtifactMetadataSource
|
||||
{
|
||||
Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
throws ArtifactMetadataRetrievalException, ArtifactResolutionException;
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
package org.apache.maven.artifact.resolver;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
|
@ -33,19 +37,55 @@ public class ArtifactResolutionException
|
|||
|
||||
private String type;
|
||||
|
||||
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, Throwable t )
|
||||
private List remoteRepositories;
|
||||
|
||||
public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type,
|
||||
List remoteRepositories, Throwable t )
|
||||
{
|
||||
super( "Unable to resolve artifact " + groupId + ":" + artifactId + ":" + version + ":" + type + "\n" + message, t );
|
||||
super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories ), t );
|
||||
|
||||
this.groupId = groupId;
|
||||
this.artifactId = artifactId;
|
||||
this.type = type;
|
||||
this.version = version;
|
||||
this.remoteRepositories = remoteRepositories;
|
||||
}
|
||||
|
||||
public ArtifactResolutionException( String message, Artifact artifact, Throwable t )
|
||||
private static final String LS = System.getProperty( "line.separator" );
|
||||
|
||||
private static String constructMessage( String message, String groupId, String artifactId, String version,
|
||||
String type, List remoteRepositories )
|
||||
{
|
||||
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), t );
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append( message );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
sb.append( groupId + ":" + artifactId + ":" + version + ":" + type );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
sb.append( "from the specified remote repositories:" );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository remoteRepository = (ArtifactRepository) i.next();
|
||||
|
||||
sb.append( remoteRepository.getUrl() );
|
||||
if ( i.hasNext() )
|
||||
{
|
||||
sb.append( ", " );
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
|
||||
{
|
||||
this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
|
||||
remoteRepositories, t );
|
||||
}
|
||||
|
||||
public ArtifactResolutionException( String message, Throwable cause )
|
||||
|
@ -72,4 +112,9 @@ public class ArtifactResolutionException
|
|||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public List getRemoteRepositories()
|
||||
{
|
||||
return remoteRepositories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.artifact.resolver;
|
|||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class DefaultArtifactResolver
|
|||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( e.getMessage(), e );
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,49 +128,19 @@ public class DefaultArtifactResolver
|
|||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( artifactNotFound( localPath, remoteRepositories ), artifact, e );
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||
}
|
||||
catch ( TransferFailedException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, e );
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e );
|
||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String LS = System.getProperty( "line.separator" );
|
||||
|
||||
private String artifactNotFound( String path, List remoteRepositories )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append( "The artifact is not present locally as:" );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
sb.append( path );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
sb.append( "or in any of the specified remote repositories:" );
|
||||
sb.append( LS );
|
||||
sb.append( LS );
|
||||
|
||||
for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
|
||||
{
|
||||
ArtifactRepository remoteRepository = (ArtifactRepository) i.next();
|
||||
|
||||
sb.append( remoteRepository.getUrl() );
|
||||
if ( i.hasNext() )
|
||||
{
|
||||
sb.append( ", " );
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Transitive modes
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -182,14 +152,7 @@ public class DefaultArtifactResolver
|
|||
{
|
||||
ArtifactResolutionResult artifactResolutionResult;
|
||||
|
||||
try
|
||||
{
|
||||
artifactResolutionResult = collect( artifacts, localRepository, remoteRepositories, source, filter );
|
||||
}
|
||||
catch ( TransitiveArtifactResolutionException e )
|
||||
{
|
||||
throw new ArtifactResolutionException( "Error transitively resolving artifacts: ", e );
|
||||
}
|
||||
|
||||
for ( Iterator i = artifactResolutionResult.getArtifacts().values().iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -223,7 +186,7 @@ public class DefaultArtifactResolver
|
|||
private ArtifactResolutionResult collect( Set artifacts, ArtifactRepository localRepository,
|
||||
List remoteRepositories, ArtifactMetadataSource source,
|
||||
ArtifactFilter filter )
|
||||
throws TransitiveArtifactResolutionException
|
||||
throws ArtifactResolutionException
|
||||
{
|
||||
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
||||
|
||||
|
@ -303,8 +266,8 @@ public class DefaultArtifactResolver
|
|||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
throw new TransitiveArtifactResolutionException( "Error retrieving metadata [" + newArtifact +
|
||||
"] : ", e );
|
||||
throw new TransitiveArtifactResolutionException( e.getMessage(), newArtifact,
|
||||
remoteRepositories, e );
|
||||
}
|
||||
|
||||
// the pom for given dependency exisit we will add it to the
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.apache.maven.artifact.resolver;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
|
@ -21,16 +25,11 @@ package org.apache.maven.artifact.resolver;
|
|||
* @version $Id$
|
||||
*/
|
||||
public class TransitiveArtifactResolutionException
|
||||
extends Exception
|
||||
extends ArtifactResolutionException
|
||||
{
|
||||
public TransitiveArtifactResolutionException( String message )
|
||||
public TransitiveArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public TransitiveArtifactResolutionException( Throwable cause )
|
||||
{
|
||||
super( cause );
|
||||
super( message, artifact, remoteRepositories, t );
|
||||
}
|
||||
|
||||
public TransitiveArtifactResolutionException( String message, Throwable cause )
|
||||
|
|
|
@ -128,6 +128,10 @@ public class DefaultMaven
|
|||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ReactorException( "Error processing projects for the reactor: ", e );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -169,7 +173,7 @@ public class DefaultMaven
|
|||
}
|
||||
|
||||
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive )
|
||||
throws ProjectBuildingException, ReactorException, IOException
|
||||
throws ProjectBuildingException, ReactorException, IOException, ArtifactResolutionException
|
||||
{
|
||||
List projects = new ArrayList( files.size() );
|
||||
|
||||
|
@ -278,7 +282,7 @@ public class DefaultMaven
|
|||
}
|
||||
|
||||
public MavenProject getProject( File pom, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
if ( pom.exists() )
|
||||
{
|
||||
|
|
|
@ -252,7 +252,7 @@ public class DefaultPluginManager
|
|||
if ( groupId.equals( e.getGroupId() ) && artifactId.equals( e.getArtifactId() ) &&
|
||||
version.equals( e.getVersion() ) && "maven-plugin".equals( e.getType() ) )
|
||||
{
|
||||
throw new PluginNotFoundException( groupId, artifactId, version, e );
|
||||
throw new PluginNotFoundException( e );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -27,9 +27,9 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|||
public class PluginNotFoundException
|
||||
extends ArtifactResolutionException
|
||||
{
|
||||
public PluginNotFoundException( String groupId, String artifactId, String version, ArtifactResolutionException e )
|
||||
public PluginNotFoundException( ArtifactResolutionException e )
|
||||
{
|
||||
super( "Mojo could not be found - check that the goal name is correct", groupId, artifactId, version,
|
||||
"maven-plugin", e );
|
||||
super( "Mojo could not be found - check that the goal name is correct", e.getGroupId(), e.getArtifactId(),
|
||||
e.getVersion(), "maven-plugin", e.getRemoteRepositories(), e );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,12 @@ package org.apache.maven.usability;
|
|||
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.TransitiveArtifactResolutionException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ArtifactResolverDiagnoser
|
||||
implements ErrorDiagnoser
|
||||
{
|
||||
|
|
|
@ -137,13 +137,13 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
return buildFromSourceFile( projectDescriptor, localRepository );
|
||||
}
|
||||
|
||||
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
Model model = readModel( projectDescriptor );
|
||||
|
||||
|
@ -168,7 +168,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
|
||||
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
|
||||
|
@ -178,20 +178,13 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
Model model = getCachedModel( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
|
||||
if ( model == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
// TODO: can't assume artifact is a POM
|
||||
artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Unable to find artifact: " + artifact.toString(), e );
|
||||
}
|
||||
|
||||
// String path = localRepository.pathOfMetadata( new ProjectArtifactMetadata( artifact, null ) );
|
||||
// File file = new File( localRepository.getBasedir(), path );
|
||||
|
@ -202,7 +195,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
|
||||
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
Model superModel = getSuperModel();
|
||||
|
||||
|
@ -285,7 +278,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private MavenProject assembleLineage( Model model, LinkedList lineage, List aggregatedRemoteWagonRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories() ) );
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ public interface MavenProjectBuilder
|
|||
static final String STANDALONE_SUPERPOM_VERSION = "2.0";
|
||||
|
||||
MavenProject build( File project, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
throws ProjectBuildingException, ArtifactResolutionException;
|
||||
|
||||
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
|
||||
ArtifactMetadataSource artifactMetadataSource )
|
||||
|
@ -53,7 +53,7 @@ public interface MavenProjectBuilder
|
|||
*/
|
||||
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
throws ProjectBuildingException, ArtifactResolutionException;
|
||||
|
||||
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
|
|
|
@ -74,7 +74,7 @@ public class MavenMetadataSource
|
|||
}
|
||||
|
||||
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
throws ArtifactMetadataRetrievalException, ArtifactResolutionException
|
||||
{
|
||||
// TODO: only metadata is really needed - resolve as metadata
|
||||
artifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||
|
@ -103,14 +103,7 @@ public class MavenMetadataSource
|
|||
// 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?
|
||||
|
||||
try
|
||||
{
|
||||
artifactResolver.resolve( artifact, remoteRepositories, localRepository );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Error while resolving metadata artifact", e );
|
||||
}
|
||||
|
||||
FileReader reader = null;
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue