PR: MNG-122

cleanup artifact metadata retrieval exceptions

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320701 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-13 09:13:11 +00:00
parent 864371e12d
commit 562facf5d2
9 changed files with 152 additions and 177 deletions

View File

@ -118,8 +118,8 @@ public class DeployTask
} }
catch ( ArtifactDeploymentException e ) catch ( ArtifactDeploymentException e )
{ {
// TODO: deployment exception that does not give a trace throw new BuildException(
throw new BuildException( "Error deploying artifact", e ); "Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
} }

View File

@ -69,8 +69,8 @@ public class InstallTask
} }
catch ( ArtifactInstallationException e ) catch ( ArtifactInstallationException e )
{ {
// TODO: install exception that does not give a trace throw new BuildException(
throw new BuildException( "Error installing artifact", e ); "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
} }

View File

@ -440,7 +440,8 @@ public class DefaultPluginManager
} }
public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
ArtifactResolutionException
{ {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
@ -495,7 +496,8 @@ public class DefaultPluginManager
private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report, private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report,
MojoExecution mojoExecution ) MojoExecution mojoExecution )
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException,
ArtifactResolutionException
{ {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -570,7 +572,7 @@ public class DefaultPluginManager
private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, PlexusContainer pluginContainer, private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, PlexusContainer pluginContainer,
MavenProject project, MavenSession session ) MavenProject project, MavenSession session )
throws PluginConfigurationException, ArtifactNotFoundException throws ArtifactNotFoundException, PluginManagerException, ArtifactResolutionException
{ {
// if the plugin's already been used once, don't re-do this step... // if the plugin's already been used once, don't re-do this step...
// otherwise, we have to finish resolving the plugin's classpath and start the container. // otherwise, we have to finish resolving the plugin's classpath and start the container.
@ -578,12 +580,19 @@ public class DefaultPluginManager
{ {
Artifact pluginArtifact = (Artifact) pluginDescriptor.getArtifacts().get( 0 ); Artifact pluginArtifact = (Artifact) pluginDescriptor.getArtifacts().get( 0 );
try
{
ArtifactRepository localRepository = session.getLocalRepository(); ArtifactRepository localRepository = session.getLocalRepository();
ResolutionGroup resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository, ResolutionGroup resolutionGroup;
try
{
resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository,
project.getPluginArtifactRepositories() ); project.getPluginArtifactRepositories() );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new ArtifactResolutionException( "Unable to download metadata from repository for plugin '" +
pluginArtifact.getId() + "': " + e.getMessage(), pluginArtifact, e );
}
Set dependencies = new HashSet( resolutionGroup.getArtifacts() ); Set dependencies = new HashSet( resolutionGroup.getArtifacts() );
@ -605,8 +614,16 @@ public class DefaultPluginManager
{ {
artifact = project.replaceWithActiveArtifact( artifact ); artifact = project.replaceWithActiveArtifact( artifact );
try
{
pluginContainer.addJarResource( artifact.getFile() ); pluginContainer.addJarResource( artifact.getFile() );
} }
catch ( PlexusContainerException e )
{
throw new PluginManagerException( "Error adding plugin dependency '" +
artifact.getDependencyConflictId() + "' into plugin manager: " + e.getMessage(), e );
}
}
} }
pluginDescriptor.setClassRealm( pluginContainer.getContainerRealm() ); pluginDescriptor.setClassRealm( pluginContainer.getContainerRealm() );
@ -624,19 +641,6 @@ public class DefaultPluginManager
pluginDescriptor.setArtifacts( allResolved ); pluginDescriptor.setArtifacts( allResolved );
} }
catch ( ArtifactResolutionException e )
{
throw new PluginConfigurationException( pluginDescriptor, "Cannot resolve plugin dependencies", e );
}
catch ( PlexusContainerException e )
{
throw new PluginConfigurationException( pluginDescriptor, "Cannot start plugin container", e );
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new PluginConfigurationException( pluginDescriptor, "Cannot resolve plugin dependencies", e );
}
}
} }
private void resolveCoreArtifacts( List unresolved, ArtifactRepository localRepository, private void resolveCoreArtifacts( List unresolved, ArtifactRepository localRepository,

View File

@ -46,7 +46,8 @@ public interface PluginManager
InvalidDependencyVersionException, PluginManagerException; InvalidDependencyVersionException, PluginManagerException;
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException; throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
ArtifactResolutionException;
PluginDescriptor getPluginDescriptorForPrefix( String prefix ); PluginDescriptor getPluginDescriptorForPrefix( String prefix );

View File

@ -624,11 +624,13 @@ public class DefaultPluginVersionManager
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new PluginVersionResolutionException( groupId, artifactId, "Cannot read plugin registry", e ); throw new PluginVersionResolutionException( groupId, artifactId,
"Error readin plugin registry: " + e.getMessage(), e );
} }
catch ( XmlPullParserException e ) catch ( XmlPullParserException e )
{ {
throw new PluginVersionResolutionException( groupId, artifactId, "Cannot parse plugin registry", e ); throw new PluginVersionResolutionException( groupId, artifactId,
"Error parsing plugin registry: " + e.getMessage(), e );
} }
if ( pluginRegistry == null ) if ( pluginRegistry == null )
@ -648,6 +650,7 @@ public class DefaultPluginVersionManager
String version = null; String version = null;
// This takes the spec version and resolves a real version
try try
{ {
ResolutionGroup resolutionGroup = ResolutionGroup resolutionGroup =
@ -656,12 +659,27 @@ public class DefaultPluginVersionManager
// switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom // switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom
// artifact. // artifact.
artifact = resolutionGroup.getPomArtifact(); artifact = resolutionGroup.getPomArtifact();
}
catch ( ArtifactMetadataRetrievalException e )
{
throw new PluginVersionResolutionException( groupId, artifactId, e.getMessage(), e );
}
// make sure this artifact was actually resolved to a file in the repo... // make sure this artifact was actually resolved to a file in the repo...
if ( artifact.getFile() != null ) if ( artifact.getFile() != null )
{ {
MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project MavenProject pluginProject;
.getPluginArtifactRepositories(), localRepository, false ); try
{
pluginProject = mavenProjectBuilder.buildFromRepository( artifact,
project.getPluginArtifactRepositories(),
localRepository, false );
}
catch ( ProjectBuildingException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Unable to build resolve plugin project information", e );
}
boolean pluginValid = true; boolean pluginValid = true;
@ -686,16 +704,6 @@ public class DefaultPluginVersionManager
version = artifactVersion; version = artifactVersion;
} }
} }
}
catch ( ArtifactMetadataRetrievalException e )
{
getLogger().debug( "Failed to resolve " + metaVersionId + " version", e );
}
catch ( ProjectBuildingException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Unable to build resolve plugin project information", e );
}
return version; return version;
} }

