You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2015/12/13 18:11:08 UTC

svn commit: r1719808 - in /maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src: main/java/org/apache/maven/doxia/tools/ test/java/org/apache/maven/doxia/tools/

Author: hboutemy
Date: Sun Dec 13 17:11:08 2015
New Revision: 1719808

URL: http://svn.apache.org/viewvc?rev=1719808&view=rev
Log:
[DOXIASITETOOLS-124] streamlined SiteTools API: removed methods that are noly used internally

Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
    maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
    maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java

Modified: maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java?rev=1719808&r1=1719807&r2=1719808&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java Sun Dec 13 17:11:08 2015
@@ -323,32 +323,32 @@ public class DefaultSiteTool
     }
 
     /** {@inheritDoc} */
-    public File getSiteDescriptorFromBasedir( String siteDirectory, File basedir, Locale locale )
+    public File getSiteDescriptor( File siteDirectory, Locale locale )
     {
-        checkNotNull( "basedir", basedir );
-
-        String dir = siteDirectory;
-        if ( dir == null )
-        {
-            // TODO need to be more dynamic
-            dir = "src/site";
-        }
-
         final Locale llocale = ( locale == null ) ? new Locale( "" ) : locale;
 
-        File siteDir = new File( basedir, dir );
-
-        File siteDescriptor = new File( siteDir, "site_" + llocale.getLanguage() + ".xml" );
+        File siteDescriptor = new File( siteDirectory, "site_" + llocale.getLanguage() + ".xml" );
 
         if ( !siteDescriptor.isFile() )
         {
-            siteDescriptor = new File( siteDir, "site.xml" );
+            siteDescriptor = new File( siteDirectory, "site.xml" );
         }
         return siteDescriptor;
     }
 
-    /** {@inheritDoc} */
-    public File getSiteDescriptorFromRepository( MavenProject project, ArtifactRepository localRepository,
+    /**
+     * Get a site descriptor from one of the repositories.
+     *
+     * @param project the Maven project, not null.
+     * @param localRepository the Maven local repository, not null.
+     * @param repositories the Maven remote repositories, not null.
+     * @param locale the locale wanted for the site descriptor. If not null, searching for
+     * <code>site_<i>localeLanguage</i>.xml</code>, otherwise searching for <code>site.xml</code>.
+     * @return the site descriptor into the local repository after download of it from repositories or null if not
+     * found in repositories.
+     * @throws SiteToolException if any
+     */
+    File getSiteDescriptorFromRepository( MavenProject project, ArtifactRepository localRepository,
                                                  List<ArtifactRepository> repositories, Locale locale )
         throws SiteToolException
     {
@@ -434,7 +434,7 @@ public class DefaultSiteTool
             populateParentMenu( decorationModel, llocale, project, parentProject, true );
         }
 
-        populateModulesMenu( project, reactorProjects, localRepository, decorationModel, llocale, true );
+        populateModulesMenu( decorationModel, llocale, project, reactorProjects, localRepository, true );
 
         if ( decorationModel.getBannerLeft() == null )
         {
@@ -448,57 +448,6 @@ public class DefaultSiteTool
     }
 
     /** {@inheritDoc} */
-    public void populateReportsMenu( DecorationModel decorationModel, Locale locale,
-                                     Map<String, List<MavenReport>> categories )
-    {
-        checkNotNull( "decorationModel", decorationModel );
-        checkNotNull( "categories", categories );
-
-        Menu menu = decorationModel.getMenuRef( "reports" );
-
-        if ( menu == null )
-        {
-            return;
-        }
-
-        final Locale llocale = ( locale == null ) ? Locale.getDefault() : locale;
-
-        if ( menu.getName() == null )
-        {
-            menu.setName( i18n.getString( "site-tool", llocale, "decorationModel.menu.projectdocumentation" ) );
-        }
-
-        boolean found = false;
-        if ( menu.getItems().isEmpty() )
-        {
-            List<MavenReport> categoryReports = categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION );
-            if ( !isEmptyList( categoryReports ) )
-            {
-                MenuItem item = createCategoryMenu(
-                                                    i18n.getString( "site-tool", llocale,
-                                                                    "decorationModel.menu.projectinformation" ),
-                                                    "/project-info.html", categoryReports, llocale );
-                menu.getItems().add( item );
-                found = true;
-            }
-
-            categoryReports = categories.get( MavenReport.CATEGORY_PROJECT_REPORTS );
-            if ( !isEmptyList( categoryReports ) )
-            {
-                MenuItem item =
-                    createCategoryMenu( i18n.getString( "site-tool", llocale, "decorationModel.menu.projectreports" ),
-                                        "/project-reports.html", categoryReports, llocale );
-                menu.getItems().add( item );
-                found = true;
-            }
-        }
-        if ( !found )
-        {
-            decorationModel.removeMenuRef( "reports" );
-        }
-    }
-
-    /** {@inheritDoc} */
     public String getInterpolatedSiteDescriptorContent( Map<String, String> props, MavenProject aProject,
                                                         String siteDescriptorContent )
         throws SiteToolException
