diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 86dea6c543..087cb2fc1b 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionResponse; +import org.apache.maven.execution.MavenProjectExecutionRequest; import org.apache.maven.execution.MavenReactorExecutionRequest; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutor; @@ -39,7 +40,6 @@ import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; -import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.util.ArrayList; @@ -78,14 +78,18 @@ public class DefaultMaven public MavenExecutionResponse execute( MavenExecutionRequest request ) throws GoalNotFoundException, Exception { - MavenExecutionResponse response = new MavenExecutionResponse(); - - handleProject( request ); - - return response; + // TODO: not happy about this: + if ( request instanceof MavenReactorExecutionRequest ) + { + return handleReactor( (MavenReactorExecutionRequest) request ); + } + else + { + return handleProject( request ); + } } - public void handleProject( MavenExecutionRequest request ) + public MavenExecutionResponse handleProject( MavenExecutionRequest request ) throws Exception { MavenSession session = createSession( request ); @@ -98,10 +102,13 @@ public void handleProject( MavenExecutionRequest request ) MavenExecutionResponse response = lifecycleExecutor.execute( request.getGoals(), session ); + // TODO: is this perhaps more appropriate in the CLI? if ( response.isExecutionFailure() ) { if ( response.getException() != null ) { + // 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 @@ -113,14 +120,15 @@ public void handleProject( MavenExecutionRequest request ) { logSuccess( response ); } + return response; } // ---------------------------------------------------------------------- // Reactor // ---------------------------------------------------------------------- - public void handleReactor( MavenExecutionRequest request, MavenExecutionResponse response ) - throws Exception + public MavenExecutionResponse handleReactor( MavenReactorExecutionRequest request ) + throws ReactorException { List projects = new ArrayList(); @@ -128,9 +136,7 @@ public void handleReactor( MavenExecutionRequest request, MavenExecutionResponse try { - List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ), - ( (MavenReactorExecutionRequest) request ).getIncludes(), - ( (MavenReactorExecutionRequest) request ).getExcludes() ); + List files = request.getProjectFiles(); for ( Iterator iterator = files.iterator(); iterator.hasNext(); ) { @@ -169,15 +175,26 @@ public void handleReactor( MavenExecutionRequest request, MavenExecutionResponse line(); - //MavenProjectExecutionRequest projectExecutionRequest = request.createProjectExecutionRequest( project ); + MavenProjectExecutionRequest projectExecutionRequest = request.createProjectExecutionRequest( project ); - //handleProject( projectExecutionRequest, response ); - - if ( response.isExecutionFailure() ) + try { - break; + MavenExecutionResponse response = handleProject( projectExecutionRequest ); + + if ( response.isExecutionFailure() ) + { + return response; + } } + catch ( Exception e ) + { + throw new ReactorException( "Error executing project within the reactor", e ); + } + } + + // TODO: not really satisfactory + return null; } public MavenProject getProject( File pom, ArtifactRepository localRepository ) diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 9f4344c352..058e0dab73 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -136,8 +136,6 @@ public static int main( String[] args, ClassWorld classWorld ) request = new MavenInitializingExecutionRequest( localRepository, mavenProperties, commandLine.getArgList() ); } - MavenExecutionResponse response = new MavenExecutionResponse(); - // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. @@ -158,9 +156,9 @@ public static int main( String[] args, ClassWorld classWorld ) // // ---------------------------------------------------------------------- - response = maven.execute( request ); + MavenExecutionResponse response = maven.execute( request ); - if ( response.isExecutionFailure() ) + if ( response != null && response.isExecutionFailure() ) { return 1; } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenReactorExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenReactorExecutionRequest.java index a18144fbce..8d502f5fb6 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenReactorExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenReactorExecutionRequest.java @@ -18,10 +18,11 @@ */ import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.AbstractMavenExecutionRequest; +import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Properties; @@ -68,10 +69,13 @@ public File getBaseDirectory() } public List getProjectFiles() - throws Exception + throws IOException { - List files = FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ), includes, excludes ); + return FileUtils.getFiles( new File( System.getProperty( "user.dir" ) ), includes, excludes ); + } - return files; + public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project ) + { + return new MavenProjectExecutionRequest( localRepository, parameters, goals, project.getFile() ); } }