[MNG-6562] added WARNING on default bindings plugins unlocked versions

This commit is contained in:
Hervé Boutemy 2019-01-14 11:50:57 +01:00
parent b0d2846e07
commit d9bf929c74
2 changed files with 69 additions and 5 deletions

View File

@ -22,6 +22,7 @@ package org.apache.maven.model.plugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -75,7 +76,7 @@ public class DefaultLifecycleBindingsInjector
lifecycleModel.setBuild( new Build() ); lifecycleModel.setBuild( new Build() );
lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins ); lifecycleModel.getBuild().getPlugins().addAll( defaultPlugins );
merger.merge( model, lifecycleModel ); merger.merge( model, lifecycleModel, problems );
} }
} }
@ -87,18 +88,36 @@ public class DefaultLifecycleBindingsInjector
{ {
private static final String PLUGIN_MANAGEMENT = "plugin-management"; 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 ) public void merge( Model target, Model source, ModelProblemCollector problems )
{ {
if ( target.getBuild() == null ) if ( target.getBuild() == null )
{ {
target.setBuild( new Build() ); target.setBuild( new Build() );
} }
Map<Object, Object> context = Map<Object, Object> context = new HashMap<Object, Object>();
Collections.<Object, Object>singletonMap( PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement() ); context.put( PLUGIN_MANAGEMENT, target.getBuild().getPluginManagement() );
mergePluginContainer_Plugins( target.getBuild(), source.getBuild(), false, context ); 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" } ) @SuppressWarnings( { "checkstyle:methodname" } )
@ -144,7 +163,8 @@ public class DefaultLifecycleBindingsInjector
for ( Plugin managedPlugin : pluginMgmt.getPlugins() ) for ( Plugin managedPlugin : pluginMgmt.getPlugins() )
{ {
Object key = getPluginKey().apply( managedPlugin ); Object key = getPluginKey().apply( managedPlugin );
Plugin addedPlugin = added.get( key ); Plugin addedPlugin = // remove plugin only if managedPlugin defines version
( managedPlugin.getVersion() == null ) ? added.get( key ) : added.remove( key );
if ( addedPlugin != null ) if ( addedPlugin != null )
{ {
Plugin plugin = managedPlugin.clone(); Plugin plugin = managedPlugin.clone();
@ -153,6 +173,12 @@ 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() ); List<Plugin> result = new ArrayList<>( merged.values() );

View File

@ -8,4 +8,42 @@
<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>