mirror of https://github.com/apache/maven.git
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:
parent
864371e12d
commit
562facf5d2
|
@ -118,8 +118,8 @@ public class DeployTask
|
|||
}
|
||||
catch ( ArtifactDeploymentException e )
|
||||
{
|
||||
// TODO: deployment exception that does not give a trace
|
||||
throw new BuildException( "Error deploying artifact", e );
|
||||
throw new BuildException(
|
||||
"Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,8 @@ public class InstallTask
|
|||
}
|
||||
catch ( ArtifactInstallationException e )
|
||||
{
|
||||
// TODO: install exception that does not give a trace
|
||||
throw new BuildException( "Error installing artifact", e );
|
||||
throw new BuildException(
|
||||
"Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -440,7 +440,8 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
|
||||
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException
|
||||
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
|
||||
ArtifactResolutionException
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||
PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor();
|
||||
|
@ -495,7 +496,8 @@ public class DefaultPluginManager
|
|||
|
||||
private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report,
|
||||
MojoExecution mojoExecution )
|
||||
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException
|
||||
throws PluginConfigurationException, ArtifactNotFoundException, PluginManagerException,
|
||||
ArtifactResolutionException
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||
|
||||
|
@ -570,7 +572,7 @@ public class DefaultPluginManager
|
|||
|
||||
private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor, PlexusContainer pluginContainer,
|
||||
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...
|
||||
// otherwise, we have to finish resolving the plugin's classpath and start the container.
|
||||
|
@ -578,64 +580,66 @@ public class DefaultPluginManager
|
|||
{
|
||||
Artifact pluginArtifact = (Artifact) pluginDescriptor.getArtifacts().get( 0 );
|
||||
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
||||
ResolutionGroup resolutionGroup;
|
||||
try
|
||||
{
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
||||
ResolutionGroup resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository,
|
||||
project.getPluginArtifactRepositories() );
|
||||
|
||||
Set dependencies = new HashSet( resolutionGroup.getArtifacts() );
|
||||
|
||||
dependencies.addAll( pluginDescriptor.getIntroducedDependencyArtifacts() );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
|
||||
localRepository,
|
||||
resolutionGroup.getResolutionRepositories(),
|
||||
artifactMetadataSource,
|
||||
artifactFilter );
|
||||
|
||||
Set resolved = result.getArtifacts();
|
||||
|
||||
for ( Iterator it = resolved.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
|
||||
if ( !artifact.equals( pluginArtifact ) )
|
||||
{
|
||||
artifact = project.replaceWithActiveArtifact( artifact );
|
||||
|
||||
pluginContainer.addJarResource( artifact.getFile() );
|
||||
}
|
||||
}
|
||||
|
||||
pluginDescriptor.setClassRealm( pluginContainer.getContainerRealm() );
|
||||
|
||||
List unresolved = new ArrayList( dependencies );
|
||||
|
||||
unresolved.removeAll( resolved );
|
||||
|
||||
resolveCoreArtifacts( unresolved, localRepository, resolutionGroup.getResolutionRepositories() );
|
||||
|
||||
List allResolved = new ArrayList( resolved.size() + unresolved.size() );
|
||||
|
||||
allResolved.addAll( resolved );
|
||||
allResolved.addAll( unresolved );
|
||||
|
||||
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 );
|
||||
resolutionGroup = artifactMetadataSource.retrieve( pluginArtifact, localRepository,
|
||||
project.getPluginArtifactRepositories() );
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
throw new PluginConfigurationException( pluginDescriptor, "Cannot resolve plugin dependencies", e );
|
||||
throw new ArtifactResolutionException( "Unable to download metadata from repository for plugin '" +
|
||||
pluginArtifact.getId() + "': " + e.getMessage(), pluginArtifact, e );
|
||||
}
|
||||
|
||||
Set dependencies = new HashSet( resolutionGroup.getArtifacts() );
|
||||
|
||||
dependencies.addAll( pluginDescriptor.getIntroducedDependencyArtifacts() );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
|
||||
localRepository,
|
||||
resolutionGroup.getResolutionRepositories(),
|
||||
artifactMetadataSource,
|
||||
artifactFilter );
|
||||
|
||||
Set resolved = result.getArtifacts();
|
||||
|
||||
for ( Iterator it = resolved.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
|
||||
if ( !artifact.equals( pluginArtifact ) )
|
||||
{
|
||||
artifact = project.replaceWithActiveArtifact( artifact );
|
||||
|
||||
try
|
||||
{
|
||||
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() );
|
||||
|
||||
List unresolved = new ArrayList( dependencies );
|
||||
|
||||
unresolved.removeAll( resolved );
|
||||
|
||||
resolveCoreArtifacts( unresolved, localRepository, resolutionGroup.getResolutionRepositories() );
|
||||
|
||||
List allResolved = new ArrayList( resolved.size() + unresolved.size() );
|
||||
|
||||
allResolved.addAll( resolved );
|
||||
allResolved.addAll( unresolved );
|
||||
|
||||
pluginDescriptor.setArtifacts( allResolved );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,8 @@ public interface PluginManager
|
|||
InvalidDependencyVersionException, PluginManagerException;
|
||||
|
||||
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
|
||||
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException;
|
||||
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
|
||||
ArtifactResolutionException;
|
||||
|
||||
PluginDescriptor getPluginDescriptorForPrefix( String prefix );
|
||||
|
||||
|
|
|
@ -624,11 +624,13 @@ public class DefaultPluginVersionManager
|
|||
}
|
||||
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 )
|
||||
{
|
||||
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 )
|
||||
|
@ -648,6 +650,7 @@ public class DefaultPluginVersionManager
|
|||
|
||||
String version = null;
|
||||
|
||||
// This takes the spec version and resolves a real version
|
||||
try
|
||||
{
|
||||
ResolutionGroup resolutionGroup =
|
||||
|
@ -656,45 +659,50 @@ public class DefaultPluginVersionManager
|
|||
// switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom
|
||||
// artifact.
|
||||
artifact = resolutionGroup.getPomArtifact();
|
||||
|
||||
// make sure this artifact was actually resolved to a file in the repo...
|
||||
if ( artifact.getFile() != null )
|
||||
{
|
||||
MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project
|
||||
.getPluginArtifactRepositories(), localRepository, false );
|
||||
|
||||
boolean pluginValid = true;
|
||||
|
||||
// if we don't have the required Maven version, then ignore an update
|
||||
if ( pluginProject.getPrerequisites() != null && pluginProject.getPrerequisites().getMaven() != null )
|
||||
{
|
||||
DefaultArtifactVersion requiredVersion =
|
||||
new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
|
||||
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
|
||||
{
|
||||
getLogger().info( "Ignoring available plugin update: " + artifact.getVersion() +
|
||||
" as it requires Maven version " + requiredVersion );
|
||||
pluginValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
String artifactVersion = artifact.getVersion();
|
||||
|
||||
if ( pluginValid && !metaVersionId.equals( artifactVersion ) )
|
||||
{
|
||||
version = artifactVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ArtifactMetadataRetrievalException e )
|
||||
{
|
||||
getLogger().debug( "Failed to resolve " + metaVersionId + " version", e );
|
||||
throw new PluginVersionResolutionException( groupId, artifactId, e.getMessage(), e );
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
|
||||
// make sure this artifact was actually resolved to a file in the repo...
|
||||
if ( artifact.getFile() != null )
|
||||
{
|
||||
throw new PluginVersionResolutionException( groupId, artifactId,
|
||||
"Unable to build resolve plugin project information", e );
|
||||
MavenProject pluginProject;
|
||||
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;
|
||||
|
||||
// if we don't have the required Maven version, then ignore an update
|
||||
if ( pluginProject.getPrerequisites() != null && pluginProject.getPrerequisites().getMaven() != null )
|
||||
{
|
||||
DefaultArtifactVersion requiredVersion =
|
||||
new DefaultArtifactVersion( pluginProject.getPrerequisites().getMaven() );
|
||||
|
||||
if ( runtimeInformation.getApplicationVersion().compareTo( requiredVersion ) < 0 )
|
||||
{
|
||||
getLogger().info( "Ignoring available plugin update: " + artifact.getVersion() +
|
||||
" as it requires Maven version " + requiredVersion );
|
||||
pluginValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
String artifactVersion = artifact.getVersion();
|
||||
|
||||
if ( pluginValid && !metaVersionId.equals( artifactVersion ) )
|
||||
{
|
||||
version = artifactVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
|
|
|
@ -156,8 +156,8 @@ public class DeployMojo
|
|||
}
|
||||
catch ( ArtifactDeploymentException e )
|
||||
{
|
||||
// TODO: deployment exception that does not give a trace
|
||||
throw new MojoExecutionException( "Error deploying artifact", e );
|
||||
throw new MojoExecutionException(
|
||||
"Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ import java.io.File;
|
|||
* @version $Id$
|
||||
* @goal install-file
|
||||
* @requiresProject false
|
||||
* @aggregator
|
||||
* @aggregator
|
||||
*/
|
||||
public class InstallFileMojo
|
||||
extends AbstractInstallMojo
|
||||
|
@ -90,8 +90,8 @@ public class InstallFileMojo
|
|||
}
|
||||
catch ( ArtifactInstallationException e )
|
||||
{
|
||||
// TODO: install exception that does not give a trace
|
||||
throw new MojoExecutionException( "Error installing artifact", e );
|
||||
throw new MojoExecutionException(
|
||||
"Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ public class InstallMojo
|
|||
}
|
||||
catch ( ArtifactInstallationException e )
|
||||
{
|
||||
// TODO: install exception that does not give a trace
|
||||
throw new MojoExecutionException( "Error installing artifact", e );
|
||||
throw new MojoExecutionException(
|
||||
"Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.RepositoryMetadataManager;
|
||||
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.ArtifactFilter;
|
||||
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.ProjectBuildingException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
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.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -118,7 +111,8 @@ public class MavenMetadataSource
|
|||
}
|
||||
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 )
|
||||
|
@ -172,52 +166,56 @@ public class MavenMetadataSource
|
|||
// TODO: this could come straight from the project, negating the need to set it in the project itself?
|
||||
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
|
||||
|
||||
try
|
||||
{
|
||||
ResolutionGroup result;
|
||||
ResolutionGroup result;
|
||||
|
||||
if ( project == null )
|
||||
if ( project == null )
|
||||
{
|
||||
// if the project is null, we encountered an invalid model (read: m1 POM)
|
||||
// we'll just return an empty resolution group.
|
||||
// or used the inherited scope (should that be passed to the buildFromRepository method above?)
|
||||
result = new ResolutionGroup( pomArtifact, Collections.EMPTY_SET, Collections.EMPTY_LIST );
|
||||
}
|
||||
else
|
||||
{
|
||||
Set artifacts = Collections.EMPTY_SET;
|
||||
if ( !artifact.getArtifactHandler().isIncludesDependencies() )
|
||||
{
|
||||
// if the project is null, we encountered an invalid model (read: m1 POM)
|
||||
// we'll just return an empty resolution group.
|
||||
// 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?)
|
||||
result = new ResolutionGroup( pomArtifact, Collections.EMPTY_SET, Collections.EMPTY_LIST );
|
||||
}
|
||||
else
|
||||
{
|
||||
Set artifacts = Collections.EMPTY_SET;
|
||||
if ( !artifact.getArtifactHandler().isIncludesDependencies() )
|
||||
try
|
||||
{
|
||||
// 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?)
|
||||
artifacts =
|
||||
project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() );
|
||||
}
|
||||
|
||||
List repositories =
|
||||
aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
|
||||
|
||||
result = new ResolutionGroup( pomArtifact, artifacts, repositories );
|
||||
catch ( InvalidDependencyVersionException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Error in metadata for artifact '" +
|
||||
artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
|
||||
|
||||
result = new ResolutionGroup( pomArtifact, artifacts, repositories );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories )
|
||||
throws ProjectBuildingException
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
if ( superProject == null )
|
||||
{
|
||||
superProject = mavenProjectBuilder.buildStandaloneSuperProject( null );
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
@ -372,40 +370,4 @@ public class MavenMetadataSource
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue