Working on issue: MNG-469

o Changed <reports/> in the Model to <reporting/>, to accommodate the <reports/> inside of <reportSet/>.

o Changed the report-plugin class <plugins/> inside of <report[ing]/> to <reporters/>, which means using a new class called Reporter (this is meant to be a Plugin-like model for reports, with reportSets rather than executions...)

o Changed the MavenProject to reflect these two model changes

o Added support to the inheritance assembler to perform deep inheritance of the reporting model (complete with calculations based on the <inherit/> attributes on Reporter and ReportSet).

o Updated DoxiaMojo, Pom, and DefaultPluginVersionManager to reflect the new model classes and MavenProject methods.

This is only round one of the changes for this issue. The next step is to start binding report configuration to the plugin manager via the lifecycle executor (it will traverse the reporting section, and verifyPlugin() to enable direct calls to the report's mojo).



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191239 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-18 00:43:00 +00:00
parent 819c70975c
commit 60750dede2
6 changed files with 348 additions and 94 deletions

View File

@ -24,7 +24,7 @@ import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Reports;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@ -232,9 +232,9 @@ public class Pom
return getMavenProject().getPluginRepositories();
} //-- java.util.List getPluginRepositories()
public Reports getReports()
public Reporting getReporting()
{
return getMavenProject().getReports();
return getMavenProject().getReporting();
} //-- Reports getReports()
public java.util.List getRepositories()

View File