@@ -638,8 +587,17 @@ public class DefaultSiteTool
         return parentProject;
     }
 
-    /** {@inheritDoc} */
-    public void populateParentMenu( DecorationModel decorationModel, Locale locale, MavenProject project,
+    /**
+     * Populate the pre-defined <code>parent</code> menu of the decoration model,
+     * if used through <code>&lt;menu ref="parent"/&gt;</code>.
+     *
+     * @param decorationModel the Doxia Sitetools DecorationModel, not null.
+     * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
+     * @param project a Maven project, not null.
+     * @param parentProject a Maven parent project, not null.
+     * @param keepInheritedRefs used for inherited references.
+     */
+    private void populateParentMenu( DecorationModel decorationModel, Locale locale, MavenProject project,
                                     MavenProject parentProject, boolean keepInheritedRefs )
     {
         checkNotNull( "decorationModel", decorationModel );
@@ -708,10 +666,21 @@ public class DefaultSiteTool
         }
     }
 
-    /** {@inheritDoc} */
-    public void populateModulesMenu( MavenProject project, List<MavenProject> reactorProjects,
-                                     ArtifactRepository localRepository, DecorationModel decorationModel,
-                                     Locale locale, boolean keepInheritedRefs )
+    /**
+     * Populate the pre-defined <code>modules</code> menu of the decoration model,
+     * if used through <code>&lt;menu ref="modules"/&gt;</code>.
+     *
+     * @param decorationModel the Doxia Sitetools DecorationModel, not null.
+     * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
+     * @param project a Maven project, not null.
+     * @param reactorProjects the Maven reactor projects, not null.
+     * @param localRepository the Maven local repository, not null.
+     * @param keepInheritedRefs used for inherited references.
+     * @throws SiteToolException if any
+     */
+    private void populateModulesMenu( DecorationModel decorationModel, Locale locale, MavenProject project,
+                                     List<MavenProject> reactorProjects, ArtifactRepository localRepository,
+                                     boolean keepInheritedRefs )
         throws SiteToolException
     {
         checkNotNull( "project", project );
@@ -780,6 +749,57 @@ public class DefaultSiteTool
     }
 
     /** {@inheritDoc} */
+    public void populateReportsMenu( DecorationModel decorationModel, Locale locale,
+                                     Map<String, List<MavenReport>> categories )
+    {
+        checkNotNull( "decorationModel", decorationModel );
+        checkNotNull( "categories", categories );
+
+        Menu menu = decorationModel.getMenuRef( "reports" );
+
+        if ( menu == null )
+        {
+            return;
+        }
+
+        final Locale llocale = ( locale == null ) ? Locale.getDefault() : locale;
+
+        if ( menu.getName() == null )
+        {
+            menu.setName( i18n.getString( "site-tool", llocale, "decorationModel.menu.projectdocumentation" ) );
+        }
+
+        boolean found = false;
+        if ( menu.getItems().isEmpty() )
+        {
+            List<MavenReport> categoryReports = categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION );
+            if ( !isEmptyList( categoryReports ) )
+            {
+                MenuItem item = createCategoryMenu(
+                                                    i18n.getString( "site-tool", llocale,
+                                                                    "decorationModel.menu.projectinformation" ),
+                                                    "/project-info.html", categoryReports, llocale );
+                menu.getItems().add( item );
+                found = true;
+            }
+
+            categoryReports = categories.get( MavenReport.CATEGORY_PROJECT_REPORTS );
+            if ( !isEmptyList( categoryReports ) )
+            {
+                MenuItem item =
+                    createCategoryMenu( i18n.getString( "site-tool", llocale, "decorationModel.menu.projectreports" ),
+                                        "/project-reports.html", categoryReports, llocale );
+                menu.getItems().add( item );
+                found = true;
+            }
+        }
+        if ( !found )
+        {
+            decorationModel.removeMenuRef( "reports" );
+        }
+    }
+
+    /** {@inheritDoc} */
     public List<Locale> getSiteLocales( String locales )
     {
         if ( locales == null )
@@ -1031,7 +1051,7 @@ public class DefaultSiteTool
         }
         else
         {
-            siteDescriptor = getSiteDescriptorFromBasedir( siteDirectory, project.getBasedir(), locale );
+            siteDescriptor = getSiteDescriptor( new File( project.getBasedir(), siteDirectory ), locale );
         }
 
         String siteDescriptorContent = null;

