o Improved some exception messages

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@825852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-16 11:39:40 +00:00
parent 85089c7273
commit d6ad00a1f3
7 changed files with 127 additions and 39 deletions

View File

@ -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<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
throws ProjectBuildingException
{
List<MavenProject> projects = new ArrayList<MavenProject>();
@ -348,7 +356,7 @@ public class DefaultMaven
}
private void collectProjects( List<MavenProject> projects, List<File> files, MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
throws ProjectBuildingException
{
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();

View File

@ -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;
}
}

View File

@ -32,11 +32,42 @@ public class NoPluginFoundForPrefixException
private List<ArtifactRepository> remoteRepositories;
public NoPluginFoundForPrefixException( String prefix, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
public NoPluginFoundForPrefixException( String prefix, List<String> pluginGroups,
ArtifactRepository localRepository,
List<ArtifactRepository> 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;
}
private static String format( ArtifactRepository localRepository, List<ArtifactRepository> 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;
}
}

View File

@ -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() );
}
}

View File

@ -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<ArtifactRepository> 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<ArtifactRepository> 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;
}
}

View File

@ -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;

View File

@ -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() );
}
}