Author: hboutemy
Date: Sun Jan  3 15:24:33 2016
New Revision: 1722730

URL: http://svn.apache.org/viewvc?rev=1722730&view=rev
Log:
refactoring: extract site descriptor related mojos to dedicated package

Added:
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
   (with props)
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java
      - copied, changed from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java
      - copied, changed from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorArtifactMetadata.java
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorAttachMojo.java
      - copied, changed from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java
Removed:
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorArtifactMetadata.java
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java
Modified:
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
    
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java

Modified: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java?rev=1722730&r1=1722729&r2=1722730&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
 Sun Jan  3 15:24:33 2016
@@ -19,7 +19,6 @@ package org.apache.maven.plugins.site;
  * under the License.
  */
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
@@ -66,16 +65,6 @@ public abstract class AbstractSiteMojo
     protected I18N i18n;
 
     /**
-     * Directory containing the <code>site.xml</code> file and the source for 
hand written docs (one directory
-     * per Doxia-supported markup sources:
-     * see <a href="/doxia/references/index.html">Doxia Markup Languages 
References</a>).
-     *
-     * @since 2.3
-     */
-    @Parameter( defaultValue = "${basedir}/src/site" )
-    protected File siteDirectory;
-
-    /**
      * The Maven project.
      */
     @Parameter( defaultValue = "${project}", readonly = true )

Added: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java?rev=1722730&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
 (added)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
 Sun Jan  3 15:24:33 2016