Modified: maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java?rev=1719808&r1=1719807&r2=1719808&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/SiteTool.java Sun Dec 13 17:11:08 2015
@@ -78,83 +78,14 @@ public interface SiteTool
         throws SiteToolException;
 
     /**
-     * Calculate the relative path between two URLs or between two files.
+     * Get a site descriptor from the project's site directory.
      *
-     * For example:
-     * <dl>
-     * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org"</dt>
-     * <dd>return ""</dd>
-     * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"</dt>
-     * <dd>return "../.."</dd>
-     * <dt>to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"</dt>
-     * <dd>return "plugins/maven-site-plugin"</dd>
-     * <dt>to = "/myproject/myproject-module1" and from = "/myproject/myproject"</dt>
-     * <dd>return "../myproject-module1"</dd>
-     * </dl>
-     * <b>Note</b>: The file separator depends on the system.
-     *
-     * @param to the <code>to</code> url of file as string
-     * @param from the <code>from</code> url of file as string
-     * @return a relative path from <code>from</code> to <code>to</code>.
-     */
-    String getRelativePath( String to, String from );
-
-    /**
-     * Get a site descriptor from the project's base directory.
-     *
-     * @param siteDirectory The path to the directory containing the <code>site.xml</code> file, relative to the
-     * project base directory. If null, using by default "src/site".
-     * @param basedir not null.
-     * @param locale the locale wanted for the site descriptor. If not null, searching for
-     * <code>site_<i>localeLanguage</i>.xml</code>, otherwise searching for <code>site.xml</code>.
-     * @return the site descriptor relative file, i.e. <code>src/site/site.xml</code>, depending on parameter values.
-     */
-    File getSiteDescriptorFromBasedir( String siteDirectory, File basedir, Locale locale );
-
-    /**
-     * Get a site descriptor from one of the repositories.
-     *
-     * @param project the Maven project, not null.
-     * @param localRepository the Maven local repository, not null.
-     * @param repositories the Maven remote repositories, not null.
+     * @param siteDirectory the site directory
      * @param locale the locale wanted for the site descriptor. If not null, searching for
      * <code>site_<i>localeLanguage</i>.xml</code>, otherwise searching for <code>site.xml</code>.
-     * @return the site descriptor into the local repository after download of it from repositories or null if not
-     * found in repositories.
-     * @throws SiteToolException if any
-     */
-    File getSiteDescriptorFromRepository( MavenProject project, ArtifactRepository localRepository,
-                                          List<ArtifactRepository> repositories, Locale locale )
-        throws SiteToolException;
-
-    /**
-     * Get a decoration model for a project.
-     *
-     * @param project the Maven project, not null.
-     * @param reactorProjects the Maven reactor projects, not null.
-     * @param localRepository the Maven local repository, not null.
-     * @param repositories the Maven remote repositories, not null.
-     * @param siteDirectory The path to the directory containing the <code>site.xml</code> file, relative to the
-     * project base directory. If null, using by default "src/site".
-     * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
-     * @return the <code>DecorationModel</code> object corresponding to the <code>site.xml</code> file with some
-     * interpolations.
-     * @throws SiteToolException if any
-     */
-    DecorationModel getDecorationModel( MavenProject project, List<MavenProject> reactorProjects,
-                                        ArtifactRepository localRepository, List<ArtifactRepository> repositories,
-                                        String siteDirectory, Locale locale )
-        throws SiteToolException;
-
-    /**
-     * Populate the reports menu part of the decoration model.
-     *
-     * @param decorationModel the Doxia DecorationModel, not null.
-     * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
-     * @param categories a map to put on the decoration model, not null.
-     */
-    void populateReportsMenu( DecorationModel decorationModel, Locale locale,
-                              Map<String, List<MavenReport>> categories );
+     * @return the site descriptor file
+     */ // used by maven-pdf-plugin (should not?)
+    File getSiteDescriptor( File siteDirectory, Locale locale );
 
     /**
      * Interpolating several expressions in the site descriptor content. Actually, the expressions can be in
@@ -182,59 +113,46 @@ public interface SiteTool
      *
      * @param props a map used for interpolation, not null.
      * @param aProject a Maven project, not null.
-     * @param inputEncoding the input encoding of the site descriptor, not null.
-     * @param outputEncoding the output encoding wanted, not null.
      * @param siteDescriptorContent the site descriptor file, not null.
-     * @return the site descriptor content based on the <code>site.xml</code> file with interpolated strings.
+     * @return the interpolated site descriptor content.
      * @throws SiteToolException if errors happened during the interpolation.
-     */
+     */ // used by maven-pdf-plugin (should not?)
     String getInterpolatedSiteDescriptorContent( Map<String, String> props, MavenProject aProject,
                                                  String siteDescriptorContent )
         throws SiteToolException;
 
     /**
-     * Returns the parent POM with interpolated URLs. Attempts to source this value from the
-     * <code>reactorProjects</code> parameters if available (reactor env model attributes
-     * are interpolated), or if the reactor is unavailable (-N) resorts to the
-     * <code>project.getParent().getUrl()</code> value which will NOT have been interpolated.
-     * <p/>
-     * TODO: once bug is fixed in Maven proper, remove this.
+     * Get a decoration model for a project.
      *
-     * @param aProject a Maven project, not null.
+     * @param project the Maven project, not null.
      * @param reactorProjects the Maven reactor projects, not null.
      * @param localRepository the Maven local repository, not null.
-     * @return the parent project with interpolated URLs.
-     */
-    MavenProject getParentProject( MavenProject aProject, List<MavenProject> reactorProjects,
-                                   ArtifactRepository localRepository );
-
-    /**
-     * Populate the parent menu part of the decoration model.
-     *
-     * @param decorationModel the Doxia DecorationModel, not null.
+     * @param repositories the Maven remote repositories, not null.
+     * @param siteDirectory The path to the directory containing the <code>site.xml</code> file, relative to the
+     * project base directory. If null, using by default "src/site".
      * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
-     * @param project a Maven project, not null.
-     * @param parentProject a Maven parent project, not null.
-     * @param keepInheritedRefs used for inherited references.
+     * @return the <code>DecorationModel</code> object corresponding to the <code>site.xml</code> file with some
+     * interpolations.
+     * @throws SiteToolException if any
      */
