maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r385427 - in /maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site: AbstractSiteMojo.java AbstractSiteRenderingMojo.java ReportComparator.java SiteMojo.java SiteRunMojo.java
Date Mon, 13 Mar 2006 05:16:56 GMT
Author: brett
Date: Sun Mar 12 21:16:54 2006
New Revision: 385427

URL: http://svn.apache.org/viewcvs?rev=385427&view=rev
Log:
[MSITE-80] clean up site and push features into Doxia site renderer

Added:
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
  (contents, props changed)
      - copied, changed from r384801, maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
Modified:
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportComparator.java
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java

Added: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java?rev=385427&view=auto
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
(added)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
Sun Mar 12 21:16:54 2006
@@ -0,0 +1,191 @@
+package org.apache.maven.plugins.site;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+/**
+ * Base class for site mojos.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public abstract class AbstractSiteMojo
+    extends AbstractMojo
+{
+    /**
+     * The locale by default for all default bundles
+     */
+    private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+    /**
+     * A comma separated list of locales supported by Maven. The first valid token will be
the default Locale
+     * for this instance of the Java Virtual Machine.
+     *
+     * @parameter expression="${locales}"
+     */
+    private String locales;
+
+    /**
+     * Internationalization.
+     *
+     * @component
+     */
+    protected I18N i18n;
+
+    /**
+     * Init the <code>localesList</code> variable.
+     * <p>If <code>locales</code> variable is available, the first valid
token will be the <code>defaultLocale</code>
+     * for this instance of the Java Virtual Machine.</p>
+     *
+     * @return a list of <code>Locale</code>
+     */
+    protected List initLocalesList()
+    {
+        List localesList = new ArrayList();
+        if ( locales != null )
+        {
+            String[] localesArray = StringUtils.split( locales, "," );
+
+            for ( int i = 0; i < localesArray.length; i++ )
+            {
+                Locale locale = codeToLocale( localesArray[i] );
+
+                if ( locale != null )
+                {
+                    if ( !Arrays.asList( Locale.getAvailableLocales() ).contains( locale
) )
+                    {
+                        getLog().warn( "The locale parsed defined by '" + locale +
+                            "' is not available in this Java Virtual Machine (" + System.getProperty(
"java.version" ) +
+                            " from " + System.getProperty( "java.vendor" ) + ") - IGNORING"
);
+                        continue;
+                    }
+
+                    // Default bundles are in English
+                    if ( !locale.getLanguage().equals( DEFAULT_LOCALE.getLanguage() ) )
+                    {
+                        if ( !i18n.getBundle( "site-plugin", locale ).getLocale().getLanguage().equals(
locale
+                            .getLanguage() ) )
+                        {
+                            StringBuffer sb = new StringBuffer();
+
+                            sb.append( "The locale '" ).append( locale ).append( "' (" );
+                            sb.append( locale.getDisplayName( Locale.ENGLISH ) );
+                            sb.append( ") is not currently support by Maven - IGNORING. "
);
+                            sb.append( "\n" );
+                            sb.append( "Contribution are welcome and greatly appreciated!
" );
+                            sb.append( "\n" );
+                            sb.append( "If you want to contribute a new translation, please
visit " );
+                            sb.append( "http://maven.apache.org/plugins/maven-site-plugin/i18n.html
" );
+                            sb.append( "for detailed instructions." );
+
+                            getLog().warn( sb.toString() );
+
+                            continue;
+                        }
+                    }
+
+                    localesList.add( locale );
+                }
+            }
+        }
+
+        if ( localesList.isEmpty() )
+        {
+            localesList = Collections.singletonList( DEFAULT_LOCALE );
+        }
+
+        return localesList;
+    }
+
+    /**
+     * Converts a locale code like "en", "en_US" or "en_US_win" to a <code>java.util.Locale</code>
+     * object.
+     * <p>If localeCode = <code>default</code>, return the current value
of the default locale for this instance
+     * of the Java Virtual Machine.</p>
+     *
+     * @param localeCode the locale code string.
+     * @return a java.util.Locale object instancied or null if errors occurred
+     * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
+     */
+    private Locale codeToLocale( String localeCode )
+    {
+        if ( localeCode == null )
+        {
+            return null;
+        }
+
+        if ( "default".equalsIgnoreCase( localeCode ) )
+        {
+            return Locale.getDefault();
+        }
+
+        String language = "";
+        String country = "";
+        String variant = "";
+
+        StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
+        if ( tokenizer.countTokens() > 3 )
+        {
+            getLog().warn( "Invalid java.util.Locale format for '" + localeCode + "' entry
- IGNORING" );
+            return null;
+        }
+
+        if ( tokenizer.hasMoreTokens() )
+        {
+            language = tokenizer.nextToken();
+            if ( tokenizer.hasMoreTokens() )
+            {
+                country = tokenizer.nextToken();
+                if ( tokenizer.hasMoreTokens() )
+                {
+                    variant = tokenizer.nextToken();
+                }
+            }
+        }
+
+        return new Locale( language, country, variant );
+    }
+
+    /**
+     * Get the path of the site descriptor for a given locale.
+     *
+     * @param locale the locale
+     * @return the site descriptor path
+     */
+    protected File getSiteDescriptorFile( File basedir, Locale locale )
+    {
+        // TODO: get proper siteDirectory from site configuration of the project this relates
to
+
+        File siteDescriptor = new File( basedir, "src/site/site_" + locale.getLanguage()
+ ".xml" );
+
+        if ( !siteDescriptor.exists() )
+        {
+            siteDescriptor = new File( basedir, "src/site/site.xml" );
+        }
+        return siteDescriptor;
+    }
+}

Copied: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
(from r384801, maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java)
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java?p2=maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java&p1=maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java&r1=384801&r2=385427&rev=385427&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteMojo.java
(original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
Sun Mar 12 21:16:54 2006
@@ -16,66 +16,45 @@
  * limitations under the License.
  */
 
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.site.decoration.Skin;
 import org.apache.maven.doxia.site.decoration.inheritance.DecorationModelInheritanceAssembler;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
-import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.codehaus.plexus.i18n.I18N;
-import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
-import java.io.InputStream;
-import java.io.LineNumberReader;
-import java.io.InputStreamReader;
-import java.io.FileOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
-import java.util.StringTokenizer;
 import java.util.Map;
-import java.util.HashMap;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipEntry;
-import java.net.URLClassLoader;
-import java.net.URL;
 
 /**
- * Base class for site mojos.
+ * Base class for site rendering mojos.
  *
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @version $Id$
  */
-public abstract class AbstractSiteMojo
-    extends AbstractMojo
+public abstract class AbstractSiteRenderingMojo
+    extends AbstractSiteMojo
 {
-    /**
-     * The locale by default for all default bundles
-     */
-    private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
 
     /**
      * Directory containing source for apt, fml and xdoc docs.
@@ -86,21 +65,6 @@
     protected File siteDirectory;
 
     /**
-     * A comma separated list of locales supported by Maven. The first valid token will be
the default Locale
-     * for this instance of the Java Virtual Machine.
-     *
-     * @parameter expression="${locales}"
-     */
-    private String locales;
-
-    /**
-     * Internationalization.
-     *
-     * @component
-     */
-    protected I18N i18n;
-
-    /**
      * Specifies the output encoding.
      *
      * @parameter expression="${outputEncoding}"
@@ -153,14 +117,11 @@
      */
     protected ArtifactFactory artifactFactory;
 
-    protected static final String RESOURCE_DIR = "org/apache/maven/plugins/site";
-
-    private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/default-site.vm";
-
     /**
      * Directory containing the template page.
      *
-     * @parameter expression="${templateDirectory}"
+     * @parameter expression="${templateDirectory}" default-value="src/site"
+     * @deprecated use templateFile or skinning instead
      */
     private File templateDirectory;
 
@@ -168,16 +129,23 @@
      * Default template page.
      *
      * @parameter expression="${template}"
+     * @deprecated use templateFile or skinning instead
      */
     private String template;
 
     /**
+     * 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.
+     *
+     * @parameter expression="${templateFile}"
+     */
+    private File templateFile;
+
+    /**
      * @parameter expression="${attributes}"
      */
     protected Map attributes;
 
-    private static final String SKIN_TEMPLATE_LOCATION = "META-INF/maven/site.vm";
-
     /**
      * Directory which contains the resources for the site.
      *
@@ -187,137 +155,11 @@
     protected File resourcesDirectory;
 
     /**
-     * Get the path of the site descriptor for a given locale.
+     * Site renderer.
      *
-     * @param locale the locale
-     * @return the site descriptor path
-     */
-    protected File getSiteDescriptorFile( File basedir, Locale locale )
-    {
-        // TODO: get proper siteDirectory from site configuration of the project this relates
to
-
-        File siteDescriptor = new File( basedir, "src/site/site_" + locale.getLanguage()
+ ".xml" );
-
-        if ( !siteDescriptor.exists() )
-        {
-            siteDescriptor = new File( basedir, "src/site/site.xml" );
-        }
-        return siteDescriptor;
-    }
-
-    /**
-     * Init the <code>localesList</code> variable.
-     * <p>If <code>locales</code> variable is available, the first valid
token will be the <code>defaultLocale</code>
-     * for this instance of the Java Virtual Machine.</p>
-     *
-     * @return a list of <code>Locale</code>
-     */
-    protected List initLocalesList()
-    {
-        List localesList = new ArrayList();
-        if ( locales != null )
-        {
-            String[] localesArray = StringUtils.split( locales, "," );
-
-            for ( int i = 0; i < localesArray.length; i++ )
-            {
-                Locale locale = codeToLocale( localesArray[i] );
-
-                if ( locale != null )
-                {
-                    if ( !Arrays.asList( Locale.getAvailableLocales() ).contains( locale
) )
-                    {
-                        getLog().warn( "The locale parsed defined by '" + locale +
-                            "' is not available in this Java Virtual Machine (" + System.getProperty(
"java.version" ) +
-                            " from " + System.getProperty( "java.vendor" ) + ") - IGNORING"
);
-                        continue;
-                    }
-
-                    // Default bundles are in English
-                    if ( !locale.getLanguage().equals( DEFAULT_LOCALE.getLanguage() ) )
-                    {
-                        if ( !i18n.getBundle( "site-plugin", locale ).getLocale().getLanguage().equals(
locale
-                            .getLanguage() ) )
-                        {
-                            StringBuffer sb = new StringBuffer();
-
-                            sb.append( "The locale '" ).append( locale ).append( "' (" );
-                            sb.append( locale.getDisplayName( Locale.ENGLISH ) );
-                            sb.append( ") is not currently support by Maven - IGNORING. "
);
-                            sb.append( "\n" );
-                            sb.append( "Contribution are welcome and greatly appreciated!
" );
-                            sb.append( "\n" );
-                            sb.append( "If you want to contribute a new translation, please
visit " );
-                            sb.append( "http://maven.apache.org/plugins/maven-site-plugin/i18n.html
" );
-                            sb.append( "for detailed instructions." );
-
-                            getLog().warn( sb.toString() );
-
-                            continue;
-                        }
-                    }
-
-                    localesList.add( locale );
-                }
-            }
-        }
-
-        if ( localesList.isEmpty() )
-        {
-            localesList = Collections.singletonList( DEFAULT_LOCALE );
-        }
-
-        return localesList;
-    }
-
-    /**
-     * Converts a locale code like "en", "en_US" or "en_US_win" to a <code>java.util.Locale</code>
-     * object.
-     * <p>If localeCode = <code>default</code>, return the current value
of the default locale for this instance
-     * of the Java Virtual Machine.</p>
-     *
-     * @param localeCode the locale code string.
-     * @return a java.util.Locale object instancied or null if errors occurred
-     * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Locale.html">java.util.Locale#getDefault()</a>
+     * @component
      */
-    private Locale codeToLocale( String localeCode )
-    {
-        if ( localeCode == null )
-        {
-            return null;
-        }
-
-        if ( "default".equalsIgnoreCase( localeCode ) )
-        {
-            return Locale.getDefault();
-        }
-
-        String language = "";
-        String country = "";
-        String variant = "";
-
-        StringTokenizer tokenizer = new StringTokenizer( localeCode, "_" );
-        if ( tokenizer.countTokens() > 3 )
-        {
-            getLog().warn( "Invalid java.util.Locale format for '" + localeCode + "' entry
- IGNORING" );
-            return null;
-        }
-
-        if ( tokenizer.hasMoreTokens() )
-        {
-            language = tokenizer.nextToken();
-            if ( tokenizer.hasMoreTokens() )
-            {
-                country = tokenizer.nextToken();
-                if ( tokenizer.hasMoreTokens() )
-                {
-                    variant = tokenizer.nextToken();
-                }
-            }
-        }
-
-        return new Locale( language, country, variant );
-    }
+    protected Renderer siteRenderer;
 
     protected DecorationModel getDecorationModel( MavenProject project, Locale locale, Map
origProps )
         throws MojoExecutionException
@@ -501,68 +343,42 @@
         return buffer.toString();
     }
 
-    protected SiteRenderingContext createSiteRenderingContext( File skinArtifactFile, Locale
locale,
-                                                               DecorationModel decoration
)
-        throws IOException, MojoExecutionException
+    protected SiteRenderingContext createSiteRenderingContext( Locale locale, DecorationModel
decoration,
+                                                               Renderer siteRenderer )
+        throws IOException, MojoExecutionException, MojoFailureException
     {
-        boolean hasSiteTemplate = false;
-        if ( template == null )
+        if ( template != null )
         {
-            if ( skinArtifactFile != null && skinArtifactFile.exists() )
+            if ( templateFile != null )
             {
-                ZipFile zipFile = new ZipFile( skinArtifactFile );
-                try
-                {
-                    if ( zipFile.getEntry( SKIN_TEMPLATE_LOCATION ) != null )
-                    {
-                        hasSiteTemplate = true;
-                        template = SKIN_TEMPLATE_LOCATION;
-                    }
-                }
-                finally
-                {
-                    zipFile.close();
-                }
+                getLog().warn( "'template' configuration is ignored when 'templateFile' is
set" );
+            }
+            else
+            {
+                templateFile = new File( templateDirectory, template );
             }
         }
 
-        if ( template == null )
-        {
-            template = DEFAULT_TEMPLATE;
-        }
-
-        ClassLoader templateClassLoader;
-
-        if ( hasSiteTemplate )
+        File skinFile = getSkinArtifactFile( decoration );
+        SiteRenderingContext context;
+        if ( templateFile != null )
         {
-            templateClassLoader = new URLClassLoader( new URL[]{skinArtifactFile.toURL()}
);
-        }
-        else if ( templateDirectory == null )
-        {
-            templateClassLoader = SiteMojo.class.getClassLoader();
+            if ( !templateFile.exists() )
+            {
+                throw new MojoFailureException( "Template file '" + templateFile + "' does
not exist" );
+            }
+            context = siteRenderer.createContextForTemplate( templateFile, attributes, decoration,
locale,
+                                                             project.getName(), skinFile,
resourcesDirectory );
         }
         else
         {
-            if ( !templateDirectory.exists() )
-            {
-                throw new MojoExecutionException(
-                    "This templateDirectory=[" + templateDirectory + "] doesn't exist." );
-            }
-
-            templateClassLoader = new URLClassLoader( new URL[]{templateDirectory.toURL()}
);
+            context = siteRenderer.createContextForSkin( skinFile, attributes, decoration,
locale, project.getName(),
+                                                         resourcesDirectory );
         }
-
-        SiteRenderingContext context = new SiteRenderingContext();
-        context.setTemplate( template );
-        context.setTemplateProperties( attributes );
-        context.setLocale( locale );
-        context.setTemplateClassLoader( templateClassLoader );
-        context.setDecoration( decoration );
-        context.setDefaultWindowTitle( project.getName() );
         return context;
     }
 
-    protected File getSkinArtifactFile( DecorationModel decoration )
+    private File getSkinArtifactFile( DecorationModel decoration )
         throws MojoFailureException, MojoExecutionException
     {
         Skin skin = decoration.getSkin();
@@ -602,139 +418,21 @@
         return artifact.getFile();
     }
 
-    /**
-     * Copy Resources
-     *
-     * @param outputDir the output directory
-     * @param skinFile
-     * @throws java.io.IOException if any
-     * @todo move to skin functionality in site renderer
-     */
-    protected void copyResources( File outputDir, File skinFile )
-        throws IOException
+    protected void setDefaultAttributes()
     {
-        InputStream resourceList = getStream( RESOURCE_DIR + "/resources.txt" );
-
-        if ( resourceList != null )
+        if ( attributes == null )
         {
-            LineNumberReader reader = new LineNumberReader( new InputStreamReader( resourceList
) );
-
-            String line = reader.readLine();
-
-            while ( line != null )
-            {
-                InputStream is = getStream( RESOURCE_DIR + "/" + line );
-
-                if ( is == null )
-                {
-                    throw new IOException( "The resource " + line + " doesn't exist." );
-                }
-
-                File outputFile = new File( outputDir, line );
-
-                if ( !outputFile.getParentFile().exists() )
-                {
-                    outputFile.getParentFile().mkdirs();
-                }
-
-                FileOutputStream w = new FileOutputStream( outputFile );
-
-                IOUtil.copy( is, w );
-
-                IOUtil.close( is );
-
-                IOUtil.close( w );
-
-                line = reader.readLine();
-            }
+            attributes = new HashMap();
         }
 
-        // TODO: plexus-archiver, if it could do the excludes
-        ZipFile file = new ZipFile( skinFile );
-        try
+        if ( attributes.get( "project" ) == null )
         {
-            for ( Enumeration e = file.entries(); e.hasMoreElements(); )
-            {
-                ZipEntry entry = (ZipEntry) e.nextElement();
-
-                if ( !entry.getName().startsWith( "META-INF/" ) )
-                {
-                    File destFile = new File( outputDir, entry.getName() );
-                    if ( !entry.isDirectory() )
-                    {
-                        destFile.getParentFile().mkdirs();
-
-                        FileOutputStream fos = new FileOutputStream( destFile );
-
-                        try
-                        {
-                            IOUtil.copy( file.getInputStream( entry ), fos );
-                        }
-                        finally
-                        {
-                            IOUtil.close( fos );
-                        }
-                    }
-                    else
-                    {
-                        destFile.mkdirs();
-                    }
-                }
-            }
+            attributes.put( "project", project );
         }
-        finally
-        {
-            file.close();
-        }
-    }
 
-    /**
-     * Get the resource as stream
-     *
-     * @param name
-     * @return the inputstream
-     */
-    private InputStream getStream( String name )
-    {
-        return SiteMojo.class.getClassLoader().getResourceAsStream( name );
-    }
-
-    /**
-     * Copy the directory
-     *
-     * @param source      source file to be copied
-     * @param destination destination file
-     * @throws java.io.IOException if any
-     */
-    protected void copyDirectory( File source, File destination )
-        throws IOException
-    {
-        if ( source.exists() )
+        if ( attributes.get( "outputEncoding" ) == null )
         {
-            DirectoryScanner scanner = new DirectoryScanner();
-
-            String[] includedResources = {"**/**"};
-
-            scanner.setIncludes( includedResources );
-
-            scanner.addDefaultExcludes();
-
-            scanner.setBasedir( source );
-
-            scanner.scan();
-
-            List includedFiles = Arrays.asList( scanner.getIncludedFiles() );
-
-            for ( Iterator j = includedFiles.iterator(); j.hasNext(); )
-            {
-                String name = (String) j.next();
-
-                File sourceFile = new File( source, name );
-
-                File destinationFile = new File( destination, name );
-
-                FileUtils.copyFile( sourceFile, destinationFile );
-            }
+            attributes.put( "outputEncoding", outputEncoding );
         }
     }
 }

Propchange: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/AbstractSiteRenderingMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportComparator.java
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportComparator.java?rev=385427&r1=385426&r2=385427&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportComparator.java
(original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportComparator.java
Sun Mar 12 21:16:54 2006
@@ -18,25 +18,34 @@
 
 import org.apache.maven.reporting.MavenReport;
 
+import java.text.Collator;
 import java.util.Comparator;
 import java.util.Locale;
 
 /**
  * Sorts reports.
  *
- * @todo move to reporting API?
- * @todo allow reports to define their order in some other way?
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @version $Id$
+ * @todo move to reporting API?
+ * @todo allow reports to define their order in some other way?
  */
 public class ReportComparator
     implements Comparator
 {
+    private final Locale locale;
+
+    public ReportComparator( Locale locale )
+    {
+        this.locale = locale;
+    }
+
     public int compare( Object o1, Object o2 )
     {
         MavenReport r1 = (MavenReport) o1;
         MavenReport r2 = (MavenReport) o2;
 
-        return r1.getName( Locale.getDefault() ).compareTo( r2.getName( Locale.getDefault()
) );
+        Collator collator = Collator.getInstance( locale );
+        return collator.compare( r1.getName( locale ), r2.getName( locale ) );
     }
 }

Modified: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java?rev=385427&r1=385426&r2=385427&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
(original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteMojo.java
Sun Mar 12 21:16:54 2006
@@ -20,7 +20,6 @@
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 import org.apache.maven.doxia.siterenderer.RendererException;
 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
-import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -59,19 +58,18 @@
  * @version $Id$
  * @goal site
  * @requiresDependencyResolution test
- * @todo refactor out the parts that could go to doxia-site-renderer/maven-reporting-impl
to make this much thinner
- * @todo map out renderers in advance, accounting for duplicates, to make site:run easier
(eg index -> this report, project-info -> project info summary report, foo -> src/site/apt/foo.apt)
- * @todo GO OVER OTHER TODOS IN THIS PROJECT! :)
+ * @todo [IMPORTANT] refactor out the parts that could go to doxia-site-renderer/maven-reporting-impl
to make this much thinner
+ * @todo [IMPORTANT] map out renderers in advance, accounting for duplicates, to make site:run
easier (eg index -> this report, project-info -> project info summary report, foo ->
src/site/apt/foo.apt)
  */
 public class SiteMojo
-    extends AbstractSiteMojo
+    extends AbstractSiteRenderingMojo
 {
 
     /**
      * Alternative directory for xdoc source, useful for m1 to m2 migration
      *
-     * @parameter expression="${basedir}/xdocs"
-     * @required
+     * @parameter default-value="${basedir}/xdocs"
+     * @deprecated
      */
     private File xdocDirectory;
 
@@ -115,14 +113,6 @@
     private boolean generateReports;
 
     /**
-     * Site renderer. Not included in the abstract mojo so that deploy/attach-descriptor
don't need to go through it's
-     * initialisation.
-     *
-     * @component
-     */
-    protected Renderer siteRenderer;
-
-    /**
      * Generate the project site
      * <p/>
      * throws MojoExecutionException if any
@@ -132,20 +122,8 @@
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
-        if ( attributes == null )
-        {
-            attributes = new HashMap();
-        }
-
-        if ( attributes.get( "project" ) == null )
-        {
-            attributes.put( "project", project );
-        }
-
-        if ( attributes.get( "outputEncoding" ) == null )
-        {
-            attributes.put( "outputEncoding", outputEncoding );
-        }
+        // TODO: use in :run as well? better way to call it?
+        setDefaultAttributes();
 
         List reports = filterReports( this.reports );
 
@@ -159,36 +137,34 @@
             Locale defaultLocale = (Locale) localesList.get( 0 );
             Locale.setDefault( defaultLocale );
 
-            // Sort projectInfos and projectReports with the default locale setted
-            // TODO Beautify the output by sorting with each current locale
-            Comparator reportComparator = new ReportComparator();
-            for ( Iterator i = categories.values().iterator(); i.hasNext(); )
-            {
-                List reportSet = (List) i.next();
-                Collections.sort( reportSet, reportComparator );
-            }
-
             for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
             {
                 Locale locale = (Locale) iterator.next();
 
-                File outputDirectory = getOutputDirectory( locale, defaultLocale );
-
-                // Safety
-                if ( !outputDirectory.exists() )
+                // Sort projectInfos and projectReports
+                Comparator reportComparator = new ReportComparator( locale );
+                for ( Iterator i = categories.values().iterator(); i.hasNext(); )
                 {
-                    outputDirectory.mkdirs();
+                    List reportSet = (List) i.next();
+                    Collections.sort( reportSet, reportComparator );
                 }
 
+                File outputDirectory = getOutputDirectory( locale, defaultLocale );
+
                 // Generate static site
-                File siteDirectoryFile = siteDirectory;
-                File xdocDirectoryFile = xdocDirectory;
+                File siteDirectoryFile;
+                File xdocDirectoryFile;
                 if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
                 {
                     siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
 
                     xdocDirectoryFile = new File( xdocDirectory, locale.getLanguage() );
                 }
+                else
+                {
+                    siteDirectoryFile = siteDirectory;
+                    xdocDirectoryFile = xdocDirectory;
+                }
 
                 // Try to find duplicate files
                 Map duplicate = new LinkedHashMap();
@@ -222,9 +198,7 @@
 
                 DecorationModel decoration = getDecorationModel( categories, locale );
 
-                File skinArtifactFile = getSkinArtifactFile( decoration );
-
-                SiteRenderingContext context = createSiteRenderingContext( skinArtifactFile,
locale, decoration );
+                SiteRenderingContext context = createSiteRenderingContext( locale, decoration,
siteRenderer );
 
                 //Generate reports
                 List generatedReportsFileName = Collections.EMPTY_LIST;
@@ -236,8 +210,7 @@
                 // Try to generate the index.html
                 String displayLanguage = locale.getDisplayLanguage( Locale.ENGLISH );
 
-                // TODO: Be good to generate a module's summary page thats referenced off
the
-                // Modules menu item.
+                // TODO: [IMPORTANT] Be good to generate a module's summary page thats referenced
off the Modules menu item.
 
                 // Log if a user override a report file
                 for ( Iterator it = generatedReportsFileName.iterator(); it.hasNext(); )
@@ -267,14 +240,6 @@
                     }
                 }
 
-                copyResources( outputDirectory, skinArtifactFile );
-
-                // Copy site resources
-                if ( resourcesDirectory != null && resourcesDirectory.exists() )
-                {
-                    copyDirectory( resourcesDirectory, outputDirectory );
-                }
-
                 if ( generatedSiteDirectory.exists() )
                 {
                     siteRenderer.render( generatedSiteDirectory, outputDirectory, context
);
@@ -484,7 +449,7 @@
     {
         if ( reports.size() > 0 )
         {
-            // TODO: this is a hack, change to a different class - Category instead of MavenReport
+            // TODO: [IMPORTANT] this is a hack, change to a different class - Category instead
of MavenReport
             MavenReport summary = null;
             for ( Iterator i = reports.iterator(); i.hasNext() && summary == null;
)
             {
@@ -685,6 +650,7 @@
                     outputFile.getParentFile().mkdirs();
                 }
 
+                // TODO: outputDirectory should be in rendering context
                 siteRenderer.generateDocument(
                     new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding
), sink, context );
             }
@@ -703,6 +669,13 @@
         {
             file = new File( outputDirectory, locale.getLanguage() );
         }
+
+        // Safety
+        if ( !file.exists() )
+        {
+            file.mkdirs();
+        }
+
         return file;
     }
 

Modified: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java?rev=385427&r1=385426&r2=385427&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java
(original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java
Sun Mar 12 21:16:54 2006
@@ -17,7 +17,6 @@
  */
 
 import org.apache.maven.doxia.site.decoration.DecorationModel;
-import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -46,7 +45,7 @@
  * @goal run
  */
 public class SiteRunMojo
-    extends AbstractSiteMojo
+    extends AbstractSiteRenderingMojo
 {
     /**
      * Where to create the dummy web application.
@@ -62,14 +61,6 @@
      */
     private int port;
 
-    /**
-     * Site renderer. Not included in the abstract mojo so that deploy/attach-descriptor
don't need to go through it's
-     * initialisation.
-     *
-     * @component
-     */
-    protected Renderer siteRenderer;
-
     private static final int MAX_IDLE_TIME = 30000;
 
     public void execute()
@@ -155,19 +146,10 @@
 
         try
         {
-            File skinArtifactFile = getSkinArtifactFile( decorationModel );
-
             SiteRenderingContext context =
-                createSiteRenderingContext( skinArtifactFile, Locale.getDefault(), decorationModel
);
-
-
-            copyResources( tempWebappDirectory, skinArtifactFile );
+                createSiteRenderingContext( Locale.getDefault(), decorationModel, siteRenderer
);
 
-            // Copy site resources
-            if ( resourcesDirectory != null && resourcesDirectory.exists() )
-            {
-                copyDirectory( resourcesDirectory, tempWebappDirectory );
-            }
+            siteRenderer.copyResources( tempWebappDirectory, context );
 
             webapp.setAttribute( "context", context );
         }



Mime
View raw message