diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index b336371825..b0ded1c57a 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -31,6 +31,8 @@ import org.apache.maven.model.Goal; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginExecution; import org.apache.maven.model.PluginManagement; +import org.apache.maven.model.ReportPlugin; +import org.apache.maven.model.ReportSet; import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.MavenEvents; import org.apache.maven.plugin.MojoExecution; @@ -47,6 +49,7 @@ import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.reactor.ReactorException; +import org.apache.maven.reporting.MavenReport; import org.apache.maven.settings.Settings; import org.codehaus.plexus.PlexusContainerException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -474,6 +477,13 @@ public class DefaultLifecycleExecutor forkLifecycle( mojoDescriptor, session, project ); } + if ( mojoDescriptor.isRequiresReports() ) + { + List reports = getReports( project, mojoExecution, session ); + + mojoExecution.setReports( reports ); + } + try { pluginManager.executeMojo( project, mojoExecution, session ); @@ -485,6 +495,91 @@ public class DefaultLifecycleExecutor } } + private List getReports( MavenProject project, MojoExecution mojoExecution, MavenSession session ) + throws ArtifactResolutionException, LifecycleExecutionException + { + List reportPlugins = project.getReportPlugins(); + + if ( project.getModel().getReports() != null ) + { + getLogger().error( + "DEPRECATED: Plugin contains a section: this is IGNORED - please use instead." ); + } + + List reports = new ArrayList(); + if ( reportPlugins != null ) + { + for ( Iterator it = reportPlugins.iterator(); it.hasNext(); ) + { + ReportPlugin reportPlugin = (ReportPlugin) it.next(); + + List reportSets = reportPlugin.getReportSets(); + + try + { + if ( reportSets == null || reportSets.isEmpty() ) + { + reports.addAll( getReports( reportPlugin, null, project, session, mojoExecution ) ); + } + else + { + for ( Iterator j = reportSets.iterator(); j.hasNext(); ) + { + ReportSet reportSet = (ReportSet) j.next(); + + reports.addAll( getReports( reportPlugin, reportSet, project, session, mojoExecution ) ); + } + } + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Error getting reports", e ); + } + catch ( PluginVersionResolutionException e ) + { + throw new LifecycleExecutionException( "Error getting reports", e ); + } + } + } + return reports; + } + + private List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session, + MojoExecution mojoExecution ) + throws PluginManagerException, PluginVersionResolutionException, ArtifactResolutionException + { + PluginDescriptor pluginDescriptor = pluginManager.verifyReportPlugin( reportPlugin, project, session ); + + List reports = new ArrayList(); + for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) + { + MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next(); + + // TODO: check ID is correct for reports + // if the POM configured no reports, give all from plugin + if ( reportSet == null || reportSet.getReports().contains( mojoDescriptor.getGoal() ) ) + { + String id = null; + if ( reportSet != null ) + { + id = reportSet.getId(); + } + + MojoExecution reportExecution = new MojoExecution( mojoDescriptor, id ); + + MavenReport reportMojo = pluginManager.getReport( project, reportExecution, session ); + + // Comes back null if it was a plugin, not a report - these are mojos in the reporting plugins that are not reports + if ( reportMojo != null ) + { + reports.add( reportMojo ); + mojoExecution.addMojoExecution( reportExecution ); + } + } + } + return reports; + } + private void forkLifecycle( MojoDescriptor mojoDescriptor, MavenSession session, MavenProject project ) throws LifecycleExecutionException, MojoExecutionException, ArtifactResolutionException { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 6723960826..847a6bbdec 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -17,7 +17,6 @@ package org.apache.maven.plugin; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; @@ -36,7 +35,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; -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; @@ -160,6 +158,13 @@ public class DefaultPluginManager plugin.setVersion( version ); } + return verifyVersionedPlugin( plugin, project, localRepository ); + } + + private PluginDescriptor verifyVersionedPlugin( Plugin plugin, MavenProject project, + ArtifactRepository localRepository ) + throws PluginVersionResolutionException, PluginManagerException, ArtifactResolutionException + { // TODO: this might result in an artifact "RELEASE" being resolved continuously // FIXME: need to find out how a plugin gets marked as 'installed' // and no ChildContainer exists. The check for that below fixes @@ -327,7 +332,7 @@ public class DefaultPluginManager dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() ); } - plugin = getConfiguredMojo( mojoDescriptor, session, dom, project, false ); + plugin = getConfiguredMojo( session, dom, project, false, mojoExecution ); } catch ( PluginConfigurationException e ) { @@ -390,69 +395,55 @@ public class DefaultPluginManager } } - public List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session ) - throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException, - ArtifactResolutionException + public MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) + throws PluginManagerException { - Plugin forLookup = new Plugin(); + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + PluginDescriptor descriptor = mojoDescriptor.getPluginDescriptor(); + Xpp3Dom dom = project.getReportConfiguration( descriptor.getGroupId(), descriptor.getArtifactId(), + mojoExecution.getExecutionId() ); + if ( mojoExecution.getConfiguration() != null ) + { + dom = Xpp3Dom.mergeXpp3Dom( dom, mojoExecution.getConfiguration() ); + } - String groupId = reportPlugin.getGroupId(); - String artifactId = reportPlugin.getArtifactId(); - - forLookup.setGroupId( groupId ); - forLookup.setArtifactId( artifactId ); + MavenReport reportMojo; + try + { + reportMojo = (MavenReport) getConfiguredMojo( session, dom, project, true, mojoExecution ); + } + catch ( ComponentLookupException e ) + { + throw new PluginManagerException( "Error looking up report: ", e ); + } + catch ( PluginConfigurationException e ) + { + throw new PluginManagerException( "Error configuring report: ", e ); + } + return reportMojo; + } + public PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session ) + throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException + { String version = reportPlugin.getVersion(); - Artifact existingPluginArtifact = (Artifact) project.getReportArtifactMap().get( reportPlugin.getKey() ); - - if ( existingPluginArtifact == null || - !reportPlugin.getKey().equals( ArtifactUtils.versionlessKey( existingPluginArtifact ) ) || version == null ) + if ( version == null ) { - version = pluginVersionManager.resolvePluginVersion( groupId, artifactId, project, session.getSettings(), - session.getLocalRepository(), true ); + version = pluginVersionManager.resolveReportPluginVersion( reportPlugin.getGroupId(), + reportPlugin.getArtifactId(), project, + session.getSettings(), + session.getLocalRepository() ); + reportPlugin.setVersion( version ); } + Plugin forLookup = new Plugin(); + + forLookup.setGroupId( reportPlugin.getGroupId() ); + forLookup.setArtifactId( reportPlugin.getArtifactId() ); forLookup.setVersion( version ); - PluginDescriptor pluginDescriptor = verifyPlugin( forLookup, project, session - .getSettings(), session.getLocalRepository() ); - - List reports = new ArrayList(); - for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) - { - MojoDescriptor mojoDescriptor = (MojoDescriptor) i.next(); - - // TODO: check ID is correct for 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 = project.getReportConfiguration( reportPlugin.getGroupId(), - reportPlugin.getArtifactId(), executionId ); - - Mojo reportMojo = getConfiguredMojo( mojoDescriptor, session, dom, project, true ); - if ( reportMojo != null ) - { - reports.add( reportMojo ); - } - } - catch ( ComponentLookupException e ) - { - throw new PluginManagerException( "Error looking up plugin: ", e ); - } - } - } - return reports; + return verifyVersionedPlugin( forLookup, project, session.getLocalRepository() ); } private PlexusContainer getPluginContainer( PluginDescriptor pluginDescriptor ) @@ -469,10 +460,12 @@ public class DefaultPluginManager return pluginContainer; } - private Mojo getConfiguredMojo( MojoDescriptor mojoDescriptor, MavenSession session, Xpp3Dom dom, - MavenProject project, boolean report ) + private Mojo getConfiguredMojo( MavenSession session, Xpp3Dom dom, MavenProject project, boolean report, + MojoExecution mojoExecution ) throws ComponentLookupException, PluginConfigurationException, PluginManagerException { + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor ); @@ -511,7 +504,7 @@ public class DefaultPluginManager // PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration, // mojoDescriptor.getConfiguration() ); - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoDescriptor, + ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution, pathTranslator, getLogger(), project ); @@ -1019,8 +1012,8 @@ public class DefaultPluginManager configurator = (ComponentConfigurator) pluginContainer.lookup( ComponentConfigurator.ROLE ); } - configurator.configureComponent( plugin, configuration, expressionEvaluator, pluginContainer - .getContainerRealm() ); + configurator.configureComponent( plugin, configuration, expressionEvaluator, + pluginContainer.getContainerRealm() ); } catch ( ComponentConfigurationException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index 15f1a32648..e57a8113ec 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -19,6 +19,9 @@ package org.apache.maven.plugin; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.util.ArrayList; +import java.util.List; + /** * Describes a single mojo invocation. * @@ -33,6 +36,10 @@ public class MojoExecution private final Xpp3Dom configuration; + private List forkedExecutions = new ArrayList(); + + private List reports; + public MojoExecution( MojoDescriptor mojoDescriptor ) { this.mojoDescriptor = mojoDescriptor; @@ -68,4 +75,19 @@ public class MojoExecution { return configuration; } + + public void addMojoExecution( MojoExecution execution ) + { + forkedExecutions.add( execution ); + } + + public void setReports( List reports ) + { + this.reports = reports; + } + + public List getReports() + { + return reports; + } } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index d9e13b8ec5..17188378ed 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -19,16 +19,15 @@ package org.apache.maven.plugin; 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.Plugin; +import org.apache.maven.model.ReportPlugin; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.MavenReport; import org.apache.maven.settings.Settings; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.model.ReportSet; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import java.util.List; import java.util.Map; /** @@ -42,6 +41,9 @@ public interface PluginManager void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) throws MojoExecutionException, PluginManagerException, ArtifactResolutionException; + MavenReport getReport( MavenProject project, MojoExecution mojoExecution, MavenSession session ) + throws PluginManagerException; + PluginDescriptor getPluginDescriptorForPrefix( String prefix ) throws PluginManagerException; @@ -52,9 +54,8 @@ public interface PluginManager ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException; - List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session ) - throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException, - ArtifactResolutionException; + PluginDescriptor verifyReportPlugin( ReportPlugin reportPlugin, MavenProject project, MavenSession session ) + throws PluginVersionResolutionException, ArtifactResolutionException, PluginManagerException; Object getPluginComponent( Plugin plugin, String role, String roleHint ) throws ComponentLookupException, PluginManagerException; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index 0b83c10025..c56beb8d45 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -62,15 +62,15 @@ public class PluginParameterExpressionEvaluator private final Logger logger; - private final MojoDescriptor mojoDescriptor; + private final MojoExecution mojoExecution; private final MavenProject project; - public PluginParameterExpressionEvaluator( MavenSession context, MojoDescriptor mojoDescriptor, - PathTranslator pathTranslator, Logger logger, MavenProject project ) + public PluginParameterExpressionEvaluator( MavenSession context, MojoExecution mojoExecution, + PathTranslator pathTranslator, Logger logger, MavenProject project ) { this.context = context; - this.mojoDescriptor = mojoDescriptor; + this.mojoExecution = mojoExecution; this.pathTranslator = pathTranslator; this.logger = logger; this.project = project; @@ -106,18 +106,20 @@ public class PluginParameterExpressionEvaluator return expression; } + MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); if ( BANNED_EXPRESSIONS.containsKey( expression ) ) { - throw new ExpressionEvaluationException( "The parameter expression: \'" + expression - + "\' used in mojo: \'" + mojoDescriptor.getGoal() + "\' is banned. Use \'" - + BANNED_EXPRESSIONS.get( expression ) + "\' instead." ); + throw new ExpressionEvaluationException( "The parameter expression: \'" + expression + + "\' used in mojo: \'" + mojoDescriptor.getGoal() + "\' is banned. Use \'" + + BANNED_EXPRESSIONS.get( expression ) + "\' instead." ); } else if ( DEPRECATED_EXPRESSIONS.containsKey( expression ) ) { - logger.warn( "The parameter expression: \'" + expression + "\' used in mojo: \'" + mojoDescriptor.getGoal() - + "\' has been deprecated. Use \'" + DEPRECATED_EXPRESSIONS.get( expression ) + "\' instead." ); + logger.warn( "The parameter expression: \'" + expression + "\' used in mojo: \'" + + mojoDescriptor.getGoal() + "\' has been deprecated. Use \'" + DEPRECATED_EXPRESSIONS.get( expression ) + + "\' instead." ); } - + if ( "localRepository".equals( expression ) ) { value = context.getLocalRepository(); @@ -130,6 +132,10 @@ public class PluginParameterExpressionEvaluator { value = context.getSortedProjects(); } + else if ( "reports".equals( expression ) ) + { + value = mojoExecution.getReports(); + } else if ( "project".equals( expression ) ) { value = project; @@ -233,7 +239,7 @@ public class PluginParameterExpressionEvaluator logger.error( "Got expression '" + expression + "' that was not recognised" ); } } - + if ( value == null ) { // Check properties that have been injected via profiles before we default over to diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index b2f5e512fe..d50ebc3dec 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -80,8 +80,15 @@ public class DefaultPluginVersionManager return resolvePluginVersion( groupId, artifactId, project, settings, localRepository, false ); } - public String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, - ArtifactRepository localRepository, boolean resolveAsReportPlugin ) + public String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, + Settings settings, ArtifactRepository localRepository ) + throws PluginVersionResolutionException + { + return resolvePluginVersion( groupId, artifactId, project, settings, localRepository, true ); + } + + private String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, + ArtifactRepository localRepository, boolean resolveAsReportPlugin ) throws PluginVersionResolutionException { // first pass...if the plugin is specified in the pom, try to retrieve the version from there. diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java index 3d5d8f4274..a2a05802be 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/PluginVersionManager.java @@ -1,9 +1,5 @@ package org.apache.maven.plugin.version; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.MavenProject; -import org.apache.maven.settings.Settings; - /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -20,15 +16,20 @@ import org.apache.maven.settings.Settings; * limitations under the License. */ +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Settings; + public interface PluginVersionManager { - String ROLE = PluginVersionManager.class.getName(); - String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository ) + String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, + ArtifactRepository localRepository ) throws PluginVersionResolutionException; - String resolvePluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, ArtifactRepository localRepository, boolean resolveAsReportPlugin ) + String resolveReportPluginVersion( String groupId, String artifactId, MavenProject project, Settings settings, + ArtifactRepository localRepository ) throws PluginVersionResolutionException; } diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 88b7af8a17..6f13f7f597 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -69,8 +69,8 @@ public class PluginParameterExpressionEvaluatorTest assertEquals( expected, actual ); } - private static MavenSession createSession( PlexusContainer container, - ArtifactRepository repo ) throws CycleDetectedException + private static MavenSession createSession( PlexusContainer container, ArtifactRepository repo ) + throws CycleDetectedException { return new MavenSession( container, new Settings(), repo, new DefaultEventDispatcher(), new ReactorManager( Collections.EMPTY_LIST ), Collections.EMPTY_LIST, "." ); @@ -141,12 +141,14 @@ public class PluginParameterExpressionEvaluatorTest PlexusContainer container = getContainer(); MavenSession session = createSession( container, repo ); - + MojoDescriptor mojo = new MojoDescriptor(); mojo.setPluginDescriptor( pluginDescriptor ); mojo.setGoal( "goal" ); - return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, mojo, null, + MojoExecution mojoExecution = new MojoExecution( mojo ); + + return (ExpressionEvaluator) new PluginParameterExpressionEvaluator( session, mojoExecution, null, container.getLogger(), project ); } @@ -159,4 +161,4 @@ public class PluginParameterExpressionEvaluatorTest return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" ); } -} \ No newline at end of file +} diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java index 3a6cc79ef1..28452d70f3 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -61,7 +61,7 @@ public class MojoDescriptor private String executeLifecycle; private String deprecated; - + private boolean aggregator = false; // ---------------------------------------------------------------------- @@ -79,9 +79,11 @@ public class MojoDescriptor private PluginDescriptor pluginDescriptor; private boolean inheritedByDefault = true; - + private boolean directInvocationOnly = false; + private boolean requiresReports = false; + public MojoDescriptor() { setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY ); @@ -132,9 +134,9 @@ public class MojoDescriptor { if ( parameters != null && parameters.contains( parameter ) ) { - throw new DuplicateParameterException( parameter.getName() - + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " - + getImplementation() + ")" ); + throw new DuplicateParameterException( parameter.getName() + + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: " + + getImplementation() + ")" ); } else { @@ -393,12 +395,12 @@ public class MojoDescriptor { this.executeLifecycle = executeLifecycle; } - + public void setAggregator( boolean aggregator ) { this.aggregator = aggregator; } - + public boolean isAggregator() { return aggregator; @@ -413,4 +415,14 @@ public class MojoDescriptor { this.directInvocationOnly = directInvocationOnly; } + + public boolean isRequiresReports() + { + return requiresReports; + } + + public void setRequiresReports( boolean requiresReports ) + { + this.requiresReports = requiresReports; + } } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index da4de31d45..6b50706641 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -37,10 +37,10 @@ public class PluginDescriptorBuilder pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() ); pluginDescriptor.setVersion( c.getChild( "version" ).getValue() ); pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).getValue() ); - + String isolatedRealm = c.getChild( "isolatedRealm" ).getValue(); - - if( isolatedRealm != null ) + + if ( isolatedRealm != null ) { pluginDescriptor.setIsolatedRealm( Boolean.valueOf( isolatedRealm ).booleanValue() ); } @@ -63,7 +63,7 @@ public class PluginDescriptorBuilder PlexusConfiguration component = mojoConfigurations[i]; MojoDescriptor mojoDescriptor = buildComponentDescriptor( component, pluginDescriptor ); - + pluginDescriptor.addMojo( mojoDescriptor ); } @@ -174,6 +174,13 @@ public class PluginDescriptorBuilder mojo.setProjectRequired( Boolean.valueOf( requiresProject ).booleanValue() ); } + String requiresReports = c.getChild( "requiresReports" ).getValue(); + + if ( requiresReports != null ) + { + mojo.setRequiresReports( Boolean.valueOf( requiresReports ).booleanValue() ); + } + String aggregator = c.getChild( "aggregator" ).getValue(); if ( aggregator != null ) @@ -194,7 +201,7 @@ public class PluginDescriptorBuilder { mojo.setInheritedByDefault( Boolean.valueOf( inheritedByDefault ).booleanValue() ); } - + // ---------------------------------------------------------------------- // Parameters // ---------------------------------------------------------------------- diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index c40e269e76..b371efed3c 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -139,6 +139,12 @@ public class PluginDescriptorGenerator // // ---------------------------------------------------------------------- + element( w, "requiresReports", "" + mojoDescriptor.isRequiresReports() ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + element( w, "aggregator", "" + mojoDescriptor.isAggregator() ); // ---------------------------------------------------------------------- diff --git a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh index 5ba496efd5..37a6250f71 100644 --- a/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh +++ b/maven-plugin-tools/maven-plugin-tools-beanshell/src/main/resources/extractor.bsh @@ -140,6 +140,10 @@ extract( file, mojoDescriptor ) this.parameter = createParameter( text, method ); if ( parameter != null ) { + if ( "${reports}".equals( parameter.getExpression() ) ) + { + mojoDescriptor.setRequiresReports( true ); + } mojoDescriptor.addParameter( parameter ); } diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index b940dbad9d..9a72d08a1a 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -29,8 +29,8 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.Requirement; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; -import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.util.ArrayList; @@ -68,8 +68,7 @@ public class JavaMojoDescriptorExtractor * Would say there is a getProject() method and a setProject(Project) method. Here the field * name would not be the basis for the parameter's name. This mode of operation will allow the * mojos to be usable as beans and will be the promoted form of use. - * - **/ + */ public static final String PARAMETER_PROPERTY = "property"; public static final String REQUIRED = "required"; @@ -90,6 +89,8 @@ public class JavaMojoDescriptorExtractor public static final String GOAL_REQUIRES_PROJECT = "requiresProject"; + public static final String GOAL_REQUIRES_REPORTS = "requiresReports"; + public static final String GOAL_IS_AGGREGATOR = "aggregator"; public static final String GOAL_REQUIRES_ONLINE = "requiresOnline"; @@ -414,6 +415,11 @@ public class JavaMojoDescriptorExtractor pd.setExpression( parameter.getNamedParameter( PARAMETER_EXPRESSION ) ); + if ( "${reports}".equals( pd.getExpression() ) ) + { + mojoDescriptor.setRequiresReports( true ); + } + pd.setDefaultValue( parameter.getNamedParameter( PARAMETER_DEFAULT_VALUE ) ); } diff --git a/maven-plugins/maven-plugin-plugin/pom.xml b/maven-plugins/maven-plugin-plugin/pom.xml index 56699d6314..ab4f5f6e52 100644 --- a/maven-plugins/maven-plugin-plugin/pom.xml +++ b/maven-plugins/maven-plugin-plugin/pom.xml @@ -11,52 +11,32 @@ 2.0-beta-2-SNAPSHOT 2001 - - org.apache.maven - maven-repository-metadata - 2.0-beta-1 - org.apache.maven maven-project - - org.apache.maven - maven-core - 2.0-beta-1 - org.apache.maven maven-plugin-tools-api - 2.0-beta-1 + 2.0-beta-2-SNAPSHOT org.apache.maven maven-plugin-tools-java - 2.0-beta-1 + 2.0-beta-2-SNAPSHOT runtime - - org.apache.maven - maven-artifact-manager - 2.0-beta-1 - org.apache.maven maven-plugin-tools-beanshell - 2.0-beta-1 + 2.0-beta-2-SNAPSHOT runtime - - org.apache.maven - maven-artifact - 2.0-beta-1 - org.apache.maven maven-plugin-tools-marmalade - 2.0-beta-1 + 2.0-beta-2-SNAPSHOT runtime - \ No newline at end of file + diff --git a/maven-plugins/maven-site-plugin/pom.xml b/maven-plugins/maven-site-plugin/pom.xml index 3c2d26e452..9fc5148903 100644 --- a/maven-plugins/maven-site-plugin/pom.xml +++ b/maven-plugins/maven-site-plugin/pom.xml @@ -9,6 +9,9 @@ maven-plugin Maven Site plugin 2.0-beta-2-SNAPSHOT + + 2.0-beta-2-SNAPSHOT + vsiveton @@ -22,21 +25,11 @@ - - org.apache.maven - maven-settings - 2.0-beta-1 - plexus plexus-site-renderer 1.0-alpha-2 - - org.apache.maven - maven-core - 2.0-beta-1 - plexus plexus-utils @@ -46,6 +39,11 @@ maven-reporting-api 2.0-beta-1 + + org.apache.maven + maven-project + 2.0-beta-1 + org.apache.maven.wagon wagon-ssh diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java index e3b5eadb15..c4052d6db4 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -16,16 +16,8 @@ package org.apache.maven.doxia; * limitations under the License. */ -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.ReportPlugin; -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; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReportException; @@ -106,19 +98,19 @@ public class DoxiaMojo * @parameter expression="${basedir}/src/site" * @required */ - private String siteDirectory; + private File siteDirectory; /** * @parameter alias="workingDirectory" expression="${project.build.directory}/generated-site" * @required */ - private String generatedSiteDirectory; + private File generatedSiteDirectory; /** * @parameter expression="${project.build.directory}/site" * @required */ - private String outputDirectory; + private File outputDirectory; /** * @parameter expression="${basedir}/src/site/resources" @@ -127,17 +119,17 @@ public class DoxiaMojo private File resourcesDirectory; /** - * @parameter expression="${templateDirectory} + * @parameter expression="${templateDirectory}" */ private String templateDirectory; /** - * @parameter expression="${template} + * @parameter expression="${template}" */ private String template = DEFAULT_TEMPLATE; /** - * @parameter expression="${attributes} + * @parameter expression="${attributes}" */ private Map attributes; @@ -145,7 +137,7 @@ public class DoxiaMojo * A comma separated list of locales supported by Maven. The first valid token will be the default Locale * for this instance of the Java Virtual Machine. * - * @parameter expression="${locales} + * @parameter expression="${locales}" */ private String locales; @@ -183,18 +175,11 @@ public class DoxiaMojo private MavenProject project; /** - * @parameter expression="${component.org.apache.maven.plugin.PluginManager}" + * @parameter expression="${reports}" * @required * @readonly */ - private PluginManager pluginManager; - - /** - * @parameter expression="${session}" - * @required - * @readonly - */ - private MavenSession session; + private List reports; /** * @see org.apache.maven.plugin.Mojo#execute() @@ -239,6 +224,21 @@ public class DoxiaMojo attributes.put( "outputEncoding", outputEncoding ); } + Map categories = categorizeReports( reports ); + + List projectInfos = (List) categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION ); + List projectReports = (List) categories.get( MavenReport.CATEGORY_PROJECT_REPORTS ); + + if ( projectInfos == null ) + { + projectInfos = Collections.EMPTY_LIST; + } + + if ( projectReports == null ) + { + projectReports = Collections.EMPTY_LIST; + } + try { List localesList = initLocalesList(); @@ -264,7 +264,7 @@ public class DoxiaMojo } // Generate static site - File siteDirectoryFile = new File( siteDirectory ); + File siteDirectoryFile = siteDirectory; if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) ) { siteDirectoryFile = new File( siteDirectory, locale.getLanguage() ); @@ -278,11 +278,9 @@ public class DoxiaMojo } // Handle the GeneratedSite Directory - File generatedSiteFile = new File( generatedSiteDirectory ); - - if ( generatedSiteFile.exists() ) + if ( generatedSiteDirectory.exists() ) { - tryToFindDuplicates( generatedSiteFile, duplicate ); + tryToFindDuplicates( generatedSiteDirectory, duplicate ); } // Exception if a file is duplicate @@ -292,28 +290,11 @@ public class DoxiaMojo throw new MavenReportException( msg ); } - List reports = getReports(); - - Map categories = categorizeReports( reports ); - - List projectInfos = (List) categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION ); - List projectReports = (List) categories.get( MavenReport.CATEGORY_PROJECT_REPORTS ); - - if ( projectInfos == null ) - { - projectInfos = Collections.EMPTY_LIST; - } - - if ( projectReports == null ) - { - projectReports = Collections.EMPTY_LIST; - } - String siteDescriptor = getSiteDescriptor( reports, locale, projectInfos, projectReports ); - if ( generatedSiteFile.exists() ) + if ( generatedSiteDirectory.exists() ) { - siteRenderer.render( generatedSiteFile, outputDirectory, siteDescriptor, template, attributes, + siteRenderer.render( generatedSiteDirectory, outputDirectory, siteDescriptor, template, attributes, locale ); } @@ -437,6 +418,7 @@ public class DoxiaMojo MavenReport report = (MavenReport) i.next(); List category = (List) categories.get( report.getCategoryName() ); + if ( category == null ) { category = new ArrayList(); @@ -699,7 +681,7 @@ public class DoxiaMojo { String outputFileName = "index.html"; - SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName, siteDescriptor ); + SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName, siteDescriptor ); String title = i18n.getString( "site-plugin", locale, "report.index.title" ).trim() + " " + project.getName(); @@ -775,8 +757,7 @@ public class DoxiaMojo String outputFileName = reportFileName + ".html"; - SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName, - siteDescriptor ); + SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName, siteDescriptor ); report.generate( sink, locale ); @@ -803,7 +784,7 @@ public class DoxiaMojo { String outputFileName = "project-info.html"; - SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName, siteDescriptor ); + SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName, siteDescriptor ); String title = i18n.getString( "site-plugin", locale, "report.information.title" ); @@ -884,7 +865,7 @@ public class DoxiaMojo { String outputFileName = "maven-reports.html"; - SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName, siteDescriptor ); + SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName, siteDescriptor ); String title = i18n.getString( "site-plugin", locale, "report.project.title" ); @@ -1037,76 +1018,12 @@ public class DoxiaMojo { if ( locale.getLanguage().equals( defaultLocale.getLanguage() ) ) { - return new File( outputDirectory ); + return outputDirectory; } return new File( outputDirectory, locale.getLanguage() ); } - private List getReports() - throws MojoExecutionException - { - // TODO: not the best solution. Perhaps a mojo tag that causes the plugin manager to populate project reports instead? - - List reportPlugins = project.getReportPlugins(); - - if ( project.getModel().getReports() != null ) - { - getLog().error( - "DEPRECATED: Plugin contains a section: this is IGNORED - please use instead." ); - } - - List reports = new ArrayList(); - if ( reportPlugins != null ) - { - for ( Iterator it = reportPlugins.iterator(); it.hasNext(); ) - { - ReportPlugin reportPlugin = (ReportPlugin) it.next(); - - try - { - List reportSets = reportPlugin.getReportSets(); - - List reportsList = new ArrayList(); - - if ( reportSets == null || reportSets.isEmpty() ) - { - reportsList = pluginManager.getReports( reportPlugin, null, project, session ); - - } - else - { - for ( Iterator j = reportSets.iterator(); j.hasNext(); ) - { - ReportSet reportSet = (ReportSet) j.next(); - - reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session ); - } - } - - reports.addAll( reportsList ); - } - 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 ); - } - catch ( ArtifactResolutionException e ) - { - throw new MojoExecutionException( "Cannot find report plugin", e ); - } - } - } - return reports; - } - /** * Convenience method that try to find duplicate files in sub-directories of a given directory. *

The scan is case sensitive.

diff --git a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/MetadataTag.java b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/MetadataTag.java index 910a60f34c..e4a56d71f6 100644 --- a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/MetadataTag.java +++ b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/MetadataTag.java @@ -63,6 +63,8 @@ public class MetadataTag private String lifecyclePhase; + private boolean requiresReports; + protected boolean alwaysProcessChildren() { return false; @@ -132,7 +134,8 @@ public class MetadataTag { throw new TagExecutionException( getTagInfo(), "One or more mojo parameters is invalid.", e ); } - + + descriptor.setRequiresReports( requiresReports ); descriptor.setDependencyResolutionRequired( requiresDependencyResolution ); descriptor.setProjectRequired( requiresProject ); descriptor.setAggregator( aggregator ); @@ -201,12 +204,12 @@ public class MetadataTag public void setAggregator( boolean aggregator ) { - this.aggregator = aggregator; + this.aggregator = aggregator; } public void setInheritByDefault( boolean inheritByDefault ) { - this.inheritByDefault = inheritByDefault; + this.inheritByDefault = inheritByDefault; } public void setRequiresOnline( boolean requiresOnline ) @@ -229,4 +232,8 @@ public class MetadataTag this.lifecyclePhase = lifecyclePhase; } + public void setRequiresReports( boolean requiresReports ) + { + this.requiresReports = requiresReports; + } } \ No newline at end of file diff --git a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/ParametersTag.java b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/ParametersTag.java index a55d4e2c58..6cda05bdb8 100644 --- a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/ParametersTag.java +++ b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/ParametersTag.java @@ -30,19 +30,26 @@ import java.util.List; public class ParametersTag extends AbstractMarmaladeTag { + private boolean requiresReports = false; private List parameters = new ArrayList(); - protected void doExecute( MarmaladeExecutionContext context ) throws MarmaladeExecutionException + protected void doExecute( MarmaladeExecutionContext context ) + throws MarmaladeExecutionException { processChildren( context ); MetadataTag metadataTag = (MetadataTag) requireParent( MetadataTag.class ); metadataTag.setParameters( parameters ); + metadataTag.setRequiresReports( requiresReports ); } public void addParameter( Parameter parameter ) { + if ( "${reports}".equals( parameter.getExpression() ) ) + { + requiresReports = true; + } this.parameters.add( parameter ); }