You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2010/02/08 22:35:43 UTC

svn commit: r907809 - in /maven/plugins/trunk/maven-project-info-reports-plugin/src: main/java/org/apache/maven/report/projectinfo/ main/resources/ test/java/org/apache/maven/report/projectinfo/ test/java/org/apache/maven/report/projectinfo/stubs/ test...

Author: olamy
Date: Mon Feb  8 21:35:43 2010
New Revision: 907809

URL: http://svn.apache.org/viewvc?rev=907809&view=rev
Log:
[MPIR-170] Create a module overview page ala m1
Patch submitted by Lukas Theussl

Added:
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java   (with props)
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java   (with props)
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java   (with props)
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml   (with props)
Modified:
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_de.properties
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_es.properties
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml

Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java?rev=907809&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java Mon Feb  8 21:35:43 2010
@@ -0,0 +1,209 @@
+package org.apache.maven.report.projectinfo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.reporting.AbstractMavenReportRenderer;
+
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+/**
+ * Generates the Project Modules report.
+ *
+ * @author ltheussl
+ * @version $Id$
+ * @since 2.2
+ * @goal modules
+ */
+public class ModulesReport
+    extends AbstractProjectInfoReport
+{
+    // ----------------------------------------------------------------------
+    // Public methods
+    // ----------------------------------------------------------------------
+
+    /** {@inheritDoc} */
+    public String getName( Locale locale )
+    {
+        return i18n.getString( "project-info-report", locale, "report.modules.name" );
+    }
+
+    /** {@inheritDoc} */
+    public String getDescription( Locale locale )
+    {
+        return i18n.getString( "project-info-report", locale, "report.modules.description" );
+    }
+
+    /** {@inheritDoc} */
+    public void executeReport( Locale locale )
+    {
+        new ModulesRenderer( getSink(), getProject().getModel(), i18n, locale ).render();
+    }
+
+    /** {@inheritDoc} */
+    public String getOutputName()
+    {
+        return "modules";
+    }
+
+    /** {@inheritDoc} */
+    public boolean canGenerateReport()
+    {
+        return ( getProject().getModel().getModules() != null && !getProject().getModel().getModules().isEmpty() );
+    }
+
+    // ----------------------------------------------------------------------
+    // Private
+    // ----------------------------------------------------------------------
+
+    /**
+     * Internal renderer class
+     */
+    private class ModulesRenderer
+        extends AbstractMavenReportRenderer
+    {
+        private Model model;
+
+        private I18N i18n;
+
+        private Locale locale;
+
+        ModulesRenderer( Sink sink, Model model, I18N i18n, Locale locale )
+        {
+            super( sink );
+
+            this.model = model;
+
+            this.i18n = i18n;
+
+            this.locale = locale;
+        }
+
+        /** {@inheritDoc} */
+        public String getTitle()
+        {
+            return i18n.getString( "project-info-report", locale, "report.modules.title" );
+        }
+
+        /** {@inheritDoc} */
+        public void renderBody()
+        {
+            List modules = model.getModules();
+
+            startSection( getTitle() );
+
+            paragraph( i18n.getString( "project-info-report", locale, "report.modules.intro" ) );
+
+            startTable();
+
+            String name = i18n.getString( "project-info-report", locale, "report.modules.header.name" );
+            String description = i18n.getString( "project-info-report", locale, "report.modules.header.description" );
+            tableHeader( new String[] {name, description} );
+
+            for ( Iterator it = modules.iterator(); it.hasNext(); )
+            {
+                String module = (String) it.next();
+
+                Model moduleModel;
+                File f = new File( project.getBasedir(), module + "/pom.xml" );
+
+                if ( f.exists() )
+                {
+                    moduleModel = readModel( f );
+
+                    if ( moduleModel == null )
+                    {
+                        getLog().warn( "Unable to read filesystem POM for module " + module );
+
+                        moduleModel = new Model();
+                        moduleModel.setName( module );
+                    }
+                }
+                else
+                {
+                    getLog().warn( "No filesystem POM found for module " + module );
+
+                    moduleModel = new Model();
+                    moduleModel.setName( module );
+                }
+
+                tableRow( new String[] {linkedName( moduleModel.getName(), module ), moduleModel.getDescription()} );
+            }
+
+            endTable();
+
+            endSection();
+        }
+    }
+
+    private String linkedName( String name, String link )
+    {
+        return "{" + name + ", ./" + link + "/}";
+    }
+
+    /**
+     * Gets the pom model for this file.
+     *
+     * @param pom the pom
+     *
+     * @return the model
+     */
+    private Model readModel ( File pom )
+    {
+        MavenXpp3Reader xpp3 = new MavenXpp3Reader();
+        Model model = null;
+        Reader reader = null;
+
+        try
+        {
+            reader = ReaderFactory.newXmlReader( pom );
+            model = xpp3.read( reader );
+        }
+        catch ( IOException io )
+        {
+            getLog().debug( io );
+            return null;
+        }
+        catch ( XmlPullParserException xe )
+        {
+            getLog().debug( xe );
+            return null;
+        }
+        finally
+        {
+            IOUtil.close( reader );
+            reader = null;
+        }
+
+        return model;
+    }
+}

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties?rev=907809&r1=907808&r2=907809&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report.properties Mon Feb  8 21:35:43 2010
@@ -247,3 +247,9 @@
 report.plugins.report.title                                        = Project Report Plugins
 report.plugins.nolist                                              = There are no plugins defined in the Build part of this project.
 report.plugins.report.nolist                                       = There are no plugins reports defined in the Reporting part of this project.
