mirror of https://github.com/apache/maven.git
[MNG-3811] - Report plugins don't inherit configuration
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@758357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
72c4417369
commit
d2c1d1e42e
|
@ -20,11 +20,14 @@ package org.apache.maven.project.processor;
|
|||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
public class ReportingProcessor extends BaseProcessor
|
||||
{
|
||||
|
@ -51,9 +54,7 @@ public class ReportingProcessor extends BaseProcessor
|
|||
}
|
||||
|
||||
copy(c.getReporting(), t.getReporting());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void copy(Reporting source, Reporting target)
|
||||
|
@ -68,11 +69,67 @@ public class ReportingProcessor extends BaseProcessor
|
|||
|
||||
for ( ReportPlugin plugin : source.getPlugins() )
|
||||
{
|
||||
target.addPlugin( copyPlugin( plugin ) );
|
||||
ReportPlugin match = contains(plugin, target.getPlugins());
|
||||
if(match == null)
|
||||
{
|
||||
target.addPlugin( copyNewPlugin( plugin ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
copyPluginToPlugin(plugin, match);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static ReportPlugin copyPlugin(ReportPlugin plugin)
|
||||
private static ReportPlugin contains(ReportPlugin plugin, List<ReportPlugin> list)
|
||||
{
|
||||
for(ReportPlugin p :list)
|
||||
{
|
||||
if(match(p, plugin))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void copyPluginToPlugin(ReportPlugin source, ReportPlugin target)
|
||||
{
|
||||
if(source.getInherited() != null)
|
||||
{
|
||||
target.setInherited( source.getInherited() );
|
||||
}
|
||||
|
||||
if(source.getVersion() != null)
|
||||
{
|
||||
target.setVersion( source.getVersion() );
|
||||
}
|
||||
|
||||
if(source.getConfiguration() != null)
|
||||
{
|
||||
if(target.getConfiguration() != null)
|
||||
{
|
||||
target.setConfiguration( Xpp3Dom.mergeXpp3Dom( (Xpp3Dom) source.getConfiguration(), (Xpp3Dom) target.getConfiguration() ));
|
||||
}
|
||||
else
|
||||
{
|
||||
target.setConfiguration( source.getConfiguration() );
|
||||
}
|
||||
}
|
||||
|
||||
for(ReportSet rs : source.getReportSets())
|
||||
{
|
||||
ReportSet r = new ReportSet();
|
||||
r.setId( rs.getId() );
|
||||
r.setInherited( rs.getInherited() );
|
||||
r.setReports( new ArrayList<String>(rs.getReports()) );
|
||||
r.setConfiguration( rs.getConfiguration() );
|
||||
target.addReportSet( r );
|
||||
}
|
||||
}
|
||||
|
||||
private static ReportPlugin copyNewPlugin(ReportPlugin plugin)
|
||||
{
|
||||
ReportPlugin rp = new ReportPlugin();
|
||||
rp.setArtifactId( plugin.getArtifactId() );
|
||||
|
@ -92,4 +149,16 @@ public class ReportingProcessor extends BaseProcessor
|
|||
}
|
||||
return rp;
|
||||
}
|
||||
|
||||
private static boolean match( ReportPlugin d1, ReportPlugin d2 )
|
||||
{
|
||||
return getId( d1 ).equals( getId( d2 ));
|
||||
}
|
||||
|
||||
private static String getId( ReportPlugin d )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( d.getGroupId() ).append( ":" ).append( d.getArtifactId() ).append( ":" );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -953,6 +953,18 @@ public class PomConstructionTest
|
|||
assertEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
|
||||
}
|
||||
|
||||
/* MNG-3811*/
|
||||
public void testReportingPluginConfig()
|
||||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "reporting-plugin-config/sub" );
|
||||
|
||||
assertEquals(2, ( (List<?>) pom.getValue( "reporting/plugins[1]/configuration/stringParams" ) ).size());
|
||||
assertEquals("parentParam", pom.getValue( "reporting/plugins[1]/configuration/stringParams[1]/stringParam[1]"));
|
||||
assertEquals("childParam", pom.getValue( "reporting/plugins[1]/configuration/stringParams[1]/stringParam[2]"));
|
||||
assertEquals("true", pom.getValue( "reporting/plugins[1]/configuration/booleanParam"));
|
||||
}
|
||||
|
||||
public void testCompleteModelWithoutParent()
|
||||
throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue