PR: MNG-469

configure reports according to spec:
- <reporting> section affects reports run through site and standalone
- <build> section affects reports run standalone and overrides anything already in <reporting>
- command line parameters rule all



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191298 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-18 16:21:49 +00:00
parent 28b5d25b61
commit 1a63032af4
8 changed files with 283 additions and 137 deletions

View File

@ -14,6 +14,13 @@
<artifactId>wagon-provider-api</artifactId>
<version>1.0-alpha-3</version>
</dependency>
<!-- TODO: remove -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-monitor</artifactId>

View File

@ -27,6 +27,7 @@ import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.artifact.resolver.filter.InversionArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.ReportSet;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.monitor.logging.DefaultLog;
@ -349,8 +350,6 @@ public class DefaultPluginManager
public void executeMojo( MojoExecution mojoExecution, MavenSession session )
throws ArtifactResolutionException, PluginManagerException, MojoExecutionException
{
PlexusContainer pluginContainer = null;
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
@ -391,88 +390,24 @@ public class DefaultPluginManager
}
}
Mojo plugin = null;
String goalName = mojoDescriptor.getFullGoalName();
PlexusContainer pluginContainer = getPluginContainer( mojoDescriptor.getPluginDescriptor() );
Mojo plugin = null;
try
{
String pluginKey = mojoDescriptor.getPluginDescriptor().getPluginLookupKey();
pluginContainer = container.getChildContainer( pluginKey );
if ( pluginContainer == null )
{
throw new PluginConfigurationException( "Cannot find PlexusContainer for plugin: " + pluginKey );
}
plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
plugin.setLog( mojoLogger );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
String goalId = mojoDescriptor.getGoal();
String groupId = pluginDescriptor.getGroupId();
String artifactId = pluginDescriptor.getArtifactId();
String executionId = mojoExecution.getExecutionId();
Xpp3Dom dom = session.getProject().getGoalConfiguration( groupId, artifactId, executionId, goalId );
Xpp3Dom reportDom = session.getProject().getReportConfiguration( groupId, artifactId, executionId );
dom = Xpp3Dom.mergeXpp3Dom( dom, reportDom );
PlexusConfiguration pomConfiguration;
if ( dom == null )
{
pomConfiguration = new XmlPlexusConfiguration( "configuration" );
}
else
{
pomConfiguration = new XmlPlexusConfiguration( dom );
}
// Validate against non-editable (@readonly) parameters, to make sure users aren't trying to
// override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor
.getMojoConfiguration() );
// TODO: plexus
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
// mojoDescriptor.getConfiguration() );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pluginDescriptor,
pathTranslator,
getLogger() );
checkRequiredParameters( mojoDescriptor, mergedConfiguration, expressionEvaluator, plugin );
populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, pluginContainer, expressionEvaluator );
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.MOJO_EXECUTION;
EventDispatcher dispatcher = session.getEventDispatcher();
String goalExecId = goalName;
if ( mojoExecution.getExecutionId() != null )
{
goalExecId += " {execution: " + mojoExecution.getExecutionId() + "}";
}
dispatcher.dispatchStart( event, goalExecId );
try
{
plugin.execute();
dispatcher.dispatchEnd( event, goalExecId );
}
catch ( MojoExecutionException e )
{
session.getEventDispatcher().dispatchError( event, goalExecId, e );
throw e;
}
// End event monitoring.
plugin = getConfiguredMojo( pluginContainer, mojoDescriptor, session, dom );
}
catch ( PluginConfigurationException e )
{
@ -483,6 +418,32 @@ public class DefaultPluginManager
{
throw new MojoExecutionException( "Error looking up plugin: ", e );
}
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.MOJO_EXECUTION;
EventDispatcher dispatcher = session.getEventDispatcher();
String goalExecId = goalName;
if ( mojoExecution.getExecutionId() != null )
{
goalExecId += " {execution: " + mojoExecution.getExecutionId() + "}";
}
dispatcher.dispatchStart( event, goalExecId );
try
{
plugin.execute();
dispatcher.dispatchEnd( event, goalExecId );
}
catch ( MojoExecutionException e )
{
session.getEventDispatcher().dispatchError( event, goalExecId, e );
throw e;
}
finally
{
try
@ -499,6 +460,100 @@ public class DefaultPluginManager
}
}
public List getReports( String groupId, String artifactId, String version, ReportSet reportSet,
MavenSession session )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException
{
PluginDescriptor pluginDescriptor = getPluginDescriptor( groupId, artifactId, version );
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
List reports = new ArrayList();
for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); )
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next();
// TODO: check ID is correct for reports
// TODO: this returns mojos that aren't reports
// if the POM configured no reports, give all from plugin
if ( reportSet == null || reportSet.getReports().contains( mojoDescriptor.getGoal() ) )
{
try
{
String id = null;
if ( reportSet != null )
{
id = reportSet.getId();
}
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, id );
String executionId = mojoExecution.getExecutionId();
Xpp3Dom dom = session.getProject().getReportConfiguration( groupId, artifactId, executionId );
reports.add( getConfiguredMojo( pluginContainer, mojoDescriptor, session, dom ) );
}
catch ( ComponentLookupException e )
{
throw new PluginManagerException( "Error looking up plugin: ", e );
}
}
}
return reports;
}
private PlexusContainer getPluginContainer( PluginDescriptor pluginDescriptor )
throws PluginManagerException
{
String pluginKey = pluginDescriptor.getPluginLookupKey();
PlexusContainer pluginContainer = container.getChildContainer( pluginKey );
if ( pluginContainer == null )
{
throw new PluginManagerException( "Cannot find PlexusContainer for plugin: " + pluginKey );
}
return pluginContainer;
}
private Mojo getConfiguredMojo( PlexusContainer pluginContainer, MojoDescriptor mojoDescriptor,
MavenSession session, Xpp3Dom dom )
throws ComponentLookupException, PluginConfigurationException
{
Mojo plugin = (Mojo) pluginContainer.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
plugin.setLog( mojoLogger );
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
PlexusConfiguration pomConfiguration;
if ( dom == null )
{
pomConfiguration = new XmlPlexusConfiguration( "configuration" );
}
else
{
pomConfiguration = new XmlPlexusConfiguration( dom );
}
// Validate against non-editable (@readonly) parameters, to make sure users aren't trying to
// override in the POM.
validatePomConfiguration( mojoDescriptor, pomConfiguration );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, mojoDescriptor
.getMojoConfiguration() );
// TODO: plexus
// PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
// mojoDescriptor.getConfiguration() );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pluginDescriptor,
pathTranslator, getLogger() );
checkRequiredParameters( mojoDescriptor, mergedConfiguration, expressionEvaluator, plugin );
populatePluginFields( plugin, mojoDescriptor, mergedConfiguration, pluginContainer, expressionEvaluator );
return plugin;
}
private void checkRequiredParameters( MojoDescriptor goal, PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator, Mojo plugin )
throws PluginConfigurationException
@ -816,8 +871,9 @@ public class DefaultPluginManager
public void initialize()
{
// TODO: configure this from bootstrap or scan lib
// TODO: remove doxia
artifactFilter = new ExclusionSetFilter(
new String[]{"classworlds", "maven-artifact", "maven-core", "maven-model", "maven-monitor", "maven-plugin-api", "maven-plugin-descriptor", "maven-project", "maven-settings", "plexus-container-default", "plexus-utils", "wagon-provider-api", "wagon-ssh", "wagon-http-lightweight", "wagon-file"} );
new String[]{"classworlds", "maven-artifact", "maven-core", "maven-model", "maven-monitor", "maven-plugin-api", "maven-plugin-descriptor", "maven-project", "maven-settings", "plexus-container-default", "plexus-utils", "wagon-provider-api", "wagon-ssh", "wagon-http-lightweight", "wagon-file", "doxia-core", "maven-reporting-api"} );
}
// ----------------------------------------------------------------------