-    void populateParentMenu( DecorationModel decorationModel, Locale locale, MavenProject project,
-                             MavenProject parentProject, boolean keepInheritedRefs );
+    DecorationModel getDecorationModel( MavenProject project, List<MavenProject> reactorProjects,
+                                        ArtifactRepository localRepository, List<ArtifactRepository> repositories,
+                                        String siteDirectory, Locale locale )
+        throws SiteToolException;
 
     /**
-     * Populate the modules menu part of the decoration model.
+     * Populate the pre-defined <code>reports</code> menu of the decoration model,
+     * if used through <code>&lt;menu ref="reports"/&gt;</code>. Notice this menu reference is translated into
+     * 2 separate menus: "Project Information" and "Project Reports".
      *
-     * @param project a Maven project, not null.
-     * @param reactorProjects the Maven reactor projects, not null.
-     * @param localRepository the Maven local repository, not null.
-     * @param decorationModel the Doxia site descriptor model, not null.
+     * @param decorationModel the Doxia Sitetools DecorationModel, not null.
      * @param locale the locale used for the i18n in DecorationModel. If null, using the default locale in the jvm.
-     * @param keepInheritedRefs used for inherited references.
-     * @throws SiteToolException if any
+     * @param reportsPerCategory reports per category to put in "Reports" or "Information" menus, not null.
+     * @see MavenReport#CATEGORY_PROJECT_INFORMATION
+     * @see MavenReport#CATEGORY_PROJECT_REPORTS
      */
