maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From micha...@apache.org
Subject svn commit: r1639526 - in /maven/plugins/trunk/maven-project-info-reports-plugin: ./ src/main/java/org/apache/maven/report/projectinfo/ src/test/java/org/apache/maven/report/projectinfo/stubs/ src/test/resources/plugin-configs/ src/test/resources/plugi...
Date Thu, 13 Nov 2014 21:23:40 GMT
Author: michaelo
Date: Thu Nov 13 21:23:39 2014
New Revision: 1639526

URL: http://svn.apache.org/r1639526
Log:
[MPIR-279] Wrong hyperlinks on index and modules page

* Logic adapted from the DefaultSiteTool which builds <menu ref="modules" />
  The behavior now completely resembles the menu and the breadcrumb links
* Thanks to Stuart McCulloch and Grzegorz Slowikowski for helping out and testing

Modified:
    maven/plugins/trunk/maven-project-info-reports-plugin/   (props changed)
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectIndexPageReport.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/dependency-convergence-plugin-config.xml
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject1/pom.xml
    maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject2/pom.xml

Propchange: maven/plugins/trunk/maven-project-info-reports-plugin/
------------------------------------------------------------------------------
    svn:mergeinfo = /maven/plugins/branches/MPIR-279:1636164-1639524

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java?rev=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/AbstractProjectInfoReport.java
Thu Nov 13 21:23:39 2014
@@ -54,6 +54,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.reporting.AbstractMavenReport;
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.settings.Settings;
@@ -113,6 +114,12 @@ public abstract class AbstractProjectInf
     @Component
     private I18N i18n;
 
+    /**
+     * Project builder.
+     */
+    @Component
+    protected MavenProjectBuilder mavenProjectBuilder;
+
     // ----------------------------------------------------------------------
     // Mojo parameters
     // ----------------------------------------------------------------------

Modified: 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=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ModulesReport.java
Thu Nov 13 21:23:39 2014
@@ -19,16 +19,22 @@ package org.apache.maven.report.projecti
  * under the License.
  */
 
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Locale;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.tools.SiteTool;
+import org.apache.maven.model.DistributionManagement;
 import org.apache.maven.model.Model;
+import org.apache.maven.model.Site;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
 import org.codehaus.plexus.i18n.I18N;
 
-import java.util.List;
-import java.util.Locale;
-
 /**
  * Generates the Project Modules report.
  *
@@ -47,7 +53,8 @@ public class ModulesReport
     @Override
     public void executeReport( Locale locale )
     {
-        new ModulesRenderer( getSink(), getProject(), getI18N( locale ), locale, siteTool
).render();
+        new ModulesRenderer( getSink(), getProject(), mavenProjectBuilder, localRepository,
+                             getI18N( locale ), locale, siteTool ).render();
     }
 
     /** {@inheritDoc} */
