You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by jv...@apache.org on 2004/06/20 04:02:19 UTC
cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/script DefaultGoalDecorator.java
jvanzyl 2004/06/19 19:02:19
Modified: maven-core pom.xml
maven-core/src/main/java/org/apache/maven
DefaultMavenCore.java Maven.java MavenCli.java
MavenCore.java
maven-core/src/main/java/org/apache/maven/lifecycle
AbstractMavenLifecyclePhase.java
DefaultMavenLifecycleManager.java
MavenLifecycleContext.java
MavenLifecycleManager.java
maven-core/src/main/java/org/apache/maven/lifecycle/phase
GoalAttainmentPhase.java
maven-core/src/main/java/org/apache/maven/script
DefaultGoalDecorator.java
Added: maven-core/src/main/java/org/apache/maven
ExecutionResponse.java
Log:
o first pass at a rework to make sure all execeptions and failures filter
all the way back up to MavenCore.
Revision Changes Path
1.2 +7 -2 maven-components/maven-core/pom.xml
Index: pom.xml
===================================================================
RCS file: /home/cvs/maven-components/maven-core/pom.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pom.xml 11 Jun 2004 15:11:52 -0000 1.1
+++ pom.xml 20 Jun 2004 02:02:18 -0000 1.2
@@ -65,8 +65,13 @@
<!-- This will eventually be removed -->
<dependency>
<groupId>plexus</groupId>
- <artifactId>plexus-compiler</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <artifactId>plexus-compiler-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>plexus</groupId>
+ <artifactId>plexus-compiler-javac</artifactId>
+ <version>1.0</version>
</dependency>
<dependency>
<groupId>surefire</groupId>
1.5 +58 -12 maven-components/maven-core/src/main/java/org/apache/maven/DefaultMavenCore.java
Index: DefaultMavenCore.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMavenCore.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultMavenCore.java 17 Jun 2004 01:16:02 -0000 1.4
+++ DefaultMavenCore.java 20 Jun 2004 02:02:18 -0000 1.5
@@ -26,6 +26,7 @@
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.i18n.I18N;
@@ -41,6 +42,7 @@
import java.util.Arrays;
public class DefaultMavenCore
+ extends AbstractLogEnabled
implements MavenCore, Contextualizable
{
private PlexusContainer container;
@@ -63,21 +65,23 @@
// Project execution
// ----------------------------------------------------------------------
- public void execute( List goals )
+ public ExecutionResponse execute( List goals )
throws GoalNotFoundException
{
- execute( (MavenProject) null, goals );
+ return execute( (MavenProject) null, goals );
}
- public void execute( File projectFile, List goals )
+ public ExecutionResponse execute( File projectFile, List goals )
throws ProjectBuildingException, GoalNotFoundException
{
- execute( getProject( projectFile ), goals );
+ return execute( getProject( projectFile ), goals );
}
- public void execute( MavenProject project, List goals )
+ public ExecutionResponse execute( MavenProject project, List goals )
throws GoalNotFoundException
{
+ ExecutionResponse response = new ExecutionResponse();
+
for ( Iterator iterator = goals.iterator(); iterator.hasNext(); )
{
String goal = (String) iterator.next();
@@ -87,27 +91,65 @@
throw new GoalNotFoundException( goal );
}
+ MavenLifecycleContext context;
+
try
{
- lifecycleManager.execute( new MavenLifecycleContext( container, project, getGoalDescriptor( goal ) ) );
+ context = new MavenLifecycleContext( container, project, getGoalDescriptor( goal ) );
+
+ lifecycleManager.execute( context );
+
+ if ( context.isExecutionFailure() )
+ {
+ response.setExecutionFailure( context.getGoal().getName(), context.getFailureResponse() );
+
+ break;
+ }
}
catch ( Exception e )
{
- e.printStackTrace();
+ response.setException( e );
}
}
+
+ if ( response.isExecutionFailure() )
+ {
+ getLogger().info( "----------------------------------------------------------------------------" );
+
+ getLogger().info( "BUILD FAILURE" );
+
+ getLogger().info( "----------------------------------------------------------------------------" );
+
+ getLogger().info( "Reason: " + response.getFailureResponse().shortMessage() + "\n" );
+
+ getLogger().info( "----------------------------------------------------------------------------" );
+
+ getLogger().info( response.getFailureResponse().longMessage() );
+
+ getLogger().info( "----------------------------------------------------------------------------" );
+ }
+ else
+ {
+ getLogger().info( "----------------------------------------------------------------------------" );
+
+ getLogger().info( "BUILD SUCCESSFUL" );
+
+ getLogger().info( "----------------------------------------------------------------------------" );
+ }
+
+ return response;
}
// ----------------------------------------------------------------------
// Reactor execution
// ----------------------------------------------------------------------
- public void executeReactor( String goals, String includes, String excludes )
+ public ExecutionResponse executeReactor( String goals, String includes, String excludes )
throws ReactorException, GoalNotFoundException
{
List projects = new ArrayList();
- System.out.println( "Starting the reactor..." );
+ getLogger().info( "Starting the reactor..." );
try
{
@@ -125,21 +167,25 @@
throw new ReactorException( "Error processing projects for the reactor: ", e );
}
- System.out.println( "Our processing order:" );
+ getLogger().info( "Our processing order:" );
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
MavenProject project = (MavenProject) iterator.next();
- System.out.println( project.getName() );
+ getLogger().info( project.getName() );
}
List goalsList = Arrays.asList( StringUtils.split( goals, "," ) );
+ ExecutionResponse response = null;
+
for ( Iterator iterator = projects.iterator(); iterator.hasNext(); )
{
- execute( (MavenProject) iterator.next(), goalsList );
+ response = execute( (MavenProject) iterator.next(), goalsList );
}
+
+ return response;
}
// ----------------------------------------------------------------------
1.3 +9 -9 maven-components/maven-core/src/main/java/org/apache/maven/Maven.java
Index: Maven.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/Maven.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Maven.java 17 Jun 2004 00:07:23 -0000 1.2
+++ Maven.java 20 Jun 2004 02:02:18 -0000 1.3
@@ -70,32 +70,32 @@
// Project execution
// ----------------------------------------------------------------------
- public void execute( List goals )
+ public ExecutionResponse execute( List goals )
throws GoalNotFoundException
{
- maven.execute( (MavenProject) null, goals );
+ return maven.execute( (MavenProject) null, goals );
}
- public void execute( File projectFile, List goals )
+ public ExecutionResponse execute( File projectFile, List goals )
throws ProjectBuildingException, GoalNotFoundException
{
- maven.execute( getProject( projectFile ), goals );
+ return maven.execute( getProject( projectFile ), goals );
}
- public void execute( MavenProject project, List goals )
+ public ExecutionResponse execute( MavenProject project, List goals )
throws GoalNotFoundException
{
- maven.execute( project, goals );
+ return maven.execute( project, goals );
}
// ----------------------------------------------------------------------
// Reactor execution
// ----------------------------------------------------------------------
- public void executeReactor( String goal, String includes, String excludes )
+ public ExecutionResponse executeReactor( String goal, String includes, String excludes )
throws ReactorException, GoalNotFoundException
{
- maven.executeReactor( goal, includes, excludes );
+ return maven.executeReactor( goal, includes, excludes );
}
// ----------------------------------------------------------------------
1.3 +7 -5 maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java
Index: MavenCli.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenCli.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MavenCli.java 17 Jun 2004 00:07:23 -0000 1.2
+++ MavenCli.java 20 Jun 2004 02:02:18 -0000 1.3
@@ -101,13 +101,15 @@
while ( goals.hasNext() )
{
Goal goal = (Goal)goals.next();
-
+
System.out.println( " " + goal.getName() );
}
return;
}
+ ExecutionResponse response = null;
+
// ----------------------------------------------------------------------
// Execute the goals
// ----------------------------------------------------------------------
@@ -129,15 +131,15 @@
goals += ",";
}
}
-
+
if ( !"".equals( goals ) )
{
- maven.executeReactor( goals, includes, excludes );
+ response = maven.executeReactor( goals, includes, excludes );
}
}
else
{
- maven.execute( projectFile, commandLine.getArgList() );
+ response = maven.execute( projectFile, commandLine.getArgList() );
}
}
1.3 +5 -5 maven-components/maven-core/src/main/java/org/apache/maven/MavenCore.java
Index: MavenCore.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenCore.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MavenCore.java 17 Jun 2004 00:07:23 -0000 1.2
+++ MavenCore.java 20 Jun 2004 02:02:18 -0000 1.3
@@ -37,20 +37,20 @@
// Execution
// ----------------------------------------------------------------------
- void execute( List goals )
+ ExecutionResponse execute( List goals )
throws GoalNotFoundException;
- void execute( MavenProject project, List goals )
+ ExecutionResponse execute( MavenProject project, List goals )
throws GoalNotFoundException;
- void execute( File project, List goals )
+ ExecutionResponse execute( File project, List goals )
throws ProjectBuildingException, GoalNotFoundException;
// ----------------------------------------------------------------------
// Reactor execution
// ----------------------------------------------------------------------
- void executeReactor( String goal, String includes, String excludes )
+ ExecutionResponse executeReactor( String goal, String includes, String excludes )
throws ReactorException, GoalNotFoundException;
// ----------------------------------------------------------------------
1.1 maven-components/maven-core/src/main/java/org/apache/maven/ExecutionResponse.java
Index: ExecutionResponse.java
===================================================================
package org.apache.maven;
import org.apache.maven.plugin.FailureResponse;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id: ExecutionResponse.java,v 1.1 2004/06/20 02:02:18 jvanzyl Exp $
*/
public class ExecutionResponse
{
private String failedGoal;
private FailureResponse failureResponse;
private Throwable exception;
// ----------------------------------------------------------------------
// Execution failure
// ----------------------------------------------------------------------
public void setExecutionFailure( String failedGoal, FailureResponse response )
{
this.failedGoal = failedGoal;
this.failureResponse = response;
}
public boolean isExecutionFailure()
{
return ( failedGoal != 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;
}
// ----------------------------------------------------------------------
// Error
// ----------------------------------------------------------------------
public Throwable getException()
{
return exception;
}
public void setException( Throwable exception )
{
this.exception = exception;
}
}
1.2 +6 -1 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/AbstractMavenLifecyclePhase.java
Index: AbstractMavenLifecyclePhase.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/AbstractMavenLifecyclePhase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractMavenLifecyclePhase.java 11 Jun 2004 15:11:54 -0000 1.1
+++ AbstractMavenLifecyclePhase.java 20 Jun 2004 02:02:18 -0000 1.2
@@ -1,10 +1,15 @@
package org.apache.maven.lifecycle;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractMavenLifecyclePhase
+ extends AbstractLogEnabled
implements MavenLifecyclePhase
{
+ public abstract void execute( MavenLifecycleContext context )
+ throws Exception;
}
1.2 +7 -7 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultMavenLifecycleManager.java
Index: DefaultMavenLifecycleManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultMavenLifecycleManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultMavenLifecycleManager.java 11 Jun 2004 15:11:54 -0000 1.1
+++ DefaultMavenLifecycleManager.java 20 Jun 2004 02:02:18 -0000 1.2
@@ -1,5 +1,7 @@
package org.apache.maven.lifecycle;
+import org.apache.maven.ExecutionResponse;
+
import java.util.Iterator;
import java.util.List;
@@ -24,13 +26,11 @@
{
MavenLifecyclePhase phase = (MavenLifecyclePhase) iterator.next();
- try
- {
- phase.execute( context );
- }
- catch ( Exception cause )
+ phase.execute( context );
+
+ if ( context.isExecutionFailure() )
{
- throw new Exception( "Exception occurred during the execution of " + phase.getClass().getName() + ".", cause );
+ break;
}
}
}
1.6 +42 -1 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java
Index: MavenLifecycleContext.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MavenLifecycleContext.java 18 Jun 2004 02:14:05 -0000 1.5
+++ MavenLifecycleContext.java 20 Jun 2004 02:02:18 -0000 1.6
@@ -1,6 +1,7 @@
package org.apache.maven.lifecycle;
import org.apache.maven.plugin.PluginManager;
+import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.descriptor.Goal;
import org.apache.maven.project.MavenProject;
import org.apache.maven.script.MavenScript;
@@ -15,6 +16,10 @@
*/
public class MavenLifecycleContext
{
+ private String failedGoal;
+
+ private FailureResponse failureResponse;
+
private PlexusContainer container;
private MavenProject project;
@@ -124,5 +129,41 @@
public String getPluginId( Goal goal )
{
return pluginManager.getPluginDescriptor( goal.getName() ).getId();
+ }
+
+ // ----------------------------------------------------------------------
+ // Execution failure
+ // ----------------------------------------------------------------------
+
+ public void setExecutionFailure( String failedGoal, FailureResponse response )
+ {
+ this.failedGoal = failedGoal;
+
+ this.failureResponse = response;
+ }
+
+ public boolean isExecutionFailure()
+ {
+ return ( failedGoal != 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;
}
}
1.2 +3 -1 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleManager.java
Index: MavenLifecycleManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenLifecycleManager.java 11 Jun 2004 15:11:54 -0000 1.1
+++ MavenLifecycleManager.java 20 Jun 2004 02:02:18 -0000 1.2
@@ -1,5 +1,7 @@
package org.apache.maven.lifecycle;
+import org.apache.maven.ExecutionResponse;
+
import java.util.List;
/**
1.7 +16 -14 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalAttainmentPhase.java
Index: GoalAttainmentPhase.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalAttainmentPhase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GoalAttainmentPhase.java 18 Jun 2004 02:14:05 -0000 1.6
+++ GoalAttainmentPhase.java 20 Jun 2004 02:02:19 -0000 1.7
@@ -36,29 +36,26 @@
Goal goal = context.getGoal( goalName );
- System.out.println( "[" + goal.getName() + "]" );
+ getLogger().info( "[" + goal.getName() + "]" );
request = new PluginExecutionRequest( createParameters( goal, context.getProject(), context.getContainer() ) );
response = new PluginExecutionResponse();
- try
- {
- Plugin plugin = (Plugin) context.lookup( Plugin.ROLE, context.getPluginId( goal ) );
+ Plugin plugin = (Plugin) context.lookup( Plugin.ROLE, context.getPluginId( goal ) );
- plugin.execute( request, response );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
+ plugin.execute( request, response );
- response.setException( e );
+ if ( response.isExecutionFailure() )
+ {
+ context.setExecutionFailure( goal.getName(), response.getFailureResponse() );
break;
}
}
}
+ // invalid parameter exception
private Map createParameters( Goal goal, MavenProject project, PlexusContainer container )
{
Map map = null;
@@ -71,13 +68,18 @@
for ( int i = 0; i < parameters.size(); i++ )
{
- Parameter c = (Parameter) parameters.get( i );
+ Parameter parameter = (Parameter) parameters.get( i );
- String key = c.getName();
+ String key = parameter.getName();
- String expression = c.getExpression();
+ String expression = parameter.getExpression();
Object value = OgnlProjectValueExtractor.evaluate( expression, project, container );
+
+ if ( value == null && parameter.isRequired() )
+ {
+
+ }
map.put( key, value );
}
1.2 +1 -1 maven-components/maven-core/src/main/java/org/apache/maven/script/DefaultGoalDecorator.java
Index: DefaultGoalDecorator.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/script/DefaultGoalDecorator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultGoalDecorator.java 11 Jun 2004 15:11:54 -0000 1.1
+++ DefaultGoalDecorator.java 20 Jun 2004 02:02:19 -0000 1.2
@@ -64,7 +64,7 @@
}
catch ( Exception e )
{
- response.setException( e );
+ //response.setException( e );
}
}
}