diff --git a/maven-plugins/maven-plugin-plugin/pom.xml b/maven-plugins/maven-plugin-plugin/pom.xml index ab4f5f6e52..9c01677c07 100644 --- a/maven-plugins/maven-plugin-plugin/pom.xml +++ b/maven-plugins/maven-plugin-plugin/pom.xml @@ -20,6 +20,11 @@ maven-plugin-tools-api 2.0-beta-2-SNAPSHOT + + org.apache.maven.reporting + maven-reporting-impl + 2.0-beta-1 + org.apache.maven maven-plugin-tools-java diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java new file mode 100644 index 0000000000..a593915603 --- /dev/null +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java @@ -0,0 +1,235 @@ +package org.apache.maven.plugin.plugin; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; +import org.apache.maven.reporting.AbstractMavenReport; +import org.apache.maven.reporting.AbstractMavenReportRenderer; +import org.apache.maven.reporting.MavenReportException; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.generator.Generator; +import org.apache.maven.tools.plugin.generator.PluginXdocGenerator; +import org.apache.maven.tools.plugin.scanner.MojoScanner; +import org.apache.maven.tools.plugin.util.PluginUtils; +import org.codehaus.doxia.sink.Sink; +import org.codehaus.doxia.site.renderer.SiteRenderer; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Generates the Plugin's documentation report. + * + * @author Stephane Nicoll + * @version $Id: EarMojo.java 267433 2005-09-03 07:34:07Z brett $ + * @goal report + */ +public class PluginReport + extends AbstractMavenReport +{ + /** + * @parameter expression="${project.build.directory}/generated-site/xdoc" + * @required + */ + private String outputDirectory; + + /** + * @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}" + * @required + * @readonly + */ + private SiteRenderer siteRenderer; + + /** + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * @parameter expression="${component.org.apache.maven.tools.plugin.scanner.MojoScanner}" + * @required + */ + protected MojoScanner mojoScanner; + + protected SiteRenderer getSiteRenderer() + { + return siteRenderer; + } + + protected String getOutputDirectory() + { + return outputDirectory; + } + + protected MavenProject getProject() + { + return project; + } + + protected void executeReport( Locale locale ) + throws MavenReportException + { + if ( !project.getPackaging().equals( "maven-plugin" ) ) + { + return; + } + + String goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); + + // TODO: could use this more, eg in the writing of the plugin descriptor! + PluginDescriptor pluginDescriptor = new PluginDescriptor(); + + pluginDescriptor.setGroupId( project.getGroupId() ); + + pluginDescriptor.setArtifactId( project.getArtifactId() ); + + pluginDescriptor.setVersion( project.getVersion() ); + + pluginDescriptor.setGoalPrefix( goalPrefix ); + + try + { + pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); + + mojoScanner.populatePluginDescriptor( project, pluginDescriptor ); + + // Generate the plugin's documentation + generatePluginDocumentation( pluginDescriptor ); + + // Write the overview + PluginOverviewRenderer r = new PluginOverviewRenderer( getSink(), pluginDescriptor, locale ); + r.render(); + } + catch ( InvalidPluginDescriptorException e ) + { + throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + catch ( ExtractionException e ) + { + throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", + e ); + } + } + + public String getDescription( Locale locale ) + { + return getBundle( locale ).getString( "report.plugin.description" ); + } + + public String getName( Locale locale ) + { + return getBundle( locale ).getString( "report.plugin.name" ); + } + + public String getOutputName() + { + return "plugin-info"; + } + + private void generatePluginDocumentation( PluginDescriptor pluginDescriptor ) + throws MavenReportException + { + try + { + File outputDir = new File( getOutputDirectory() ); + outputDir.mkdirs(); + + Generator generator = new PluginXdocGenerator(); + generator.execute( outputDir, pluginDescriptor ); + } + catch ( IOException e ) + { + throw new MavenReportException( "Error writing plugin documentation", e ); + } + + } + + private static ResourceBundle getBundle( Locale locale ) + { + return ResourceBundle.getBundle( "plugin-report", locale, PluginReport.class.getClassLoader() ); + } + + /** + * Generates an overview page with the list of goals + * and a link to the goal's page. + */ + static class PluginOverviewRenderer + extends AbstractMavenReportRenderer + { + private final PluginDescriptor pluginDescriptor; + + private final Locale locale; + + public PluginOverviewRenderer( Sink sink, PluginDescriptor pluginDescriptor, Locale locale ) + { + super( sink ); + + this.pluginDescriptor = pluginDescriptor; + + this.locale = locale; + } + + public String getTitle() + { + return getBundle( locale ).getString( "report.plugin.title" ); + } + + public void renderBody() + { + startSection( getTitle() ); + + paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) ); + + startTable(); + + String goalColumnName = getBundle( locale ).getString( "report.plugin.goals.column.goal" ); + String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" ); + + tableHeader( new String[]{goalColumnName, descriptionColumnName} ); + + for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) + { + MojoDescriptor mojo = (MojoDescriptor) i.next(); + + String goalName = mojo.getFullGoalName(); + String goalDocumentationLink = mojo.getGoal() + "-mojo.html"; + String description = mojo.getDescription(); + if ( StringUtils.isEmpty( mojo.getDescription() ) ) + { + description = getBundle( locale ).getString( "report.plugin.goal.nodescription" ); + + } + + tableRow( new String[]{createLinkPatternedText( goalName, goalDocumentationLink ), description} ); + } + + endTable(); + + endSection(); + } + } +} \ No newline at end of file diff --git a/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties b/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties new file mode 100644 index 0000000000..d7c7d75390 --- /dev/null +++ b/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties @@ -0,0 +1,8 @@ +report.plugin.name=Plugin documentation +report.plugin.description=This report provides goals and parameters documentation of a plugin +report.plugin.title=Plugin documentation + +report.plugin.goals.intro=Goals available: +report.plugin.goals.column.goal=Goal +report.plugin.goals.column.description=Description +report.plugin.goal.nodescription=No description \ No newline at end of file diff --git a/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties b/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties new file mode 100644 index 0000000000..a791b24202 --- /dev/null +++ b/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties @@ -0,0 +1,8 @@ +report.plugin.name=Documentation du plugin +report.plugin.description=Ce rapport fournit de la documenations sur les goals et les paramètres d'un plugin +report.plugin.title=Documentation du plugin + +report.plugin.goals.intro=Goals disponibles : +report.plugin.goals.column.goal=Goal +report.plugin.goals.column.description=Description +report.plugin.goal.nodescription=Pas de description \ No newline at end of file