@@ -80,13 +87,21 @@ public class ModulesReport
     {
         protected MavenProject project;
 
+        protected MavenProjectBuilder mavenProjectBuilder;
+
+        protected ArtifactRepository localRepository;
+
         protected SiteTool siteTool;
 
-        ModulesRenderer( Sink sink, MavenProject project, I18N i18n, Locale locale, SiteTool
siteTool )
+        ModulesRenderer( Sink sink, MavenProject project, MavenProjectBuilder mavenProjectBuilder,
+                         ArtifactRepository localRepository, I18N i18n, Locale locale,
+                         SiteTool siteTool )
         {
             super( sink, i18n, locale );
 
             this.project = project;
+            this.mavenProjectBuilder = mavenProjectBuilder;
+            this.localRepository = localRepository;
             this.siteTool = siteTool;
         }
 
@@ -109,21 +124,36 @@ public class ModulesReport
             String description = getI18nString( "header.description" );
             tableHeader( new String[] { name, description } );
 
-            final String baseURL = project.getUrl();
+            final String baseUrl = getDistMgmntSiteUrl( project );
 
-            // before MPIR-229 this was model.getModules(), which could have uninherited/unresolved
values
-            // @todo also include modules which are not part of reactor, e.g. caused by -pl
-            List<MavenProject> modules = project.getCollectedProjects();
-            for ( MavenProject moduleProject : modules )
+            for ( Object module : project.getModules() )
             {
-                Model moduleModel = moduleProject.getModel();
-
-                final String moduleName = moduleProject.getName();
-
-                final String moduleHref =
-                    getRelativeLink( baseURL, moduleProject.getUrl(), moduleProject.getArtifactId()
);
+                Model moduleModel;
+                File f = new File( project.getBasedir(), module + "/pom.xml" );
+                if ( f.exists() )
+                {
+                    try
+                    {
+                        moduleModel = mavenProjectBuilder.build( f, localRepository, null
).getModel();
+                    }
+                    catch ( ProjectBuildingException e )
+                    {
+                       throw new IllegalStateException( "Unable to read local module POM",
e );
+                    }
+                }
+                else
+                {
+                    moduleModel = new Model();
+                    moduleModel.setName( module.toString() );
+                    setDistMgmntSiteUrl( moduleModel, module.toString() );
+                }
+
+                final String moduleName = name( moduleModel );
+                final String moduleHref = getRelativeLink( baseUrl, getDistMgmntSiteUrl(
moduleModel ),
+                                            moduleModel.getArtifactId() );
 
                 tableRow( new String[] { linkedName( moduleName, moduleHref ), moduleModel.getDescription()
} );
+
             }
 
             endTable();
@@ -131,6 +161,83 @@ public class ModulesReport
             endSection();
         }
 