+report.modules.name                                                = Project Modules
+report.modules.description                                         = This document lists the modules (sub-projects) of this project.
+report.modules.title                                               = Project Modules
+report.modules.intro                                               = This project has declared the following modules:
+report.modules.header.name                                         = Name
+report.modules.header.description                                  = Description
\ No newline at end of file

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_de.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_de.properties?rev=907809&r1=907808&r2=907809&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_de.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_de.properties Mon Feb  8 21:35:43 2010
@@ -247,3 +247,9 @@
 report.plugins.report.title                                        = Report-Plugins
 report.plugins.nolist                                              = F\u00fcr dieses Projekt sind keine Build-Plugins definiert.
 report.plugins.report.nolist                                       = F\u00fcr dieses Projekt sind keine Report-Plugins definiert.
+report.modules.name                                                = Projekt Module
+report.modules.description                                         = Informationen \u00fcber die Module (Unter-Projekte) dieses Projektes.
+report.modules.title                                               = Projekt Module
+report.modules.intro                                               = F\u00fcr dieses Projekt sind die folgenden Module definiert:
+report.modules.header.name                                         = Name
+report.modules.header.description                                  = Beschreibung

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_es.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_es.properties?rev=907809&r1=907808&r2=907809&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_es.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_es.properties Mon Feb  8 21:35:43 2010
@@ -247,4 +247,9 @@
 report.plugins.report.title                                        = Plugins para la Generaci\u00f3n de Informes del Proyecto
 report.plugins.nolist                                              = No hay plugins definidos en la secci\u00f3n Build de este proyecto.
 report.plugins.report.nolist                                       = No hay plugins de informes definidos en la secci\u00f3n Reporting de este proyecto.
-
+report.modules.name                                                = Subm\u00f3dulos
+report.modules.description                                         = Esta es una lista de las subm\u00f3dulos del proyecto.
+report.modules.title                                               = Subm\u00f3dulos
+report.modules.intro                                               = Subm\u00f3dulos del proyecto:
+report.modules.header.name                                         = Nombre
+report.modules.header.description                                  = Description
\ No newline at end of file

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties?rev=907809&r1=907808&r2=907809&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/resources/project-info-report_fr.properties Mon Feb  8 21:35:43 2010
@@ -246,4 +246,10 @@
 report.plugins.title                                               = Plugins du projet de type build
 report.plugins.report.title                                        = Plugins du projet de type rapport
 report.plugins.nolist                                              = Il n'y a aucun plugin de type build d\u00e9fini dans la partie Build du projet.