View File

@ -156,8 +156,8 @@ public class DeployMojo
} }
catch ( ArtifactDeploymentException e ) catch ( ArtifactDeploymentException e )
{ {
// TODO: deployment exception that does not give a trace throw new MojoExecutionException(
throw new MojoExecutionException( "Error deploying artifact", e ); "Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
} }
} }

View File

@ -90,8 +90,8 @@ public class InstallFileMojo
} }
catch ( ArtifactInstallationException e ) catch ( ArtifactInstallationException e )
{ {
// TODO: install exception that does not give a trace throw new MojoExecutionException(
throw new MojoExecutionException( "Error installing artifact", e ); "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
} }
} }

View File

@ -125,8 +125,8 @@ public class InstallMojo
} }
catch ( ArtifactInstallationException e ) catch ( ArtifactInstallationException e )
{ {
// TODO: install exception that does not give a trace throw new MojoExecutionException(
throw new MojoExecutionException( "Error installing artifact", e ); "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
} }
} }

View File

@ -27,7 +27,6 @@ import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
@ -43,15 +42,9 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -118,7 +111,8 @@ public class MavenMetadataSource
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e ); throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file for artifact '" +
artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
} }
if ( project != null ) if ( project != null )
@ -172,8 +166,6 @@ public class MavenMetadataSource
// TODO: this could come straight from the project, negating the need to set it in the project itself? // TODO: this could come straight from the project, negating the need to set it in the project itself?
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() ); artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
try
{
ResolutionGroup result; ResolutionGroup result;
if ( project == null ) if ( project == null )
@ -190,35 +182,41 @@ public class MavenMetadataSource
{ {
// TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered // TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered
// or used the inherited scope (should that be passed to the buildFromRepository method above?) // or used the inherited scope (should that be passed to the buildFromRepository method above?)
try
{
artifacts = artifacts =
project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() ); project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() );
} }
catch ( InvalidDependencyVersionException e )
{
throw new ArtifactMetadataRetrievalException( "Error in metadata for artifact '" +
artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
}
}
List repositories = List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
result = new ResolutionGroup( pomArtifact, artifacts, repositories ); result = new ResolutionGroup( pomArtifact, artifacts, repositories );
} }
return result; return result;
} }
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
catch ( InvalidDependencyVersionException e )
{
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
}
}
private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories ) private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories )
throws ProjectBuildingException throws ArtifactMetadataRetrievalException
{ {
if ( superProject == null ) if ( superProject == null )
{
try
{ {
superProject = mavenProjectBuilder.buildStandaloneSuperProject( null ); superProject = mavenProjectBuilder.buildStandaloneSuperProject( null );
} }
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException(
"Unable to parse the Maven built-in model: " + e.getMessage(), e );
}
}
List repositories = new ArrayList(); List repositories = new ArrayList();
@ -372,40 +370,4 @@ public class MavenMetadataSource
return versions; return versions;
} }
/**
* @todo share with DefaultPluginMappingManager.
*/
private static Metadata readMetadata( File mappingFile )
throws ArtifactMetadataRetrievalException
{
Metadata result;
Reader fileReader = null;
try
{
fileReader = new FileReader( mappingFile );
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
result = mappingReader.read( fileReader );
}
catch ( FileNotFoundException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e );
}
catch ( IOException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e );
}
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( "Cannot parse version information from: " + mappingFile, e );
}
finally
{
IOUtil.close( fileReader );
}
return result;
}
} }