+        private static void setDistMgmntSiteUrl( Model model, String url )
+        {
+            if ( model.getDistributionManagement() == null )
+            {
+                model.setDistributionManagement( new DistributionManagement() );
+            }
+
+            if ( model.getDistributionManagement().getSite() == null )
+            {
+                model.getDistributionManagement().setSite( new Site() );
+            }
+
+            model.getDistributionManagement().getSite().setUrl( url );
+        }
+
+        /**
+         * Return distributionManagement.site.url if defined, null otherwise.
+         *
+         * @param project not null
+         * @return could be null
+         */
+        private static String getDistMgmntSiteUrl( MavenProject project )
+        {
+            return getDistMgmntSiteUrl( project.getDistributionManagement() );
+        }
+
+        /**
+         * Return distributionManagement.site.url if defined, null otherwise.
+         *
+         * @param model not null
+         * @return could be null
+         */
+        private static String getDistMgmntSiteUrl( Model model )
+        {
+            return getDistMgmntSiteUrl( model.getDistributionManagement() );
+        }
+
+        private static String getDistMgmntSiteUrl( DistributionManagement distMgmnt )
+        {
+            if ( distMgmnt != null && distMgmnt.getSite() != null && distMgmnt.getSite().getUrl()
!= null )
+            {
+                return urlEncode( distMgmnt.getSite().getUrl() );
+            }
+
+            return null;
+        }
+
+        private static String urlEncode( final String url )
+        {
+            if ( url == null )
+            {
+                return null;
+            }
+
+            try
+            {
+                return new File( url ).toURI().toURL().toExternalForm();
+            }
+            catch ( MalformedURLException ex )
+            {
+                return url; // this will then throw somewhere else
+            }
+        }
+
+        private static String name( final Model model )
+        {
+            String name = model.getName();
+
+            if ( name == null )
+            {
+                name = "Unnamed &#x2013; " + model.getGroupId() + ":" + model.getArtifactId()
+ ":"
+                        + model.getPackaging() + ":" + model.getVersion();
+            }
+
+            return name;
+        }
+
         // adapted from DefaultSiteTool#appendMenuItem
         private String getRelativeLink( String baseUrl, String href, String defaultHref )
         {

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectIndexPageReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectIndexPageReport.java?rev=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectIndexPageReport.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/main/java/org/apache/maven/report/projectinfo/ProjectIndexPageReport.java
Thu Nov 13 21:23:39 2014
@@ -19,10 +19,12 @@ package org.apache.maven.report.projecti
  * under the License.
  */
 
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
 import org.codehaus.plexus.i18n.I18N;
 
 import java.util.Locale;
@@ -69,7 +71,8 @@ public class ProjectIndexPageReport
     public void executeReport( Locale locale )
     {
         ProjectIndexRenderer r =
-            new ProjectIndexRenderer( project, getName( locale ), getDescription( locale
), getSink(),
+            new ProjectIndexRenderer( project, mavenProjectBuilder, localRepository,
+                                      getName( locale ), getDescription( locale ), getSink(),
                                       getI18N( locale ), locale, siteTool );
 
         r.render();
@@ -103,10 +106,11 @@ public class ProjectIndexPageReport
 
         private boolean modules = false;
 
-        ProjectIndexRenderer( MavenProject project, String title, String description, Sink
sink, I18N i18n,
-                              Locale locale, SiteTool siteTool )
+        ProjectIndexRenderer( MavenProject project, MavenProjectBuilder mavenProjectBuilder,
+                              ArtifactRepository localRepository, String title, String description,
+                              Sink sink, I18N i18n, Locale locale, SiteTool siteTool )
         {
-            super( sink, project, i18n, locale, siteTool );
+            super( sink, project, mavenProjectBuilder, localRepository, i18n, locale, siteTool
);
 
             this.title = title;
 

Modified: 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=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/java/org/apache/maven/report/projectinfo/stubs/ModulesStub.java
Thu Nov 13 21:23:39 2014
@@ -3,7 +3,6 @@ package org.apache.maven.report.projecti
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.maven.project.MavenProject;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -36,10 +35,10 @@ public class ModulesStub
     {
         return "modules-plugin-config.xml";
     }
-    
+
     @Override
-    public List<MavenProject> getCollectedProjects()
+    public List getModules()
     {
-        return Arrays.<MavenProject>asList( new SubProject1Stub(), new SubProject2Stub()
);
+        return Arrays.<String>asList( "subproject1", "subproject2" );
     }
 }

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/dependency-convergence-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/dependency-convergence-plugin-config.xml?rev=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/dependency-convergence-plugin-config.xml
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/dependency-convergence-plugin-config.xml
Thu Nov 13 21:23:39 2014
@@ -22,7 +22,7 @@ under the License.
   <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
   <artifactId>dependency-convergence</artifactId>
   <version>1.0-SNAPSHOT</version>
-  <packaging>jar</packaging>
+  <packaging>pom</packaging>
   <name>dependency-convergence project info</name>
   <dependencies>
     <dependency>

Modified: maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject1/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject1/pom.xml?rev=1639526&r1=1639525&r2=1639526&view=diff
==============================================================================
--- maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject1/pom.xml
(original)
+++ maven/plugins/trunk/maven-project-info-reports-plugin/src/test/resources/plugin-configs/subproject1/pom.xml
Thu Nov 13 21:23:39 2014
@@ -23,6 +23,7 @@ under the License.
     <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
     <artifactId>dependency-convergence</artifactId>
     <version>1.0-SNAPSHOT</version>
+    <relativePath>../dependency-convergence-plugin-config.xml</relativePath>
   </parent>
   <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
   <artifactId>project1</artifactId>

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=1639526&r1=1639525&r2=1639526&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
Thu Nov 13 21:23:39 2014
@@ -23,6 +23,7 @@ under the License.
     <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
     <artifactId>dependency-convergence</artifactId>
     <version>1.0-SNAPSHOT</version>
+    <relativePath>../dependency-convergence-plugin-config.xml</relativePath>
   </parent>
   <groupId>org.apache.maven.plugin.projectinfo.tests</groupId>
   <artifactId>project2</artifactId>



Mime
View raw message