Skip to content

Commit

Permalink
[MNG-6601] add input location tracking for m-site-p converted reports
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Mar 11, 2019
1 parent 0b10fe7 commit 49c8f17
Showing 1 changed file with 38 additions and 16 deletions.
Expand Up @@ -20,6 +20,8 @@
*/

import org.apache.maven.model.Build;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputSource;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
Expand All @@ -45,6 +47,15 @@
public class DefaultReportingConverter
implements ReportingConverter
{
private final InputLocation location;
{
String modelId = "org.apache.maven:maven-model-builder:"
+ this.getClass().getPackage().getImplementationVersion() + ":reporting-converter";
InputSource inputSource = new InputSource();
inputSource.setModelId( modelId );
location = new InputLocation( -1, -1, inputSource );
location.setLocation( 0, location );
}

@Override
public void convertReporting( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
Expand All @@ -62,6 +73,7 @@ public void convertReporting( Model model, ModelBuildingRequest request, ModelPr
{
build = new Build();
model.setBuild( build );
model.setLocation( "build", location );
}

Plugin sitePlugin = findSitePlugin( build );
Expand All @@ -70,6 +82,7 @@ public void convertReporting( Model model, ModelBuildingRequest request, ModelPr
{
sitePlugin = new Plugin();
sitePlugin.setArtifactId( "maven-site-plugin" );
sitePlugin.setLocation( "artifactId", location );
PluginManagement pluginManagement = build.getPluginManagement();
if ( pluginManagement == null )
{
Expand All @@ -83,7 +96,7 @@ public void convertReporting( Model model, ModelBuildingRequest request, ModelPr

if ( configuration == null )
{
configuration = new Xpp3Dom( "configuration" );
configuration = new Xpp3Dom( "configuration", location );
sitePlugin.setConfiguration( configuration );
}

Expand All @@ -102,10 +115,11 @@ public void convertReporting( Model model, ModelBuildingRequest request, ModelPr

if ( configuration.getChild( "outputDirectory" ) == null )
{
addDom( configuration, "outputDirectory", reporting.getOutputDirectory() );
addDom( configuration, "outputDirectory", reporting.getOutputDirectory(),
reporting.getLocation( "outputDirectory" ) );
}

reportPlugins = new Xpp3Dom( "reportPlugins" );
reportPlugins = new Xpp3Dom( "reportPlugins", location );
configuration.addChild( reportPlugins );

boolean hasMavenProjectInfoReportsPlugin = false;
Expand Down Expand Up @@ -136,7 +150,7 @@ public void convertReporting( Model model, ModelBuildingRequest request, ModelPr

if ( !reporting.isExcludeDefaults() && !hasMavenProjectInfoReportsPlugin )
{
Xpp3Dom dom = new Xpp3Dom( "reportPlugin" );
Xpp3Dom dom = new Xpp3Dom( "reportPlugin", location );

addDom( dom, "groupId", "org.apache.maven.plugins" );
addDom( dom, "artifactId", "maven-project-info-reports-plugin" );
Expand Down Expand Up @@ -178,11 +192,11 @@ private boolean isSitePlugin( Plugin plugin )

private Xpp3Dom convert( ReportPlugin plugin )
{
Xpp3Dom dom = new Xpp3Dom( "reportPlugin" );
Xpp3Dom dom = new Xpp3Dom( "reportPlugin", plugin.getLocation( "" ) );

addDom( dom, "groupId", plugin.getGroupId() );
addDom( dom, "artifactId", plugin.getArtifactId() );
addDom( dom, "version", plugin.getVersion() );
addDom( dom, "groupId", plugin.getGroupId(), plugin.getLocation( "groupId" ) );
addDom( dom, "artifactId", plugin.getArtifactId(), plugin.getLocation( "artifactId" ) );
addDom( dom, "version", plugin.getVersion(), plugin.getLocation( "version" ) );

Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
if ( configuration != null )
Expand All @@ -193,7 +207,7 @@ private Xpp3Dom convert( ReportPlugin plugin )

if ( !plugin.getReportSets().isEmpty() )
{
Xpp3Dom reportSets = new Xpp3Dom( "reportSets" );
Xpp3Dom reportSets = new Xpp3Dom( "reportSets", plugin.getLocation( "reportSets" ) );
for ( ReportSet reportSet : plugin.getReportSets() )
{
Xpp3Dom rs = convert( reportSet );
Expand All @@ -207,9 +221,10 @@ private Xpp3Dom convert( ReportPlugin plugin )

private Xpp3Dom convert( ReportSet reportSet )
{
Xpp3Dom dom = new Xpp3Dom( "reportSet" );
Xpp3Dom dom = new Xpp3Dom( "reportSet", reportSet.getLocation( "" ) );

addDom( dom, "id", reportSet.getId() );
InputLocation idLocation = reportSet.getLocation( "id" );
addDom( dom, "id", reportSet.getId(), idLocation == null ? location : idLocation );

Xpp3Dom configuration = (Xpp3Dom) reportSet.getConfiguration();
if ( configuration != null )
Expand All @@ -220,10 +235,12 @@ private Xpp3Dom convert( ReportSet reportSet )

if ( !reportSet.getReports().isEmpty() )
{
Xpp3Dom reports = new Xpp3Dom( "reports" );
InputLocation location = reportSet.getLocation( "reports" );
Xpp3Dom reports = new Xpp3Dom( "reports", location );
int n = 0;
for ( String report : reportSet.getReports() )
{
addDom( reports, "report", report );
addDom( reports, "report", report, location.getLocation( n++ ) );
}
dom.addChild( reports );
}
Expand All @@ -232,16 +249,21 @@ private Xpp3Dom convert( ReportSet reportSet )
}

private void addDom( Xpp3Dom parent, String childName, String childValue )
{
addDom( parent, childName, childValue, location );
}

private void addDom( Xpp3Dom parent, String childName, String childValue, InputLocation location )
{
if ( StringUtils.isNotEmpty( childValue ) )
{
parent.addChild( newDom( childName, childValue ) );
parent.addChild( newDom( childName, childValue, location ) );
}
}

private Xpp3Dom newDom( String name, String value )
private Xpp3Dom newDom( String name, String value, InputLocation location )
{
Xpp3Dom dom = new Xpp3Dom( name );
Xpp3Dom dom = new Xpp3Dom( name, location );
dom.setValue( value );
return dom;
}
Expand Down

0 comments on commit 49c8f17

Please sign in to comment.