mirror of https://github.com/apache/maven.git
Merge remote-tracking branch 'remotes/origin/MNG-6562'
This commit is contained in:
commit
c7aa002c74
|
@ -56,6 +56,8 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
|||
public class DefaultLifecyclePluginAnalyzer
|
||||
implements LifeCyclePluginAnalyzer
|
||||
{
|
||||
public static final String DEFAULTLIFECYCLEBINDINGS_MODELID = "org.apache.maven:maven-core:"
|
||||
+ DefaultLifecyclePluginAnalyzer.class.getPackage().getImplementationVersion() + ":default-lifecycle-bindings";
|
||||
|
||||
@Requirement( role = LifecycleMapping.class )
|
||||
private Map<String, LifecycleMapping> lifecycleMappings;
|
||||
|
@ -143,10 +145,8 @@ public class DefaultLifecyclePluginAnalyzer
|
|||
|
||||
private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals )
|
||||
{
|
||||
String modelId = "org.apache.maven:maven-core:" + this.getClass().getPackage().getImplementationVersion()
|
||||
+ ":default-lifecycle-bindings";
|
||||
InputSource inputSource = new InputSource();
|
||||
inputSource.setModelId( modelId );
|
||||
inputSource.setModelId( DEFAULTLIFECYCLEBINDINGS_MODELID );
|
||||
InputLocation location = new InputLocation( -1, -1, inputSource );
|
||||
location.setLocation( 0, location );
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@ package org.apache.maven.lifecycle.internal.builder;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -34,6 +36,7 @@ import org.apache.maven.lifecycle.LifecycleExecutionException;
|
|||
import org.apache.maven.lifecycle.LifecycleNotFoundException;
|
||||
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.lifecycle.internal.DefaultLifecyclePluginAnalyzer;
|
||||
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
|
||||
import org.apache.maven.lifecycle.internal.LifecycleDebugLogger;
|
||||
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
|
||||
|
@ -41,6 +44,7 @@ import org.apache.maven.lifecycle.internal.ReactorContext;
|
|||
import org.apache.maven.lifecycle.internal.TaskSegment;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoNotFoundException;
|
||||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
||||
import org.apache.maven.plugin.PluginNotFoundException;
|
||||
|
@ -136,6 +140,23 @@ public class BuilderCommon
|
|||
logger.warn( "*****************************************************************" );
|
||||
}
|
||||
}
|
||||
|
||||
final String defaulModelId = DefaultLifecyclePluginAnalyzer.DEFAULTLIFECYCLEBINDINGS_MODELID;
|
||||
|
||||
List<String> unversionedPlugins = executionPlan.getMojoExecutions().stream()
|
||||
.map( MojoExecution::getPlugin )
|
||||
.filter( p -> p.getLocation( "version" ) != null ) // versionless cli goal (?)
|
||||
.filter( p -> p.getLocation( "version" ).getSource() != null ) // versionless in pom (?)
|
||||
.filter( p -> defaulModelId.equals( p.getLocation( "version" ).getSource().getModelId() ) )
|
||||
.distinct()
|
||||
.map( Plugin::getArtifactId ) // managed by us, groupId is always o.a.m.plugins
|
||||
.collect( Collectors.toList() );
|
||||
|
||||
if ( !unversionedPlugins.isEmpty() )
|
||||
{
|
||||
logger.warn( "Version not locked for default bindings plugins " + unversionedPlugins
|
||||
+ ", you should define versions in pluginManagement section of your " + "pom.xml or parent" );
|
||||
}
|
||||
|
||||
return executionPlan;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.apache.maven.model.plugin;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -79,7 +78,7 @@ public class DefaultLifecycleBindingsInjector
|
|||
lifecycleModel.setBuild( new Build() );
|
||||
lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins );
|
||||
|
||||
merger.merge( model, lifecycleModel, problems );
|
||||
merger.merge( model, lifecycleModel );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,36 +90,18 @@ public class DefaultLifecycleBindingsInjector
|
|||
{
|
||||
|
||||
private static final String PLUGIN_MANAGEMENT = "plugin-management";
|
||||
private static final String NO_VERSION_PLUGINS = "no-version-plugins";
|
||||
|
||||
public void merge( Model target, Model source, ModelProblemCollector problems )
|
||||
public void merge( Model target, Model source )
|
||||
{
|
||||
if ( target.getBuild() == null )
|
||||
{
|
||||
target.setBuild( new Build() );
|
||||
}
|
||||
|
||||
Map<Object, Object> context = new HashMap<Object, Object>();
|
||||
context.put( PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement() );
|
||||
Map<Object, Object> context =
|
||||
Collections.<Object, Object>singletonMap( PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement() );
|
||||
|
||||
mergePluginContainer_Plugins( target.getBuild(), source.getBuild(), false, context );
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
Collection<Plugin> defaultVersionPlugins = (Collection<Plugin>) context.get( NO_VERSION_PLUGINS );
|
||||
if ( defaultVersionPlugins != null )
|
||||
{
|
||||
List<String> plugins = new ArrayList<>( defaultVersionPlugins.size() );
|
||||
for ( Plugin p : defaultVersionPlugins )
|
||||
{
|
||||
plugins.add( p.getArtifactId() );
|
||||
}
|
||||
|
||||
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.BASE )
|
||||
.setMessage( "Version not locked for default bindings plugins " + plugins
|
||||
+ ", you should define versions in pluginManagement section of your "
|
||||
+ "pom.xml or parent" )
|
||||
.setLocation( target.getLocation( "packaging" ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "checkstyle:methodname" } )
|
||||
|
@ -166,8 +147,7 @@ public class DefaultLifecycleBindingsInjector
|
|||
for ( Plugin managedPlugin : pluginMgmt.getPlugins() )
|
||||
{
|
||||
Object key = getPluginKey().apply( managedPlugin );
|
||||
Plugin addedPlugin = // remove plugin only if managedPlugin defines version
|
||||
( managedPlugin.getVersion() == null ) ? added.get( key ) : added.remove( key );
|
||||
Plugin addedPlugin = added.get( key );
|
||||
if ( addedPlugin != null )
|
||||
{
|
||||
Plugin plugin = managedPlugin.clone();
|
||||
|
@ -176,12 +156,6 @@ public class DefaultLifecycleBindingsInjector
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !added.isEmpty() )
|
||||
{
|
||||
// some plugins added with default version from bindings
|
||||
context.put( NO_VERSION_PLUGINS, added.values() );
|
||||
}
|
||||
}
|
||||
|
||||
List<Plugin> result = new ArrayList<>( merged.values() );
|
||||
|
|
|
@ -15,14 +15,18 @@ package org.apache.maven.lifecycle.internal;
|
|||
* the License.
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
|
||||
import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
|
||||
import org.apache.maven.lifecycle.internal.stub.LoggerStub;
|
||||
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
|
@ -30,8 +34,10 @@ import java.util.HashSet;
|
|||
* @author Kristian Rosenvold
|
||||
*/
|
||||
public class BuilderCommonTest
|
||||
extends TestCase
|
||||
{
|
||||
private Logger logger = mock( Logger.class );
|
||||
|
||||
@Test
|
||||
public void testResolveBuildPlan()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -46,10 +52,32 @@ public class BuilderCommonTest
|
|||
builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
|
||||
new HashSet<>() );
|
||||
assertEquals( LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan().size(), plan.size() );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBindingPluginsWarning()
|
||||
throws Exception
|
||||
{
|
||||
MavenSession original = ProjectDependencyGraphStub.getMavenSession();
|
||||
|
||||
final TaskSegment taskSegment1 = new TaskSegment( false );
|
||||
final MavenSession session1 = original.clone();
|
||||
session1.setCurrentProject( ProjectDependencyGraphStub.A );
|
||||
|
||||
getBuilderCommon().resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1, new HashSet<>() );
|
||||
|
||||
verify( logger ).warn("Version not locked for default bindings plugins ["
|
||||
+ "stub-plugin-initialize, "
|
||||
+ "stub-plugin-process-resources, "
|
||||
+ "stub-plugin-compile, "
|
||||
+ "stub-plugin-process-test-resources, "
|
||||
+ "stub-plugin-test-compile, "
|
||||
+ "stub-plugin-test, "
|
||||
+ "stub-plugin-package, "
|
||||
+ "stub-plugin-install], "
|
||||
+ "you should define versions in pluginManagement section of your pom.xml or parent");
|
||||
}
|
||||
|
||||
public void testHandleBuildError()
|
||||
throws Exception
|
||||
{
|
||||
|
@ -65,11 +93,11 @@ public class BuilderCommonTest
|
|||
{
|
||||
}
|
||||
|
||||
public static BuilderCommon getBuilderCommon()
|
||||
public BuilderCommon getBuilderCommon()
|
||||
{
|
||||
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
|
||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
|
||||
new LoggerStub() );
|
||||
final LifecycleDebugLogger debugLogger = new LifecycleDebugLogger( logger );
|
||||
return new BuilderCommon( debugLogger, new LifecycleExecutionPlanCalculatorStub(),
|
||||
logger );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,13 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.lifecycle.LifecycleNotFoundException;
|
||||
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
|
||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||
import org.apache.maven.lifecycle.internal.DefaultLifecyclePluginAnalyzer;
|
||||
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
|
||||
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
|
||||
import org.apache.maven.lifecycle.internal.ProjectBuildList;
|
||||
import org.apache.maven.lifecycle.internal.ProjectSegment;
|
||||
import org.apache.maven.model.InputLocation;
|
||||
import org.apache.maven.model.InputSource;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
|
@ -203,7 +206,11 @@ public class LifecycleExecutionPlanCalculatorStub
|
|||
|
||||
private static MojoExecution createMojoExecution( String goal, String executionId, MojoDescriptor mojoDescriptor )
|
||||
{
|
||||
InputSource defaultBindings = new InputSource();
|
||||
defaultBindings.setModelId( DefaultLifecyclePluginAnalyzer.DEFAULTLIFECYCLEBINDINGS_MODELID );
|
||||
|
||||
final Plugin plugin = mojoDescriptor.getPluginDescriptor().getPlugin();
|
||||
plugin.setLocation( "version", new InputLocation( 12, 34, defaultBindings ) );
|
||||
MojoExecution result = new MojoExecution( plugin, goal, executionId );
|
||||
result.setConfiguration( new Xpp3Dom( executionId + "-" + goal ) );
|
||||
result.setMojoDescriptor( mojoDescriptor );
|
||||
|
@ -224,8 +231,8 @@ public class LifecycleExecutionPlanCalculatorStub
|
|||
mojoDescriptor.setPhase( phaseName );
|
||||
final PluginDescriptor descriptor = new PluginDescriptor();
|
||||
Plugin plugin = new Plugin();
|
||||
plugin.setArtifactId( "org.apache.maven.test.MavenExecutionPlan" );
|
||||
plugin.setGroupId( "stub-plugin-" + phaseName );
|
||||
plugin.setGroupId( "org.apache.maven.test.MavenExecutionPlan" );
|
||||
plugin.setArtifactId( "stub-plugin-" + phaseName );
|
||||
descriptor.setPlugin( plugin );
|
||||
descriptor.setArtifactId( "artifact." + phaseName );
|
||||
mojoDescriptor.setPluginDescriptor( descriptor );
|
||||
|
|
|
@ -8,42 +8,4 @@
|
|||
<modules>
|
||||
<module>child</module>
|
||||
</modules>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue