o Refactored execution event firing

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@933000 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-04-11 21:41:33 +00:00
parent d6c1136f93
commit 91e83d2424
13 changed files with 256 additions and 259 deletions

View File

@ -29,10 +29,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.execution.DefaultLifecycleEvent;
import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequestPopulationException; import org.apache.maven.execution.MavenExecutionRequestPopulationException;
import org.apache.maven.execution.MavenExecutionRequestPopulator; import org.apache.maven.execution.MavenExecutionRequestPopulator;
@ -40,6 +38,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ProjectDependencyGraph; import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.lifecycle.internal.LifecycleWeaveBuilder; import org.apache.maven.lifecycle.internal.LifecycleWeaveBuilder;
import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelSource; import org.apache.maven.model.building.ModelSource;
@ -84,17 +83,8 @@ public class DefaultMaven
@Requirement @Requirement
MavenExecutionRequestPopulator populator; MavenExecutionRequestPopulator populator;
private void fireEvent( MavenSession session, ExecutionEventCatapult catapult ) @Requirement
{ private ExecutionEventCatapult eventCatapult;
ExecutionListener listener = session.getRequest().getExecutionListener();
if ( listener != null )
{
ExecutionEvent event = new DefaultLifecycleEvent( session, null );
catapult.fire( listener, event );
}
}
public MavenExecutionResult execute( MavenExecutionRequest request ) public MavenExecutionResult execute( MavenExecutionRequest request )
{ {
@ -162,7 +152,7 @@ public class DefaultMaven
return processResult( result, e ); return processResult( result, e );
} }
fireEvent( session, ExecutionEventCatapult.PROJECT_DISCOVERY_STARTED ); eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );
//TODO: optimize for the single project or no project //TODO: optimize for the single project or no project

View File

@ -30,6 +30,37 @@ import org.apache.maven.project.MavenProject;
public interface ExecutionEvent public interface ExecutionEvent
{ {
/**
* The possible types of execution events.
*/
enum Type
{
ProjectDiscoveryStarted,
SessionStarted,
SessionEnded,
ProjectSkipped,
ProjectStarted,
ProjectSucceeded,
ProjectFailed,
MojoSkipped,
MojoStarted,
MojoSucceeded,
MojoFailed,
ForkStarted,
ForkSucceeded,
ForkFailed,
ForkedProjectStarted,
ForkedProjectSucceeded,
ForkedProjectFailed,
}
/**
* Gets the type of the event.
*
* @return The type of the event, never {@code null}.
*/
Type getType();
/** /**
* Gets the session from which this event originates. * Gets the session from which this event originates.
* *

View File

@ -14,14 +14,13 @@
*/ */
package org.apache.maven.lifecycle; package org.apache.maven.lifecycle;
import org.apache.maven.execution.DefaultLifecycleEvent;
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.BuildListCalculator; import org.apache.maven.lifecycle.internal.BuildListCalculator;
import org.apache.maven.lifecycle.internal.ConcurrencyDependencyGraph; import org.apache.maven.lifecycle.internal.ConcurrencyDependencyGraph;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.lifecycle.internal.LifecycleDebugLogger; import org.apache.maven.lifecycle.internal.LifecycleDebugLogger;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator; import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.LifecycleModuleBuilder; import org.apache.maven.lifecycle.internal.LifecycleModuleBuilder;
@ -38,7 +37,6 @@ import org.apache.maven.lifecycle.internal.TaskSegment;
import org.apache.maven.lifecycle.internal.ThreadConfigurationService; import org.apache.maven.lifecycle.internal.ThreadConfigurationService;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.InvalidPluginDescriptorException; import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoNotFoundException; import org.apache.maven.plugin.MojoNotFoundException;
import org.apache.maven.plugin.PluginDescriptorParsingException; import org.apache.maven.plugin.PluginDescriptorParsingException;
import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginManagerException;
@ -68,6 +66,10 @@ import java.util.concurrent.ExecutorService;
public class DefaultLifecycleExecutor public class DefaultLifecycleExecutor
implements LifecycleExecutor implements LifecycleExecutor
{ {
@Requirement
private ExecutionEventCatapult eventCatapult;
@Requirement @Requirement
private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer; private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer;
@ -107,7 +109,7 @@ public class DefaultLifecycleExecutor
public void execute( MavenSession session ) public void execute( MavenSession session )
{ {
fireEvent( session, null, LifecycleEventCatapult.SESSION_STARTED ); eventCatapult.fire( ExecutionEvent.Type.SessionStarted, session, null );
MavenExecutionResult result = session.getResult(); MavenExecutionResult result = session.getResult();
@ -200,8 +202,7 @@ public class DefaultLifecycleExecutor
result.addException( e ); result.addException( e );
} }
fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED ); eventCatapult.fire( ExecutionEvent.Type.SessionEnded, session, null );
} }
private void singleThreadedBuild( MavenSession session, ReactorContext callableContext, private void singleThreadedBuild( MavenSession session, ReactorContext callableContext,
@ -230,18 +231,6 @@ public class DefaultLifecycleExecutor
} }
} }
public static void fireEvent( MavenSession session, MojoExecution mojoExecution, LifecycleEventCatapult catapult )
{
ExecutionListener listener = session.getRequest().getExecutionListener();
if ( listener != null )
{
ExecutionEvent event = new DefaultLifecycleEvent( session, mojoExecution );
catapult.fire( listener, event );
}
}
/** /**
* * CRUFT GOES BELOW HERE *** * * CRUFT GOES BELOW HERE ***
*/ */