-report.plugins.report.nolist                                       = Il n'y a aucun plugin de type rapport d\u00e9fini dans la partie Reporting du projet.
\ No newline at end of file
+report.plugins.report.nolist                                       = Il n'y a aucun plugin de type rapport d\u00e9fini dans la partie Reporting du projet.
+report.modules.name                                                = Modules du projet
+report.modules.description                                         = Ce document liste les modules (sous-projets) de ce projet.
+report.modules.title                                               = Modules du projet
+report.modules.intro                                               = Ce sont les modules qui ont \u00e9t\u00e9 declar\u00e9 pour ce projet:
+report.modules.header.name                                         = Nom
+report.modules.header.description                                  = Description
\ No newline at end of file

Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java?rev=907809&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java Mon Feb  8 21:35:43 2010
@@ -0,0 +1,84 @@
+package org.apache.maven.report.projectinfo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 java.net.URL;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.TextBlock;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+/**
+ * @author ltheussl
+ * @version $Id$
+ */
+public class ModulesReportTest
+    extends AbstractProjectInfoTestCase
+{
+    /**
+     * WebConversation object
+     */
+    private static final WebConversation WEB_CONVERSATION = new WebConversation();
+
+    /**
+     * Test report
+     *
+     * @throws Exception if any
+     */
+    public void testReport()
+        throws Exception
+    {
+        generateReport( "modules", "modules-plugin-config.xml" );
+        assertTrue( "Test html generated", getGeneratedReport( "modules.html" ).exists() );
+
+        URL reportURL = getGeneratedReport( "modules.html" ).toURI().toURL();
+        assertNotNull( reportURL );
+
+        // HTTPUnit
+        WebRequest request = new GetMethodWebRequest( reportURL.toString() );
+        WebResponse response = WEB_CONVERSATION.getResponse( request );
+
+        // Basic HTML tests
+        assertTrue( response.isHTML() );
+        assertTrue( response.getContentLength() > 0 );
+
+        // Test the Page title
+        assertEquals( getString( "report.modules.name" ) + " - " + getString( "report.modules.title" ),
+                      response.getTitle() );
+
+        // Test the texts
+        TextBlock[] textBlocks = response.getTextBlocks();
+        assertEquals( 2, textBlocks.length );
+        assertEquals( getString( "report.modules.title" ), textBlocks[0].getText() );
+        assertEquals( getString( "report.modules.intro" ), textBlocks[1].getText() );
+
+        String[][] cellTexts = response.getTables()[0].asText();
+        assertEquals( 3, cellTexts.length );
+        assertEquals( 2, cellTexts[0].length );
+        assertEquals( getString( "report.modules.header.name" ), cellTexts[0][0] );
+        assertEquals( getString( "report.modules.header.description" ), cellTexts[0][1] );
+        assertEquals( "project1", cellTexts[1][0] );
+        assertEquals( "-", cellTexts[1][1] );
+        assertEquals( "project2", cellTexts[2][0] );
+        assertEquals( "project2 description", cellTexts[2][1] );
+    }
+}

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/ModulesReportTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java?rev=907809&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java Mon Feb  8 21:35:43 2010
@@ -0,0 +1,34 @@
+package org.apache.maven.report.projectinfo.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * @author ltheussl
+ * @version $Id$
+ */
+public class ModulesStub
+    extends ProjectInfoProjectStub
+{
+    /** {@inheritDoc} */
+    protected String getPOM()
+    {
+        return "modules-plugin-config.xml";
+    }
+}

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml?rev=907809&view=auto
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml (added)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml Mon Feb  8 21:35:43 2010
@@ -0,0 +1,54 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
+  <artifactId>modules</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <name>modules project info</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <modules>
+    <module>subproject1</module>
+    <module>subproject2</module>
+  </modules>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <configuration>
+          <outputDirectory>target/test-harness/modules</outputDirectory>
+          <localRepository>${localRepository}</localRepository>
+          <project implementation="org.apache.maven.report.projectinfo.stubs.ModulesStub"/>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/modules-plugin-config.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml?rev=907809&r1=907808&r2=907809&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml (original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml Mon Feb  8 21:35:43 2010
@@ -29,4 +29,5 @@
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   <name>project2</name>
+  <description>project2 description</description>
 </project>