change the plugin execution response to be an exception instead since it only handled failures.

any returns from success will be conveyed by the request, soon to be converted into fields on the plugin. These will eventually be extracted using OGNL, but this is all post alpha-1 work


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163621 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-20 23:22:01 +00:00
parent 6e21de0ed2
commit a593e7df88
17 changed files with 155 additions and 207 deletions

View File

@ -27,6 +27,7 @@ import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.model.Repository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -223,7 +224,12 @@ public class DefaultMaven
// TODO: is this perhaps more appropriate in the CLI?
if ( response.isExecutionFailure() )
{
if ( response.getException() != null )
// TODO: yuck! Revisit when cleaning up the exception handling from the top down
if ( response.getException() instanceof PluginExecutionException )
{
logFailure( response, (PluginExecutionException) response.getException() );
}
else
{
// TODO: this should be a "FATAL" exception, reported to the
// developers - however currently a LOT of
@ -231,10 +237,6 @@ public class DefaultMaven
// one example)
logError( response );
}
else
{
logFailure( response );
}
}
else
{
@ -336,7 +338,7 @@ public class DefaultMaven
line();
}
protected void logFailure( MavenExecutionResponse r )
protected void logFailure( MavenExecutionResponse r, PluginExecutionException e )
{
line();
@ -344,11 +346,11 @@ public class DefaultMaven
line();
getLogger().info( "Reason: " + r.getFailureResponse().shortMessage() );
getLogger().info( "Reason: " + e.getMessage() );
line();
getLogger().info( r.getFailureResponse().longMessage() );
getLogger().info( e.getLongMessage() );
line();

View File

@ -17,8 +17,6 @@ package org.apache.maven.execution;
* ====================================================================
*/
import org.apache.maven.plugin.FailureResponse;
import java.util.Date;
/**
@ -27,10 +25,6 @@ import java.util.Date;
*/
public class MavenExecutionResponse
{
private String failedGoal;
private FailureResponse failureResponse;
private Throwable exception;
private Date start;
@ -41,36 +35,9 @@ public class MavenExecutionResponse
// Execution failure
// ----------------------------------------------------------------------
public void setExecutionFailure( String failedGoal, FailureResponse response )
{
this.failedGoal = failedGoal;
this.failureResponse = response;
}
public boolean isExecutionFailure()
{
return ( failedGoal != null || exception != null );
}
public String getFailedGoal()
{
return failedGoal;
}
public void setFailedGoal( String failedGoal )
{
this.failedGoal = failedGoal;
}
public FailureResponse getFailureResponse()
{
return failureResponse;
}
public void setFailureResponse( FailureResponse failureResponse )
{
this.failureResponse = failureResponse;
return ( exception != null );
}
// ----------------------------------------------------------------------

View File

@ -26,7 +26,7 @@ import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -76,6 +76,7 @@ public class DefaultLifecycleExecutor
* @param session
*/
public MavenExecutionResponse execute( List tasks, MavenSession session )
throws LifecycleExecutionException
{
MavenExecutionResponse response = new MavenExecutionResponse();
@ -132,27 +133,22 @@ public class DefaultLifecycleExecutor
if ( phaseMap.containsKey( task ) )
{
executePhase( task, session, response, phaseMap );
executePhase( task, session, phaseMap );
}
else
{
PluginExecutionResponse pluginResponse = executeMojo( task, session );
if ( pluginResponse.isExecutionFailure() )
{
response.setExecutionFailure( task, pluginResponse.getFailureResponse() );
}
}
if ( response.isExecutionFailure() )
{
break;
executeMojo( task, session );
}
}
}
catch ( Exception e )
catch ( PluginExecutionException e )
{
response.setException( e );
}
catch ( Exception e )
{
throw new LifecycleExecutionException( "Error during lifecycle execution", e );
}
finally
{
response.setFinish( new Date() );
@ -210,7 +206,6 @@ public class DefaultLifecycleExecutor
* @param mavenSession
* @throws Exception
*/
// TODO: don't throw Exception
private void processPluginPhases( Plugin plugin, MavenSession mavenSession, Map phaseMap )
throws Exception
{
@ -337,8 +332,8 @@ public class DefaultLifecycleExecutor
configureMojo( mojoDescriptor, phaseMap );
}
private void executePhase( String phase, MavenSession session, MavenExecutionResponse response, Map phaseMap )
throws LifecycleExecutionException
private void executePhase( String phase, MavenSession session, Map phaseMap )
throws PluginExecutionException
{
// only execute up to the given phase
int index = phases.indexOf( phaseMap.get( phase ) );
@ -364,31 +359,22 @@ public class DefaultLifecycleExecutor
{
String goal = (String) i.next();
PluginExecutionResponse pluginResponse = executeMojo( goal, session );
if ( pluginResponse.isExecutionFailure() )
{
response.setExecutionFailure( goal, pluginResponse.getFailureResponse() );
return;
}
executeMojo( goal, session );
}
}
dispatcher.dispatchEnd( event, p.getId() );
}
catch ( LifecycleExecutionException e )
catch ( PluginExecutionException e )
{
dispatcher.dispatchError( event, p.getId(), e );
throw e;
}
// End event monitoring.
dispatcher.dispatchEnd( event, p.getId() );
}
}
protected PluginExecutionResponse executeMojo( String id, MavenSession session )
throws LifecycleExecutionException
protected void executeMojo( String id, MavenSession session )
throws PluginExecutionException
{
// ----------------------------------------------------------------------
// We have something of the form <pluginId>:<mojoId>, so this might be
@ -399,18 +385,12 @@ public class DefaultLifecycleExecutor
// archetype:create
// ----------------------------------------------------------------------
try
{
Logger logger = getLogger();
logger.debug( "Resolving artifacts from:\n" + "\t{localRepository: " + session.getLocalRepository() +
"}\n" + "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
Logger logger = getLogger();
logger.debug( "Resolving artifacts from:" );
logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );
logger.debug( "\t{remoteRepositories: " + session.getRemoteRepositories() + "}" );
return pluginManager.executeMojo( session, id );
}
catch ( GoalExecutionException e )
{
throw new LifecycleExecutionException( "Problem executing " + id, e );
}
pluginManager.executeMojo( session, id );
}
// ----------------------------------------------------------------------

