Author: jdcasey Date: Thu Jul 28 20:47:07 2005 New Revision: 226334 URL: http://svn.apache.org/viewcvs?rev=226334&view=rev Log: Resolving: MNG-250
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=226334&r1=226333&r2=226334&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Thu Jul 28 20:47:07 2005 @@ -125,11 +125,14 @@ } EventDispatcher dispatcher = request.getEventDispatcher(); + String event = MavenEvents.REACTOR_EXECUTION; dispatcher.dispatchStart( event, request.getBaseDirectory() ); List projects; + + MavenProject topLevelProject; try { @@ -137,8 +140,14 @@ projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), request.getSettings() ); - - projects = ProjectSorter.getSortedProjects( projects ); + + // 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. + + // TODO: !![jc; 28-jul-2005] check this; if we're using '-r' and there are aggregator tasks, this will result in weirdness. + topLevelProject = (MavenProject) projects.get( 0 ); + + projects = ProjectSorter.getSortedProjects(projects); if ( projects.isEmpty() ) { @@ -152,10 +161,6 @@ { throw new ReactorException( "Error processing projects for the reactor: ", e ); } - catch ( CycleDetectedException e ) - { - throw new ReactorException( "Error processing projects for the reactor: ", e ); - } catch ( ArtifactResolutionException e ) { dispatcher.dispatchError( event, request.getBaseDirectory(), e ); @@ -180,38 +185,73 @@ return response; } + catch ( CycleDetectedException e ) + { + dispatcher.dispatchError( event, request.getBaseDirectory(), e ); + + MavenExecutionResponse response = new MavenExecutionResponse(); + response.setStart( new Date() ); + response.setFinish( new Date() ); + response.setException( e ); + logFailure( response, e, null ); + + return response; + } try { MavenSession session = createSession( request, projects ); - List goals = request.getGoals(); - - for ( Iterator iterator = projects.iterator(); iterator.hasNext(); ) + try { - MavenProject project = (MavenProject) iterator.next(); - - line(); - - getLogger().info( "Building " + project.getName() ); + MavenExecutionResponse response = lifecycleExecutor.execute( session, topLevelProject, dispatcher ); + + // TODO: is this perhaps more appropriate in the CLI? + if ( response.isExecutionFailure() ) + { + dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() ); - line(); + // TODO: yuck! Revisit when cleaning up the exception handling from the top down + Throwable exception = response.getException(); - try - { - MavenExecutionResponse response = processProject( session, goals, project, dispatcher ); - if ( response.isExecutionFailure() ) + if ( exception instanceof MojoExecutionException ) { - dispatcher.dispatchError( event, request.getBaseDirectory(), response.getException() ); - - return response; + if ( exception.getCause() == null ) + { + MojoExecutionException e = (MojoExecutionException) exception; + + logFailure( response, e, e.getLongMessage() ); + } + else + { + // TODO: throw exceptions like this, so "failures" are just that + logError( response ); + } + } + else if ( exception instanceof ArtifactResolutionException ) + { + logFailure( response, 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 ); } + + return response; } - catch ( LifecycleExecutionException e ) + else { - throw new ReactorException( "Error executing project within the reactor", e ); + logSuccess( response ); } } + catch ( LifecycleExecutionException e ) + { + throw new ReactorException( "Error executing project within the reactor", e ); + } dispatcher.dispatchEnd( event, request.getBaseDirectory() ); @@ -277,70 +317,6 @@ return projects; } - private MavenExecutionResponse processProject( MavenSession session, List goals, MavenProject project, - EventDispatcher dispatcher ) - throws LifecycleExecutionException - { - // !! This is ripe for refactoring to an aspect. - // Event monitoring. - String event = MavenEvents.PROJECT_EXECUTION; - - dispatcher.dispatchStart( event, project.getId() ); - - MavenExecutionResponse response; - try - { - // Actual meat of the code. - response = lifecycleExecutor.execute( goals, session, project ); - - dispatcher.dispatchEnd( event, project.getId() ); - } - catch ( LifecycleExecutionException e ) - { - dispatcher.dispatchError( event, project.getId(), e ); - throw e; - } - // End event monitoring. - - // TODO: is this perhaps more appropriate in the CLI? - if ( response.isExecutionFailure() ) - { - // TODO: yuck! Revisit when cleaning up the exception handling from the top down - Throwable exception = response.getException(); - - if ( exception instanceof MojoExecutionException ) - { - if ( exception.getCause() == null ) - { - MojoExecutionException e = (MojoExecutionException) exception; - logFailure( response, e, e.getLongMessage() ); - } - else - { - // TODO: throw exceptions like this, so "failures" are just that - logError( response ); - } - } - else if ( exception instanceof ArtifactResolutionException ) - { - logFailure( response, 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 ); - } - return response; - } - public MavenProject getProject( File pom, ArtifactRepository localRepository, Settings settings ) throws ProjectBuildingException, ArtifactResolutionException { @@ -691,6 +667,7 @@ files = Collections.singletonList( projectFile ); } } + return files; } Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=226334&r1=226333&r2=226334&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java Thu Jul 28 20:47:07 2005 @@ -30,6 +30,8 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; 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.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.PluginManager; @@ -40,7 +42,6 @@ import org.apache.maven.plugin.lifecycle.Execution; import org.apache.maven.plugin.lifecycle.Lifecycle; import org.apache.maven.plugin.lifecycle.Phase; -import org.apache.maven.plugin.mapping.MavenPluginMappingBuilder; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.injection.ModelDefaultsInjector; @@ -77,8 +78,6 @@ private ModelDefaultsInjector modelDefaultsInjector; - private MavenPluginMappingBuilder pluginMappingBuilder; - private PluginManager pluginManager; private ExtensionManager extensionManager; @@ -101,9 +100,11 @@ * @param session * @param project */ - public MavenExecutionResponse execute( List tasks, MavenSession session, MavenProject project ) + public MavenExecutionResponse execute( MavenSession session, MavenProject project, EventDispatcher dispatcher ) throws LifecycleExecutionException { + List taskSegments = segmentTaskListByAggregationNeeds( session.getGoals(), session, project ); + MavenExecutionResponse response = new MavenExecutionResponse(); response.setStart( new Date() ); @@ -119,11 +120,7 @@ Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() ); artifactHandlerManager.addHandlers( handlers ); - for ( Iterator i = tasks.iterator(); i.hasNext(); ) - { - String task = (String) i.next(); - executeGoal( task, session, project ); - } + executeTaskSegments( taskSegments, session, project, dispatcher ); } catch ( MojoExecutionException e ) { @@ -157,6 +154,178 @@ return response; } + private void executeTaskSegments( List taskSegments, MavenSession session, MavenProject project, + EventDispatcher dispatcher ) + throws PluginNotFoundException, MojoExecutionException, ArtifactResolutionException, + LifecycleExecutionException + { + for ( Iterator it = taskSegments.iterator(); it.hasNext(); ) + { + TaskSegment segment = (TaskSegment) it.next(); + + if ( segment.aggregate() ) + { + line(); + + getLogger().info( "Building " + project.getName() ); + + getLogger().info( " " + segment ); + + line(); + + // !! This is ripe for refactoring to an aspect. + // Event monitoring. + String event = MavenEvents.PROJECT_EXECUTION; + + dispatcher.dispatchStart( event, project.getId() + " ( " + segment + " )" ); + + try + { + // 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(); + + executeGoal( task, session, project ); + } + + dispatcher.dispatchEnd( event, project.getId() + " ( " + segment + " )" ); + } + catch ( LifecycleExecutionException e ) + { + dispatcher.dispatchError( event, project.getId() + " ( " + segment + " )", e ); + + throw e; + } + } + else + { + List sortedProjects = session.getSortedProjects(); + + // iterate over projects, and execute on each... + for ( Iterator projectIterator = sortedProjects.iterator(); projectIterator.hasNext(); ) + { + MavenProject currentProject = (MavenProject) projectIterator.next(); + + line(); + + getLogger().info( "Building " + currentProject.getName() ); + + getLogger().info( " " + segment ); + + line(); + + // !! This is ripe for refactoring to an aspect. + // Event monitoring. + String event = MavenEvents.PROJECT_EXECUTION; + + dispatcher.dispatchStart( event, currentProject.getId() + " ( " + segment + " )" ); + + try + { + for ( Iterator goalIterator = segment.getTasks().iterator(); goalIterator.hasNext(); ) + { + String task = (String) goalIterator.next(); + + executeGoal( task, session, currentProject ); + } + + dispatcher.dispatchEnd( event, currentProject.getId() + " ( " + segment + " )" ); + } + catch ( LifecycleExecutionException e ) + { + dispatcher.dispatchError( event, currentProject.getId() + " ( " + segment + " )", e ); + + throw e; + } + } + } + } + } + + private List segmentTaskListByAggregationNeeds( List tasks, MavenSession session, MavenProject project ) + throws LifecycleExecutionException + { + List segments = new ArrayList(); + + TaskSegment currentSegment = null; + for ( Iterator it = tasks.iterator(); it.hasNext(); ) + { + String task = (String) it.next(); + + // if it's a phase, then we don't need to check whether it's an aggregator. + // simply add it to the current task partition. + if ( phases.contains( task ) ) + { + if ( currentSegment != null && currentSegment.aggregate() ) + { + segments.add( currentSegment ); + currentSegment = null; + } + + if ( currentSegment == null ) + { + currentSegment = new TaskSegment(); + } + + currentSegment.add( task ); + } + else + { + MojoDescriptor mojo = null; + try + { + mojo = getMojoDescriptor( task, session, project ); + } + catch ( LifecycleExecutionException e ) + { + getLogger().info( "Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." ); + getLogger().debug( "", e ); + } + catch ( ArtifactResolutionException e ) + { + getLogger().info( "Cannot find mojo descriptor for: \'" + task + "\' - Treating as non-aggregator." ); + getLogger().debug( "", e ); + } + + if ( mojo != null && mojo.isAggregator() ) + { + if ( currentSegment != null && !currentSegment.aggregate() ) + { + segments.add( currentSegment ); + currentSegment = null; + } + + if ( currentSegment == null ) + { + currentSegment = new TaskSegment( true ); + } + + currentSegment.add( task ); + } + else + { + if ( currentSegment != null && currentSegment.aggregate() ) + { + segments.add( currentSegment ); + currentSegment = null; + } + + if ( currentSegment == null ) + { + currentSegment = new TaskSegment(); + } + + currentSegment.add( task ); + } + } + } + + segments.add( currentSegment ); + + return segments; + } + private void executeGoal( String task, MavenSession session, MavenProject project ) throws LifecycleExecutionException, PluginNotFoundException, MojoExecutionException, ArtifactResolutionException { @@ -716,6 +885,70 @@ } project.addPlugin( plugin ); + } + } + + protected void line() + { + getLogger().info( "----------------------------------------------------------------------------" ); + } + + private static class TaskSegment + { + private boolean aggregate = false; + private List tasks = new ArrayList(); + + TaskSegment() + { + + } + + TaskSegment( boolean aggregate ) + { + this.aggregate = aggregate; + } + + public String toString() + { + StringBuffer message = new StringBuffer(); + + message.append( " task-segment: [" ); + + for ( Iterator it = tasks.iterator(); it.hasNext(); ) + { + String task = (String) it.next(); + + message.append( task ); + + if ( it.hasNext() ) + { + message.append( ", "); + } + } + + message.append( "]" ); + + if ( aggregate ) + { + message.append( " (aggregator-style)" ); + } + + return message.toString(); + } + + boolean aggregate() + { + return aggregate; + } + + void add( String task ) + { + tasks.add( task ); + } + + List getTasks() + { + return tasks; } } } Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=226334&r1=226333&r2=226334&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java Thu Jul 28 20:47:07 2005 @@ -18,10 +18,9 @@ import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenSession; +import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.project.MavenProject; -import java.util.List; - /** * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @version $Id$ @@ -30,7 +29,7 @@ { String ROLE = LifecycleExecutor.class.getName(); - MavenExecutionResponse execute( List tasks, MavenSession session, MavenProject project ) + MavenExecutionResponse execute( MavenSession session, MavenProject project, EventDispatcher dispatcher ) throws LifecycleExecutionException; } Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=226334&r1=226333&r2=226334&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original) +++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Thu Jul 28 20:47:07 2005 @@ -276,7 +276,7 @@ throws ArtifactResolutionException, PlexusContainerException { artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository ); - + PlexusContainer child = container.createChildContainer( plugin.getKey(), Collections.singletonList( pluginArtifact.getFile() ), Collections.EMPTY_MAP, Modified: maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=226334&r1=226333&r2=226334&view=diff ============================================================================== --- maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml (original) +++ maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml Thu Jul 28 20:47:07 2005 @@ -137,9 +137,6 @@ <role>org.apache.maven.project.injection.ModelDefaultsInjector</role> </requirement> <requirement> - <role>org.apache.maven.plugin.mapping.MavenPluginMappingBuilder</role> - </requirement> - <requirement> <role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role> </requirement> </requirements> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]