PR: MNG-122

final exception cleanup - reduce the noise in the lifecycle executor, get rid of response object in favour of exception handling from DefaultMaven.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-13 16:36:54 +00:00
parent 665759970a
commit 11df168337
19 changed files with 566 additions and 659 deletions

View File

@ -25,8 +25,27 @@ package org.apache.maven;
public class BuildFailureException
extends Exception
{
private String longMessage;
public BuildFailureException( String message )
{
super( message );
}
public BuildFailureException( String message, String longMessage )
{
super( message );
this.longMessage = longMessage;
}
public BuildFailureException( String message, String longMessage, Throwable cause )
{
super( message, cause );
this.longMessage = longMessage;
}
public String getLongMessage()
{
return longMessage;
}
}

View File

@ -18,11 +18,10 @@ package org.apache.maven;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.execution.RuntimeInformation;
@ -31,8 +30,6 @@ import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Profile;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.project.MavenProject;
@ -71,14 +68,11 @@ import java.util.TimeZone;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
* @todo unify error reporting. We should return one response, always - and let the CLI decide how to render it. The reactor response should contain individual project responses
*/
public class DefaultMaven
extends AbstractLogEnabled
implements Maven, Contextualizable
{
public static File userDir = new File( System.getProperty( "user.dir" ) );
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
@ -103,8 +97,103 @@ public class DefaultMaven
// Project execution
// ----------------------------------------------------------------------
public MavenExecutionResponse execute( MavenExecutionRequest request )
throws SettingsConfigurationException, MavenExecutionException
public void execute( MavenExecutionRequest request )
throws MavenExecutionException
{
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.REACTOR_EXECUTION;
dispatcher.dispatchStart( event, request.getBaseDirectory() );
try
{
ReactorManager rm = doExecute( request, dispatcher );
// TODO: shoul all the logging be left to the CLI?
logReactorSummary( rm );
if ( rm.hasBuildFailures() )
{
logErrors( rm, request.isShowErrors() );
}
else
{
logSuccess( rm );
}
stats( request.getStartTime() );
line();
dispatcher.dispatchEnd( event, request.getBaseDirectory() );
}
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
logError( e, request.isShowErrors() );
stats( request.getStartTime() );
line();
throw new MavenExecutionException( e.getMessage(), e );
}
catch ( BuildFailureException e )
{
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
logFailure( e, request.isShowErrors() );
stats( request.getStartTime() );
line();
throw new MavenExecutionException( e.getMessage(), e );
}
catch ( Throwable t )
{
dispatcher.dispatchError( event, request.getBaseDirectory(), t );
logFatal( t );
stats( request.getStartTime() );
line();
throw new MavenExecutionException( "Error executing project within the reactor", t );
}
}
private void logErrors( ReactorManager rm, boolean showErrors )
{
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
BuildFailure buildFailure = rm.getBuildFailure( project );
line();
getLogger().info(
"Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
line();
logDiagnostics( buildFailure.getCause() );
logTrace( buildFailure.getCause(), showErrors );
line();
}
}
}
private ReactorManager doExecute( MavenExecutionRequest request, EventDispatcher dispatcher )
throws MavenExecutionException, BuildFailureException, LifecycleExecutionException
{
if ( request.getSettings().isOffline() )
{
@ -147,12 +236,10 @@ public class DefaultMaven
{
throw new MavenExecutionException( "Unable to configure Maven for execution", e );
}
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.REACTOR_EXECUTION;
dispatcher.dispatchStart( event, request.getBaseDirectory() );
catch ( SettingsConfigurationException e )
{
throw new MavenExecutionException( "Unable to configure Maven for execution", e );
}
ProfileManager globalProfileManager = request.getGlobalProfileManager();
@ -161,44 +248,11 @@ public class DefaultMaven
getLogger().info( "Scanning for projects..." );
boolean foundProjects = true;
List projects;
try
List projects = getProjects( request, globalProfileManager );
if ( projects.isEmpty() )
{
List files = getProjectFiles( request );
projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
request.getSettings(), globalProfileManager, !request.isReactorActive() );
// the reasoning here is that the list is still unsorted according to dependency, so the first project
// SHOULD BE the top-level, or the one we want to start with if we're doing an aggregated build.
if ( projects.isEmpty() )
{
MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() );
projects.add( superProject );
foundProjects = false;
}
}
catch ( IOException e )
{
throw new MavenExecutionException( "Error processing projects for the reactor: ", e );
}
catch ( ArtifactResolutionException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
catch ( ProjectBuildingException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
catch ( ProfileActivationException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
}
catch ( BuildFailureException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
projects.add( getSuperProject( request ) );
foundProjects = false;
}
ReactorManager rm;
@ -215,7 +269,8 @@ public class DefaultMaven
}
catch ( CycleDetectedException e )
{
return dispatchErrorResponse( dispatcher, event, request.getBaseDirectory(), e );
throw new MavenExecutionException(
"The projects in the reactor contain a cyclic reference: " + e.getMessage(), e );
}
if ( rm.hasMultipleProjects() )
@ -233,113 +288,56 @@ public class DefaultMaven
session.setUsingPOMsFromFilesystem( foundProjects );
try
{
MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, dispatcher );
lifecycleExecutor.execute( session, rm, dispatcher );
// TODO: is this perhaps more appropriate in the CLI?
if ( response.isExecutionFailure() )
{
dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() );
// TODO: yuck! Revisit when cleaning up the exception handling from the top down
Throwable exception = response.getException();
// TODO: replace all handling by buildfailureexception/mavenexecutionexception or lifecycleexecutionexception
if ( exception instanceof BuildFailureException )
{
logFailure( response, rm, exception, null );
}
else if ( exception instanceof MojoFailureException )
{
MojoFailureException e = (MojoFailureException) exception;
logFailure( response, rm, e, e.getLongMessage() );
}
else if ( exception instanceof MojoExecutionException )
{
// TODO: replace by above
if ( exception.getCause() == null )
{
MojoExecutionException e = (MojoExecutionException) exception;
logFailure( response, rm, e, e.getLongMessage() );
}
else
{
// TODO: throw exceptions like this, so "failures" are just that
logError( response );
}
}
else if ( exception instanceof ArtifactNotFoundException )
{
logFailure( response, rm, exception, null );
}
else
{
// TODO: this should be a "FATAL" exception, reported to the
// developers - however currently a LOT of
// "user" errors fall through the cracks (like invalid POMs, as
// one example)
logError( response );
}
}
else
{
logSuccess( response, rm );
}
dispatcher.dispatchEnd( event, request.getBaseDirectory() );
return response;
}
catch ( LifecycleExecutionException e )
{
logFatal( e );
dispatcher.dispatchError( event, request.getBaseDirectory(), e );
throw new MavenExecutionException( "Error executing project within the reactor", e );
}
return rm;
}
private void writeReactorSummary( ReactorManager rm )
private MavenProject getSuperProject( MavenExecutionRequest request )
throws MavenExecutionException
{
// -------------------------
// Reactor Summary:
// -------------------------
// o project-name...........FAILED
// o project2-name..........SKIPPED (dependency build failed or was skipped)
// o project-3-name.........SUCCESS
line();
getLogger().info( "Reactor Summary:" );
line();
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
MavenProject superProject;
try
{
MavenProject project = (MavenProject) it.next();
superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() );
if ( rm.hasBuildFailure( project ) )
{
logReactorSummaryLine( project.getName(), "FAILED", rm.getBuildFailure( project ).getTime() );
}
else if ( rm.isBlackListed( project ) )
{
logReactorSummaryLine( project.getName(), "SKIPPED (dependency build failed or was skipped)" );
}
else if ( rm.hasBuildSuccess( project ) )
{
logReactorSummaryLine( project.getName(), "SUCCESS", rm.getBuildSuccess( project ).getTime() );
}
else
{
logReactorSummaryLine( project.getName(), "NOT BUILT" );
}
}
catch ( ProjectBuildingException e )
{
throw new MavenExecutionException( e.getMessage(), e );
}
return superProject;
}
getLogger().info( "" );
getLogger().info( "" );
private List getProjects( MavenExecutionRequest request, ProfileManager globalProfileManager )
throws MavenExecutionException, BuildFailureException
{
List projects;
try
{
List files = getProjectFiles( request );
projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(),
request.getSettings(), globalProfileManager, !request.isReactorActive() );
}
catch ( IOException e )
{
throw new MavenExecutionException( "Error processing projects for the reactor: " + e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new MavenExecutionException( e.getMessage(), e );
}
catch ( ProjectBuildingException e )
{
throw new MavenExecutionException( e.getMessage(), e );
}
catch ( ProfileActivationException e )
{
throw new MavenExecutionException( e.getMessage(), e );
}
return projects;
}
private void logReactorSummaryLine( String name, String status )
@ -396,20 +394,6 @@ public class DefaultMaven
return fmt.format( new Date( time ) );
}
private MavenExecutionResponse dispatchErrorResponse( EventDispatcher dispatcher, String event,
String baseDirectory, Exception e )
{
dispatcher.dispatchError( event, baseDirectory, e );
MavenExecutionResponse response = new MavenExecutionResponse();
response.setStart( new Date() );
response.setFinish( new Date() );
response.setException( e );
logError( response );
return response;
}
private List collectProjects( List files, ArtifactRepository localRepository, boolean recursive, Settings settings,
ProfileManager globalProfileManager, boolean isRoot )
throws ArtifactResolutionException, ProjectBuildingException, ProfileActivationException,
@ -606,134 +590,141 @@ public class DefaultMaven
{
line();
getLogger().error( "FATAL ERROR" );
getLogger().info( "FATAL ERROR" );
line();
diagnoseError( error );
logDiagnostics( error );
line();
getLogger().error( "FATAL ERROR" );
line();
logTrace( error, true );
}
protected void logError( MavenExecutionResponse r )
protected void logError( Exception e, boolean showErrors )
{
line();
getLogger().error( "BUILD ERROR" );
getLogger().info( "BUILD ERROR" );
line();
diagnoseError( r.getException() );
logDiagnostics( e );
line();
getLogger().error( "BUILD ERROR" );
line();
stats( r.getStart(), r.getFinish() );
line();
logTrace( e, showErrors );
}
private void diagnoseError( Throwable error )
protected void logFailure( BuildFailureException e, boolean showErrors )
{
String message = null;
if ( errorDiagnostics != null )
{
message = errorDiagnostics.diagnose( error );
}
if ( message == null )
{
message = error.getMessage();
}
getLogger().info( "Diagnosis: " + message );
line();
// TODO: needs to honour -e
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Trace:\n", error );
line();
}
}
protected void logFailure( MavenExecutionResponse r, ReactorManager rm, Throwable error, String longMessage )
{
if ( rm.hasMultipleProjects() && r.executedMultipleProjects() )
{
writeReactorSummary( rm );
}
line();
getLogger().info( "BUILD FAILURE" );
line();
logDiagnostics( e );
if ( e.getLongMessage() != null )
{
getLogger().info( e.getLongMessage() );
line();
}
logTrace( e, showErrors );
}
private void logTrace( Throwable t, boolean showErrors )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Trace", t );
line();
}
else if ( showErrors )
{
getLogger().error( "Trace", t );
line();
}
else
{
getLogger().info( "For more information, run Maven with the -e switch" );
}
}
private void logDiagnostics( Throwable t )
{
String message = null;
if ( errorDiagnostics != null )
{
message = errorDiagnostics.diagnose( error );
message = errorDiagnostics.diagnose( t );
}
if ( message == null )
{
message = "Reason: " + error.getMessage();
message = t.getMessage();
}
getLogger().info( message );
line();
if ( longMessage != null )
{
getLogger().info( longMessage );
line();
}
// TODO: needs to honour -e
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Trace", error );
line();
}
stats( r.getStart(), r.getFinish() );
getLogger().error( message );
line();
}
protected void logSuccess( MavenExecutionResponse r, ReactorManager rm )
protected void logSuccess( ReactorManager rm )
{
if ( rm.hasMultipleProjects() && r.executedMultipleProjects() )
{
writeReactorSummary( rm );
}
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
stats( r.getStart(), r.getFinish() );
line();
}
protected void stats( Date start, Date finish )
private void logReactorSummary( ReactorManager rm )
{
if ( rm.hasMultipleProjects() && rm.executedMultipleProjects() )
{
// -------------------------
// Reactor Summary:
// -------------------------
// o project-name...........FAILED
// o project2-name..........SKIPPED (dependency build failed or was skipped)
// o project-3-name.........SUCCESS
line();
getLogger().info( "Reactor Summary:" );
line();
for ( Iterator it = rm.getSortedProjects().iterator(); it.hasNext(); )
{
MavenProject project = (MavenProject) it.next();
if ( rm.hasBuildFailure( project ) )
{
logReactorSummaryLine( project.getName(), "FAILED", rm.getBuildFailure( project ).getTime() );
}
else if ( rm.isBlackListed( project ) )
{
logReactorSummaryLine( project.getName(), "SKIPPED (dependency build failed or was skipped)" );
}
else if ( rm.hasBuildSuccess( project ) )
{
logReactorSummaryLine( project.getName(), "SUCCESS", rm.getBuildSuccess( project ).getTime() );
}
else
{
logReactorSummaryLine( project.getName(), "NOT BUILT" );
}
}
getLogger().info( "" );
getLogger().info( "" );
}
}
protected void stats( Date start )
{
Date finish = new Date();
long time = finish.getTime() - start.getTime();
getLogger().info( "Total time: " + formatTime( time ) );
@ -793,6 +784,7 @@ public class DefaultMaven
{
List files = Collections.EMPTY_LIST;
File userDir = new File( System.getProperty( "user.dir" ) );
if ( request.isReactorActive() )
{
// TODO: should we now include the pom.xml in the current directory?

View File

@ -17,7 +17,6 @@ package org.apache.maven;
*/
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.reactor.MavenExecutionException;
/**
@ -32,6 +31,6 @@ public interface Maven
String RELEASE_POMv4 = "release-pom.xml";
MavenExecutionResponse execute( MavenExecutionRequest request )
throws MavenExecutionException, SettingsConfigurationException;
void execute( MavenExecutionRequest request )
throws MavenExecutionException;
}

View File

@ -33,7 +33,6 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor;
@ -218,7 +217,7 @@ public class MavenCli
}
request = createRequest( commandLine, settings, eventDispatcher, loggerManager, profileManager,
executionProperties );
executionProperties, showErrors );
setProjectFileOptions( commandLine, request );
@ -245,30 +244,16 @@ public class MavenCli
}
}
MavenExecutionResponse response;
try
{
response = maven.execute( request );
maven.execute( request );
}
catch ( MavenExecutionException e )
{
showFatalError( "Error executing Maven for a project", e, showErrors );
return 1;
}
catch ( SettingsConfigurationException e )
{
showError( e.getMessage(), e, showErrors );
return 1;
}
if ( response != null && response.isExecutionFailure() )
{
return 1;
}
else
{
return 0;
}
return 0;
}
private static Settings buildSettings( CommandLine commandLine )
@ -382,7 +367,8 @@ public class MavenCli
private static MavenExecutionRequest createRequest( CommandLine commandLine, Settings settings,
EventDispatcher eventDispatcher, LoggerManager loggerManager,
ProfileManager profileManager, Properties executionProperties )
ProfileManager profileManager, Properties executionProperties,
boolean showErrors )
throws ComponentLookupException
{
MavenExecutionRequest request;
@ -393,7 +379,7 @@ public class MavenCli
request = new DefaultMavenExecutionRequest( localRepository, settings, eventDispatcher,
commandLine.getArgList(), userDir.getPath(), profileManager,
executionProperties );
executionProperties, showErrors );
// TODO [BP]: do we set one per mojo? where to do it?
Logger logger = loggerManager.getLoggerForComponent( Mojo.ROLE );

View File

@ -37,12 +37,12 @@ public class BuildFailure
this.time = time;
}
String getTask()
public String getTask()
{
return task;
}
Exception getCause()
public Exception getCause()
{
return cause;
}

View File

@ -62,9 +62,12 @@ public class DefaultMavenExecutionRequest
private final Date startTime;
private final boolean showErrors;
public DefaultMavenExecutionRequest( ArtifactRepository localRepository, Settings settings,
EventDispatcher eventDispatcher, List goals, String baseDirectory,
ProfileManager globalProfileManager, Properties executionProperties )
ProfileManager globalProfileManager, Properties executionProperties,
boolean showErrors )
{
this.localRepository = localRepository;
@ -81,6 +84,8 @@ public class DefaultMavenExecutionRequest
this.executionProperties = executionProperties;
this.startTime = new Date();
this.showErrors = showErrors;
}
public Settings getSettings()
@ -181,4 +186,9 @@ public class DefaultMavenExecutionRequest
{
return startTime;
}
public boolean isShowErrors()
{
return showErrors;
}
}

View File

@ -69,4 +69,6 @@ public interface MavenExecutionRequest
Properties getExecutionProperties();
Date getStartTime();
boolean isShowErrors();
}

View File

@ -1,91 +0,0 @@
package org.apache.maven.execution;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Date;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenExecutionResponse
{
private Throwable exception;
private Date start;
private Date finish;
private boolean executedMultipleProjects;
// ----------------------------------------------------------------------
// Execution failure
// ----------------------------------------------------------------------
public boolean isExecutionFailure()
{
return exception != null;
}
// ----------------------------------------------------------------------
// Error
// ----------------------------------------------------------------------
public Throwable getException()
{
return exception;
}
public void setException( Throwable exception )
{
this.exception = exception;
}
// ----------------------------------------------------------------------
// Timing
// ----------------------------------------------------------------------
public Date getStart()
{
return start;
}
public void setStart( Date start )
{
this.start = start;
}
public Date getFinish()
{
return finish;
}
public void setFinish( Date finish )
{
this.finish = finish;
}
public boolean executedMultipleProjects()
{
return executedMultipleProjects;
}
public void setExecutedMultipleProjects( boolean executedMultipleProjects )
{
this.executedMultipleProjects = executedMultipleProjects;
}
}

View File

@ -50,7 +50,7 @@ public class MavenSession
private final String executionRootDir;
private boolean usingPOMsFromFilesystem;
private boolean usingPOMsFromFilesystem = true;
private final Properties executionProperties;

View File

@ -183,4 +183,8 @@ public class ReactorManager
return (BuildSuccess) buildSuccessesByProject.get( getProjectKey( project ) );
}
public boolean executedMultipleProjects()
{
return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
}
}

View File

@ -23,7 +23,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.extension.ExtensionManager;
@ -47,6 +46,7 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.lifecycle.Execution;
import org.apache.maven.plugin.lifecycle.Phase;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
@ -61,7 +61,6 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -107,8 +106,8 @@ public class DefaultLifecycleExecutor
* @param rm
* @param dispatcher
*/
public MavenExecutionResponse execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
throws LifecycleExecutionException
public void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
throws BuildFailureException, LifecycleExecutionException
{
// TODO: This is dangerous, particularly when it's just a collection of loose-leaf projects being built
// within the same reactor (using an inclusion pattern to gather them up)...
@ -125,65 +124,21 @@ public class DefaultLifecycleExecutor
}
}
MavenExecutionResponse response = new MavenExecutionResponse();
response.setStart( session.getStartTime() );
try
if ( goals.isEmpty() )
{
if ( goals.isEmpty() )
{
// TODO: delete
throw new NoGoalsSpecifiedException( "You must specify at least one goal. Try 'install'" );
}
List taskSegments = segmentTaskListByAggregationNeeds( goals, session, rootProject );
// TODO: probably don't want to do all this up front
findExtensions( session );
executeTaskSegments( taskSegments, rm, session, rootProject, dispatcher, response );
if ( ReactorManager.FAIL_AT_END.equals( rm.getFailureBehavior() ) && rm.hasBuildFailures() )
{
response.setException( new BuildFailureException( "One or more projects failed to build." ) );
}
}
catch ( MojoExecutionException e )
{
response.setException( e );
}
catch ( ArtifactNotFoundException e )
{
response.setException( e );
}
catch ( ArtifactResolutionException e )
{
response.setException( e );
}
catch ( NoGoalsSpecifiedException e )
{
response.setException( e );
}
catch ( MojoFailureException e )
{
response.setException( e );
}
catch ( PluginNotFoundException e )
{
response.setException( e );
}
finally
{
response.setFinish( new Date() );
throw new BuildFailureException( "You must specify at least one goal. Try 'install'" );
}
return response;
List taskSegments = segmentTaskListByAggregationNeeds( goals, session, rootProject );
// TODO: probably don't want to do all this up front
findExtensions( session );
executeTaskSegments( taskSegments, rm, session, rootProject, dispatcher );
}
private void findExtensions( MavenSession session )
throws ArtifactNotFoundException, ArtifactResolutionException, LifecycleExecutionException,
PluginNotFoundException
throws LifecycleExecutionException
{
for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
{
@ -200,18 +155,31 @@ public class DefaultLifecycleExecutor
{
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
}
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
artifactHandlerManager.addHandlers( handlers );
try
{
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
artifactHandlerManager.addHandlers( handlers );
}
catch ( PluginNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
}
}
private void executeTaskSegments( List taskSegments, ReactorManager rm, MavenSession session,
MavenProject rootProject, EventDispatcher dispatcher,
MavenExecutionResponse response )
throws ArtifactNotFoundException, MojoExecutionException, LifecycleExecutionException, MojoFailureException,
ArtifactResolutionException, PluginNotFoundException
MavenProject rootProject, EventDispatcher dispatcher )
throws LifecycleExecutionException, BuildFailureException
{
for ( Iterator it = taskSegments.iterator(); it.hasNext(); )
{
@ -238,27 +206,18 @@ public class DefaultLifecycleExecutor
String target = rootProject.getId() + " ( " + segment + " )";
dispatcher.dispatchStart( event, target );
try
// only call once, with the top-level project (assumed to be provided as a parameter)...
for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
{
// only call once, with the top-level project (assumed to be provided as a parameter)...
for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
{
String task = (String) goalIterator.next();
String task = (String) goalIterator.next();
executeGoalAndHandleFailures( task, session, rootProject, response, dispatcher, event, rm,
buildStartTime, target );
}
rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
dispatcher.dispatchEnd( event, target );
executeGoalAndHandleFailures( task, session, rootProject, dispatcher, event, rm, buildStartTime,
target );
}
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, target, e );
throw e;
}
rm.registerBuildSuccess( rootProject, System.currentTimeMillis() - buildStartTime );
dispatcher.dispatchEnd( event, target );
}
else
{
@ -278,8 +237,6 @@ public class DefaultLifecycleExecutor
{
List sortedProjects = session.getSortedProjects();
response.setExecutedMultipleProjects( true );
// iterate over projects, and execute on each...
for ( Iterator projectIterator = sortedProjects.iterator(); projectIterator.hasNext(); )
{
@ -304,26 +261,17 @@ public class DefaultLifecycleExecutor
String target = currentProject.getId() + " ( " + segment + " )";
dispatcher.dispatchStart( event, target );
try
for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
{
for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); )
{
String task = (String) goalIterator.next();
String task = (String) goalIterator.next();
executeGoalAndHandleFailures( task, session, currentProject, response, dispatcher,
event, rm, buildStartTime, target );
}
rm.registerBuildSuccess( currentProject, System.currentTimeMillis() - buildStartTime );
dispatcher.dispatchEnd( event, target );
executeGoalAndHandleFailures( task, session, currentProject, dispatcher, event, rm,
buildStartTime, target );
}
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, target, e );
throw e;
}
rm.registerBuildSuccess( currentProject, System.currentTimeMillis() - buildStartTime );
dispatcher.dispatchEnd( event, target );
}
else
{
@ -344,93 +292,52 @@ public class DefaultLifecycleExecutor
}
private void executeGoalAndHandleFailures( String task, MavenSession session, MavenProject project,
MavenExecutionResponse response, EventDispatcher dispatcher,
String event, ReactorManager rm, long buildStartTime, String target )
throws LifecycleExecutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException,
ArtifactResolutionException, PluginNotFoundException
EventDispatcher dispatcher, String event, ReactorManager rm,
long buildStartTime, String target )
throws BuildFailureException, LifecycleExecutionException
{
try
{
executeGoal( task, session, project, response );
executeGoal( task, session, project );
}
catch ( MojoExecutionException e )
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
{
throw e;
}
}
catch ( ArtifactResolutionException e )
catch ( BuildFailureException e )
{
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
}
catch ( MojoFailureException e )
{
// TODO: should be dispatchFailure?
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
}
catch ( ArtifactNotFoundException e )
{
// TODO: should be dispatchFailure?
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
}
catch ( InvalidDependencyVersionException e )
{
// TODO: should be dispatchFailure?
dispatcher.dispatchError( event, target, e );
handleExecutionFailure( rm, project, e, task, buildStartTime );
if ( handleExecutionFailure( rm, project, e, task, buildStartTime ) )
{
throw e;
}
}
}
private void handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, String task,
long buildStartTime )
throws MojoExecutionException, MojoFailureException, ArtifactNotFoundException, ArtifactResolutionException
private boolean handleExecutionFailure( ReactorManager rm, MavenProject project, Exception e, String task,
long buildStartTime )
{
rm.registerBuildFailure( project, e, task, System.currentTimeMillis() - buildStartTime );
if ( ReactorManager.FAIL_FAST.equals( rm.getFailureBehavior() ) )
{
rm.registerBuildFailure( project, e, task, System.currentTimeMillis() - buildStartTime );
if ( e instanceof MojoExecutionException )
{
throw (MojoExecutionException) e;
}
if ( e instanceof MojoFailureException )
{
throw (MojoFailureException) e;
}
else if ( e instanceof ArtifactNotFoundException )
{
throw (ArtifactNotFoundException) e;
}
else if ( e instanceof ArtifactResolutionException )
{
throw (ArtifactResolutionException) e;
}
else
{
getLogger().error( "Attempt to register inappropriate build-failure Exception.", e );
throw new IllegalArgumentException( "Inappropriate build-failure Exception: " + e );
}
return true;
}
else if ( ReactorManager.FAIL_AT_END.equals( rm.getFailureBehavior() ) )
{
rm.registerBuildFailure( project, e, task, System.currentTimeMillis() - buildStartTime );
rm.blackList( project );
}
// FIXME: how about the other cases?
return false;
}
private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project )
throws LifecycleExecutionException, ArtifactNotFoundException, PluginNotFoundException,
ArtifactResolutionException
throws LifecycleExecutionException, BuildFailureException
{
List segments = new ArrayList();
@ -526,34 +433,39 @@ public class DefaultLifecycleExecutor
return segments;
}
private void executeGoal( String task, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, ArtifactNotFoundException, MojoExecutionException,
ArtifactResolutionException, MojoFailureException, InvalidDependencyVersionException, PluginNotFoundException
private void executeGoal( String task, MavenSession session, MavenProject project )
throws LifecycleExecutionException, BuildFailureException
{
if ( getPhaseToLifecycleMap().containsKey( task ) )
try
{
Lifecycle lifecycle = getLifecycleForPhase( task );
if ( getPhaseToLifecycleMap().containsKey( task ) )
{
Lifecycle lifecycle = getLifecycleForPhase( task );
// we have a lifecycle phase, so lets bind all the necessary goals
Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle );
executeGoalWithLifecycle( task, session, lifecycleMappings, project, response, lifecycle );
// we have a lifecycle phase, so lets bind all the necessary goals
Map lifecycleMappings = constructLifecycleMappings( session, task, project, lifecycle );
executeGoalWithLifecycle( task, session, lifecycleMappings, project, lifecycle );
}
else
{
executeStandaloneGoal( task, session, project );
}
}
else
catch ( PluginNotFoundException e )
{
executeStandaloneGoal( task, session, project, response );
throw new BuildFailureException( "A required plugin was not found", e.getMessage(), e );
}
}
private void executeGoalWithLifecycle( String task, MavenSession session, Map lifecycleMappings,
MavenProject project, MavenExecutionResponse response, Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
MavenProject project, Lifecycle lifecycle )
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
List goals = processGoalChain( task, lifecycleMappings, lifecycle );
if ( !goals.isEmpty() )
{
executeGoals( goals, session, project, response );
executeGoals( goals, session, project );
}
else
{
@ -561,19 +473,16 @@ public class DefaultLifecycleExecutor
}
}
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
private void executeStandaloneGoal( String task, MavenSession session, MavenProject project )
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
// guaranteed to come from the CLI and not be part of a phase
MojoDescriptor mojoDescriptor = getMojoDescriptor( task, session, project, task, true );
executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), session, project, response );
executeGoals( Collections.singletonList( new MojoExecution( mojoDescriptor ) ), session, project );
}
private void executeGoals( List goals, MavenSession session, MavenProject project, MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
private void executeGoals( List goals, MavenSession session, MavenProject project )
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
@ -583,7 +492,7 @@ public class DefaultLifecycleExecutor
if ( mojoDescriptor.getExecutePhase() != null || mojoDescriptor.getExecuteGoal() != null )
{
forkLifecycle( mojoDescriptor, session, project, response );
forkLifecycle( mojoDescriptor, session, project );
}
if ( mojoDescriptor.isRequiresReports() )
@ -599,7 +508,7 @@ public class DefaultLifecycleExecutor
if ( descriptor.getExecutePhase() != null )
{
forkLifecycle( descriptor, session, project, response );
forkLifecycle( descriptor, session, project );
}
}
}
@ -613,12 +522,35 @@ public class DefaultLifecycleExecutor
throw new LifecycleExecutionException( "Internal error in the plugin manager executing goal '" +
mojoDescriptor.getId() + "': " + e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( InvalidDependencyVersionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( MojoFailureException e )
{
throw new BuildFailureException( e.getMessage(), e.getLongMessage(), e );
}
catch ( MojoExecutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( PluginConfigurationException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
}
}
private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
List reportPlugins = project.getReportPlugins();
@ -704,8 +636,7 @@ public class DefaultLifecycleExecutor
private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session,
MojoExecution mojoExecution )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = verifyReportPlugin( reportPlugin, project, session );
@ -747,23 +678,27 @@ public class DefaultLifecycleExecutor
throw new LifecycleExecutionException(
"Error getting reports from the plugin '" + reportPlugin.getKey() + "'", e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
}
}
return reports;
}
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project )
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
getLogger().info( "Preparing " + pluginDescriptor.getGoalPrefix() + ":" + mojoDescriptor.getGoal() );
if ( mojoDescriptor.isAggregator() )
{
response.setExecutedMultipleProjects( true );
for ( Iterator i = session.getSortedProjects().iterator(); i.hasNext(); )
{
MavenProject reactorProject = (MavenProject) i.next();
@ -774,19 +709,17 @@ public class DefaultLifecycleExecutor
line();
forkProjectLifecycle( mojoDescriptor, session, reactorProject, response );
forkProjectLifecycle( mojoDescriptor, session, reactorProject );
}
}
else
{
forkProjectLifecycle( mojoDescriptor, session, project, response );
forkProjectLifecycle( mojoDescriptor, session, project );
}
}
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project,
MavenExecutionResponse response )
throws ArtifactResolutionException, LifecycleExecutionException, MojoExecutionException, MojoFailureException,
ArtifactNotFoundException, InvalidDependencyVersionException, PluginNotFoundException
private void forkProjectLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project )
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
@ -852,25 +785,25 @@ public class DefaultLifecycleExecutor
{
Lifecycle lifecycle = getLifecycleForPhase( targetPhase );
executeGoalWithLifecycle( targetPhase, session, lifecycleMappings, executionProject, response, lifecycle );
executeGoalWithLifecycle( targetPhase, session, lifecycleMappings, executionProject, lifecycle );
}
else
{
String goal = mojoDescriptor.getExecuteGoal();
MojoDescriptor desc = getMojoDescriptor( pluginDescriptor, goal );
executeGoals( Collections.singletonList( new MojoExecution( desc ) ), session, executionProject, response );
executeGoals( Collections.singletonList( new MojoExecution( desc ) ), session, executionProject );
}
project.setExecutionProject( executionProject );
}
private Lifecycle getLifecycleForPhase( String phase )
throws LifecycleExecutionException
throws BuildFailureException, LifecycleExecutionException
{
Lifecycle lifecycle = (Lifecycle) getPhaseToLifecycleMap().get( phase );
if ( lifecycle == null )
{
throw new LifecycleExecutionException( "Unable to find lifecycle for phase '" + phase + "'" );
throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" );
}
return lifecycle;
}
@ -922,8 +855,7 @@ public class DefaultLifecycleExecutor
private Map constructLifecycleMappings( MavenSession session, String selectedPhase, MavenProject project,
Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
// first, bind those associated with the packaging
Map lifecycleMappings = bindLifecycleForPackaging( session, selectedPhase, project, lifecycle );
@ -941,8 +873,7 @@ public class DefaultLifecycleExecutor
private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project,
Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, BuildFailureException, PluginNotFoundException
{
Map mappings = findMappingsForLifecycle( session, project, lifecycle );
@ -985,8 +916,7 @@ public class DefaultLifecycleExecutor
}
private Map findMappingsForLifecycle( MavenSession session, MavenProject project, Lifecycle lifecycle )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
String packaging = project.getPackaging();
Map mappings = null;
@ -1035,8 +965,7 @@ public class DefaultLifecycleExecutor
private Object findExtension( MavenProject project, String role, String roleHint, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
Object pluginComponent = null;
@ -1072,8 +1001,7 @@ public class DefaultLifecycleExecutor
* lookup directly, or have them passed in
*/
private Map findArtifactTypeHandlers( MavenProject project, Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException, LifecycleExecutionException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
Map map = new HashMap();
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
@ -1123,8 +1051,7 @@ public class DefaultLifecycleExecutor
* @param session
*/
private void bindPluginToLifecycle( Plugin plugin, MavenSession session, Map phaseMap, MavenProject project )
throws LifecycleExecutionException, ArtifactResolutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
Settings settings = session.getSettings();
@ -1159,8 +1086,7 @@ public class DefaultLifecycleExecutor
private PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
try
@ -1174,22 +1100,33 @@ public class DefaultLifecycleExecutor
}
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( "Error resolving plugin version: " + e.getMessage(), e );
}
catch ( InvalidVersionSpecificationException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
return pluginDescriptor;
}
private PluginDescriptor verifyReportPlugin( ReportPlugin plugin, MavenProject project, MavenSession session )
throws ArtifactResolutionException, LifecycleExecutionException, ArtifactNotFoundException,
PluginNotFoundException
throws LifecycleExecutionException, PluginNotFoundException
{
PluginDescriptor pluginDescriptor;
try
@ -1203,15 +1140,27 @@ public class DefaultLifecycleExecutor
}
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( "Error resolving plugin version: " + e.getMessage(), e );
}
catch ( InvalidVersionSpecificationException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new LifecycleExecutionException( "Error resolving plugin version", e );
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new LifecycleExecutionException( e.getMessage(), e );
}
return pluginDescriptor;
}
@ -1227,7 +1176,8 @@ public class DefaultLifecycleExecutor
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
if ( mojoDescriptor == null )
{
throw new LifecycleExecutionException( "Goal from the POM '" + goal + "' was not found in the plugin" );
throw new LifecycleExecutionException(
"'" + goal + "' was specified in an execution, but not found in the plugin" );
}
// We have to check to see that the inheritance rules have been applied before binding this mojo.
@ -1303,8 +1253,7 @@ public class DefaultLifecycleExecutor
private MojoDescriptor getMojoDescriptor( String task, MavenSession session, MavenProject project,
String invokedVia, boolean canUsePrefix )
throws LifecycleExecutionException, ArtifactNotFoundException, PluginNotFoundException,
ArtifactResolutionException
throws BuildFailureException, LifecycleExecutionException, PluginNotFoundException
{
String goal;
Plugin plugin;
@ -1398,7 +1347,7 @@ public class DefaultLifecycleExecutor
{
String message = "Invalid task '" + task + "': you must specify a valid lifecycle phase, or" +
" a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
throw new LifecycleExecutionException( message );
throw new BuildFailureException( message );
}
if ( pluginDescriptor == null )
@ -1413,7 +1362,7 @@ public class DefaultLifecycleExecutor
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
if ( mojoDescriptor == null )
{
throw new LifecycleExecutionException( "Required goal not found: " + task );
throw new BuildFailureException( "Required goal not found: " + task );
}
return mojoDescriptor;

View File

@ -16,7 +16,7 @@ package org.apache.maven.lifecycle;
* limitations under the License.
*/
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.BuildFailureException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.monitor.event.EventDispatcher;
@ -29,7 +29,7 @@ public interface LifecycleExecutor
{
String ROLE = LifecycleExecutor.class.getName();
MavenExecutionResponse execute( MavenSession session, ReactorManager rpm, EventDispatcher dispatcher )
throws LifecycleExecutionException;
void execute( MavenSession session, ReactorManager rpm, EventDispatcher dispatcher )
throws LifecycleExecutionException, BuildFailureException;
}

View File

@ -45,6 +45,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -147,7 +148,8 @@ public class DefaultPluginManager
public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
// TODO: this should be possibly outside
// All version-resolution logic has been moved to DefaultPluginVersionManager.
@ -238,7 +240,7 @@ public class DefaultPluginManager
* manager which executes before the plugin is instantiated
*/
private void checkRequiredMavenVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories )
throws PluginVersionResolutionException
throws PluginVersionResolutionException, InvalidPluginException
{
try
{
@ -260,8 +262,8 @@ public class DefaultPluginManager
}
catch ( ProjectBuildingException e )
{
throw new PluginVersionResolutionException( plugin.getGroupId(), plugin.getArtifactId(),
"Unable to build project for plugin", e );
throw new InvalidPluginException(
"Unable to build project for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
}
@ -313,7 +315,7 @@ public class DefaultPluginManager
public void executeMojo( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, MojoExecutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException
{
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
@ -359,28 +361,20 @@ public class DefaultPluginManager
Mojo plugin;
try
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
String goalId = mojoDescriptor.getGoal();
String groupId = pluginDescriptor.getGroupId();
String artifactId = pluginDescriptor.getArtifactId();
String executionId = mojoExecution.getExecutionId();
Xpp3Dom dom = project.getGoalConfiguration( groupId, artifactId, executionId, goalId );
Xpp3Dom reportDom = project.getReportConfiguration( groupId, artifactId, executionId );
dom = Xpp3Dom.mergeXpp3Dom( dom, reportDom );
if ( mojoExecution.getConfiguration() != null )
{
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
String goalId = mojoDescriptor.getGoal();
String groupId = pluginDescriptor.getGroupId();
String artifactId = pluginDescriptor.getArtifactId();
String executionId = mojoExecution.getExecutionId();
Xpp3Dom dom = project.getGoalConfiguration( groupId, artifactId, executionId, goalId );
Xpp3Dom reportDom = project.getReportConfiguration( groupId, artifactId, executionId );
dom = Xpp3Dom.mergeXpp3Dom( dom, reportDom );
if ( mojoExecution.getConfiguration() != null )
{
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
}
dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() );
}
plugin = getConfiguredMojo( session, dom, project, false, mojoExecution );
}
catch ( PluginConfigurationException e )
{
String msg = "Error configuring plugin for execution of '" + goalName + "'.";
throw new MojoExecutionException( msg, e );
}
plugin = getConfiguredMojo( session, dom, project, false, mojoExecution );
// Event monitoring.
String event = MavenEvents.MOJO_EXECUTION;
@ -457,7 +451,8 @@ public class DefaultPluginManager
public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
String version = reportPlugin.getVersion();

View File

@ -24,6 +24,7 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
@ -43,7 +44,7 @@ public interface PluginManager
void executeMojo( MavenProject project, MojoExecution execution, MavenSession session )
throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException,
InvalidDependencyVersionException, PluginManagerException;
InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException;
MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session )
throws ArtifactNotFoundException, PluginConfigurationException, PluginManagerException,
@ -56,11 +57,13 @@ public interface PluginManager
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException;
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session )
throws PluginVersionResolutionException, ArtifactResolutionException, ArtifactNotFoundException,
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException;
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException;
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws PluginManagerException, ComponentLookupException;

