mirror of https://github.com/apache/maven.git
[MNG-5477] inject pluginManagement and build plugins versions into
report plugins to avoid validation warnings
This commit is contained in:
parent
ed1501ecb5
commit
4db66fd06c
|
@ -31,6 +31,8 @@ import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginContainer;
|
import org.apache.maven.model.PluginContainer;
|
||||||
import org.apache.maven.model.PluginExecution;
|
import org.apache.maven.model.PluginExecution;
|
||||||
import org.apache.maven.model.PluginManagement;
|
import org.apache.maven.model.PluginManagement;
|
||||||
|
import org.apache.maven.model.ReportPlugin;
|
||||||
|
import org.apache.maven.model.Reporting;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelProblemCollector;
|
import org.apache.maven.model.building.ModelProblemCollector;
|
||||||
import org.apache.maven.model.merge.MavenModelMerger;
|
import org.apache.maven.model.merge.MavenModelMerger;
|
||||||
|
@ -67,6 +69,12 @@ public class DefaultPluginManagementInjector
|
||||||
{
|
{
|
||||||
mergePluginContainer_Plugins( build, pluginManagement );
|
mergePluginContainer_Plugins( build, pluginManagement );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mergeReporting_Plugins( model.getReporting(), build );
|
||||||
|
if ( pluginManagement != null )
|
||||||
|
{
|
||||||
|
mergeReporting_Plugins( model.getReporting(), pluginManagement );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +140,35 @@ public class DefaultPluginManagementInjector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merge plugin version to reporting if report plugin version not set
|
||||||
|
*/
|
||||||
|
private void mergeReporting_Plugins( Reporting target, PluginContainer source )
|
||||||
|
{
|
||||||
|
List<Plugin> src = source.getPlugins();
|
||||||
|
if ( !src.isEmpty() )
|
||||||
|
{
|
||||||
|
List<ReportPlugin> tgt = target.getPlugins();
|
||||||
|
|
||||||
|
Map<Object, Plugin> managedPlugins = new LinkedHashMap<Object, Plugin>( src.size() * 2 );
|
||||||
|
|
||||||
|
for ( Plugin element : src )
|
||||||
|
{
|
||||||
|
Object key = getPluginKey( element );
|
||||||
|
managedPlugins.put( key, element );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ReportPlugin element : tgt )
|
||||||
|
{
|
||||||
|
Object key = getReportPluginKey( element );
|
||||||
|
Plugin managedPlugin = managedPlugins.get( key );
|
||||||
|
if ( managedPlugin != null && element.getVersion() == null )
|
||||||
|
{
|
||||||
|
element.setVersion( managedPlugin.getVersion() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.maven.model.building;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple model problem collector for testing the model building components.
|
* A simple model problem collector for testing the model building components.
|
||||||
|
@ -31,6 +33,7 @@ import java.util.List;
|
||||||
public class SimpleProblemCollector
|
public class SimpleProblemCollector
|
||||||
implements ModelProblemCollector
|
implements ModelProblemCollector
|
||||||
{
|
{
|
||||||
|
private Model model;
|
||||||
|
|
||||||
private List<String> warnings = new ArrayList<String>();
|
private List<String> warnings = new ArrayList<String>();
|
||||||
|
|
||||||
|
@ -38,6 +41,20 @@ public class SimpleProblemCollector
|
||||||
|
|
||||||
private List<String> fatals = new ArrayList<String>();
|
private List<String> fatals = new ArrayList<String>();
|
||||||
|
|
||||||
|
public SimpleProblemCollector()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleProblemCollector( Model model )
|
||||||
|
{
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Model getModel()
|
||||||
|
{
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getWarnings()
|
public List<String> getWarnings()
|
||||||
{
|
{
|
||||||
return warnings;
|
return warnings;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.ModelBuildingRequest;
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
import org.apache.maven.model.building.SimpleProblemCollector;
|
import org.apache.maven.model.building.SimpleProblemCollector;
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
|
import org.apache.maven.model.management.PluginManagementInjector;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,6 +39,8 @@ public class DefaultModelValidatorTest
|
||||||
|
|
||||||
private ModelValidator validator;
|
private ModelValidator validator;
|
||||||
|
|
||||||
|
private PluginManagementInjector pluginManagementInjector;
|
||||||
|
|
||||||
private Model read( String pom )
|
private Model read( String pom )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -64,9 +67,22 @@ public class DefaultModelValidatorTest
|
||||||
{
|
{
|
||||||
ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
|
ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
|
||||||
|
|
||||||
SimpleProblemCollector problems = new SimpleProblemCollector();
|
SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) );
|
||||||
|
|
||||||
validator.validateEffectiveModel( read( pom ), request, problems );
|
validator.validateEffectiveModel( problems.getModel(), request, problems );
|
||||||
|
|
||||||
|
return problems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SimpleProblemCollector validateEffective( Model model )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ModelBuildingRequest request =
|
||||||
|
new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
|
||||||
|
|
||||||
|
SimpleProblemCollector problems = new SimpleProblemCollector( model );
|
||||||
|
|
||||||
|
validator.validateEffectiveModel( problems.getModel(), request, problems );
|
||||||
|
|
||||||
return problems;
|
return problems;
|
||||||
}
|
}
|
||||||
|
@ -76,9 +92,9 @@ public class DefaultModelValidatorTest
|
||||||
{
|
{
|
||||||
ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
|
ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
|
||||||
|
|
||||||
SimpleProblemCollector problems = new SimpleProblemCollector();
|
SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) );
|
||||||
|
|
||||||
validator.validateRawModel( read( pom ), request, problems );
|
validator.validateRawModel( problems.getModel(), request, problems );
|
||||||
|
|
||||||
return problems;
|
return problems;
|
||||||
}
|
}
|
||||||
|
@ -95,12 +111,14 @@ public class DefaultModelValidatorTest
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
validator = lookup( ModelValidator.class );
|
validator = lookup( ModelValidator.class );
|
||||||
|
pluginManagementInjector = lookup( PluginManagementInjector.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown()
|
protected void tearDown()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
this.pluginManagementInjector = null;
|
||||||
this.validator = null;
|
this.validator = null;
|
||||||
|
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
@ -620,8 +638,26 @@ public class DefaultModelValidatorTest
|
||||||
|
|
||||||
assertViolations( result, 0, 0, 3 );
|
assertViolations( result, 0, 0, 3 );
|
||||||
|
|
||||||
assertContains( result.getWarnings().get( 0 ), "'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-noversion-plugin is missing." );
|
assertContains( result.getWarnings().get( 0 ),
|
||||||
assertContains( result.getWarnings().get( 1 ), "'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-from-plugins-plugin is missing." );
|
"'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-noversion-plugin is missing." );
|
||||||
assertContains( result.getWarnings().get( 2 ), "'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-from-pluginManagement-plugin is missing." );
|
assertContains( result.getWarnings().get( 1 ),
|
||||||
|
"'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-from-plugins-plugin is missing." );
|
||||||
|
assertContains( result.getWarnings().get( 2 ),
|
||||||
|
"'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-from-pluginManagement-plugin is missing." );
|
||||||
|
|
||||||
|
// after pluginManagement injection
|
||||||
|
ModelBuildingRequest request =
|
||||||
|
new DefaultModelBuildingRequest().setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
|
||||||
|
|
||||||
|
SimpleProblemCollector problems = new SimpleProblemCollector();
|
||||||
|
|
||||||
|
pluginManagementInjector.injectManagement( result.getModel(), request, problems );
|
||||||
|
|
||||||
|
result = validateEffective( result.getModel() );
|
||||||
|
|
||||||
|
assertViolations( result, 0, 0, 1 );
|
||||||
|
|
||||||
|
assertContains( result.getWarnings().get( 0 ),
|
||||||
|
"'reporting.plugins.plugin.version' for org.apache.maven.plugins:maven-noversion-plugin is missing." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue