implements ReportingConverter
{
public void convertReporting( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
{
Reporting reporting = model.getReporting();
if ( reporting == null )
{
return;
}
Build build = model.getBuild();
if ( build == null )
{
build = new Build();
model.setBuild( build );
}
Plugin sitePlugin = findSitePlugin( build );
if ( sitePlugin == null )
{
sitePlugin = new Plugin();
sitePlugin.setArtifactId( "maven-site-plugin" );
PluginManagement pluginManagement = build.getPluginManagement();
if ( pluginManagement == null )
{
pluginManagement = new PluginManagement();
build.setPluginManagement( pluginManagement );
}
pluginManagement.addPlugin( sitePlugin );
}
Xpp3Dom configuration = (Xpp3Dom) sitePlugin.getConfiguration();
if ( configuration == null )
{
configuration = new Xpp3Dom( "configuration" );
sitePlugin.setConfiguration( configuration );
}
Xpp3Dom reportPlugins = configuration.getChild( "reportPlugins" );
if ( reportPlugins != null )
{
// new-style report configuration already present, assume user handled entire conversion
return;
}
if ( configuration.getChild( "outputDirectory" ) == null )
{
addDom( configuration, "outputDirectory", reporting.getOutputDirectory() );
}
reportPlugins = new Xpp3Dom( "reportPlugins" );
configuration.addChild( reportPlugins );
boolean hasMavenProjectInfoReportsPlugin = false;
/* waiting for MSITE-484 before deprecating <reporting> section
if ( !reporting.getPlugins().isEmpty()
&& request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 )
{
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V31 )
.setMessage( "The <reporting> section is deprecated, please move the reports to the <configuration> section of the new Maven Site Plugin." )
.setLocation( reporting.getLocation( "" ) ) );
}*/
for ( ReportPlugin plugin : reporting.getPlugins() )
{
Xpp3Dom reportPlugin = convert( plugin );
reportPlugins.addChild( reportPlugin );
if ( !reporting.isExcludeDefaults() && !hasMavenProjectInfoReportsPlugin
&& "org.apache.maven.plugins".equals( plugin.getGroupId() )
&& "maven-project-info-reports-plugin".equals( plugin.getArtifactId() ) )
{
hasMavenProjectInfoReportsPlugin = true;
}
}
if ( !reporting.isExcludeDefaults() && !hasMavenProjectInfoReportsPlugin )
{
Xpp3Dom dom = new Xpp3Dom( "reportPlugin" );
addDom( dom, "groupId", "org.apache.maven.plugins" );
addDom( dom, "artifactId", "maven-project-info-reports-plugin" );