View File

@ -1,42 +0,0 @@
package org.apache.maven.lifecycle;
/* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: GoalExecutionException.java,v 1.3 2004/12/25 16:26:24 jvanzyl
* Exp $
*/
public class GoalExecutionException
extends Exception
{
public GoalExecutionException( String message )
{
super( message );
}
public GoalExecutionException( Throwable cause )
{
super( cause );
}
public GoalExecutionException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -1,32 +0,0 @@
package org.apache.maven.lifecycle;
/*
* ====================================================================
* Copyright 2001-2004 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.
* ====================================================================
*/
public class GoalNotFoundException
extends GoalExecutionException
{
private String goalName;
public GoalNotFoundException( String goal )
{
super( "Unknown goal \"" + goal + "\"" );
this.goalName = goal;
}
public String getGoalName()
{
return this.goalName;
}
}

View File

@ -27,7 +27,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.GoalExecutionException;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Repository;
import org.apache.maven.monitor.event.EventDispatcher;
@ -318,8 +317,8 @@ public class DefaultPluginManager
// Plugin execution
// ----------------------------------------------------------------------
public PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException
public void executeMojo( MavenSession session, String goalName )
throws PluginExecutionException
{
try
{
@ -327,7 +326,7 @@ public class DefaultPluginManager
}
catch ( Exception e )
{
throw new GoalExecutionException( "Unable to execute goal: " + goalName, e );
throw new PluginExecutionException( "Unable to execute goal: " + goalName, e );
}
PluginExecutionRequest request;
@ -337,7 +336,7 @@ public class DefaultPluginManager
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
if ( mojoDescriptor == null )
{
throw new GoalExecutionException( "Unable to find goal: " + goalName );
throw new PluginExecutionException( "Unable to find goal: " + goalName );
}
try
@ -372,7 +371,7 @@ public class DefaultPluginManager
}
catch ( Exception e )
{
throw new GoalExecutionException( "Unable to resolve required dependencies for goal", e );
throw new PluginExecutionException( "Unable to resolve required dependencies for goal", e );
}
try
@ -383,11 +382,9 @@ public class DefaultPluginManager
}
catch ( PluginConfigurationException e )
{
throw new GoalExecutionException( "Error configuring plugin for execution.", e );
throw new PluginExecutionException( "Error configuring plugin for execution.", e );
}
response = new PluginExecutionResponse();
Plugin plugin = null;
try
@ -402,31 +399,36 @@ public class DefaultPluginManager
dispatcher.dispatchStart( event, goalName );
try
{
plugin.execute( request, response );
plugin.execute( request );
dispatcher.dispatchEnd( event, goalName );
}
catch ( Exception e )
catch ( PluginExecutionException e )
{
session.getEventDispatcher().dispatchError( event, goalName, e );
throw e;
}
// End event monitoring.
releaseComponents( mojoDescriptor, request );
container.release( plugin );
}
catch ( ComponentLookupException e )
{
throw new GoalExecutionException( "Error looking up plugin: ", e );
throw new PluginExecutionException( "Error looking up plugin: ", e );
}
catch ( Exception e )
finally
{
throw new GoalExecutionException( "Error executing plugin: ", e );
}
try
{
releaseComponents( mojoDescriptor, request );
return response;
container.release( plugin );
}
catch ( Exception e )
{
// TODO: better error handling, needed!
e.printStackTrace();
}
}
}
// TODO: don't throw Exception
@ -651,21 +653,14 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void downloadDependencies( MavenSession context, ArtifactResolver artifactResolver )
throws GoalExecutionException
throws ArtifactResolutionException
{
try
{
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
artifactResolver.resolve( artifact, context.getRemoteRepositories(), context.getLocalRepository() );
}
}
catch ( ArtifactResolutionException e )
{
throw new GoalExecutionException( "Can't resolve artifact: ", e );
}
}
}