View File

@ -1,170 +0,0 @@
package org.apache.maven.lifecycle;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener;
/**
* Assists in firing events from a generic method by abstracting from the actual callback method to be called on the
* listener.
*
* @author Benjamin Bentmann
*/
public interface LifecycleEventCatapult
{
/**
* Notifies the specified listener of the given event.
*
* @param listener The listener to notify, must not be {@code null}.
* @param event The event to fire, must not be {@code null}.
*/
void fire( ExecutionListener listener, ExecutionEvent event );
static final LifecycleEventCatapult SESSION_STARTED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.sessionStarted( event );
}
};
static final LifecycleEventCatapult SESSION_ENDED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.sessionEnded( event );
}
};
static final LifecycleEventCatapult PROJECT_SKIPPED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.projectSkipped( event );
}
};
static final LifecycleEventCatapult PROJECT_STARTED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.projectStarted( event );
}
};
static final LifecycleEventCatapult PROJECT_SUCCEEDED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.projectSucceeded( event );
}
};
static final LifecycleEventCatapult PROJECT_FAILED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.projectFailed( event );
}
};
static final LifecycleEventCatapult MOJO_SKIPPED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.mojoSkipped( event );
}
};
static final LifecycleEventCatapult MOJO_STARTED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.mojoStarted( event );
}
};
static final LifecycleEventCatapult MOJO_SUCCEEDED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.mojoSucceeded( event );
}
};
static final LifecycleEventCatapult MOJO_FAILED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.mojoFailed( event );
}
};
static final LifecycleEventCatapult FORK_STARTED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkStarted( event );
}
};
static final LifecycleEventCatapult FORK_SUCCEEDED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkSucceeded( event );
}
};
static final LifecycleEventCatapult FORK_FAILED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkFailed( event );
}
};
static final LifecycleEventCatapult FORKED_PROJECT_STARTED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkedProjectStarted( event );
}
};
static final LifecycleEventCatapult FORKED_PROJECT_SUCCEEDED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkedProjectSucceeded( event );
}
};
static final LifecycleEventCatapult FORKED_PROJECT_FAILED = new LifecycleEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.forkedProjectFailed( event );
}
};
}

View File

