mirror of https://github.com/apache/maven.git
[MNG-6562] WARN if plugins injected by default lifecycle bindings don't have their version locked in pom.xml or parent
This commit is contained in:
parent
958380685d
commit
628a5756d3
|
@ -56,6 +56,8 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
public class DefaultLifecyclePluginAnalyzer
|
public class DefaultLifecyclePluginAnalyzer
|
||||||
implements LifeCyclePluginAnalyzer
|
implements LifeCyclePluginAnalyzer
|
||||||
{
|
{
|
||||||
|
public static final String DEFAULTLIFECYCLEBINDINGS_MODELID = "org.apache.maven:maven-core:"
|
||||||
|
+ DefaultLifecyclePluginAnalyzer.class.getPackage().getImplementationVersion() + ":default-lifecycle-bindings";
|
||||||
|
|
||||||
@Requirement( role = LifecycleMapping.class )
|
@Requirement( role = LifecycleMapping.class )
|
||||||
private Map<String, LifecycleMapping> lifecycleMappings;
|
private Map<String, LifecycleMapping> lifecycleMappings;
|
||||||
|
@ -143,10 +145,8 @@ public class DefaultLifecyclePluginAnalyzer
|
||||||
|
|
||||||
private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals )
|
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 inputSource = new InputSource();
|
||||||
inputSource.setModelId( modelId );
|
inputSource.setModelId( DEFAULTLIFECYCLEBINDINGS_MODELID );
|
||||||
InputLocation location = new InputLocation( -1, -1, inputSource );
|
InputLocation location = new InputLocation( -1, -1, inputSource );
|
||||||
location.setLocation( 0, location );
|
location.setLocation( 0, location );
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@ package org.apache.maven.lifecycle.internal.builder;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
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.LifecycleNotFoundException;
|
||||||
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
|
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
|
||||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
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.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;
|
||||||
|
@ -41,6 +44,7 @@ import org.apache.maven.lifecycle.internal.ReactorContext;
|
||||||
import org.apache.maven.lifecycle.internal.TaskSegment;
|
import org.apache.maven.lifecycle.internal.TaskSegment;
|
||||||
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.PluginNotFoundException;
|
import org.apache.maven.plugin.PluginNotFoundException;
|
||||||
|
@ -137,6 +141,23 @@ public class BuilderCommon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return executionPlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,18 @@ package org.apache.maven.lifecycle.internal;
|
||||||
* the License.
|
* 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.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||||
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
|
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
|
||||||
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.ProjectDependencyGraphStub;
|
import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@ -30,8 +34,10 @@ import java.util.HashSet;
|
||||||
* @author Kristian Rosenvold
|
* @author Kristian Rosenvold
|
||||||
*/
|
*/
|
||||||
public class BuilderCommonTest
|
public class BuilderCommonTest
|
||||||
extends TestCase
|
|
||||||
{
|
{
|
||||||
|
private Logger logger = mock( Logger.class );
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testResolveBuildPlan()
|
public void testResolveBuildPlan()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -46,9 +52,31 @@ public class BuilderCommonTest
|
||||||
builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
|
builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
|
||||||
new HashSet<>() );
|
new HashSet<>() );
|
||||||
assertEquals( LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan().size(), plan.size() );
|
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()
|
public void testHandleBuildError()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -65,11 +93,11 @@ public class BuilderCommonTest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BuilderCommon getBuilderCommon()
|
public BuilderCommon getBuilderCommon()
|
||||||
{
|
{
|
||||||
final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
|
final LifecycleDebugLogger debugLogger = new LifecycleDebugLogger( logger );
|
||||||
return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(),
|
return new BuilderCommon( debugLogger, new LifecycleExecutionPlanCalculatorStub(),
|
||||||
new LoggerStub() );
|
logger );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,13 @@ 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.MavenExecutionPlan;
|
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.ExecutionPlanItem;
|
||||||
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
|
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
|
||||||
import org.apache.maven.lifecycle.internal.ProjectBuildList;
|
import org.apache.maven.lifecycle.internal.ProjectBuildList;
|
||||||
import org.apache.maven.lifecycle.internal.ProjectSegment;
|
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.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.MojoExecution;
|
||||||
|
@ -203,7 +206,11 @@ public class LifecycleExecutionPlanCalculatorStub
|
||||||
|
|
||||||
private static MojoExecution createMojoExecution( String goal, String executionId, MojoDescriptor mojoDescriptor )
|
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();
|
final Plugin plugin = mojoDescriptor.getPluginDescriptor().getPlugin();
|
||||||
|
plugin.setLocation( "version", new InputLocation( 12, 34, defaultBindings ) );
|
||||||
MojoExecution result = new MojoExecution( plugin, goal, executionId );
|
MojoExecution result = new MojoExecution( plugin, goal, executionId );
|
||||||
result.setConfiguration( new Xpp3Dom( executionId + "-" + goal ) );
|
result.setConfiguration( new Xpp3Dom( executionId + "-" + goal ) );
|
||||||
result.setMojoDescriptor( mojoDescriptor );
|
result.setMojoDescriptor( mojoDescriptor );
|
||||||
|
@ -224,8 +231,8 @@ public class LifecycleExecutionPlanCalculatorStub
|
||||||
mojoDescriptor.setPhase( phaseName );
|
mojoDescriptor.setPhase( phaseName );
|
||||||
final PluginDescriptor descriptor = new PluginDescriptor();
|
final PluginDescriptor descriptor = new PluginDescriptor();
|
||||||
Plugin plugin = new Plugin();
|
Plugin plugin = new Plugin();
|
||||||
plugin.setArtifactId( "org.apache.maven.test.MavenExecutionPlan" );
|
plugin.setGroupId( "org.apache.maven.test.MavenExecutionPlan" );
|
||||||
plugin.setGroupId( "stub-plugin-" + phaseName );
|
plugin.setArtifactId( "stub-plugin-" + phaseName );
|
||||||
descriptor.setPlugin( plugin );
|
descriptor.setPlugin( plugin );
|
||||||
descriptor.setArtifactId( "artifact." + phaseName );
|
descriptor.setArtifactId( "artifact." + phaseName );
|
||||||
mojoDescriptor.setPluginDescriptor( descriptor );
|
mojoDescriptor.setPluginDescriptor( descriptor );
|
||||||
|
|
|
@ -8,42 +8,4 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>child</module>
|
<module>child</module>
|
||||||
</modules>
|
</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>
|
</project>
|
||||||
|
|
Loading…
Reference in New Issue