-    void populateModulesMenu( MavenProject project, List<MavenProject> reactorProjects,
-                              ArtifactRepository localRepository, DecorationModel decorationModel, Locale locale,
-                              boolean keepInheritedRefs )
-        throws SiteToolException;
+    void populateReportsMenu( DecorationModel decorationModel, Locale locale,
+                              Map<String, List<MavenReport>> reportsPerCategory );
 
     /**
      * Extracts from a comma-separated list the locales that are available in <code>site-tool</code>
@@ -245,4 +163,42 @@ public interface SiteTool
      * @return a list of <code>Locale</code>, which at least contains the Maven default locale which is english
      */
     List<Locale> getSiteLocales( String locales );
+
+    /**
+     * Calculate the relative path between two URLs or between two files.
+     *
+     * For example:
+     * <dl>
+     * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org"</dt>
+     * <dd>return ""</dd>
+     * <dt>to = "http://maven.apache.org" and from = "http://maven.apache.org/plugins/maven-site-plugin/"</dt>
+     * <dd>return "../.."</dd>
+     * <dt>to = "http://maven.apache.org/plugins/maven-site-plugin/" and from = "http://maven.apache.org"</dt>
+     * <dd>return "plugins/maven-site-plugin"</dd>
+     * <dt>to = "/myproject/myproject-module1" and from = "/myproject/myproject"</dt>
+     * <dd>return "../myproject-module1"</dd>
+     * </dl>
+     * <b>Note</b>: The file separator depends on the system.
+     *
+     * @param to the <code>to</code> url of file as string
+     * @param from the <code>from</code> url of file as string
+     * @return a relative path from <code>from</code> to <code>to</code>.
+     */
+    String getRelativePath( String to, String from );
+
+    /**
+     * Returns the parent POM with interpolated URLs. Attempts to source this value from the
+     * <code>reactorProjects</code> parameters if available (reactor env model attributes
+     * are interpolated), or if the reactor is unavailable (-N) resorts to the
+     * <code>project.getParent().getUrl()</code> value which will NOT have been interpolated.
+     * <p/>
+     * TODO: once bug is fixed in Maven proper, remove this.
+     *
+     * @param aProject a Maven project, not null.
+     * @param reactorProjects the Maven reactor projects, not null.
+     * @param localRepository the Maven local repository, not null.
+     * @return the parent project with interpolated URLs.
+     */
+    MavenProject getParentProject( MavenProject aProject, List<MavenProject> reactorProjects,
+                                   ArtifactRepository localRepository );
 }

Modified: maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java?rev=1719808&r1=1719807&r2=1719808&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java (original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java Sun Dec 13 17:11:08 2015
@@ -210,12 +210,12 @@ public class SiteToolTest
         assertNotNull( tool );
 
         SiteToolMavenProjectStub project = new SiteToolMavenProjectStub( "site-tool-test" );
-        assertEquals( tool.getSiteDescriptorFromBasedir( null, project.getBasedir(), null ).toString(),
+        assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), null ).toString(),
             project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
-        assertEquals( tool.getSiteDescriptorFromBasedir( null, project.getBasedir(), Locale.ENGLISH ).toString(),
+        assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), "src/site" ), Locale.ENGLISH ).toString(),
             project.getBasedir() + File.separator + "src" + File.separator + "site" + File.separator + "site.xml" );
         String siteDir = "src/blabla";
-        assertEquals( tool.getSiteDescriptorFromBasedir( siteDir, project.getBasedir(), null ).toString(),
+        assertEquals( tool.getSiteDescriptor( new File( project.getBasedir(), siteDir ), null ).toString(),
             project.getBasedir() + File.separator + "src" + File.separator + "blabla" + File.separator + "site.xml" );
     }
 
@@ -225,7 +225,7 @@ public class SiteToolTest
     public void testGetSiteDescriptorFromRepository()
         throws Exception
     {
-        SiteTool tool = (SiteTool) lookup( SiteTool.ROLE );
+        DefaultSiteTool tool = (DefaultSiteTool) lookup( SiteTool.ROLE );
         assertNotNull( tool );
 
         SiteToolMavenProjectStub project = new SiteToolMavenProjectStub( "site-tool-test" );