View File

@ -27,6 +27,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.registry.MavenPluginRegistryBuilder;
import org.apache.maven.plugin.registry.PluginRegistry;
import org.apache.maven.plugin.registry.PluginRegistryUtils;
@ -74,21 +75,21 @@ public class DefaultPluginVersionManager
public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws PluginVersionResolutionException
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, settings, localRepository, false );
}
public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project,
Settings settings, ArtifactRepository localRepository )
throws PluginVersionResolutionException
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
return resolvePluginVersion( groupId, artifactId, project, settings, localRepository, true );
}
private String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
ArtifactRepository localRepository, boolean resolveAsReportPlugin )
throws PluginVersionResolutionException
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException
{
// first pass...if the plugin is specified in the pom, try to retrieve the version from there.
String version = getVersionFromPluginConfig( groupId, artifactId, project, resolveAsReportPlugin );
@ -214,8 +215,8 @@ public class DefaultPluginVersionManager
// if we still haven't found a version, then fail early before we get into the update goop.
if ( StringUtils.isEmpty( version ) )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Failed to resolve a valid version for this plugin" );
throw new PluginVersionNotFoundException( groupId, artifactId,
"Failed to resolve a valid version for this plugin" );
}
// if the plugin registry is inactive, then the rest of this goop is useless...
@ -625,7 +626,7 @@ public class DefaultPluginVersionManager
catch ( IOException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Error readin plugin registry: " + e.getMessage(), e );
"Error reading plugin registry: " + e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
@ -644,7 +645,7 @@ public class DefaultPluginVersionManager
private String resolveMetaVersion( String groupId, String artifactId, MavenProject project,
ArtifactRepository localRepository, String metaVersionId )
throws PluginVersionResolutionException
throws PluginVersionResolutionException, InvalidPluginException
{
Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId );
@ -677,8 +678,8 @@ public class DefaultPluginVersionManager
}
catch ( ProjectBuildingException e )
{
throw new PluginVersionResolutionException( groupId, artifactId,
"Unable to build resolve plugin project information", e );
throw new InvalidPluginException( "Unable to build project information for plugin '" +
ArtifactUtils.versionlessKey( groupId, artifactId ) + "': " + e.getMessage(), e );
}
boolean pluginValid = true;