@ -6,6 +6,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Reporter;
import org.apache.maven.plugin.registry.MavenPluginRegistryBuilder;
import org.apache.maven.plugin.registry.PluginRegistry;
import org.apache.maven.plugin.registry.PluginRegistryUtils;
@ -383,15 +384,13 @@ public class DefaultPluginVersionManager
{
String version = null;
Plugin pluginConfig = null;
for ( Iterator it = project.getBuildPlugins().iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
{
pluginConfig = plugin;
version = plugin.getVersion();
break;
}
@ -399,26 +398,21 @@ public class DefaultPluginVersionManager
// won't this overwrite the above loop if it exists in both places (unlikely, I know)??
// maybe that's the idea...?
if ( project.getReports() != null )
if ( project.getReporters() != null )
{
for ( Iterator it = project.getReports().getPlugins().iterator(); it.hasNext(); )
for ( Iterator it = project.getReporters().iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
Reporter reporter = (Reporter) it.next();
if ( groupId.equals( plugin.getGroupId() ) && artifactId.equals( plugin.getArtifactId() ) )
if ( groupId.equals( reporter.getGroupId() ) && artifactId.equals( reporter.getArtifactId() ) )
{
pluginConfig = plugin;
version = reporter.getVersion();
break;
}
}
}
if ( pluginConfig != null )
{
version = pluginConfig.getVersion();
}
return version;
}

View File

@ -625,7 +625,7 @@
<comment>These should ultimately only be compile time dependencies when transitive dependencies come into play.</comment>
</field>
<field>
<name>reports</name>
<name>reporting</name>
<version>4.0.0</version>
<description><![CDATA[
This element includes the specification of reports to be
@ -635,7 +635,7 @@
the order they are specified.
]]></description>
<association>
<type>Reports</type>
<type>Reporting</type>
</association>
</field>
<field>
@ -2305,7 +2305,7 @@
</description>
</class>
<class>
<name>Reports</name>
<name>Reporting</name>
<version>4.0.0</version>
<description>Section for management of reports and configuration</description>
<fields>
@ -2316,16 +2316,46 @@
<description>Where to store all of the generated reports</description>
</field>
<field>
<name>plugins</name>
<name>reporters</name>
<version>4.0.0</version>
<description>The reporting plugins to use and their configuration</description>
<description>The reporters (specialized plugins) to use and their configuration</description>
<association>
<!-- TODO: goal stuff relevant or not? -->
<type>Plugin</type>
<type>Reporter</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
Map reporterMap;
public void flushReporterMap()
{
this.reporterMap = null;
}
public Map getReportersAsMap()
{
if ( reporterMap == null )
{
reporterMap = new HashMap();
if ( getReporters() != null )
{
for ( Iterator it = getReporters().iterator(); it.hasNext(); )
{
Reporter reporter = (Reporter) it.next();
reporterMap.put( reporter.getKey(), reporter );
}
}
}
return reporterMap;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<!-- Profile support -->
<class>
@ -2455,6 +2485,156 @@
</fields>
</class>
<!-- /BuildProfile support -->
<class>
<name>Reporter</name>
<version>4.0.0</version>
<fields>
<field>
<name>groupId</name>
<version>4.0.0</version>
<type>String</type>
<defaultValue>org.apache.maven.plugins</defaultValue>
</field>
<field>
<name>artifactId</name>
<version>4.0.0</version>
<type>String</type>
<required>true</required>
</field>
<field>
<name>version</name>
<version>4.0.0</version>
<description><![CDATA[The version of the reporter to be used.]]></description>
<type>String</type>
</field>
<field>
<name>inherited</name>
<version>4.0.0</version>
<type>String</type>
</field>
<field>
<name>configuration</name>
<version>4.0.0</version>
<type>DOM</type>
</field>
<field>
<name>reportSets</name>
<version>4.0.0</version>
<description>Multiple specifications of a set of reports, each having (possibly) different configuration</description>
<association>
<type>ReportSet</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
private Map reportSetMap = null;
public void flushReportSetMap()
{
this.reportSetMap = null;
}
public Map getReportSetsAsMap()
{
if ( reportSetMap == null )
{
reportSetMap = new HashMap();
if ( getReportSets() != null )
{
for ( Iterator i = getReportSets().iterator(); i.hasNext(); )
{
ReportSet reportSet = (ReportSet) i.next();
reportSetMap.put( reportSet.getId(), reportSet );
}
}
}
return reportSetMap;
}
public String getKey()
{
return constructKey( groupId, artifactId );
}
public static String constructKey( String groupId, String artifactId )
{
return groupId + ":" + artifactId;
}
private boolean inheritanceApplied = true;
public void unsetInheritanceApplied()
{
this.inheritanceApplied = false;
}
public boolean isInheritanceApplied()
{
return inheritanceApplied;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class>
<name>ReportSet</name>
<version>4.0.0</version>
<description>Represents a set of reports and configuration to be used to generate them.</description>
<fields>
<field>
<name>id</name>
<type>String</type>
<required>true</required>
<description>The unique id for this report set, to be used during POM inheritance.</description>
</field>
<field>
<name>configuration</name>
<version>4.0.0</version>
<type>DOM</type>
</field>
<field>
<name>inherited</name>
<version>4.0.0</version>
<type>String</type>
</field>
<field>
<name>reports</name>
<version>4.0.0</version>
<required>true</required>
<description><![CDATA[
The list of reports from this reporter/plugin which should be generated from this set
(this configuration)
]]></description>
<association>
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
private boolean inheritanceApplied = true;
public void unsetInheritanceApplied()
{
this.inheritanceApplied = false;
}
public boolean isInheritanceApplied()
{
return inheritanceApplied;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
</classes>
</model>

View File

@ -717,15 +717,15 @@ public class DoxiaMojo
{
// TODO: not the best solution. Perhaps a mojo tag that causes the plugin manager to populate project reports instead?
List reportPlugins = project.getReportPlugins();
List reportPlugins = project.getReporters();
if ( reportPlugins != null )
{
for ( Iterator it = reportPlugins.iterator(); it.hasNext(); )
{
org.apache.maven.model.Plugin plugin = (org.apache.maven.model.Plugin) it.next();
org.apache.maven.model.Reporter reporter = (org.apache.maven.model.Reporter) it.next();
try
{
pluginManager.verifyPlugin( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(),
pluginManager.verifyPlugin( reporter.getGroupId(), reporter.getArtifactId(), reporter.getVersion(),
project, settings, localRepository );
}
catch ( ArtifactResolutionException e )

View File

@ -27,7 +27,6 @@ import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Goal;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
@ -35,9 +34,8 @@ import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Reports;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.util.ArrayList;
@ -644,14 +642,14 @@ public class MavenProject
return model.getBuild();
}
public void setReports( Reports reports )
public void setReporting( Reporting reporting )
{
model.setReports( reports );
model.setReporting( reporting );
}
public Reports getReports()
public Reporting getReporting()
{
return model.getReports();
return model.getReporting();
}
public void setLicenses( List licenses )
@ -708,13 +706,13 @@ public class MavenProject
// Plugins
// ----------------------------------------------------------------------
public List getReportPlugins()
public List getReporters()
{
if ( model.getReports() == null )
if ( model.getReporting() == null )
{
return null;
}
return model.getReports().getPlugins();
return model.getReporting().getReporters();
}
@ -842,53 +840,6 @@ public class MavenProject
return distMgmtArtifactRepository;
}
public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String goalId )
{
Xpp3Dom dom = null;
// ----------------------------------------------------------------------
// I would like to be able to lookup the Mojo object using a key but
// we have a limitation in modello that will be remedied shortly. So
// for now I have to iterate through and see what we have.
// ----------------------------------------------------------------------
if ( getBuildPlugins() != null )
{
for ( Iterator iterator = getBuildPlugins().iterator(); iterator.hasNext(); )
{
Plugin plugin = (Plugin) iterator.next();
if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
{
dom = (Xpp3Dom) plugin.getConfiguration();
if ( goalId != null )
{
Goal goal = (Goal) plugin.getGoalsAsMap().get( goalId );
if ( goal != null )
{
Xpp3Dom goalConfiguration = (Xpp3Dom) goal.getConfiguration();
if ( goalConfiguration != null )
{
Xpp3Dom newDom = new Xpp3Dom( goalConfiguration );
dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
}
}
}
break;
}
}
}
if ( dom != null )
{
// make a copy so the original in the POM doesn't get messed with
dom = new Xpp3Dom( dom );
}
return dom;
}
public List getPluginRepositories()
{
return model.getPluginRepositories();

View File

@ -23,14 +23,19 @@ import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporter;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Repository;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import org.apache.maven.project.ModelUtils;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -198,29 +203,153 @@ public class DefaultModelInheritanceAssembler
}
// Reports :: aggregate
if ( child.getReports() != null && parent.getReports() != null )
Reporting childReporting = child.getReporting();
Reporting parentReporting = parent.getReporting();
if ( childReporting != null && parentReporting != null )
{
if ( child.getReports().getOutputDirectory() == null )
if ( StringUtils.isEmpty( childReporting.getOutputDirectory() ) )
{
child.getReports().setOutputDirectory( parent.getReports().getOutputDirectory() );
childReporting.setOutputDirectory( parentReporting.getOutputDirectory() );
}
List parentReports = parent.getReports().getPlugins();
Map mergedReporters = new HashMap();
List childReports = child.getReports().getPlugins();
Map childReportersByKey = childReporting.getReportersAsMap();
for ( Iterator iterator = parentReports.iterator(); iterator.hasNext(); )
List parentReporters = parentReporting.getReporters();
if ( parentReporters != null )
{
Plugin plugin = (Plugin) iterator.next();
if ( !childReports.contains( plugin ) )
for ( Iterator it = parentReporters.iterator(); it.hasNext(); )
{
child.getReports().addPlugin( plugin );
Reporter parentReporter = (Reporter) it.next();
String inherited = parentReporter.getInherited();
if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
{
Reporter childReporter = (Reporter) childReportersByKey.get( parentReporter.getKey() );
Reporter mergedReporter = parentReporter;
if ( childReporter != null )
{
mergedReporter = childReporter;
mergeReporters( childReporter, parentReporter );
}
else if ( StringUtils.isEmpty( inherited ) )
{
mergedReporter.unsetInheritanceApplied();
}
mergedReporters.put( mergedReporter.getKey(), mergedReporter );
}
}
}
for ( Iterator it = childReportersByKey.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
if ( !mergedReporters.containsKey( key ) )
{
mergedReporters.put( key, entry.getValue() );
}
}
childReporting.setReporters( new ArrayList( mergedReporters.values() ) );
}
assembleDependencyManagementInheritance( child, parent );
}
private void mergeReporters( Reporter dominant, Reporter recessive )
{
if ( StringUtils.isEmpty( dominant.getVersion() ) )
{
dominant.setVersion( recessive.getVersion() );
}
Xpp3Dom dominantConfig = (Xpp3Dom) dominant.getConfiguration();
Xpp3Dom recessiveConfig = (Xpp3Dom) recessive.getConfiguration();
dominant.setConfiguration( Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ) );
Map mergedReportSets = new HashMap();
Map dominantReportSetsById = dominant.getReportSetsAsMap();
for ( Iterator it = recessive.getReportSets().iterator(); it.hasNext(); )
{
ReportSet recessiveReportSet = (ReportSet) it.next();
String inherited = recessiveReportSet.getInherited();
if ( StringUtils.isEmpty( inherited ) || Boolean.valueOf( inherited ).booleanValue() )
{
ReportSet dominantReportSet = (ReportSet) dominantReportSetsById.get( recessiveReportSet.getId() );
ReportSet merged = recessiveReportSet;
if ( dominantReportSet != null )
{
merged = dominantReportSet;
Xpp3Dom recessiveRSConfig = (Xpp3Dom) recessiveReportSet.getConfiguration();
Xpp3Dom mergedRSConfig = (Xpp3Dom) merged.getConfiguration();
merged.setConfiguration( Xpp3Dom.mergeXpp3Dom( mergedRSConfig, recessiveRSConfig ) );
List mergedReports = merged.getReports();
if ( mergedReports == null )
{
mergedReports = new ArrayList();
merged.setReports( mergedReports );
}
List recessiveRSReports = recessiveReportSet.getReports();
if ( recessiveRSReports != null )
{
for ( Iterator reportIterator = recessiveRSReports.iterator(); reportIterator.hasNext(); )
{
String report = (String) reportIterator.next();
if ( !mergedReports.contains( report ) )
{
mergedReports.add( report );
}
}
}
}
else if ( StringUtils.isEmpty( inherited ) )
{
merged.unsetInheritanceApplied();
}
mergedReportSets.put( merged.getId(), merged );
}
}
assembleDependencyManagementInheritance( child, parent );
for ( Iterator rsIterator = dominantReportSetsById.entrySet().iterator(); rsIterator.hasNext(); )
{
Map.Entry entry = (Map.Entry) rsIterator.next();
String key = (String) entry.getKey();
if ( !mergedReportSets.containsKey( key ) )
{
mergedReportSets.put( key, entry.getValue() );
}
}
dominant.setReportSets( new ArrayList( mergedReportSets.values() ) );
}
private void assembleDependencyManagementInheritance( ModelBase child, ModelBase parent )