View File

@ -23,6 +23,10 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.apache.maven.model.ReportSet;
import java.util.Collection;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -38,6 +42,9 @@ public interface PluginManager
PluginDescriptor verifyPlugin( String prefix );
PluginDescriptor verifyPlugin( String groupId, String artifactId, String version, MavenProject project,
Settings settings, ArtifactRepository localRepository )
Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
List getReports( String groupId, String artifactId, String version, ReportSet reportSet, MavenSession session )
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException;
}

View File

@ -25,6 +25,11 @@ package org.apache.maven.plugin;
public class PluginManagerException
extends Exception
{
public PluginManagerException( String message )
{
super( message );
}
public PluginManagerException( String message, Exception e )
{
super( message, e );

View File

@ -84,6 +84,10 @@ public class PluginParameterExpressionEvaluator
{
value = context.getLocalRepository();
}
else if ( expression.equals( "session" ) )
{
value = context;
}
else if ( expression.equals( "project" ) )
{
value = context.getProject();

View File

@ -18,8 +18,11 @@ package org.apache.maven.doxia;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.ReportSet;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
@ -37,13 +40,6 @@ import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.PlexusContainerLocator;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.io.File;
import java.io.FileOutputStream;
@ -74,12 +70,11 @@ import java.util.StringTokenizer;
*/
public class DoxiaMojo
extends AbstractMojo
implements Contextualizable
{
private static final String RESOURCE_DIR = "org/apache/maven/doxia";
private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/maven-site.vm";
/**
* @parameter expression="${settings}"
* @required
@ -167,11 +162,11 @@ public class DoxiaMojo
private ArtifactRepository localRepository;
/**
* @parameter expression="${project.remoteArtifactRepositories}"
* @parameter expression="${session}"
* @required
* @readonly
*/
private List remoteRepositories;
private MavenSession session;
private List projectInfos = new ArrayList();
@ -181,8 +176,6 @@ public class DoxiaMojo
private List localesList = new ArrayList();
private PlexusContainer container;
public void execute()
throws MojoExecutionException
{
@ -208,7 +201,7 @@ public class DoxiaMojo
}
}
Map reports = getReports();
List reports = getReports();
try
{
@ -243,13 +236,11 @@ public class DoxiaMojo
//Generate reports
if ( reports != null )
{
for ( Iterator j = reports.keySet().iterator(); j.hasNext(); )
for ( Iterator j = reports.iterator(); j.hasNext(); )
{
String reportKey = (String) j.next();
MavenReport report = (MavenReport) j.next();
getLog().info( "Generate " + reportKey + " report." );
MavenReport report = (MavenReport) reports.get( reportKey );
getLog().info( "Generate " + report.getName( locale ) + " report." );
report.setConfiguration( config );
@ -340,10 +331,10 @@ public class DoxiaMojo
}
}
private void categorizeReports( Map reports )
private void categorizeReports( List reports )
throws MojoExecutionException
{
for ( Iterator i = reports.values().iterator(); i.hasNext(); )
for ( Iterator i = reports.iterator(); i.hasNext(); )
{
MavenReport report = (MavenReport) i.next();
if ( MavenReport.CATEGORY_PROJECT_INFORMATION.equals( report.getCategoryName() ) )
@ -356,8 +347,9 @@ public class DoxiaMojo
}
else
{
throw new MojoExecutionException( "'" + report.getCategoryName() + "' category define for " +
report.getName( defaultLocale ) + " mojo isn't valid." );
throw new MojoExecutionException(
"'" + report.getCategoryName() + "' category define for " + report.getName( defaultLocale ) +
" mojo isn't valid." );
}
}
}
@ -366,20 +358,22 @@ public class DoxiaMojo
{
StringBuffer buffer = new StringBuffer();
buffer.append( "<menu name=\"Project Documentation\">\n" );
buffer.append( " <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.about" ) + " " +
project.getName() + "\" href=\"/index.html\"/>\n" );
buffer.append(
" <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.about" ) + " " +
project.getName() + "\" href=\"/index.html\"/>\n" );
if ( projectInfos.size() > 0 )
{
buffer.append( " <item name=\"" +
i18n.getString( "site-plugin", locale, "report.menu.projectinformation" ) +
"\" href=\"/project-info.html\" collapse=\"true\">\n" );
buffer.append(
" <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.projectinformation" ) +
"\" href=\"/project-info.html\" collapse=\"true\">\n" );
for ( Iterator i = projectInfos.iterator(); i.hasNext(); )
{
MavenReport report = (MavenReport) i.next();
buffer.append( " <item name=\"" + report.getName( locale ) + "\" href=\"/" +
report.getOutputName() + ".html\"/>\n" );
buffer.append(
" <item name=\"" + report.getName( locale ) + "\" href=\"/" + report.getOutputName() +
".html\"/>\n" );
}
buffer.append( " </item>\n" );
@ -387,14 +381,16 @@ public class DoxiaMojo
if ( projectReports.size() > 0 )
{
buffer.append( " <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.projectreports" ) +
"\" href=\"/maven-reports.html\" collapse=\"true\">\n" );
buffer.append(
" <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.projectreports" ) +
"\" href=\"/maven-reports.html\" collapse=\"true\">\n" );
for ( Iterator i = projectReports.iterator(); i.hasNext(); )
{
MavenReport report = (MavenReport) i.next();
buffer.append( " <item name=\"" + report.getName( locale ) + "\" href=\"/" +
report.getOutputName() + ".html\"/>\n" );
buffer.append(
" <item name=\"" + report.getName( locale ) + "\" href=\"/" + report.getOutputName() +
".html\"/>\n" );
}
buffer.append( " </item>\n" );
@ -408,7 +404,7 @@ public class DoxiaMojo
/**
* @todo should only be needed once
*/
private InputStream getSiteDescriptor( Map reports, Locale locale )
private InputStream getSiteDescriptor( List reports, Locale locale )
throws MojoExecutionException
{
File siteDescriptor = new File( siteDirectory, "site.xml" );
@ -632,8 +628,8 @@ public class DoxiaMojo
if ( is == null )
{
throw new IOException( "The resource " + line + " doesn't exists in " + DEFAULT_TEMPLATE +
" template." );
throw new IOException(
"The resource " + line + " doesn't exists in " + DEFAULT_TEMPLATE + " template." );
}
File outputFile = new File( outputDirectory, line );
@ -712,7 +708,7 @@ public class DoxiaMojo
}
}
private Map getReports()
private List getReports()
throws MojoExecutionException
{
// TODO: not the best solution. Perhaps a mojo tag that causes the plugin manager to populate project reports instead?
@ -721,18 +717,21 @@ public class DoxiaMojo
if ( project.getModel().getReports() != null )
{
getLog().error( "DEPRECATED: Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead.");
getLog().error(
"DEPRECATED: Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
}
List reports = new ArrayList();
if ( reportPlugins != null )
{
for ( Iterator it = reportPlugins.iterator(); it.hasNext(); )
{
org.apache.maven.model.ReportPlugin reportPlugin = (org.apache.maven.model.ReportPlugin) it.next();
try
{
pluginManager.verifyPlugin( reportPlugin.getGroupId(), reportPlugin.getArtifactId(), reportPlugin.getVersion(),
project, settings, localRepository );
pluginManager.verifyPlugin( reportPlugin.getGroupId(), reportPlugin.getArtifactId(),
reportPlugin.getVersion(), project, settings, localRepository );
}
catch ( ArtifactResolutionException e )
{
@ -746,27 +745,43 @@ public class DoxiaMojo
{
throw new MojoExecutionException( "Cannot find report plugin", e );
}
try
{
List reportSets = reportPlugin.getReportSets();
if ( reportSets == null || reportSets.isEmpty() )
{
reports.addAll(
pluginManager.getReports( reportPlugin.getGroupId(), reportPlugin.getArtifactId(),
reportPlugin.getVersion(), null, session ) );
}
else
{
for ( Iterator j = reportSets.iterator(); j.hasNext(); )
{
ReportSet reportSet = (ReportSet) j.next();
reports.addAll(
pluginManager.getReports( reportPlugin.getGroupId(), reportPlugin.getArtifactId(),
reportPlugin.getVersion(), reportSet, session ) );
}
}
}
catch ( PluginManagerException e )
{
throw new MojoExecutionException( "Error getting reports", e );
}
catch ( PluginVersionResolutionException e )
{
throw new MojoExecutionException( "Error getting reports", e );
}
catch ( PluginConfigurationException e )
{
throw new MojoExecutionException( "Error getting reports", e );
}
}
}
// TODO: this is not good (using the container), also because it will import every report ever loaded
// What we need is to be able to select individual reports and know what reports are inside a plugin
// It may be better to push the report section in the pom back to "plugins", then just have a reports list
// again which are role hints to look up
try
{
return container.lookupMap( MavenReport.ROLE );
}
catch ( ComponentLookupException e )
{
throw new MojoExecutionException( "Unable to find reports", e );
}
}
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
return reports;
}
}

View File

@ -38,6 +38,8 @@ import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
@ -944,4 +946,51 @@ public class MavenProject
return dom;
}
public Xpp3Dom getReportConfiguration( String pluginGroupId, String pluginArtifactId, String reportSetId )
{
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 ( getReportPlugins() != null )
{
for ( Iterator iterator = getReportPlugins().iterator(); iterator.hasNext(); )
{
ReportPlugin plugin = (ReportPlugin) iterator.next();
if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
{
dom = (Xpp3Dom) plugin.getConfiguration();
if ( reportSetId != null )
{
ReportSet reportSet = (ReportSet) plugin.getReportSetsAsMap().get( reportSetId );
if ( reportSet != null )
{
Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet.getConfiguration();
if ( executionConfiguration != null )
{
Xpp3Dom newDom = new Xpp3Dom( executionConfiguration );
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;
}
}

View File

@ -76,6 +76,9 @@ public class CheckstyleReport
private String extraFormatter = "plain";
/**
* @parameter expression="${resultFileName}"
*/
private String resultFileName = "checkstyle-result.txt";
private String packageNamesFile;