@ -15,6 +15,7 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.BuildFailure; import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.*; import org.apache.maven.lifecycle.*;
@ -45,6 +46,9 @@ public class BuilderCommon
@Requirement @Requirement
private LifecycleDependencyResolver lifecycleDependencyResolver; private LifecycleDependencyResolver lifecycleDependencyResolver;
@Requirement
private ExecutionEventCatapult eventCatapult;
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public BuilderCommon() public BuilderCommon()
{ {
@ -79,7 +83,7 @@ public class BuilderCommon
} }
public static void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession, public void handleBuildError( final ReactorContext buildContext, final MavenSession rootSession,
final MavenProject mavenProject, final Exception e, final long buildStartTime ) final MavenProject mavenProject, final Exception e, final long buildStartTime )
{ {
buildContext.getResult().addException( e ); buildContext.getResult().addException( e );
@ -88,7 +92,7 @@ public class BuilderCommon
buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, e ) ); buildContext.getResult().addBuildSummary( new BuildFailure( mavenProject, buildEndTime - buildStartTime, e ) );
DefaultLifecycleExecutor.fireEvent( rootSession, null, LifecycleEventCatapult.PROJECT_FAILED ); eventCatapult.fire( ExecutionEvent.Type.ProjectFailed, rootSession, null );
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) ) if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( rootSession.getReactorFailureBehavior() ) )
{ {

View File

@ -1,4 +1,4 @@
package org.apache.maven.execution; package org.apache.maven.lifecycle.internal;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -19,6 +19,8 @@ package org.apache.maven.execution;
* under the License. * under the License.
*/ */
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
@ -27,20 +29,28 @@ import org.apache.maven.project.MavenProject;
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
public class DefaultLifecycleEvent class DefaultExecutionEvent
implements ExecutionEvent implements ExecutionEvent
{ {
private final Type type;
private final MavenSession session; private final MavenSession session;
private final MojoExecution mojoExecution; private final MojoExecution mojoExecution;
public DefaultLifecycleEvent( MavenSession session, MojoExecution mojoExecution ) public DefaultExecutionEvent( Type type, MavenSession session, MojoExecution mojoExecution )
{ {
this.type = type;
this.session = session; this.session = session;
this.mojoExecution = mojoExecution; this.mojoExecution = mojoExecution;
} }
public Type getType()
{
return type;
}
public MavenSession getSession() public MavenSession getSession()
{ {
return session; return session;

View File

@ -0,0 +1,113 @@
package org.apache.maven.lifecycle.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.codehaus.plexus.component.annotations.Component;
/**
* Assists in firing execution events. <strong>Warning:</strong> This is an internal utility class that is only public
* for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without
* prior notice.
*
* @author Benjamin Bentmann
*/
@Component( role = ExecutionEventCatapult.class )
public class DefaultExecutionEventCatapult
implements ExecutionEventCatapult
{
public void fire( ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution )
{
ExecutionListener listener = session.getRequest().getExecutionListener();
if ( listener != null )
{
ExecutionEvent event = new DefaultExecutionEvent( eventType, session, mojoExecution );
switch ( eventType )
{
case ProjectDiscoveryStarted:
listener.projectDiscoveryStarted( event );
break;
case SessionStarted:
listener.sessionStarted( event );
break;
case SessionEnded:
listener.sessionEnded( event );
break;
case ProjectSkipped:
listener.projectSkipped( event );
break;
case ProjectStarted:
listener.projectStarted( event );
break;
case ProjectSucceeded:
listener.projectSucceeded( event );
break;
case ProjectFailed:
listener.projectFailed( event );
break;
case MojoSkipped:
listener.mojoSkipped( event );
break;
case MojoStarted:
listener.mojoStarted( event );
break;
case MojoSucceeded:
listener.mojoSucceeded( event );
break;
case MojoFailed:
listener.mojoFailed( event );
break;
case ForkStarted:
listener.forkStarted( event );
break;
case ForkSucceeded:
listener.forkSucceeded( event );
break;
case ForkFailed:
listener.forkFailed( event );
break;
case ForkedProjectStarted:
listener.forkedProjectStarted( event );
break;
case ForkedProjectSucceeded:
listener.forkedProjectSucceeded( event );
break;
case ForkedProjectFailed:
listener.forkedProjectFailed( event );
break;
default:
throw new IllegalStateException( "Unknown execution event type " + eventType );
}
}
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven; package org.apache.maven.lifecycle.internal;
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -20,31 +20,19 @@ package org.apache.maven;
*/ */
import org.apache.maven.execution.ExecutionEvent; import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener; import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
/** /**
* Assists in firing events from a generic method by abstracting from the actual callback method to be called on the * Assists in firing execution events. <strong>Warning:</strong> This is an internal utility interface that is only
* listener. * public for technical reasons, it is not part of the public API. In particular, this interface can be changed or
* deleted without prior notice.
* *
* @author Benjamin Bentmann * @author Benjamin Bentmann
*/ */
interface ExecutionEventCatapult public interface ExecutionEventCatapult
{ {
/** void fire( ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution );
* Notifies the specified listener of the given event.
*
* @param listener The listener to notify, must not be {@code null}.
* @param event The event to fire, must not be {@code null}.
*/
void fire( ExecutionListener listener, ExecutionEvent event );
static final ExecutionEventCatapult PROJECT_DISCOVERY_STARTED = new ExecutionEventCatapult()
{
public void fire( ExecutionListener listener, ExecutionEvent event )
{
listener.projectDiscoveryStarted( event );
}
};
} }

View File

@ -16,9 +16,8 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.BuildSuccess;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.DefaultLifecycleExecutor;
import org.apache.maven.lifecycle.LifecycleEventCatapult;
import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
@ -36,12 +35,16 @@ import org.codehaus.plexus.component.annotations.Requirement;
@Component(role = LifecycleModuleBuilder.class) @Component(role = LifecycleModuleBuilder.class)
public class LifecycleModuleBuilder public class LifecycleModuleBuilder
{ {
@Requirement @Requirement
private MojoExecutor mojoExecutor; private MojoExecutor mojoExecutor;
@Requirement @Requirement
private BuilderCommon builderCommon; private BuilderCommon builderCommon;
@Requirement
private ExecutionEventCatapult eventCatapult;
public void buildProject( MavenSession session, ReactorContext reactorContext, MavenProject currentProject, public void buildProject( MavenSession session, ReactorContext reactorContext, MavenProject currentProject,
TaskSegment taskSegment ) TaskSegment taskSegment )
{ {
@ -62,11 +65,11 @@ public class LifecycleModuleBuilder
if ( reactorContext.getReactorBuildStatus().isHaltedOrBlacklisted( currentProject ) ) if ( reactorContext.getReactorBuildStatus().isHaltedOrBlacklisted( currentProject ) )
{ {
DefaultLifecycleExecutor.fireEvent( session, null, LifecycleEventCatapult.PROJECT_SKIPPED ); eventCatapult.fire( ExecutionEvent.Type.ProjectSkipped, session, null );
return; return;
} }
DefaultLifecycleExecutor.fireEvent( session, null, LifecycleEventCatapult.PROJECT_STARTED ); eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, session, null );
BuilderCommon.attachToThread( currentProject ); BuilderCommon.attachToThread( currentProject );
MavenExecutionPlan executionPlan = builderCommon.resolveBuildPlan( session, currentProject, taskSegment ); MavenExecutionPlan executionPlan = builderCommon.resolveBuildPlan( session, currentProject, taskSegment );
@ -80,11 +83,11 @@ public class LifecycleModuleBuilder
reactorContext.getResult().addBuildSummary( reactorContext.getResult().addBuildSummary(
new BuildSuccess( currentProject, buildEndTime - buildStartTime ) ); new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
DefaultLifecycleExecutor.fireEvent( session, null, LifecycleEventCatapult.PROJECT_SUCCEEDED ); eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, session, null );
} }
catch ( Exception e ) catch ( Exception e )
{ {
BuilderCommon.handleBuildError( reactorContext, rootSession, currentProject, e, buildStartTime ); builderCommon.handleBuildError( reactorContext, rootSession, currentProject, e, buildStartTime );
} }
finally finally
{ {

View File

@ -15,6 +15,7 @@
package org.apache.maven.lifecycle.internal; package org.apache.maven.lifecycle.internal;
import org.apache.maven.execution.BuildSuccess; import org.apache.maven.execution.BuildSuccess;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.*; import org.apache.maven.lifecycle.*;
@ -50,6 +51,7 @@ import java.util.concurrent.Future;
@Component(role = LifecycleWeaveBuilder.class) @Component(role = LifecycleWeaveBuilder.class)
public class LifecycleWeaveBuilder public class LifecycleWeaveBuilder
{ {
@Requirement @Requirement
private MojoExecutor mojoExecutor; private MojoExecutor mojoExecutor;
@ -62,6 +64,8 @@ public class LifecycleWeaveBuilder
@Requirement @Requirement
private LifecycleDependencyResolver lifecycleDependencyResolver; private LifecycleDependencyResolver lifecycleDependencyResolver;
@Requirement
private ExecutionEventCatapult eventCatapult;
private final Map<MavenProject, MavenExecutionPlan> executionPlans = private final Map<MavenProject, MavenExecutionPlan> executionPlans =
Collections.synchronizedMap( new HashMap<MavenProject, MavenExecutionPlan>() ); Collections.synchronizedMap( new HashMap<MavenProject, MavenExecutionPlan>() );
@ -73,12 +77,13 @@ public class LifecycleWeaveBuilder
} }
public LifecycleWeaveBuilder( MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger, public LifecycleWeaveBuilder( MojoExecutor mojoExecutor, BuilderCommon builderCommon, Logger logger,
LifecycleDependencyResolver lifecycleDependencyResolver ) LifecycleDependencyResolver lifecycleDependencyResolver, ExecutionEventCatapult eventCatapult )
{ {
this.mojoExecutor = mojoExecutor; this.mojoExecutor = mojoExecutor;
this.builderCommon = builderCommon; this.builderCommon = builderCommon;
this.logger = logger; this.logger = logger;
this.lifecycleDependencyResolver = lifecycleDependencyResolver; this.lifecycleDependencyResolver = lifecycleDependencyResolver;
this.eventCatapult = eventCatapult;
} }
public void build( ProjectBuildList projectBuilds, ReactorContext buildContext, List<TaskSegment> taskSegments, public void build( ProjectBuildList projectBuilds, ReactorContext buildContext, List<TaskSegment> taskSegments,
@ -157,13 +162,11 @@ public class LifecycleWeaveBuilder
if ( reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() ) ) if ( reactorBuildStatus.isHaltedOrBlacklisted( projectBuild.getProject() ) )
{ {
DefaultLifecycleExecutor.fireEvent( projectBuild.getSession(), null, eventCatapult.fire( ExecutionEvent.Type.ProjectSkipped, projectBuild.getSession(), null );
LifecycleEventCatapult.PROJECT_SKIPPED );
return null; return null;
} }
DefaultLifecycleExecutor.fireEvent( projectBuild.getSession(), null, eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, projectBuild.getSession(), null );
LifecycleEventCatapult.PROJECT_STARTED );
boolean packagePhaseSeen = false; boolean packagePhaseSeen = false;
boolean runBAbyRun = false; boolean runBAbyRun = false;
@ -238,13 +241,11 @@ public class LifecycleWeaveBuilder
final BuildSuccess summary = final BuildSuccess summary =
new BuildSuccess( projectBuild.getProject(), wallClockTime ); // - waitingTime new BuildSuccess( projectBuild.getProject(), wallClockTime ); // - waitingTime
reactorContext.getResult().addBuildSummary( summary ); reactorContext.getResult().addBuildSummary( summary );
DefaultLifecycleExecutor.fireEvent( projectBuild.getSession(), null, eventCatapult.fire( ExecutionEvent.Type.ProjectSucceeded, projectBuild.getSession(), null );
LifecycleEventCatapult.PROJECT_SUCCEEDED );
} }
catch ( Exception e ) catch ( Exception e )
{ {
BuilderCommon.handleBuildError( reactorContext, rootSession, projectBuild.getProject(), e, builderCommon.handleBuildError( reactorContext, rootSession, projectBuild.getProject(), e,
buildStartTime ); buildStartTime );
} }
finally finally

View File

@ -16,9 +16,8 @@ package org.apache.maven.lifecycle.internal;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter; import org.apache.maven.artifact.resolver.filter.CumulativeScopeArtifactFilter;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.DefaultLifecycleExecutor;
import org.apache.maven.lifecycle.LifecycleEventCatapult;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.MissingProjectException; import org.apache.maven.lifecycle.MissingProjectException;
import org.apache.maven.plugin.*; import org.apache.maven.plugin.*;
@ -52,6 +51,9 @@ public class MojoExecutor
@Requirement @Requirement
private LifecycleDependencyResolver lifeCycleDependencyResolver; private LifecycleDependencyResolver lifeCycleDependencyResolver;
@Requirement
private ExecutionEventCatapult eventCatapult;
public MojoExecutor() public MojoExecutor()
{ {
} }
@ -103,7 +105,7 @@ public class MojoExecutor
} }
else else
{ {
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_SKIPPED ); eventCatapult.fire( ExecutionEvent.Type.MojoSkipped, session, mojoExecution );
return; return;
} }
@ -114,7 +116,7 @@ public class MojoExecutor
List<MavenProject> forkedProjects = List<MavenProject> forkedProjects =
executeForkedExecutions( mojoExecution, session, projectIndex, dependencyContext ); executeForkedExecutions( mojoExecution, session, projectIndex, dependencyContext );
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_STARTED ); eventCatapult.fire( ExecutionEvent.Type.MojoStarted, session, mojoExecution );
ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor ); ArtifactFilter artifactFilter = getArtifactFilter( mojoDescriptor );
List<MavenProject> resolvedProjects = List<MavenProject> resolvedProjects =
@ -148,11 +150,11 @@ public class MojoExecutor
throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e ); throw new LifecycleExecutionException( mojoExecution, session.getCurrentProject(), e );
} }
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_SUCCEEDED ); eventCatapult.fire( ExecutionEvent.Type.MojoSucceeded, session, mojoExecution );
} }
catch ( LifecycleExecutionException e ) catch ( LifecycleExecutionException e )
{ {
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_FAILED ); eventCatapult.fire( ExecutionEvent.Type.MojoFailed, session, mojoExecution );
throw e; throw e;
} }
@ -200,7 +202,7 @@ public class MojoExecutor
if ( !forkedExecutions.isEmpty() ) if ( !forkedExecutions.isEmpty() )
{ {
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_STARTED ); eventCatapult.fire( ExecutionEvent.Type.ForkStarted, session, mojoExecution );
MavenProject project = session.getCurrentProject(); MavenProject project = session.getCurrentProject();
@ -228,18 +230,15 @@ public class MojoExecutor
session.getProjects().set( index, executedProject ); session.getProjects().set( index, executedProject );
projectIndex.getProjects().put( fork.getKey(), executedProject ); projectIndex.getProjects().put( fork.getKey(), executedProject );
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, eventCatapult.fire( ExecutionEvent.Type.ForkedProjectStarted, session, mojoExecution );
LifecycleEventCatapult.FORKED_PROJECT_STARTED );
execute( session, fork.getValue(), projectIndex, dependencyContext ); execute( session, fork.getValue(), projectIndex, dependencyContext );
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, eventCatapult.fire( ExecutionEvent.Type.ForkedProjectSucceeded, session, mojoExecution );
LifecycleEventCatapult.FORKED_PROJECT_SUCCEEDED );
} }
catch ( LifecycleExecutionException e ) catch ( LifecycleExecutionException e )
{ {
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, eventCatapult.fire( ExecutionEvent.Type.ForkedProjectFailed, session, mojoExecution );
LifecycleEventCatapult.FORKED_PROJECT_FAILED );
throw e; throw e;
} }
@ -251,11 +250,11 @@ public class MojoExecutor
} }
} }
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_SUCCEEDED ); eventCatapult.fire( ExecutionEvent.Type.ForkSucceeded, session, mojoExecution );
} }
catch ( LifecycleExecutionException e ) catch ( LifecycleExecutionException e )
{ {
DefaultLifecycleExecutor.fireEvent( session, mojoExecution, LifecycleEventCatapult.FORK_FAILED ); eventCatapult.fire( ExecutionEvent.Type.ForkFailed, session, mojoExecution );
throw e; throw e;
} }

