From 804e18cac094370bb0fe186bb85bc11725ed6b09 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 21 Apr 2005 14:17:14 +0000 Subject: [PATCH] improved error handling for failed downloads git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164065 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/ArtifactResolutionException.java | 41 +++++++++++++++++-- .../resolver/DefaultArtifactResolver.java | 4 +- .../lifecycle/DefaultLifecycleExecutor.java | 12 ++---- .../maven/plugin/DefaultPluginManager.java | 14 +++++-- .../apache/maven/plugin/PluginManager.java | 4 +- .../maven/plugin/PluginNotFoundException.java | 7 ++-- 6 files changed, 59 insertions(+), 23 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java index 0a49017959..b83f8f059e 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java @@ -1,5 +1,7 @@ package org.apache.maven.artifact.resolver; +import org.apache.maven.artifact.Artifact; + /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -23,20 +25,51 @@ package org.apache.maven.artifact.resolver; public class ArtifactResolutionException extends Exception { + private String groupId; + private String artifactId; - public ArtifactResolutionException( String message ) + private String version; + + private String type; + + public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, Throwable t ) { - super( message ); + super( "Unable to resolve artifact " + groupId + ":" + artifactId + ":" + version + ":" + type + "\n" + message, t ); + + this.groupId = groupId; + this.artifactId = artifactId; + this.type = type; + this.version = version; } - public ArtifactResolutionException( Throwable cause ) + public ArtifactResolutionException( String message, Artifact artifact, Throwable t ) { - super( cause ); + this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), t ); } public ArtifactResolutionException( String message, Throwable cause ) { super( message, cause ); } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public String getType() + { + return type; + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 7d5bbb4854..d3883e89f1 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -128,11 +128,11 @@ public class DefaultArtifactResolver } catch ( ResourceDoesNotExistException e ) { - throw new ArtifactResolutionException( artifactNotFound( localPath, remoteRepositories ), e ); + throw new ArtifactResolutionException( artifactNotFound( localPath, remoteRepositories ), artifact, e ); } catch ( TransferFailedException e ) { - throw new ArtifactResolutionException( "Error downloading artifact " + artifact, e ); + throw new ArtifactResolutionException( e.getMessage(), artifact, e ); } catch ( ArtifactMetadataRetrievalException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index d16e1f80b6..9d7b615b31 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -95,10 +95,6 @@ public class DefaultLifecycleExecutor { response.setException( e ); } - catch ( PluginNotFoundException e ) - { - response.setException( e ); - } catch ( ArtifactHandlerNotFoundException e ) { response.setException( e ); @@ -233,7 +229,7 @@ public class DefaultLifecycleExecutor } private void processPluginConfiguration( MavenProject project, MavenSession mavenSession, Map phaseMap ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, ArtifactResolutionException { for ( Iterator i = project.getPlugins().iterator(); i.hasNext(); ) { @@ -251,7 +247,7 @@ public class DefaultLifecycleExecutor * @param session */ private void processPluginPhases( Plugin plugin, MavenSession session, Map phaseMap ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, ArtifactResolutionException { String groupId = plugin.getGroupId(); @@ -336,7 +332,7 @@ public class DefaultLifecycleExecutor } private void processGoalChain( String task, MavenSession session, Map phaseMap ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, ArtifactResolutionException { if ( phaseMap.containsKey( task ) ) { @@ -368,7 +364,7 @@ public class DefaultLifecycleExecutor } private void verifyMojoPhase( String task, MavenSession session, Map phaseMap ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, ArtifactResolutionException { MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 670bee5ab0..c904e58c8c 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -199,7 +199,7 @@ public class DefaultPluginManager } public void verifyPluginForGoal( String goalName, MavenSession session ) - throws PluginNotFoundException, PluginManagerException + throws ArtifactResolutionException, PluginManagerException { String pluginId = PluginDescriptor.getPluginIdFromGoal( goalName ); @@ -207,7 +207,7 @@ public class DefaultPluginManager } public void verifyPlugin( String groupId, String artifactId, MavenSession session ) - throws PluginNotFoundException, PluginManagerException + throws ArtifactResolutionException, PluginManagerException { if ( !isPluginInstalled( groupId, artifactId ) ) { @@ -258,7 +258,15 @@ public class DefaultPluginManager } catch ( ArtifactResolutionException e ) { - throw new PluginNotFoundException( groupId, artifactId, version, e ); + 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 ); + } + else + { + throw e; + } } catch ( ComponentLookupException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index 6042f7b5ae..eb907a67e0 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -36,10 +36,10 @@ public interface PluginManager MojoDescriptor getMojoDescriptor( String goalId ); void verifyPluginForGoal( String goalName, MavenSession session ) - throws PluginNotFoundException, PluginManagerException; + throws ArtifactResolutionException, PluginManagerException; void verifyPlugin( String groupId, String artifactId, MavenSession session ) - throws PluginNotFoundException, PluginManagerException; + throws ArtifactResolutionException, PluginManagerException; PluginDescriptor getPluginDescriptor( String groupId, String artifactId ); } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginNotFoundException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginNotFoundException.java index 7d367f8673..7fc2fadb13 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginNotFoundException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginNotFoundException.java @@ -25,12 +25,11 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; * @version $Id$ */ public class PluginNotFoundException - extends Throwable + extends ArtifactResolutionException { public PluginNotFoundException( String groupId, String artifactId, String version, ArtifactResolutionException e ) { - super( - "Plugin could not found in any remote repositories: [" + groupId + ":" + artifactId + ":" + version + "]", - e ); + super( "Plugin could not be found - check that the goal name is correct", groupId, artifactId, version, + "maven-plugin", e ); } }