You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by sn...@apache.org on 2005/09/24 17:22:45 UTC

svn commit: r291309 - in /maven/components/trunk/maven-plugins/maven-plugin-plugin: ./ src/main/java/org/apache/maven/plugin/plugin/ src/main/resources/

Author: snicoll
Date: Sat Sep 24 08:22:36 2005
New Revision: 291309

URL: http://svn.apache.org/viewcvs?rev=291309&view=rev
Log:
MNG-706: Implemented plugin:xdoc as a report

Added:
    maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
    maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/
    maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties
    maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties
Modified:
    maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml

Modified: maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml?rev=291309&r1=291308&r2=291309&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml (original)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/pom.xml Sat Sep 24 08:22:36 2005
@@ -21,6 +21,11 @@
       <version>2.0-beta-2-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.reporting</groupId>
+      <artifactId>maven-reporting-impl</artifactId>
+      <version>2.0-beta-1</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-tools-java</artifactId>
       <version>2.0-beta-2-SNAPSHOT</version>

Added: maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java?rev=291309&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java (added)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java Sat Sep 24 08:22:36 2005
@@ -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 <a href="snicoll@apache.org">Stephane Nicoll</a>
+ * @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

Added: maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties?rev=291309&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties (added)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_en.properties Sat Sep 24 08:22:36 2005
@@ -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

Added: maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties?rev=291309&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties (added)
+++ maven/components/trunk/maven-plugins/maven-plugin-plugin/src/main/resources/plugin-report_fr.properties Sat Sep 24 08:22:36 2005
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org