PR: MNG-122

cleanup artifact/plugin not found exception

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-13 09:51:36 +00:00
parent 562facf5d2
commit 1f97932050
9 changed files with 118 additions and 116 deletions

View File

@ -102,11 +102,11 @@ public class DefaultArchetype
}
catch ( ArtifactResolutionException e )
{
throw new ArchetypeDescriptorException( "Cannot download archetype.", e );
throw new ArchetypeDescriptorException( "Error attempting to download archetype: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new ArchetypeNotFoundException( "Cannot download archetype.", e );
throw new ArchetypeNotFoundException( "Archetype does not exist: " + e.getMessage(), e );
}
// ---------------------------------------------------------------------

View File

@ -166,12 +166,11 @@ public class DependenciesTask
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Unable to resolve artifact", e );
throw new BuildException( "Unable to resolve artifact: " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
// TODO: improve handling
throw new BuildException( "Unable to locate artifact", e );
throw new BuildException( "Dependency not found: " + e.getMessage(), e );
}
catch ( InvalidDependencyVersionException e )
{

View File

@ -103,11 +103,12 @@ public class InstallWagonProviderTask
}
catch ( ArtifactResolutionException e )
{
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
throw new BuildException( "Error downloading wagon provider from the remote repository: " + e.getMessage(),
e );
}
catch ( ArtifactNotFoundException e )
{
throw new BuildException( "Unable to locate wagon provider in remote repository", e );
throw new BuildException( "Unable to locate wagon provider in remote repository: " + e.getMessage(), e );
}
log( "Installing provider: " + providerArtifact );

View File

@ -42,6 +42,7 @@ import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.lifecycle.Execution;
@ -168,6 +169,10 @@ public class DefaultLifecycleExecutor
{
response.setException( e );
}
catch ( PluginNotFoundException e )
{
response.setException( e );
}
finally
{
response.setFinish( new Date() );
@ -177,7 +182,8 @@ public class DefaultLifecycleExecutor
}
private void findExtensions( MavenSession session )
throws ArtifactNotFoundException, ArtifactResolutionException, LifecycleExecutionException
throws ArtifactNotFoundException, ArtifactResolutionException, LifecycleExecutionException,
PluginNotFoundException
{
for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
{
@ -205,7 +211,7 @@ public class DefaultLifecycleExecutor
MavenProject rootProject, EventDispatcher dispatcher,
MavenExecutionResponse response )
throws ArtifactNotFoundException, MojoExecutionException, LifecycleExecutionException, MojoFailureException,
ArtifactResolutionException
ArtifactResolutionException, PluginNotFoundException
{
for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
{
@ -341,7 +347,7 @@ public class DefaultLifecycleExecutor
MavenExecutionResponse response, EventDispatcher dispatcher,
String event, ReactorManager rm, long buildStartTime, String target )
throws LifecycleExecutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException,
ArtifactResolutionException
ArtifactResolutionException, PluginNotFoundException
{
try
{
@ -423,7 +429,8 @@ public class DefaultLifecycleExecutor
}
private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )
throws LifecycleExecutionException
throws LifecycleExecutionException, ArtifactNotFoundException, PluginNotFoundException,
ArtifactResolutionException
{
List segments = new ArrayList();
@ -454,24 +461,8 @@ public class DefaultLifecycleExecutor
}
else
{
MojoDescriptor mojo = null;
try
{
// definitely a CLI goal, can use prefix
mojo = getMojoDescriptor( task, session, project, task, true );
}
catch ( ArtifactResolutionException e )
{
getLogger().info(
"Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." );
getLogger().debug( "", e );
}
catch ( ArtifactNotFoundException e )
{
getLogger().info(
"Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." );
getLogger().debug( "", e );
}
// definitely a CLI goal, can use prefix
MojoDescriptor mojo = getMojoDescriptor( task, session, project, task, true );
// if the mojo descriptor was found, determine aggregator status according to:
// 1. whether the mojo declares itself an aggregator
@ -526,7 +517,7 @@ public class DefaultLifecycleExecutor
private void executeGoal( String task, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, ArtifactNotFoundException, MojoExecutionException,
ArtifactResolutionException, MojoFailureException, InvalidDependencyVersionException
ArtifactResolutionException, MojoFailureException, InvalidDependencyVersionException, PluginNotFoundException
{
if ( getPhaseToLifecycleMap().containsKey( task ) )
{
@ -545,7 +536,7 @@ public class DefaultLifecycleExecutor
private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
MavenProject project, MavenExecutionResponse response, Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
{
List goals = processGoalChain( task, lifecycleMappings, lifecycle );
@ -562,7 +553,7 @@ public class DefaultLifecycleExecutor
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
{
// guaranteed to come from the CLI and not be part of a phase
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
@ -571,7 +562,7 @@ public class DefaultLifecycleExecutor
private void executeGoals( List goals, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
{
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
@ -615,7 +606,8 @@ public class DefaultLifecycleExecutor
}
private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
List reportPlugins = project.getReportPlugins();
@ -701,7 +693,8 @@ public class DefaultLifecycleExecutor
private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
MojoExecution mojoExecution )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
{
PluginDescriptor pluginDescriptor = verifyReportPlugin( reportPlugin, project, session );
@ -751,7 +744,7 @@ public class DefaultLifecycleExecutor
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
@ -782,7 +775,7 @@ public class DefaultLifecycleExecutor
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -918,7 +911,8 @@ public class DefaultLifecycleExecutor
private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project,
Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
// first, bind those associated with the packaging
Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project, lifecycle );
@ -936,7 +930,8 @@ public class DefaultLifecycleExecutor
private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project,
Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
Map mappings = findMappingsForLifecycle( session, project, lifecycle );
@ -979,7 +974,8 @@ public class DefaultLifecycleExecutor
}
private Map findMappingsForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
String packaging = project.getPackaging();
Map mappings = null;
@ -1028,7 +1024,8 @@ public class DefaultLifecycleExecutor
private Object findExtension( MavenProject project, String role, String roleHint, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
{
Object pluginComponent = null;
@ -1064,7 +1061,8 @@ public class DefaultLifecycleExecutor
* lookup directly, or have them passed in
*/
private Map findArtifactTypeHandlers( MavenProject project, Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
{
Map map = new HashMap();
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
@ -1114,7 +1112,8 @@ public class DefaultLifecycleExecutor
* @param session
*/
private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap, MavenProject project )
throws LifecycleExecutionException, ArtifactResolutionException, ArtifactNotFoundException
throws LifecycleExecutionException, ArtifactResolutionException, ArtifactNotFoundException,
PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
Settings settings = session.getSettings();
@ -1149,7 +1148,8 @@ public class DefaultLifecycleExecutor
private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
try
@ -1177,7 +1177,8 @@ public class DefaultLifecycleExecutor
}
private PluginDescriptor verifyReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
try
@ -1291,7 +1292,8 @@ public class DefaultLifecycleExecutor
private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project,
String invokedVia, boolean canUsePrefix )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException
throws LifecycleExecutionException, ArtifactNotFoundException, PluginNotFoundException,
ArtifactResolutionException
{
String goal;
Plugin plugin;

View File

@ -147,7 +147,7 @@ public class DefaultPluginManager
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
@ -164,7 +164,7 @@ public class DefaultPluginManager
private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project,
ArtifactRepository localRepository )
throws PluginVersionResolutionException, ArtifactNotFoundException, ArtifactResolutionException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException
{
// TODO: this might result in an artifact "RELEASE" being resolved continuously
// FIXME: need to find out how a plugin gets marked as 'installed'
@ -457,7 +457,7 @@ public class DefaultPluginManager
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException
{
String version = reportPlugin.getVersion();

View File

@ -56,11 +56,11 @@ public interface PluginManager
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException;
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException;
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException;
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws PluginManagerException, ComponentLookupException;

View File

@ -16,6 +16,7 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
/**
@ -25,11 +26,11 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
* @version $Id$
*/
public class PluginNotFoundException
extends ArtifactNotFoundException
extends AbstractArtifactResolutionException
{
public PluginNotFoundException( ArtifactNotFoundException e )
{
super( "Plugin could not be found - check that the goal name is correct", e.getGroupId(), e.getArtifactId(),
e.getVersion(), "maven-plugin", e.getRemoteRepositories(), e.getDownloadUrl(), e.getCause() );
super( "Plugin could not be found - check that the goal name is correct: " + e.getMessage(), e.getGroupId(),
e.getArtifactId(), e.getVersion(), "maven-plugin", e.getRemoteRepositories(), null, e.getCause() );
}
}

View File

@ -28,6 +28,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -321,8 +322,7 @@ public class DescribeMojo
}
catch ( ArtifactNotFoundException e )
{
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
throw new MojoExecutionException( "Plugin dependency does not exist: " + e.getMessage(), e );
}
catch ( InvalidVersionSpecificationException e )
{
@ -334,6 +334,10 @@ public class DescribeMojo
throw new MojoExecutionException( "Error retrieving plugin descriptor for:\n\ngroupId: \'" + groupId +
"\'\nartifactId: \'" + artifactId + "\'\nversion: \'" + version + "\'\n\n", e );
}
catch ( PluginNotFoundException e )
{
throw new MojoExecutionException( "Plugin does not exist: " + e.getMessage(), e );
}
}
return descriptor;

View File

@ -380,73 +380,30 @@ public class DefaultMavenProjectBuilder
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
File file = projectArtifact.getFile();
// TODO: how can this not be true?
if ( projectArtifact.isResolved() )
model = readModel( projectId, file );
String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE;
DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement != null )
{
model = readModel( projectId, file );
downloadUrl = distributionManagement.getDownloadUrl();
String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE;
DistributionManagement distributionManagement = model.getDistributionManagement();
if ( distributionManagement != null )
{
downloadUrl = distributionManagement.getDownloadUrl();
status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
}
// TODO: configurable actions dependant on status
if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
{
// use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
// TODO: re-enable [MNG-798/865]
policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
{
getLogger().info( projectArtifact.getArtifactId() +
": updating metadata due to status of '" + status + "'" );
try
{
projectArtifact.setResolved( false );
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
localRepository );
}
catch ( ArtifactResolutionException e )
{
getLogger().warn( "Error updating POM - using existing version" );
getLogger().debug( "Cause", e );
}
catch ( ArtifactNotFoundException e )
{
getLogger().warn( "Error updating POM - not found. Removing local copy." );
getLogger().debug( "Cause", e );
file.delete();
throw e;
}
}
}
// TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
// Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
if ( downloadUrl != null )
{
projectArtifact.setDownloadUrl( downloadUrl );
}
else
{
projectArtifact.setDownloadUrl( model.getUrl() );
}
status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
}
else if ( allowStubModel )
checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository );
// TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
// Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
if ( downloadUrl != null )
{
model = createStubModel( projectArtifact );
projectArtifact.setDownloadUrl( downloadUrl );
}
else
{
throw new ProjectBuildingException( projectId, "POM could not be resolved from the repository" );
projectArtifact.setDownloadUrl( model.getUrl() );
}
}
catch ( ArtifactResolutionException e )
@ -457,6 +414,7 @@ public class DefaultMavenProjectBuilder
{
if ( allowStubModel )
{
getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
model = createStubModel( projectArtifact );
}
else
@ -473,6 +431,43 @@ public class DefaultMavenProjectBuilder
return model;
}
private void checkStatusAndUpdate( Artifact projectArtifact, ArtifactStatus status, File file,
List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ArtifactNotFoundException
{
// TODO: configurable actions dependant on status
if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
{
// use default policy (enabled, daily update, warn on bad checksum)
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
// TODO: re-enable [MNG-798/865]
policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
{
getLogger().info(
projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
try
{
projectArtifact.setResolved( false );
artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
getLogger().warn( "Error updating POM - using existing version" );
getLogger().debug( "Cause", e );
}
catch ( ArtifactNotFoundException e )
{
getLogger().warn( "Error updating POM - not found. Removing local copy." );
getLogger().debug( "Cause", e );
file.delete();
throw e;
}
}
}
}
private Model createStubModel( Artifact projectArtifact )
{
getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact + " *****\n" );