From d6ad00a1f3534c5c8dd11a4869398531bf2d9cf9 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 16 Oct 2009 11:39:40 +0000 Subject: [PATCH] o Improved some exception messages git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@825852 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/DefaultMaven.java | 20 ++++-- .../plugin/PluginExecutionException.java | 27 ++++++-- .../NoPluginFoundForPrefixException.java | 37 ++++++++++- .../internal/DefaultPluginPrefixResolver.java | 3 +- .../PluginVersionResolutionException.java | 65 ++++++++++++------- .../DefaultPluginVersionResolver.java | 3 +- .../java/org/apache/maven/cli/MavenCli.java | 11 ++++ 7 files changed, 127 insertions(+), 39 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 92c8c0f950..a00cf57247 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -91,6 +91,18 @@ public class DefaultMaven } public MavenExecutionResult execute( MavenExecutionRequest request ) + { + try + { + return doExecute( request ); + } + catch ( OutOfMemoryError e ) + { + return processResult( new DefaultMavenExecutionResult(), e ); + } + } + + private MavenExecutionResult doExecute( MavenExecutionRequest request ) { //TODO: Need a general way to inject standard properties if ( request.getStartTime() != null ) @@ -133,10 +145,6 @@ public class DefaultMaven { return processResult( result, e ); } - catch ( MavenExecutionException e ) - { - return processResult( result, e ); - } session.setProjects( projects ); @@ -286,7 +294,7 @@ public class DefaultMaven } private List getProjectsForMavenReactor( MavenExecutionRequest request ) - throws MavenExecutionException, ProjectBuildingException + throws ProjectBuildingException { List projects = new ArrayList(); @@ -348,7 +356,7 @@ public class DefaultMaven } private void collectProjects( List projects, List files, MavenExecutionRequest request ) - throws MavenExecutionException, ProjectBuildingException + throws ProjectBuildingException { ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest(); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java index 3a3e5a3d4f..a6860eac44 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionException.java @@ -42,13 +42,13 @@ public class PluginExecutionException public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, Exception cause ) { - super( mojoExecution.getMojoDescriptor(), project, constructMessage( cause ), cause ); + super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause ); this.mojoExecution = mojoExecution; } public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, DuplicateArtifactAttachmentException cause ) { - super( mojoExecution.getMojoDescriptor(), project, constructMessage( cause ), cause ); + super( mojoExecution.getMojoDescriptor(), project, constructMessage( mojoExecution, cause ), cause ); this.mojoExecution = mojoExecution; } @@ -57,16 +57,31 @@ public class PluginExecutionException return mojoExecution; } - private static String constructMessage( Throwable cause ) + private static String constructMessage( MojoExecution mojoExecution, Throwable cause ) { - if ( cause != null ) + String message; + + if ( mojoExecution != null ) { - return "Mojo execution failed: " + cause.getMessage(); + message = + "Execution " + mojoExecution.getExecutionId() + " of goal " + mojoExecution.getMojoDescriptor().getId() + + " failed"; } else { - return "Mojo execution failed."; + message = "Mojo execution failed"; } + + if ( cause != null ) + { + message = ": " + cause.getMessage(); + } + else + { + message += "."; + } + + return message; } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java b/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java index fa96a17883..5c24c37347 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/prefix/NoPluginFoundForPrefixException.java @@ -32,11 +32,42 @@ public class NoPluginFoundForPrefixException private List remoteRepositories; - public NoPluginFoundForPrefixException( String prefix, ArtifactRepository localRepository, List remoteRepositories ) + public NoPluginFoundForPrefixException( String prefix, List pluginGroups, + ArtifactRepository localRepository, + List remoteRepositories ) { - super( "No plugin found for prefix '" + prefix + "'" ); + super( "No plugin found for prefix '" + prefix + "' in the current project and in the plugin groups " + + pluginGroups + " available from the repositories " + format( localRepository, remoteRepositories ) ); this.prefix = prefix; this.localRepository = localRepository; - this.remoteRepositories = remoteRepositories; + this.remoteRepositories = remoteRepositories; } + + private static String format( ArtifactRepository localRepository, List remoteRepositories ) + { + String repos = "["; + + if ( localRepository != null ) + { + repos += localRepository.getId() + " (" + localRepository.getBasedir() + ")"; + } + + if ( remoteRepositories != null && !remoteRepositories.isEmpty() ) + { + repos += ", "; + + for ( ArtifactRepository repository : remoteRepositories ) + { + if ( repository != null ) + { + repos += repository.getId() + " (" + repository.getUrl() + ")"; + } + } + } + + repos += "]"; + + return repos; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java index eb0430a376..e77234d783 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java @@ -76,7 +76,8 @@ public class DefaultPluginPrefixResolver if ( result == null ) { - throw new NoPluginFoundForPrefixException( request.getPrefix(), request.getLocalRepository(), + throw new NoPluginFoundForPrefixException( request.getPrefix(), request.getPluginGroups(), + request.getLocalRepository(), request.getRemoteRepositories() ); } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java index dda533eaef..76f317207a 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionResolutionException.java @@ -19,8 +19,9 @@ package org.apache.maven.plugin.version; * under the License. */ -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException; +import java.util.List; + +import org.apache.maven.artifact.repository.ArtifactRepository; public class PluginVersionResolutionException extends Exception @@ -33,25 +34,7 @@ public class PluginVersionResolutionException public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, Throwable cause ) { - super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause ); - - this.groupId = groupId; - this.artifactId = artifactId; - this.baseMessage = baseMessage; - } - - public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, ArtifactMetadataRetrievalException cause ) - { - super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause ); - - this.groupId = groupId; - this.artifactId = artifactId; - this.baseMessage = baseMessage; - } - - public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage, InvalidVersionSpecificationException cause ) - { - super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause ); + super( "Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage, cause ); this.groupId = groupId; this.artifactId = artifactId; @@ -60,7 +43,18 @@ public class PluginVersionResolutionException public PluginVersionResolutionException( String groupId, String artifactId, String baseMessage ) { - super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage ); + super( "Error resolving version for plugin \'" + groupId + ":" + artifactId + "\': " + baseMessage ); + + this.groupId = groupId; + this.artifactId = artifactId; + this.baseMessage = baseMessage; + } + + public PluginVersionResolutionException( String groupId, String artifactId, ArtifactRepository localRepository, + List remoteRepositories, String baseMessage ) + { + super( "Error resolving version for plugin \'" + groupId + ":" + artifactId + "\' from the repositories " + + format( localRepository, remoteRepositories ) + ": " + baseMessage ); this.groupId = groupId; this.artifactId = artifactId; @@ -82,4 +76,31 @@ public class PluginVersionResolutionException return baseMessage; } + private static String format( ArtifactRepository localRepository, List remoteRepositories ) + { + String repos = "["; + + if ( localRepository != null ) + { + repos += localRepository.getId() + " (" + localRepository.getBasedir() + ")"; + } + + if ( remoteRepositories != null && !remoteRepositories.isEmpty() ) + { + repos += ", "; + + for ( ArtifactRepository repository : remoteRepositories ) + { + if ( repository != null ) + { + repos += repository.getId() + " (" + repository.getUrl() + ")"; + } + } + } + + repos += "]"; + + return repos; + } + } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java index 938c6dd3c1..ec62b83cec 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -149,7 +149,8 @@ public class DefaultPluginVersionResolver if ( StringUtils.isEmpty( result.getVersion() ) ) { throw new PluginVersionResolutionException( request.getGroupId(), request.getArtifactId(), - "Plugin not found in any repository" ); + request.getLocalRepository(), request.getRemoteRepositories(), + "Plugin not found in any plugin repository" ); } return result; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 2869f1a0dc..66493e9815 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -470,6 +470,17 @@ public class MavenCli else { logger.error( es.getMessage() ); + logger.error( "To see the full stack trace of the error, re-run Maven with the -e switch." ); + } + + logger.error( "Re-run Maven using the -X switch to enable full debug logging." ); + + if ( StringUtils.isNotEmpty( es.getReference() ) ) + { + logger.error( "" ); + logger.error( "For more information about the error and possible solutions" + + ", please try the following article:" ); + logger.error( " " + es.getReference() ); } }