View File

@ -18,7 +18,6 @@ package org.apache.maven.plugin;
*/
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.GoalExecutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
@ -30,8 +29,8 @@ public interface PluginManager
{
String ROLE = PluginManager.class.getName();
PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException;
void executeMojo( MavenSession session, String goalName )
throws PluginExecutionException;
MojoDescriptor getMojoDescriptor( String goalId );

View File

@ -9,7 +9,7 @@ public class GoalDecorationAndResolutionTestPlugin implements Plugin
private boolean executed = false;
public void execute(PluginExecutionRequest request, PluginExecutionResponse response) throws Exception {
public void execute(PluginExecutionRequest request) throws PluginExecutionException {
this.executed = true;
}

View File

@ -27,8 +27,8 @@ public class IntegratedPlugin
extends AbstractTestPlugin
implements Plugin
{
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request )
throws PluginExecutionException
{
name = (String) request.getParameter( "name" );

View File

@ -1,7 +1,7 @@
package org.apache.maven.plugin;
/*
* Copyright 2001-2004 The Apache Software Foundation.
* 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.
@ -16,8 +16,36 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
/** @todo: what purpose does this serve? */
public abstract class AbstractPlugin
implements Plugin
{
/**
* Default behaviour to mimic old behaviour.
*/
public void execute( PluginExecutionRequest request )
throws PluginExecutionException
{
PluginExecutionResponse response = new PluginExecutionResponse();
try
{
execute( request, response );
}
catch ( Exception e )
{
throw new PluginExecutionException( e.getMessage(), e );
}
if ( response.isExecutionFailure() )
{
throw new PluginExecutionException( response.getFailureResponse().getSource(),
response.getFailureResponse().shortMessage(),
response.getFailureResponse().longMessage() );
}
}
/**
* @deprecated
*/
public abstract void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception;
}

View File

@ -32,4 +32,9 @@ public abstract class FailureResponse
public abstract String shortMessage();
public abstract String longMessage();
public Object getSource()
{
return source;
}
}

View File

@ -24,8 +24,7 @@ public interface Plugin
{
String ROLE = Plugin.class.getName();
// TODO: return response.getFailureResponse now as that is the only member of it?
// TODO: make this throw PluginExecutionException instead of generic exception
void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception;
void execute( PluginExecutionRequest request )
throws PluginExecutionException;
}

View File

@ -0,0 +1,52 @@
package org.apache.maven.plugin;
/*
* 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.
*/
/**
* A failure or exception occuring during the execution of a plugin.
*
* @author Brett Porter
* @version $Id$
*/
public class PluginExecutionException extends Exception
{
private Object source;
private String longMessage;
public PluginExecutionException( Object source, String shortMessage, String longMessage )
{
super( shortMessage );
this.source = source;
this.longMessage = longMessage;
}
public PluginExecutionException( String message, Exception cause )
{
super( message, cause );
}
public PluginExecutionException( String message )
{
super( message );
}
public String getLongMessage()
{
return longMessage;
}
}

View File

@ -17,6 +17,7 @@ package org.apache.maven.plugin;
*/
/**
* @deprecated
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/

View File

@ -31,8 +31,6 @@ public abstract class PluginTestCase
protected PluginExecutionRequest request;
protected PluginExecutionResponse response;
protected String basedir;
// ----------------------------------------------------------------------
@ -92,9 +90,7 @@ public abstract class PluginTestCase
request = new PluginExecutionRequest( getTestParameters() );
response = new PluginExecutionResponse();
plugin.execute( request, response );
plugin.execute( request );
validatePluginExecution();
}

View File

@ -54,8 +54,8 @@ public class TestPlugin
return foo;
}
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
public void execute( PluginExecutionRequest request )
throws PluginExecutionException
{
name = (String) request.getParameter( "name" );

View File

@ -18,8 +18,8 @@ package org.apache.maven.plugin;
import junit.framework.TestCase;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -43,9 +43,7 @@ public class TestPluginTest
PluginExecutionRequest request = new PluginExecutionRequest( parameters );
PluginExecutionResponse response = new PluginExecutionResponse();
plugin.execute( request, response );
plugin.execute( request );
assertTrue( plugin.hasExecuted() );