View File

@ -21,6 +21,7 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleNotFoundException; import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException; import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.internal.stub.CompletionServiceStub; import org.apache.maven.lifecycle.internal.stub.CompletionServiceStub;
import org.apache.maven.lifecycle.internal.stub.ExecutionEventCatapultStub;
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub; import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
import org.apache.maven.lifecycle.internal.stub.LoggerStub; import org.apache.maven.lifecycle.internal.stub.LoggerStub;
import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub; import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
@ -121,8 +122,8 @@ public class LifecycleWeaveBuilderTest
final LoggerStub loggerStub = new LoggerStub(); final LoggerStub loggerStub = new LoggerStub();
final LifecycleDependencyResolver lifecycleDependencyResolver = final LifecycleDependencyResolver lifecycleDependencyResolver =
new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub ); new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub );
return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, lifecycleDependencyResolver ); return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, lifecycleDependencyResolver,
new ExecutionEventCatapultStub() );
} }
private BuilderCommon getBuilderCommon() private BuilderCommon getBuilderCommon()

View File

@ -0,0 +1,38 @@
package org.apache.maven.lifecycle.internal.stub;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ExecutionEvent.Type;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.plugin.MojoExecution;
/**
* @author Benjamin Bentmann
*/
public class ExecutionEventCatapultStub
implements ExecutionEventCatapult
{
public void fire( Type eventType, MavenSession session, MojoExecution mojoExecution )
{
}
}