Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojosExecutionStrategy;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginIncompatibleException;
Expand Down Expand Up @@ -71,18 +72,22 @@ public class MojoExecutor
private final MavenPluginManager mavenPluginManager;
private final LifecycleDependencyResolver lifeCycleDependencyResolver;
private final ExecutionEventCatapult eventCatapult;
private final MojosExecutionStrategy mojosExecutionStrategy;

@Inject
public MojoExecutor(
BuildPluginManager pluginManager,
MavenPluginManager mavenPluginManager,
LifecycleDependencyResolver lifeCycleDependencyResolver,
ExecutionEventCatapult eventCatapult )
ExecutionEventCatapult eventCatapult,
MojosExecutionStrategy mojosExecutionStrategy
)
{
this.pluginManager = pluginManager;
this.mavenPluginManager = mavenPluginManager;
this.lifeCycleDependencyResolver = lifeCycleDependencyResolver;
this.eventCatapult = eventCatapult;
this.mojosExecutionStrategy = mojosExecutionStrategy;
}

public DependencyContext newDependencyContext( MavenSession session, List<MojoExecution> mojoExecutions )
Expand Down Expand Up @@ -140,21 +145,22 @@ else if ( Artifact.SCOPE_TEST.equals( classpath ) )
return Collections.unmodifiableCollection( scopes );
}

public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
throws LifecycleExecutionException
public void execute( final MavenSession session,
List<MojoExecution> mojoExecutions,
final ProjectIndex projectIndex ) throws LifecycleExecutionException

{
DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions );

PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() );

for ( MojoExecution mojoExecution : mojoExecutions )
mojosExecutionStrategy.execute( mojoExecutions, session, mojoExecution ->
{
execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder );
}
} );
}

public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
DependencyContext dependencyContext, PhaseRecorder phaseRecorder )
throws LifecycleExecutionException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.apache.maven.plugin;

/*
* 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.lifecycle.LifecycleExecutionException;

import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;

/**
* Default mojo execution strategy. It just iterates over mojo executions and runs one by one
*/
@Named
@Singleton
public class DefaultMojosExecutionStrategy implements MojosExecutionStrategy
Comment thread
AlexanderAshitkin marked this conversation as resolved.
{
@Override
public void execute( List<MojoExecution> mojos, MavenSession session, MojoExecutionRunner mojoRunner )
throws LifecycleExecutionException
{
for ( MojoExecution mojoExecution : mojos )
{
mojoRunner.run( mojoExecution );
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.apache.maven.plugin;

/*
* 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.lifecycle.LifecycleExecutionException;

/**
* Provides context for mojo execution. Invocation of #run will result in actual execution
*/
@FunctionalInterface
public interface MojoExecutionRunner
{
/**
* Runs mojo execution
*
* @param execution mojo execution
* @throws LifecycleExecutionException
*/
void run( MojoExecution execution ) throws LifecycleExecutionException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.apache.maven.plugin;

/*
* 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.lifecycle.LifecycleExecutionException;

import java.util.List;

/**
* Interface allows overriding default mojo execution strategy For example it is possible wrap some mojo execution to
* decorate default functionality or skip some executions
*/
public interface MojosExecutionStrategy
{

/**
* Entry point to the execution strategy
*
* @param mojos list of mojos representing a project build
* @param session current session
* @param mojoExecutionRunner mojo execution task which must be invoked by a strategy to actually run it
* @throws LifecycleExecutionException
*/
void execute( List<MojoExecution> mojos, MavenSession session, MojoExecutionRunner mojoExecutionRunner )
throws LifecycleExecutionException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, Mo

ClassRealm pluginRealm = pluginDescriptor.getClassRealm();

if ( pluginRealm == null )
{
try
{
setupPluginRealm( pluginDescriptor, session, null, null, null );
}
catch ( PluginResolutionException e )
{
String msg = "Cannot setup plugin realm [mojoDescriptor=" + mojoDescriptor.getId()
+ ", pluginDescriptor=" + pluginDescriptor.getId() + "]";
throw new PluginConfigurationException( pluginDescriptor, msg, e );
}
pluginRealm = pluginDescriptor.getClassRealm();
}

if ( logger.isDebugEnabled() )
{
logger.debug( "Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.internal.DependencyContext;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver;
import org.apache.maven.lifecycle.internal.MojoExecutor;
import org.apache.maven.lifecycle.internal.PhaseRecorder;
import org.apache.maven.lifecycle.internal.ProjectIndex;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojosExecutionStrategy;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;

Expand All @@ -46,17 +45,10 @@ public MojoExecutorStub(
BuildPluginManager pluginManager,
MavenPluginManager mavenPluginManager,
LifecycleDependencyResolver lifeCycleDependencyResolver,
ExecutionEventCatapult eventCatapult )
ExecutionEventCatapult eventCatapult,
MojosExecutionStrategy mojosExecutionStrategy )
{
super( pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult );
}

@Override
public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
DependencyContext dependencyContext, PhaseRecorder phaseRecorder )
throws LifecycleExecutionException
{
executions.add( mojoExecution );
super( pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult, mojosExecutionStrategy );
}

@Override
Expand Down