View File

@ -17,6 +17,7 @@ package org.apache.maven.plugin.version;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
@ -26,10 +27,10 @@ public interface PluginVersionManager
String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws PluginVersionResolutionException;
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, Settings settings,
ArtifactRepository localRepository )
throws PluginVersionResolutionException;
throws PluginVersionResolutionException, InvalidPluginException, PluginVersionNotFoundException;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.lifecycle;
package org.apache.maven.plugin.version;
/*
* Copyright 2001-2005 The Apache Software Foundation.
@ -16,17 +16,29 @@ package org.apache.maven.lifecycle;
* limitations under the License.
*/
/**
* Exception indicating there were no goals given.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class NoGoalsSpecifiedException
public class PluginVersionNotFoundException
extends Exception
{
public NoGoalsSpecifiedException( String message )
private final String groupId;
private final String artifactId;
public PluginVersionNotFoundException( String groupId, String artifactId, String baseMessage )
{
super( message );
super( "Error resolving version for \'" + groupId + ":" + artifactId + "\': " + baseMessage );
this.groupId = groupId;
this.artifactId = artifactId;
}
public String getGroupId()
{
return groupId;
}
public String getArtifactId()
{
return artifactId;
}
}

View File

@ -32,6 +32,7 @@ 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;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -336,7 +337,13 @@ public class DescribeMojo
}
catch ( PluginNotFoundException e )
{
throw new MojoExecutionException( "Plugin does not exist: " + e.getMessage(), e );
getLog().debug( "Unable to find plugin", e );
throw new MojoFailureException( "Plugin does not exist: " + e.getMessage() );
}
catch ( PluginVersionNotFoundException e )
{
getLog().debug( "Unable to find plugin version", e );
throw new MojoFailureException( e.getMessage() );
}
}

View File

@ -32,9 +32,11 @@ import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.InvalidPluginException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.plugins.release.helpers.ProjectScmRewriter;
import org.apache.maven.plugins.release.helpers.ProjectVersionResolver;
@ -940,9 +942,17 @@ public class PrepareReleaseMojo
}
catch ( PluginVersionResolutionException e )
{
getLog().debug( "Error resolving plugin version", e );
throw new MojoFailureException(
"Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage() );
throw new MojoExecutionException(
"Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new MojoExecutionException(
"Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new MojoFailureException( e.getMessage() );
}
if ( ArtifactUtils.isSnapshot( version ) )
@ -977,9 +987,17 @@ public class PrepareReleaseMojo
}
catch ( PluginVersionResolutionException e )
{
getLog().debug( "Error resolving report version", e );
throw new MojoFailureException(
"Cannot resolve version for report '" + plugin.getKey() + "': " + e.getMessage() );
throw new MojoExecutionException(
"Cannot resolve version for report '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( InvalidPluginException e )
{
throw new MojoExecutionException(
"Cannot resolve version for plugin '" + plugin.getKey() + "': " + e.getMessage(), e );
}
catch ( PluginVersionNotFoundException e )
{
throw new MojoFailureException( e.getMessage() );
}
if ( ArtifactUtils.isSnapshot( version ) )