@@ -0,0 +1,123 @@
+package org.apache.maven.plugins.site.descriptor;
+
+/*
+ * 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.util.List;
+import java.util.Locale;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.doxia.site.decoration.DecorationModel;
+import 
org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
+import org.apache.maven.doxia.tools.SiteToolException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.site.AbstractSiteMojo;
+
+/**
+ * Abstract class to compute effective site decoration model for site 
descriptors.
+ *
+ * @since 3.5
+ */
+public abstract class AbstractSiteDescriptorMojo
+    extends AbstractSiteMojo
+{
+    /**
+     * The component for assembling site decoration model inheritance.
+     */
+    @Component
+    private DecorationModelInheritanceAssembler assembler;
+
+    /**
+     * Remote repositories used for the project.
+     *
+     * @todo this is used for site descriptor resolution - it should relate to 
the actual project but for some reason
+     *       they are not always filled in
+     */
+    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", 
readonly = true )
+    protected List<ArtifactRepository> repositories;
+
+    /**
+     * Directory containing the <code>site.xml</code> file and the source for 
hand written docs (one directory
+     * per Doxia-source-supported markup types):
+     * see <a href="/doxia/references/index.html">Doxia Markup Languages 
References</a>).
+     *
+     * @since 2.3
+     */
+    @Parameter( defaultValue = "${basedir}/src/site" )
+    protected File siteDirectory;
+
+    /**
+     * Make links in the site descriptor relative to the project URL.
+     * By default, any absolute links that appear in the site descriptor,
+     * e.g. banner hrefs, breadcrumbs, menu links, etc., will be made relative 
to project.url.
+     * <p/>
+     * Links will not be changed if this is set to false, or if the project 
has no URL defined.
+     *
+     * @since 2.3
+     */
+    @Parameter( property = "relativizeDecorationLinks", defaultValue = "true" )
+    private boolean relativizeDecorationLinks;
+
+    protected DecorationModel prepareDecorationModel( Locale locale )
+        throws MojoExecutionException
+    {
+        DecorationModel decorationModel;
+        try
+        {
+            decorationModel = siteTool.getDecorationModel( siteDirectory, 
locale, project, reactorProjects,
+                                                           localRepository, 
repositories );
+        }
+        catch ( SiteToolException e )
+        {
+            throw new MojoExecutionException( "SiteToolException: " + 
e.getMessage(), e );
+        }
+
+        if ( relativizeDecorationLinks )
+        {
+            final String url = project.getUrl();
+
+            if ( url == null )
+            {
+                getLog().warn( "No project URL defined - decoration links will 
not be relativized!" );
+            }
+            else
+            {
+                List<Locale> localesList = getLocales();
+
+                // Default is first in the list
+                Locale defaultLocale = localesList.get( 0 );
+
+                // MSITE-658
+                final String localeUrl = locale.equals( defaultLocale ) ? url 
: append( url, locale.getLanguage() );
+
+                getLog().info( "Relativizing decoration links with respect to 
localized project URL: " + localeUrl );
+                assembler.resolvePaths( decorationModel, localeUrl );
+            }
+        }
+        return decorationModel;
+    }
+
+    private String append( String url, String path )
+    {
+        return url.endsWith( "/" ) ? ( url + path ) : ( url + '/' + path );
+    }
+}

Propchange: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/AbstractSiteDescriptorMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java
 (from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java)
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java?p2=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java&p1=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java&r1=1722487&r2=1722730&rev=1722730&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/EffectiveSiteMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/EffectiveSiteMojo.java
 Sun Jan  3 15:24:33 2016
@@ -1,4 +1,4 @@
-package org.apache.maven.plugins.site;
+package org.apache.maven.plugins.site.descriptor;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -29,12 +29,10 @@ import java.util.Date;
 
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
-import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.site.render.AbstractSiteRenderingMojo;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.WriterFactory;
@@ -44,7 +42,7 @@ import org.codehaus.plexus.util.xml.XmlW
 
 /**
  * Displays the effective site descriptor as an XML for this build, after 
inheritance and interpolation of
- * <code>site.xml</code>.
+ * <code>site.xml</code>, for the first locale.
  *
  * @author <a href="mailto:hbout...@apache.org";>Hervé Boutemy</a>
  * @version $Id$
@@ -52,7 +50,7 @@ import org.codehaus.plexus.util.xml.XmlW
  */
 @Mojo( name = "effective-site", requiresReports = true )
 public class EffectiveSiteMojo
-    extends AbstractSiteRenderingMojo
+    extends AbstractSiteDescriptorMojo
 {
     /**
      * Optional parameter to write the output of this help in a given file, 
instead of writing to the console.
@@ -68,29 +66,18 @@ public class EffectiveSiteMojo
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        String effectiveSite;
-
-        try
-        {
-            SiteRenderingContext context = createSiteRenderingContext( 
getLocales().get( 0 ) );
-
-            DecorationModel decorationModel = context.getDecoration();
-
-            StringWriter w = new StringWriter();
-            XMLWriter writer =
-                new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", 
XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
-                                          decorationModel.getModelEncoding(), 
null );
-
-            writeHeader( writer );
-
-            writeEffectiveSite( decorationModel, writer );
-
-            effectiveSite = w.toString();
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Error during site descriptor 
calculation", e );
-        }
+        DecorationModel decorationModel = prepareDecorationModel( 
getLocales().get( 0 ) );
+    
+        StringWriter w = new StringWriter();
+        XMLWriter writer =
+            new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", 
XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
+                                      decorationModel.getModelEncoding(), null 
);
+    
+        writeHeader( writer );
+    
+        writeEffectiveSite( decorationModel, writer );
+    
+        String effectiveSite = w.toString();
 
         if ( output != null )
         {

Copied: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java
 (from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorArtifactMetadata.java)
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java?p2=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java&p1=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorArtifactMetadata.java&r1=1722487&r2=1722730&rev=1722730&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorArtifactMetadata.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorArtifactMetadata.java
 Sun Jan  3 15:24:33 2016
@@ -1,4 +1,4 @@
-package org.apache.maven.plugins.site;
+package org.apache.maven.plugins.site.descriptor;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one

Copied: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorAttachMojo.java
 (from r1722487, 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java)
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorAttachMojo.java?p2=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorAttachMojo.java&p1=maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java&r1=1722487&r2=1722730&rev=1722730&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteDescriptorAttachMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/descriptor/SiteDescriptorAttachMojo.java
 Sun Jan  3 15:24:33 2016
@@ -1,4 +1,4 @@
-package org.apache.maven.plugins.site;
+package org.apache.maven.plugins.site.descriptor;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -46,7 +46,7 @@ import org.codehaus.plexus.util.FileUtil
  */
 @Mojo( name = "attach-descriptor", defaultPhase = LifecyclePhase.PACKAGE, 
threadSafe = true )
 public class SiteDescriptorAttachMojo
-    extends AbstractSiteMojo
+    extends AbstractSiteDescriptorMojo
 {
     /**
      */

Modified: 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java?rev=1722730&r1=1722729&r2=1722730&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java
 Sun Jan  3 15:24:33 2016
@@ -31,11 +31,9 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.Menu;
 import org.apache.maven.doxia.site.decoration.MenuItem;
-import 
org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
 import org.apache.maven.doxia.siterenderer.DocumentRenderer;
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.doxia.siterenderer.RendererException;
@@ -47,7 +45,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.site.AbstractSiteMojo;
+import org.apache.maven.plugins.site.descriptor.AbstractSiteDescriptorMojo;
 import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.reporting.exec.MavenReportExecution;
 import org.apache.maven.reporting.exec.MavenReportExecutor;
@@ -69,7 +67,7 @@ import org.codehaus.plexus.util.ReaderFa
  * @version $Id$
  */
 public abstract class AbstractSiteRenderingMojo
-    extends AbstractSiteMojo implements Contextualizable
+    extends AbstractSiteDescriptorMojo implements Contextualizable
 {
     /**
      * Module type exclusion mappings
@@ -91,20 +89,6 @@ public abstract class AbstractSiteRender
     private Map<String, String> moduleExcludes;
 
     /**
-     * The component for assembling inheritance.
-     */
-    @Component
-    private DecorationModelInheritanceAssembler assembler;
-
-    /**
-     * Remote repositories used for the project.
-     *
-     * @todo this is used for site descriptor resolution - it should relate to 
the actual project but for some reason they are not always filled in
-     */
-    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", 
readonly = true )
-    private List<ArtifactRepository> repositories;
-
-    /**
      * The location of a Velocity template file to use. When used, skins and 
the default templates, CSS and images
      * are disabled. It is highly recommended that you package this as a skin 
instead.
      *
@@ -172,18 +156,6 @@ public abstract class AbstractSiteRender
     private PlexusContainer container;
 
     /**
-     * Make links in the site descriptor relative to the project URL.
-     * By default, any absolute links that appear in the site descriptor,
-     * e.g. banner hrefs, breadcrumbs, menu links, etc., will be made relative 
to project.url.
-     * <p/>
-     * Links will not be changed if this is set to false, or if the project 
has no URL defined.
-     *
-     * @since 2.3
-     */
-    @Parameter( property = "relativizeDecorationLinks", defaultValue = "true" )
-    private boolean relativizeDecorationLinks;
-
-    /**
      * Whether to generate the summary page for project reports: 
project-info.html.
      *
      * @since 2.3
@@ -304,6 +276,7 @@ public abstract class AbstractSiteRender
     protected SiteRenderingContext createSiteRenderingContext( Locale locale )
         throws MojoExecutionException, IOException, MojoFailureException
     {
+        DecorationModel decorationModel = prepareDecorationModel( locale );
         if ( attributes == null )
         {
             attributes = new HashMap<String, Object>();
@@ -330,35 +303,6 @@ public abstract class AbstractSiteRender
             attributes.put( (String) entry.getKey(), entry.getValue() );
         }
 
-        DecorationModel decorationModel;
-        try
-        {
-            decorationModel = siteTool.getDecorationModel( siteDirectory, 
locale, project, reactorProjects,
-                                                           localRepository, 
repositories );
-        }
-        catch ( SiteToolException e )
-        {
-            throw new MojoExecutionException( "SiteToolException: " + 
e.getMessage(), e );
-        }
-
-        if ( relativizeDecorationLinks )
-        {
-            final String url = project.getUrl();
-
-            if ( url == null )
-            {
-                getLog().warn( "No project URL defined - decoration links will 
not be relativized!" );
-            }
-            else
-            {
-                // MSITE-658
-                final String localeUrl =
-                    locale.equals( Locale.getDefault() ) ? url : url + "/" + 
locale.getLanguage();
-                getLog().info( "Relativizing decoration links with respect to 
project URL: " + localeUrl );
-                assembler.resolvePaths( decorationModel, localeUrl );
-            }
-        }
-
         SiteRenderingContext context;
         if ( templateFile != null )
         {


Reply via email to