mirror of https://github.com/apache/maven.git
MNG-5549 introduced MojoExecutionEvent and ProjectExecutionEvent
Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
parent
b610e6d045
commit
e698ce6e67
|
@ -0,0 +1,87 @@
|
|||
package org.apache.maven.execution;
|
||||
|
||||
/*
|
||||
* 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.scope.WeakMojoExecutionListener;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Encapsulates parameters of MojoExecutionListener callback methods and is meant to provide API evolution path should
|
||||
* it become necessary to introduce new parameters in the existing callbacks in the future.
|
||||
*
|
||||
* @see MojoExecutionListener
|
||||
* @see WeakMojoExecutionListener
|
||||
* @since 3.1.2
|
||||
* @provisional This class is part of work in progress and can be changed or removed without notice.
|
||||
*/
|
||||
public class MojoExecutionEvent
|
||||
{
|
||||
private final MavenSession session;
|
||||
|
||||
private final MavenProject project;
|
||||
|
||||
private final MojoExecution mojoExecution;
|
||||
|
||||
private final Mojo mojo;
|
||||
|
||||
private final Throwable cause;
|
||||
|
||||
public MojoExecutionEvent( MavenSession session, MavenProject project, MojoExecution mojoExecution, Mojo mojo )
|
||||
{
|
||||
this( session, project, mojoExecution, mojo, null );
|
||||
}
|
||||
|
||||
public MojoExecutionEvent( MavenSession session, MavenProject project, MojoExecution mojoExecution, Mojo mojo,
|
||||
Throwable cause )
|
||||
{
|
||||
this.session = session;
|
||||
this.project = project;
|
||||
this.mojoExecution = mojoExecution;
|
||||
this.mojo = mojo;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public MavenSession getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
public MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public MojoExecution getExecution()
|
||||
{
|
||||
return mojoExecution;
|
||||
}
|
||||
|
||||
public Mojo getMojo()
|
||||
{
|
||||
return mojo;
|
||||
}
|
||||
|
||||
public Throwable getCause()
|
||||
{
|
||||
return cause;
|
||||
}
|
||||
}
|
|
@ -20,10 +20,7 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.execution.scope.WeakMojoExecutionListener;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Extension point that allows build extensions observe and possibly veto mojo executions.
|
||||
|
@ -34,13 +31,11 @@ import org.apache.maven.project.MavenProject;
|
|||
*/
|
||||
public interface MojoExecutionListener
|
||||
{
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException;
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException;
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo,
|
||||
Throwable cause );
|
||||
public void afterExecutionFailure( MojoExecutionEvent event );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package org.apache.maven.execution;
|
||||
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Encapsulates parameters of ProjectExecutionListener callback methods and is meant to provide API evolution path
|
||||
* should it become necessary to introduce new parameters in the existing callbacks in the future.
|
||||
*
|
||||
* @see ProjectExecutionListener
|
||||
* @since 3.1.2
|
||||
* @provisional This class is part of work in progress and can be changed or removed without notice.
|
||||
*/
|
||||
public class ProjectExecutionEvent
|
||||
{
|
||||
|
||||
private final MavenSession session;
|
||||
|
||||
private final MavenProject project;
|
||||
|
||||
private final List<MojoExecution> executionPlan;
|
||||
|
||||
private final Throwable cause;
|
||||
|
||||
public ProjectExecutionEvent( MavenSession session, MavenProject project )
|
||||
{
|
||||
this( session, project, null, null );
|
||||
}
|
||||
|
||||
public ProjectExecutionEvent( MavenSession session, MavenProject project, List<MojoExecution> executionPlan )
|
||||
{
|
||||
this( session, project, executionPlan, null );
|
||||
}
|
||||
|
||||
public ProjectExecutionEvent( MavenSession session, MavenProject project, Throwable cause )
|
||||
{
|
||||
this( session, project, null, cause );
|
||||
}
|
||||
|
||||
public ProjectExecutionEvent( MavenSession session, MavenProject project, List<MojoExecution> executionPlan,
|
||||
Throwable cause )
|
||||
{
|
||||
this.session = session;
|
||||
this.project = project;
|
||||
this.executionPlan = executionPlan;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public MavenSession getSession()
|
||||
{
|
||||
return session;
|
||||
}
|
||||
|
||||
public MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public List<MojoExecution> getExecutionPlan()
|
||||
{
|
||||
return executionPlan;
|
||||
}
|
||||
|
||||
public Throwable getCause()
|
||||
{
|
||||
return cause;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,11 +19,7 @@ package org.apache.maven.execution;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Extension point that allows build extensions observe and possibly veto project build execution.
|
||||
|
@ -35,15 +31,14 @@ import org.apache.maven.project.MavenProject;
|
|||
*/
|
||||
public interface ProjectExecutionListener
|
||||
{
|
||||
public void beforeProjectExecution( MavenSession session, MavenProject project )
|
||||
public void beforeProjectExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException;
|
||||
|
||||
public void beforeProjectLifecycleExecution( MavenSession session, MavenProject project,
|
||||
List<MojoExecution> executionPlan )
|
||||
public void beforeProjectLifecycleExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException;
|
||||
|
||||
public void afterProjectExecutionSuccess( MavenSession session, MavenProject project )
|
||||
public void afterProjectExecutionSuccess( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException;
|
||||
|
||||
public void afterProjectExecutionFailure( MavenSession session, MavenProject project, Throwable cause );
|
||||
public void afterProjectExecutionFailure( ProjectExecutionEvent event );
|
||||
}
|
||||
|
|
|
@ -19,12 +19,9 @@ package org.apache.maven.execution.scope;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
/**
|
||||
* Extension point that allows build extensions observe and possibly veto mojo executions.
|
||||
|
@ -38,13 +35,11 @@ import org.apache.maven.project.MavenProject;
|
|||
*/
|
||||
public interface WeakMojoExecutionListener
|
||||
{
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException;
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException;
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo,
|
||||
Throwable cause );
|
||||
public void afterExecutionFailure( MojoExecutionEvent event );
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ import javax.inject.Named;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.execution.scope.MojoExecutionScoped;
|
||||
import org.apache.maven.execution.scope.WeakMojoExecutionListener;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
@ -176,40 +176,37 @@ public class MojoExecutionScope
|
|||
};
|
||||
}
|
||||
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( Object provided : getScopeState().provided.values() )
|
||||
{
|
||||
if ( provided instanceof WeakMojoExecutionListener )
|
||||
{
|
||||
( (WeakMojoExecutionListener) provided ).beforeMojoExecution( session, project, execution, mojo );
|
||||
( (WeakMojoExecutionListener) provided ).beforeMojoExecution( event );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( Object provided : getScopeState().provided.values() )
|
||||
{
|
||||
if ( provided instanceof WeakMojoExecutionListener )
|
||||
{
|
||||
( (WeakMojoExecutionListener) provided ).afterMojoExecutionSuccess( session, project, execution, mojo );
|
||||
( (WeakMojoExecutionListener) provided ).afterMojoExecutionSuccess( event );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo,
|
||||
Throwable cause )
|
||||
public void afterExecutionFailure( MojoExecutionEvent event )
|
||||
{
|
||||
for ( Object provided : getScopeState().provided.values() )
|
||||
{
|
||||
if ( provided instanceof WeakMojoExecutionListener )
|
||||
{
|
||||
( (WeakMojoExecutionListener) provided ).afterExecutionFailure( session, project, execution, mojo,
|
||||
cause );
|
||||
( (WeakMojoExecutionListener) provided ).afterExecutionFailure( event );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,10 @@ package org.apache.maven.lifecycle.internal;
|
|||
*/
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ProjectExecutionEvent;
|
||||
import org.apache.maven.execution.ProjectExecutionListener;
|
||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
class CompoundProjectExecutionListener
|
||||
implements ProjectExecutionListener
|
||||
|
@ -38,39 +35,38 @@ class CompoundProjectExecutionListener
|
|||
this.listeners = listeners; // NB this is live injected collection
|
||||
}
|
||||
|
||||
public void beforeProjectExecution( MavenSession session, MavenProject project )
|
||||
public void beforeProjectExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeProjectExecution( session, project );
|
||||
listener.beforeProjectExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeProjectLifecycleExecution( MavenSession session, MavenProject project,
|
||||
List<MojoExecution> executionPlan )
|
||||
public void beforeProjectLifecycleExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeProjectLifecycleExecution( session, project, executionPlan );
|
||||
listener.beforeProjectLifecycleExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterProjectExecutionSuccess( MavenSession session, MavenProject project )
|
||||
public void afterProjectExecutionSuccess( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterProjectExecutionSuccess( session, project );
|
||||
listener.afterProjectExecutionSuccess( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterProjectExecutionFailure( MavenSession session, MavenProject project, Throwable cause )
|
||||
public void afterProjectExecutionFailure( ProjectExecutionEvent event )
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterProjectExecutionFailure( session, project, cause );
|
||||
listener.afterProjectExecutionFailure( event );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.maven.artifact.Artifact;
|
|||
import org.apache.maven.execution.BuildSuccess;
|
||||
import org.apache.maven.execution.ExecutionEvent;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ProjectExecutionEvent;
|
||||
import org.apache.maven.execution.ProjectExecutionListener;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
|
@ -92,7 +93,7 @@ public class LifecycleModuleBuilder
|
|||
|
||||
BuilderCommon.attachToThread( currentProject );
|
||||
|
||||
projectExecutionListener.beforeProjectExecution( rootSession, currentProject );
|
||||
projectExecutionListener.beforeProjectExecution( new ProjectExecutionEvent( session, currentProject ) );
|
||||
|
||||
eventCatapult.fire( ExecutionEvent.Type.ProjectStarted, session, null );
|
||||
|
||||
|
@ -100,12 +101,15 @@ public class LifecycleModuleBuilder
|
|||
builderCommon.resolveBuildPlan( session, currentProject, taskSegment, new HashSet<Artifact>() );
|
||||
List<MojoExecution> mojoExecutions = executionPlan.getMojoExecutions();
|
||||
|
||||
projectExecutionListener.beforeProjectLifecycleExecution( rootSession, currentProject, mojoExecutions );
|
||||
projectExecutionListener.beforeProjectLifecycleExecution( new ProjectExecutionEvent( session,
|
||||
currentProject,
|
||||
mojoExecutions ) );
|
||||
mojoExecutor.execute( session, mojoExecutions, reactorContext.getProjectIndex() );
|
||||
|
||||
long buildEndTime = System.currentTimeMillis();
|
||||
|
||||
projectExecutionListener.afterProjectExecutionSuccess( rootSession, currentProject );
|
||||
projectExecutionListener.afterProjectExecutionSuccess( new ProjectExecutionEvent( session, currentProject,
|
||||
mojoExecutions ) );
|
||||
|
||||
reactorContext.getResult().addBuildSummary(
|
||||
new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
|
||||
|
@ -116,7 +120,7 @@ public class LifecycleModuleBuilder
|
|||
{
|
||||
builderCommon.handleBuildError( reactorContext, rootSession, session, currentProject, e, buildStartTime );
|
||||
|
||||
projectExecutionListener.afterProjectExecutionFailure( session, currentProject, e );
|
||||
projectExecutionListener.afterProjectExecutionFailure( new ProjectExecutionEvent( session, currentProject, e ) );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -21,9 +21,8 @@ package org.apache.maven.plugin;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
class CompoundMojoExecutionListener
|
||||
implements MojoExecutionListener
|
||||
|
@ -36,31 +35,29 @@ class CompoundMojoExecutionListener
|
|||
this.listeners = listeners; // NB this is live injected collection
|
||||
}
|
||||
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeMojoExecution( session, project, execution, mojo );
|
||||
listener.beforeMojoExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterMojoExecutionSuccess( session, project, execution, mojo );
|
||||
listener.afterMojoExecutionSuccess( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo,
|
||||
Throwable cause )
|
||||
public void afterExecutionFailure( MojoExecutionEvent event )
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterExecutionFailure( session, project, execution, mojo, cause );
|
||||
listener.afterExecutionFailure( event );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.PrintStream;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -125,11 +126,13 @@ public class DefaultBuildPluginManager
|
|||
// MavenProjectHelper.attachArtifact(..).
|
||||
try
|
||||
{
|
||||
mojoExecutionListener.beforeMojoExecution( oldSession, project, mojoExecution, mojo );
|
||||
MojoExecutionEvent mojoExecutionEvent = new MojoExecutionEvent( session, project, mojoExecution, mojo );
|
||||
|
||||
mojoExecutionListener.beforeMojoExecution( mojoExecutionEvent );
|
||||
|
||||
mojo.execute();
|
||||
|
||||
mojoExecutionListener.afterMojoExecutionSuccess( oldSession, project, mojoExecution, mojo );
|
||||
mojoExecutionListener.afterMojoExecutionSuccess( mojoExecutionEvent );
|
||||
}
|
||||
catch ( ClassCastException e )
|
||||
{
|
||||
|
@ -143,13 +146,15 @@ public class DefaultBuildPluginManager
|
|||
}
|
||||
catch ( PluginContainerException e )
|
||||
{
|
||||
mojoExecutionListener.afterExecutionFailure( oldSession, project, mojoExecution, mojo, e );
|
||||
mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo,
|
||||
e ) );
|
||||
|
||||
throw new PluginExecutionException( mojoExecution, project, e );
|
||||
}
|
||||
catch ( NoClassDefFoundError e )
|
||||
{
|
||||
mojoExecutionListener.afterExecutionFailure( oldSession, project, mojoExecution, mojo, e );
|
||||
mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo,
|
||||
e ) );
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 );
|
||||
PrintStream ps = new PrintStream( os );
|
||||
|
@ -163,7 +168,8 @@ public class DefaultBuildPluginManager
|
|||
}
|
||||
catch ( LinkageError e )
|
||||
{
|
||||
mojoExecutionListener.afterExecutionFailure( oldSession, project, mojoExecution, mojo, e );
|
||||
mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo,
|
||||
e ) );
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 );
|
||||
PrintStream ps = new PrintStream( os );
|
||||
|
@ -177,7 +183,8 @@ public class DefaultBuildPluginManager
|
|||
}
|
||||
catch ( ClassCastException e )
|
||||
{
|
||||
mojoExecutionListener.afterExecutionFailure( oldSession, project, mojoExecution, mojo, e );
|
||||
mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo,
|
||||
e ) );
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 );
|
||||
PrintStream ps = new PrintStream( os );
|
||||
|
@ -189,7 +196,8 @@ public class DefaultBuildPluginManager
|
|||
}
|
||||
catch ( RuntimeException e )
|
||||
{
|
||||
mojoExecutionListener.afterExecutionFailure( oldSession, project, mojoExecution, mojo, e );
|
||||
mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent( session, project, mojoExecution, mojo,
|
||||
e ) );
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,33 @@
|
|||
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 java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
@Named
|
||||
@Singleton
|
||||
|
@ -20,31 +36,29 @@ public class DelegatingMojoExecutionListener
|
|||
{
|
||||
private final List<MojoExecutionListener> listeners = new CopyOnWriteArrayList<MojoExecutionListener>();
|
||||
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeMojoExecution( session, project, execution, mojo );
|
||||
listener.beforeMojoExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterMojoExecutionSuccess( session, project, execution, mojo );
|
||||
listener.afterMojoExecutionSuccess( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution, Mojo mojo,
|
||||
Throwable cause )
|
||||
public void afterExecutionFailure( MojoExecutionEvent event )
|
||||
{
|
||||
for ( MojoExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterExecutionFailure( session, project, execution, mojo, cause );
|
||||
listener.afterExecutionFailure( event );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,32 @@
|
|||
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 java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.ProjectExecutionEvent;
|
||||
import org.apache.maven.execution.ProjectExecutionListener;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
@Named
|
||||
@Singleton
|
||||
|
@ -18,39 +35,38 @@ public class DelegatingProjectExecutionListener
|
|||
{
|
||||
private final List<ProjectExecutionListener> listeners = new CopyOnWriteArrayList<ProjectExecutionListener>();
|
||||
|
||||
public void beforeProjectExecution( MavenSession session, MavenProject project )
|
||||
public void beforeProjectExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeProjectExecution( session, project );
|
||||
listener.beforeProjectExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeProjectLifecycleExecution( MavenSession session, MavenProject project,
|
||||
List<MojoExecution> executionPlan )
|
||||
public void beforeProjectLifecycleExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.beforeProjectLifecycleExecution( session, project, executionPlan );
|
||||
listener.beforeProjectLifecycleExecution( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterProjectExecutionSuccess( MavenSession session, MavenProject project )
|
||||
public void afterProjectExecutionSuccess( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterProjectExecutionSuccess( session, project );
|
||||
listener.afterProjectExecutionSuccess( event );
|
||||
}
|
||||
}
|
||||
|
||||
public void afterProjectExecutionFailure( MavenSession session, MavenProject project, Throwable cause )
|
||||
public void afterProjectExecutionFailure( ProjectExecutionEvent event )
|
||||
{
|
||||
for ( ProjectExecutionListener listener : listeners )
|
||||
{
|
||||
listener.afterProjectExecutionFailure( session, project, cause );
|
||||
listener.afterProjectExecutionFailure( event );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@ import java.util.List;
|
|||
import org.apache.maven.AbstractCoreMavenComponentTestCase;
|
||||
import org.apache.maven.exception.ExceptionHandler;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.execution.MojoExecutionEvent;
|
||||
import org.apache.maven.execution.MojoExecutionListener;
|
||||
import org.apache.maven.execution.ProjectDependencyGraph;
|
||||
import org.apache.maven.execution.ProjectExecutionEvent;
|
||||
import org.apache.maven.execution.ProjectExecutionListener;
|
||||
import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator;
|
||||
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
|
||||
|
@ -35,7 +37,6 @@ import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
|
|||
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
|
||||
import org.apache.maven.lifecycle.internal.TaskSegment;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.Mojo;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoNotFoundException;
|
||||
|
@ -414,50 +415,87 @@ public class LifecycleExecutorTest
|
|||
|
||||
MojoExecutionListener mojoListener = new MojoExecutionListener()
|
||||
{
|
||||
public void beforeMojoExecution( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void beforeMojoExecution( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
log.add( "beforeMojoExecution " + project.getArtifactId() + ":" + execution.getExecutionId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNotNull( event.getExecution() );
|
||||
assertNotNull( event.getMojo() );
|
||||
assertNull( event.getCause() );
|
||||
|
||||
log.add( "beforeMojoExecution " + event.getProject().getArtifactId() + ":"
|
||||
+ event.getExecution().getExecutionId() );
|
||||
}
|
||||
|
||||
public void afterMojoExecutionSuccess( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo )
|
||||
public void afterMojoExecutionSuccess( MojoExecutionEvent event )
|
||||
throws MojoExecutionException
|
||||
{
|
||||
log.add( "afterMojoExecutionSuccess " + project.getArtifactId() + ":" + execution.getExecutionId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNotNull( event.getExecution() );
|
||||
assertNotNull( event.getMojo() );
|
||||
assertNull( event.getCause() );
|
||||
|
||||
log.add( "afterMojoExecutionSuccess " + event.getProject().getArtifactId() + ":"
|
||||
+ event.getExecution().getExecutionId() );
|
||||
}
|
||||
|
||||
public void afterExecutionFailure( MavenSession session, MavenProject project, MojoExecution execution,
|
||||
Mojo mojo, Throwable cause )
|
||||
public void afterExecutionFailure( MojoExecutionEvent event )
|
||||
{
|
||||
log.add( "afterExecutionFailure " + project.getArtifactId() + ":" + execution.getExecutionId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNotNull( event.getExecution() );
|
||||
assertNotNull( event.getMojo() );
|
||||
assertNotNull( event.getCause() );
|
||||
|
||||
log.add( "afterExecutionFailure " + event.getProject().getArtifactId() + ":"
|
||||
+ event.getExecution().getExecutionId() );
|
||||
}
|
||||
};
|
||||
ProjectExecutionListener projectListener = new ProjectExecutionListener()
|
||||
{
|
||||
public void beforeProjectExecution( MavenSession session, MavenProject project )
|
||||
public void beforeProjectExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
log.add( "beforeProjectExecution " + project.getArtifactId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNull( event.getExecutionPlan() );
|
||||
assertNull( event.getCause() );
|
||||
|
||||
log.add( "beforeProjectExecution " + event.getProject().getArtifactId() );
|
||||
}
|
||||
|
||||
public void beforeProjectLifecycleExecution( MavenSession session, MavenProject project,
|
||||
List<MojoExecution> executionPlan )
|
||||
public void beforeProjectLifecycleExecution( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
log.add( "beforeProjectLifecycleExecution " + project.getArtifactId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNotNull( event.getExecutionPlan() );
|
||||
assertNull( event.getCause() );
|
||||
|
||||
log.add( "beforeProjectLifecycleExecution " + event.getProject().getArtifactId() );
|
||||
}
|
||||
|
||||
public void afterProjectExecutionSuccess( MavenSession session, MavenProject project )
|
||||
public void afterProjectExecutionSuccess( ProjectExecutionEvent event )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
log.add( "afterProjectExecutionSuccess " + project.getArtifactId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNotNull( event.getExecutionPlan() );
|
||||
assertNull( event.getCause() );
|
||||
|
||||
log.add( "afterProjectExecutionSuccess " + event.getProject().getArtifactId() );
|
||||
}
|
||||
|
||||
public void afterProjectExecutionFailure( MavenSession session, MavenProject project, Throwable cause )
|
||||
public void afterProjectExecutionFailure( ProjectExecutionEvent event )
|
||||
{
|
||||
log.add( "afterProjectExecutionFailure " + project.getArtifactId() );
|
||||
assertNotNull( event.getSession() );
|
||||
assertNotNull( event.getProject() );
|
||||
assertNull( event.getExecutionPlan() );
|
||||
assertNotNull( event.getCause() );
|
||||
|
||||
log.add( "afterProjectExecutionFailure " + event.getProject().getArtifactId() );
|
||||
}
|
||||
};
|
||||
lookup( DelegatingProjectExecutionListener.class ).addProjectExecutionListener( projectListener );
|
||||
|
|
Loading…
Reference in New Issue