maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r384800 - in /maven/plugins/branches/site-refactor/maven-site-plugin: ./ src/main/java/org/apache/maven/plugins/site/ src/main/java/org/apache/maven/plugins/site/webapp/ src/main/resources/ src/main/resources/webapp/
Date Fri, 10 Mar 2006 14:20:05 GMT
Author: brett
Date: Fri Mar 10 06:20:04 2006
New Revision: 384800

URL: http://svn.apache.org/viewcvs?rev=384800&view=rev
Log:
add site plugin to the refactoring branch

Added:
    maven/plugins/branches/site-refactor/maven-site-plugin/
      - copied from r384789, maven/plugins/trunk/maven-site-plugin/
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/SiteRunMojo.java   (with props)
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/DoxiaFilter.java   (with props)
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml   (with props)
Modified:
    maven/plugins/branches/site-refactor/maven-site-plugin/pom.xml
    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/SiteMojo.java
    maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/site-plugin.properties

Modified: maven/plugins/branches/site-refactor/maven-site-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/pom.xml?rev=384800&r1=384789&r2=384800&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/pom.xml (original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/pom.xml Fri Mar 10 06:20:04 2006
@@ -71,7 +71,7 @@
     <dependency>
       <groupId>org.apache.maven.doxia</groupId>
       <artifactId>doxia-site-renderer</artifactId>
-      <version>1.0-alpha-7-SNAPSHOT</version>
+      <version>1.0-alpha-8-SNAPSHOT</version>
       <exclusions>
         <exclusion>
           <!-- TODO: upgrade p-velo -->
@@ -88,6 +88,11 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>6.0.0beta6</version>
     </dependency>
   </dependencies>
 </project>

Modified: 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=384800&r1=384789&r2=384800&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/AbstractSiteMojo.java Fri Mar 10 06:20:04 2006
@@ -17,16 +17,51 @@
  */
 
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+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.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.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.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.
@@ -66,6 +101,92 @@
     protected I18N i18n;
 
     /**
+     * Specifies the output encoding.
+     *
+     * @parameter expression="${outputEncoding}"
+     * default-value="ISO-8859-1"
+     */
+    protected String outputEncoding;
+
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * The component for assembling inheritance.
+     *
+     * @component
+     */
+    protected DecorationModelInheritanceAssembler assembler;
+
+    /**
+     * The component that is used to resolve additional artifacts required.
+     *
+     * @component
+     */
+    protected ArtifactResolver artifactResolver;
+
+    /**
+     * The local repository.
+     *
+     * @parameter expression="${localRepository}"
+     */
+    protected ArtifactRepository localRepository;
+
+    /**
+     * 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 expression="${project.remoteArtifactRepositories}"
+     */
+    protected List repositories;
+
+    /**
+     * The component used for creating artifact instances.
+     *
+     * @component
+     */
+    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}"
+     */
+    private File templateDirectory;
+
+    /**
+     * Default template page.
+     *
+     * @parameter expression="${template}"
+     */
+    private String template;
+
+    /**
+     * @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.
+     *
+     * @parameter expression="${basedir}/src/site/resources"
+     * @required
+     */
+    protected File resourcesDirectory;
+
+    /**
      * Get the path of the site descriptor for a given locale.
      *
      * @param locale the locale
@@ -196,5 +317,424 @@
         }
 
         return new Locale( language, country, variant );
+    }
+
+    protected DecorationModel getDecorationModel( MavenProject project, Locale locale, Map origProps )
+        throws MojoExecutionException
+    {
+        Map props = new HashMap( origProps );
+
+        // TODO: we should use a workspace API that would know if it was in the repository already or not
+        File siteDescriptor = getSiteDescriptorFile( project.getBasedir(), locale );
+
+        String siteDescriptorContent;
+
+        try
+        {
+            if ( !siteDescriptor.exists() )
+            {
+                // try the repository
+                siteDescriptor = getSiteDescriptorFromRepository( project, locale );
+            }
+
+            if ( siteDescriptor != null && siteDescriptor.exists() )
+            {
+                siteDescriptorContent = FileUtils.fileRead( siteDescriptor );
+            }
+            else
+            {
+                siteDescriptorContent = IOUtil.toString( getClass().getResourceAsStream( "/default-site.xml" ) );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "The site descriptor cannot be read!", e );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new MojoExecutionException(
+                "The site descriptor cannot be resolved from the repository: " + e.getMessage(), e );
+        }
+
+        props.put( "outputEncoding", outputEncoding );
+
+        // TODO: interpolate ${project.*} in general
+
+        if ( project.getName() != null )
+        {
+            props.put( "project.name", project.getName() );
+        }
+        else
+        {
+            props.put( "project.name", "NO_PROJECT_NAME_SET" );
+        }
+
+        if ( project.getUrl() != null )
+        {
+            props.put( "project.url", project.getUrl() );
+        }
+        else
+        {
+            props.put( "project.url", "NO_PROJECT_URL_SET" );
+        }
+
+        MavenProject parentProject = project.getParent();
+        if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null )
+        {
+            props.put( "parentProject", getProjectParentMenu( locale ) );
+        }
+        else
+        {
+            props.put( "parentProject", "" );
+        }
+
+        siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props );
+
+        DecorationModel decoration;
+        try
+        {
+            decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) );
+        }
+        catch ( XmlPullParserException e )
+        {
+            throw new MojoExecutionException( "Error parsing site descriptor", e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error reading site descriptor", e );
+        }
+
+        if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null )
+        {
+            DecorationModel parent = getDecorationModel( parentProject, locale, props );
+
+            assembler.assembleModelInheritance( project.getName(), decoration, parent, project.getUrl(),
+                                                parentProject.getUrl() );
+        }
+
+        return decoration;
+    }
+
+    private File getSiteDescriptorFromRepository( MavenProject project, Locale locale )
+        throws ArtifactResolutionException
+    {
+        File result = null;
+
+        try
+        {
+            result = resolveSiteDescriptor( project, locale );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            getLog().debug( "Unable to locate site descriptor: " + e );
+        }
+
+        return result;
+    }
+
+    private File resolveSiteDescriptor( MavenProject project, Locale locale )
+        throws ArtifactResolutionException, ArtifactNotFoundException
+    {
+        File result;
+
+        try
+        {
+            // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1?
+            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
+                                                                              project.getArtifactId(),
+                                                                              project.getVersion(), "xml",
+                                                                              "site_" + locale.getLanguage() );
+            artifactResolver.resolve( artifact, repositories, localRepository );
+
+            result = artifact.getFile();
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            getLog().debug( "Unable to locate site descriptor: " + e );
+
+            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
+                                                                              project.getArtifactId(),
+                                                                              project.getVersion(), "xml", "site" );
+            artifactResolver.resolve( artifact, repositories, localRepository );
+
+            result = artifact.getFile();
+        }
+        return result;
+    }
+
+    /**
+     * Generate a menu for the parent project
+     *
+     * @param locale the locale wanted
+     * @return a XML menu for the parent project
+     */
+    private String getProjectParentMenu( Locale locale )
+    {
+        StringBuffer buffer = new StringBuffer();
+
+        String parentUrl = project.getParent().getUrl();
+        if ( parentUrl != null )
+        {
+            if ( parentUrl.endsWith( "/" ) )
+            {
+                parentUrl += "index.html";
+            }
+            else
+            {
+                parentUrl += "/index.html";
+            }
+
+            buffer.append( "<menu name=\"" );
+            buffer.append( i18n.getString( "site-plugin", locale, "report.menu.parentproject" ) );
+            buffer.append( "\">\n" );
+
+            buffer.append( "    <item name=\"" );
+            buffer.append( project.getParent().getName() );
+            buffer.append( "\" href=\"" );
+            buffer.append( parentUrl );
+            buffer.append( "\"/>\n" );
+
+            buffer.append( "</menu>\n" );
+
+        }
+
+        return buffer.toString();
+    }
+
+    protected SiteRenderingContext createSiteRenderingContext( File skinArtifactFile, Locale locale,
+                                                               DecorationModel decoration )
+        throws IOException, MojoExecutionException
+    {
+        boolean hasSiteTemplate = false;
+        if ( template == null )
+        {
+            if ( skinArtifactFile != null && skinArtifactFile.exists() )
+            {
+                ZipFile zipFile = new ZipFile( skinArtifactFile );
+                try
+                {
+                    if ( zipFile.getEntry( SKIN_TEMPLATE_LOCATION ) != null )
+                    {
+                        hasSiteTemplate = true;
+                        template = SKIN_TEMPLATE_LOCATION;
+                    }
+                }
+                finally
+                {
+                    zipFile.close();
+                }
+            }
+        }
+
+        if ( template == null )
+        {
+            template = DEFAULT_TEMPLATE;
+        }
+
+        ClassLoader templateClassLoader;
+
+        if ( hasSiteTemplate )
+        {
+            templateClassLoader = new URLClassLoader( new URL[]{skinArtifactFile.toURL()} );
+        }
+        else if ( templateDirectory == null )
+        {
+            templateClassLoader = SiteMojo.class.getClassLoader();
+        }
+        else
+        {
+            if ( !templateDirectory.exists() )
+            {
+                throw new MojoExecutionException(
+                    "This templateDirectory=[" + templateDirectory + "] doesn't exist." );
+            }
+
+            templateClassLoader = new URLClassLoader( new URL[]{templateDirectory.toURL()} );
+        }
+
+        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 )
+        throws MojoFailureException, MojoExecutionException
+    {
+        Skin skin = decoration.getSkin();
+
+        if ( skin == null )
+        {
+            skin = Skin.getDefaultSkin();
+        }
+
+        String version = skin.getVersion();
+        Artifact artifact;
+        try
+        {
+            if ( version == null )
+            {
+                version = Artifact.RELEASE_VERSION;
+            }
+            VersionRange versionSpec = VersionRange.createFromVersionSpec( version );
+            artifact = artifactFactory.createDependencyArtifact( skin.getGroupId(), skin.getArtifactId(), versionSpec,
+                                                                 "jar", null, null );
+
+            artifactResolver.resolve( artifact, repositories, localRepository );
+        }
+        catch ( InvalidVersionSpecificationException e )
+        {
+            throw new MojoFailureException( "The skin version '" + version + "' is not valid: " + e.getMessage() );
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new MojoExecutionException( "Unable to find skin", e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new MojoFailureException( "The skin does not exist: " + e.getMessage() );
+        }
+
+        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
+    {
+        InputStream resourceList = getStream( RESOURCE_DIR + "/resources.txt" );
+
+        if ( resourceList != 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();
+            }
+        }
+
+        // TODO: plexus-archiver, if it could do the excludes
+        ZipFile file = new ZipFile( skinFile );
+        try
+        {
+            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();
+                    }
+                }
+            }
+        }
+        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() )
+        {
+            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 );
+            }
+        }
     }
 }

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=384800&r1=384789&r2=384800&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 Fri Mar 10 06:20:04 2006
@@ -16,22 +16,11 @@
  * limitations under the License.
  */
 
-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.module.xdoc.XdocSiteModule;
 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.Renderer;
 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;
@@ -40,7 +29,6 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.reporting.MavenReportException;
-import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
@@ -50,27 +38,18 @@
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
 import java.io.OutputStreamWriter;
-import java.io.StringReader;
-import java.net.URL;
-import java.net.URLClassLoader;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 
 /**
  * Generates the project site.
@@ -80,13 +59,13 @@
  * @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! :)
  */
 public class SiteMojo
     extends AbstractSiteMojo
 {
-    private static final String RESOURCE_DIR = "org/apache/maven/plugins/site";
-
-    private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/default-site.vm";
 
     /**
      * Alternative directory for xdoc source, useful for m1 to m2 migration
@@ -113,57 +92,6 @@
     protected File outputDirectory;
 
     /**
-     * Directory which contains the resources for the site.
-     *
-     * @parameter expression="${basedir}/src/site/resources"
-     * @required
-     */
-    private File resourcesDirectory;
-
-    /**
-     * Directory containing the template page.
-     *
-     * @parameter expression="${templateDirectory}"
-     */
-    private File templateDirectory;
-
-    /**
-     * Default template page.
-     *
-     * @parameter expression="${template}"
-     */
-    private String template;
-
-    /**
-     * @parameter expression="${attributes}"
-     */
-    private Map attributes;
-
-    /**
-     * Specifies the output encoding.
-     *
-     * @parameter expression="${outputEncoding}"
-     * default-value="ISO-8859-1"
-     */
-    private String outputEncoding;
-
-    /**
-     * Site Renderer
-     *
-     * @component
-     */
-    private Renderer siteRenderer;
-
-    /**
-     * The maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    protected MavenProject project;
-
-    /**
      * The reactor projects.
      *
      * @parameter expression="${reactorProjects}"
@@ -187,42 +115,12 @@
     private boolean generateReports;
 
     /**
-     * The component for assembling inheritance.
-     *
-     * @component
-     */
-    private DecorationModelInheritanceAssembler assembler;
-
-    /**
-     * The component that is used to resolve additional artifacts required.
+     * Site renderer. Not included in the abstract mojo so that deploy/attach-descriptor don't need to go through it's
+     * initialisation.
      *
      * @component
      */
-    private ArtifactResolver artifactResolver;
-
-    /**
-     * The local repository.
-     *
-     * @parameter expression="${localRepository}"
-     */
-    private ArtifactRepository localRepository;
-
-    /**
-     * 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 expression="${project.remoteArtifactRepositories}"
-     */
-    private List repositories;
-
-    /**
-     * The component used for creating artifact instances.
-     *
-     * @component
-     */
-    private ArtifactFactory artifactFactory;
-
-    private static final String SKIN_TEMPLATE_LOCATION = "META-INF/maven/site.vm";
+    protected Renderer siteRenderer;
 
     /**
      * Generate the project site
@@ -252,18 +150,6 @@
         List reports = filterReports( this.reports );
 
         Map categories = categorizeReports( reports );
-        List projectInfos = (List) categories.get( MavenReport.CATEGORY_PROJECT_INFORMATION );
-        List projectReports = (List) categories.get( MavenReport.CATEGORY_PROJECT_REPORTS );
-
-        if ( projectInfos == null )
-        {
-            projectInfos = Collections.EMPTY_LIST;
-        }
-
-        if ( projectReports == null )
-        {
-            projectReports = Collections.EMPTY_LIST;
-        }
 
         try
         {
@@ -276,8 +162,11 @@
             // Sort projectInfos and projectReports with the default locale setted
             // TODO Beautify the output by sorting with each current locale
             Comparator reportComparator = new ReportComparator();
-            Collections.sort( projectInfos, reportComparator );
-            Collections.sort( projectReports, 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(); )
             {
@@ -331,64 +220,11 @@
                 // Exception if a file is duplicate
                 checkDuplicates( duplicate, locale );
 
-                DecorationModel decoration = getDecorationModel( reports, locale, projectInfos, projectReports );
+                DecorationModel decoration = getDecorationModel( categories, locale );
 
                 File skinArtifactFile = getSkinArtifactFile( decoration );
 
-                boolean hasSiteTemplate = false;
-                if ( template == null )
-                {
-                    if ( skinArtifactFile != null && skinArtifactFile.exists() )
-                    {
-                        ZipFile zipFile = new ZipFile( skinArtifactFile );
-                        try
-                        {
-                            if ( zipFile.getEntry( SKIN_TEMPLATE_LOCATION ) != null )
-                            {
-                                hasSiteTemplate = true;
-                                template = SKIN_TEMPLATE_LOCATION;
-                            }
-                        }
-                        finally
-                        {
-                            zipFile.close();
-                        }
-                    }
-                }
-
-                if ( template == null )
-                {
-                    template = DEFAULT_TEMPLATE;
-                }
-
-                ClassLoader templateClassLoader;
-
-                if ( hasSiteTemplate )
-                {
-                    templateClassLoader = new URLClassLoader( new URL[]{skinArtifactFile.toURL()} );
-                }
-                else if ( templateDirectory == null )
-                {
-                    templateClassLoader = SiteMojo.class.getClassLoader();
-                }
-                else
-                {
-                    if ( !templateDirectory.exists() )
-                    {
-                        throw new MojoExecutionException(
-                            "This templateDirectory=[" + templateDirectory + "] doesn't exist." );
-                    }
-
-                    templateClassLoader = new URLClassLoader( new URL[]{templateDirectory.toURL()} );
-                }
-
-                SiteRenderingContext context = new SiteRenderingContext();
-                context.setTemplate( template );
-                context.setTemplateProperties( attributes );
-                context.setLocale( locale );
-                context.setTemplateClassLoader( templateClassLoader );
-                context.setDecoration( decoration );
-                context.setDefaultWindowTitle( project.getName() );
+                SiteRenderingContext context = createSiteRenderingContext( skinArtifactFile, locale, decoration );
 
                 //Generate reports
                 List generatedReportsFileName = Collections.EMPTY_LIST;
@@ -397,28 +233,8 @@
                     generatedReportsFileName = generateReportsPages( reports, outputDirectory, defaultLocale, context );
                 }
 
-                //Generate overview pages
-                if ( projectInfos.size() > 0 )
-                {
-                    generateProjectInfoPage( projectInfos, outputDirectory, context );
-                }
-
-                if ( projectReports.size() > 0 )
-                {
-                    generateProjectReportsPage( projectReports, outputDirectory, context );
-                }
-
                 // Try to generate the index.html
                 String displayLanguage = locale.getDisplayLanguage( Locale.ENGLISH );
-                if ( duplicate.get( "index" ) != null )
-                {
-                    getLog().info( "Ignoring the index file generation for the " + displayLanguage + " version." );
-                }
-                else
-                {
-                    getLog().info( "Generate an index file for the " + displayLanguage + " version." );
-                    generateIndexPage( outputDirectory, context );
-                }
 
                 // TODO: Be good to generate a module's summary page thats referenced off the
                 // Modules menu item.
@@ -479,7 +295,7 @@
         }
     }
 
-    private DecorationModel getDecorationModel( List reports, Locale locale, List projectInfos, List projectReports )
+    private DecorationModel getDecorationModel( Map categories, Locale locale )
         throws MojoExecutionException
     {
         Map props = new HashMap();
@@ -487,7 +303,7 @@
         // TODO: can we replace these with an XML tag?
         if ( reports != null )
         {
-            props.put( "reports", getReportsMenu( locale, projectInfos, projectReports ) );
+            props.put( "reports", getReportsMenu( locale, categories ) );
         }
         else
         {
@@ -573,149 +389,6 @@
         }
     }
 
-    private DecorationModel getDecorationModel( MavenProject project, Locale locale, Map origProps )
-        throws MojoExecutionException
-    {
-        Map props = new HashMap( origProps );
-
-        // TODO: we should use a workspace API that would know if it was in the repository already or not
-        File siteDescriptor = getSiteDescriptorFile( project.getBasedir(), locale );
-
-        String siteDescriptorContent;
-
-        try
-        {
-            if ( !siteDescriptor.exists() )
-            {
-                // try the repository
-                siteDescriptor = getSiteDescriptorFromRepository( project, locale );
-            }
-
-            if ( siteDescriptor != null && siteDescriptor.exists() )
-            {
-                siteDescriptorContent = FileUtils.fileRead( siteDescriptor );
-            }
-            else
-            {
-                siteDescriptorContent = IOUtil.toString( getClass().getResourceAsStream( "/default-site.xml" ) );
-            }
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "The site descriptor cannot be read!", e );
-        }
-        catch ( ArtifactResolutionException e )
-        {
-            throw new MojoExecutionException(
-                "The site descriptor cannot be resolved from the repository: " + e.getMessage(), e );
-        }
-
-        props.put( "outputEncoding", outputEncoding );
-
-        // TODO: interpolate ${project.*} in general
-
-        if ( project.getName() != null )
-        {
-            props.put( "project.name", project.getName() );
-        }
-        else
-        {
-            props.put( "project.name", "NO_PROJECT_NAME_SET" );
-        }
-
-        if ( project.getUrl() != null )
-        {
-            props.put( "project.url", project.getUrl() );
-        }
-        else
-        {
-            props.put( "project.url", "NO_PROJECT_URL_SET" );
-        }
-
-        MavenProject parentProject = project.getParent();
-        if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null )
-        {
-            props.put( "parentProject", getProjectParentMenu( locale ) );
-        }
-        else
-        {
-            props.put( "parentProject", "" );
-        }
-
-        siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props );
-
-        DecorationModel decoration;
-        try
-        {
-            decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) );
-        }
-        catch ( XmlPullParserException e )
-        {
-            throw new MojoExecutionException( "Error parsing site descriptor", e );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Error reading site descriptor", e );
-        }
-
-        if ( parentProject != null && project.getUrl() != null && parentProject.getUrl() != null )
-        {
-            DecorationModel parent = getDecorationModel( parentProject, locale, props );
-
-            assembler.assembleModelInheritance( project.getName(), decoration, parent, project.getUrl(),
-                                                parentProject.getUrl() );
-        }
-
-        return decoration;
-    }
-
-    private File getSiteDescriptorFromRepository( MavenProject project, Locale locale )
-        throws ArtifactResolutionException
-    {
-        File result = null;
-
-        try
-        {
-            result = resolveSiteDescriptor( project, locale );
-        }
-        catch ( ArtifactNotFoundException e )
-        {
-            getLog().debug( "Unable to locate site descriptor: " + e );
-        }
-
-        return result;
-    }
-
-    private File resolveSiteDescriptor( MavenProject project, Locale locale )
-        throws ArtifactResolutionException, ArtifactNotFoundException
-    {
-        File result;
-
-        try
-        {
-            // TODO: this is a bit crude - proper type, or proper handling as metadata rather than an artifact in 2.1?
-            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
-                                                                              project.getArtifactId(),
-                                                                              project.getVersion(), "xml",
-                                                                              "site_" + locale.getLanguage() );
-            artifactResolver.resolve( artifact, repositories, localRepository );
-
-            result = artifact.getFile();
-        }
-        catch ( ArtifactNotFoundException e )
-        {
-            getLog().debug( "Unable to locate site descriptor: " + e );
-
-            Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
-                                                                              project.getArtifactId(),
-                                                                              project.getVersion(), "xml", "site" );
-            artifactResolver.resolve( artifact, repositories, localRepository );
-
-            result = artifact.getFile();
-        }
-        return result;
-    }
-
     private List filterReports( List reports )
     {
         List filteredReports = new ArrayList( reports.size() );
@@ -734,7 +407,6 @@
                 }
                 catch ( AbstractMethodError e )
                 {
-
                     // the canGenerateReport() has been added just before the 2.0 release and will cause all the reporting
                     // plugins with an earlier version to fail (most of the codehaus mojo now fails)
                     // be nice with them, output a warning and don't let them break anything
@@ -777,25 +449,23 @@
     /**
      * Retrieve the reports menu
      *
-     * @param locale         the locale used
-     * @param projectInfos   list of project infos
-     * @param projectReports list of project reports
+     * @param locale     the locale used
+     * @param categories report categories, each with a list of reports
      * @return a XML for reports menu
      */
-    private String getReportsMenu( Locale locale, List projectInfos, List projectReports )
+    private String getReportsMenu( Locale locale, Map categories )
     {
         StringBuffer buffer = new StringBuffer();
         buffer.append( "<menu name=\"" );
         buffer.append( i18n.getString( "site-plugin", locale, "report.menu.projectdocumentation" ) );
         buffer.append( "\">\n" );
-        buffer.append( "    <item name=\"" );
-        buffer.append( i18n.getString( "site-plugin", locale, "report.menu.about" ) );
-        buffer.append( " " );
-        buffer.append( project.getName() );
-        buffer.append( "\" href=\"/index.html\"/>\n" );
 
-        writeReportSubMenu( projectInfos, buffer, locale, "report.menu.projectinformation", "project-info.html" );
-        writeReportSubMenu( projectReports, buffer, locale, "report.menu.projectreports", "maven-reports.html" );
+        for ( Iterator i = categories.keySet().iterator(); i.hasNext(); )
+        {
+            String key = (String) i.next();
+            List reports = (List) categories.get( key );
+            writeReportSubMenu( reports, buffer, locale, key );
+        }
 
         buffer.append( "</menu>\n" );
 
@@ -805,22 +475,66 @@
     /**
      * Create a report sub menu
      *
-     * @param reports       list of reports specified in pom
-     * @param buffer        string to be appended
-     * @param locale        the locale used
-     * @param key
-     * @param indexFilename index page filename
+     * @param reports list of reports specified in pom
+     * @param buffer  string to be appended
+     * @param locale  the locale used
+     * @param key2    the default name of the category
      */
-    private void writeReportSubMenu( List reports, StringBuffer buffer, Locale locale, String key,
-                                     String indexFilename )
+    private void writeReportSubMenu( List reports, StringBuffer buffer, Locale locale, String key2 )
     {
         if ( reports.size() > 0 )
         {
+            // TODO: 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; )
+            {
+                MavenReport report = (MavenReport) i.next();
+                if ( "".equals( report.getDescription( locale ) ) )
+                {
+                    summary = report;
+                    try
+                    {
+                        Field f = summary.getClass().getDeclaredField( "reports" );
+                        boolean acc = f.isAccessible();
+                        f.setAccessible( true );
+                        List newReports = new ArrayList( reports );
+                        newReports.remove( summary );
+                        f.set( summary, newReports );
+                        f.setAccessible( acc );
+                    }
+                    catch ( NoSuchFieldException e )
+                    {
+                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                    }
+                    catch ( IllegalAccessException e )
+                    {
+                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                    }
+                }
+            }
+
+            String name;
+            String href = null;
+            if ( summary == null )
+            {
+                name = key2;
+            }
+            else
+            {
+                name = summary.getName( locale );
+                href = summary.getOutputName() + ".html";
+            }
+
             buffer.append( "    <item name=\"" );
-            buffer.append( i18n.getString( "site-plugin", locale, key ) );
-            buffer.append( "\" href=\"/" );
-            buffer.append( indexFilename );
-            buffer.append( "\" collapse=\"true\">\n" );
+            buffer.append( name );
+            buffer.append( "\"" );
+            if ( href != null )
+            {
+                buffer.append( " href=\"/" );
+                buffer.append( href );
+                buffer.append( "\" collapse=\"true\"" );
+            }
+            buffer.append( ">\n" );
 
             for ( Iterator i = reports.iterator(); i.hasNext(); )
             {
@@ -922,98 +636,6 @@
         }
     }
 
-    /**
-     * Generate a menu for the parent project
-     *
-     * @param locale the locale wanted
-     * @return a XML menu for the parent project
-     */
-    private String getProjectParentMenu( Locale locale )
-    {
-        StringBuffer buffer = new StringBuffer();
-
-        String parentUrl = project.getParent().getUrl();
-        if ( parentUrl != null )
-        {
-            if ( parentUrl.endsWith( "/" ) )
-            {
-                parentUrl += "index.html";
-            }
-            else
-            {
-                parentUrl += "/index.html";
-            }
-
-            buffer.append( "<menu name=\"" );
-            buffer.append( i18n.getString( "site-plugin", locale, "report.menu.parentproject" ) );
-            buffer.append( "\">\n" );
-
-            buffer.append( "    <item name=\"" );
-            buffer.append( project.getParent().getName() );
-            buffer.append( "\" href=\"" );
-            buffer.append( parentUrl );
-            buffer.append( "\"/>\n" );
-
-            buffer.append( "</menu>\n" );
-
-        }
-
-        return buffer.toString();
-    }
-
-    /**
-     * Generate an index page.
-     *
-     * @param outputDirectory
-     */
-    private void generateIndexPage( File outputDirectory, SiteRenderingContext context )
-        throws RendererException, IOException
-    {
-        String outputFileName = "index.html";
-
-        SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName );
-
-        Locale locale = context.getLocale();
-        String title = i18n.getString( "site-plugin", locale, "report.index.title" ).trim() + " " + project.getName();
-
-        sink.head();
-        sink.title();
-        sink.text( title );
-        sink.title_();
-        sink.head_();
-
-        sink.body();
-
-        sink.section1();
-        sink.sectionTitle1();
-        sink.text( title );
-        sink.sectionTitle1_();
-
-        sink.paragraph();
-        if ( project.getDescription() != null )
-        {
-            // TODO How to handle i18n?
-            sink.text( project.getDescription() );
-        }
-        else
-        {
-            sink.text( i18n.getString( "site-plugin", locale, "report.index.nodescription" ) );
-        }
-        sink.paragraph_();
-        sink.section1_();
-
-        sink.body_();
-
-        sink.flush();
-
-        sink.close();
-
-        File outputFile = new File( outputDirectory, outputFileName );
-
-        siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
-                                       sink, context );
-    }
-
     // Generate specific pages
 
     /**
@@ -1068,352 +690,6 @@
             }
         }
         return generatedReportsFileName;
-    }
-
-    /**
-     * Generates Project Info Page
-     *
-     * @param projectInfos    list of projectInfos
-     * @param outputDirectory directory that will contain the generated project info page
-     */
-    private void generateProjectInfoPage( List projectInfos, File outputDirectory, SiteRenderingContext context )
-        throws RendererException, IOException
-    {
-        String outputFileName = "project-info.html";
-
-        SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName );
-
-        Locale locale = context.getLocale();
-        String title = i18n.getString( "site-plugin", locale, "report.information.title" );
-
-        sink.head();
-        sink.title();
-        sink.text( title );
-        sink.title_();
-        sink.head_();
-        sink.body();
-
-        sink.section1();
-        sink.sectionTitle1();
-        sink.text( title );
-        sink.sectionTitle1_();
-
-        sink.paragraph();
-        sink.text( i18n.getString( "site-plugin", locale, "report.information.description1" ) + " " );
-        sink.link( "http://maven.apache.org" );
-        sink.text( "Maven" );
-        sink.link_();
-        sink.text( " " + i18n.getString( "site-plugin", locale, "report.information.description2" ) );
-        sink.paragraph_();
-
-        sink.section2();
-
-        sink.sectionTitle2();
-        sink.text( i18n.getString( "site-plugin", locale, "report.information.sectionTitle" ) );
-        sink.sectionTitle2_();
-
-        sink.table();
-
-        sink.tableRow();
-        sink.tableHeaderCell();
-        sink.text( i18n.getString( "site-plugin", locale, "report.information.column.document" ) );
-        sink.tableHeaderCell_();
-        sink.tableHeaderCell();
-        sink.text( i18n.getString( "site-plugin", locale, "report.information.column.description" ) );
-        sink.tableHeaderCell_();
-        sink.tableRow_();
-
-        for ( Iterator i = projectInfos.iterator(); i.hasNext(); )
-        {
-            MavenReport report = (MavenReport) i.next();
-
-            sink.tableRow();
-            sink.tableCell();
-            sink.link( report.getOutputName() + ".html" );
-            sink.text( report.getName( locale ) );
-            sink.link_();
-            sink.tableCell_();
-            sink.tableCell();
-            sink.text( report.getDescription( locale ) );
-            sink.tableCell_();
-            sink.tableRow_();
-        }
-
-        sink.table_();
-
-        sink.section2_();
-
-        sink.section1_();
-
-        sink.body_();
-
-        sink.flush();
-
-        sink.close();
-
-        File outputFile = new File( outputDirectory, outputFileName );
-
-        siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
-                                       sink, context );
-    }
-
-    /**
-     * Generates the Project Report Pages
-     *
-     * @param projectReports  list of project reports
-     * @param outputDirectory directory that will contain the generated project report pages
-     */
-    private void generateProjectReportsPage( List projectReports, File outputDirectory, SiteRenderingContext context )
-        throws RendererException, IOException
-    {
-        String outputFileName = "maven-reports.html";
-
-        SiteRendererSink sink = siteRenderer.createSink( siteDirectory, outputFileName );
-
-        Locale locale = context.getLocale();
-        String title = i18n.getString( "site-plugin", locale, "report.project.title" );
-
-        sink.head();
-        sink.title();
-        sink.text( title );
-        sink.title_();
-        sink.head_();
-        sink.body();
-
-        sink.section1();
-        sink.sectionTitle1();
-        sink.text( title );
-        sink.sectionTitle1_();
-
-        sink.paragraph();
-        sink.text( i18n.getString( "site-plugin", locale, "report.project.description1" ) + " " );
-        sink.link( "http://maven.apache.org" );
-        sink.text( "Maven" );
-        sink.link_();
-        sink.text( ". " + i18n.getString( "site-plugin", locale, "report.project.description2" ) );
-        sink.paragraph_();
-
-        sink.section2();
-
-        sink.sectionTitle2();
-        sink.text( i18n.getString( "site-plugin", locale, "report.project.sectionTitle" ) );
-        sink.sectionTitle2_();
-
-        sink.table();
-
-        sink.tableRow();
-        sink.tableHeaderCell();
-        sink.text( i18n.getString( "site-plugin", locale, "report.project.column.document" ) );
-        sink.tableHeaderCell_();
-        sink.tableHeaderCell();
-        sink.text( i18n.getString( "site-plugin", locale, "report.project.column.description" ) );
-        sink.tableHeaderCell_();
-        sink.tableRow_();
-
-        for ( Iterator i = projectReports.iterator(); i.hasNext(); )
-        {
-            MavenReport report = (MavenReport) i.next();
-
-            sink.tableRow();
-            sink.tableCell();
-            sink.link( report.getOutputName() + ".html" );
-            sink.text( report.getName( locale ) );
-            sink.link_();
-            sink.tableCell_();
-            sink.tableCell();
-            sink.text( report.getDescription( locale ) );
-            sink.tableCell_();
-            sink.tableRow_();
-        }
-
-        sink.table_();
-
-        sink.section2_();
-
-        sink.section1_();
-
-        sink.body_();
-
-        File outputFile = new File( outputDirectory, outputFileName );
-
-        siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
-                                       sink, context );
-    }
-
-    /**
-     * Copy Resources
-     *
-     * @param outputDir the output directory
-     * @param skinFile
-     * @throws IOException if any
-     * @todo move to skin functionality in site renderer
-     */
-    private void copyResources( File outputDir, File skinFile )
-        throws IOException
-    {
-        InputStream resourceList = getStream( RESOURCE_DIR + "/resources.txt" );
-
-        if ( resourceList != 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();
-            }
-        }
-
-        // TODO: plexus-archiver, if it could do the excludes
-        ZipFile file = new ZipFile( skinFile );
-        try
-        {
-            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();
-                    }
-                }
-            }
-        }
-        finally
-        {
-            file.close();
-        }
-    }
-
-    private File getSkinArtifactFile( DecorationModel decoration )
-        throws MojoFailureException, MojoExecutionException
-    {
-        Skin skin = decoration.getSkin();
-
-        if ( skin == null )
-        {
-            skin = Skin.getDefaultSkin();
-        }
-
-        String version = skin.getVersion();
-        Artifact artifact;
-        try
-        {
-            if ( version == null )
-            {
-                version = Artifact.RELEASE_VERSION;
-            }
-            VersionRange versionSpec = VersionRange.createFromVersionSpec( version );
-            artifact = artifactFactory.createDependencyArtifact( skin.getGroupId(), skin.getArtifactId(), versionSpec,
-                                                                 "jar", null, null );
-
-            artifactResolver.resolve( artifact, repositories, localRepository );
-        }
-        catch ( InvalidVersionSpecificationException e )
-        {
-            throw new MojoFailureException( "The skin version '" + version + "' is not valid: " + e.getMessage() );
-        }
-        catch ( ArtifactResolutionException e )
-        {
-            throw new MojoExecutionException( "Unable to find skin", e );
-        }
-        catch ( ArtifactNotFoundException e )
-        {
-            throw new MojoFailureException( "The skin does not exist: " + e.getMessage() );
-        }
-
-        return artifact.getFile();
-    }
-
-    /**
-     * 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 IOException if any
-     */
-    private void copyDirectory( File source, File destination )
-        throws IOException
-    {
-        if ( source.exists() )
-        {
-            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 );
-            }
-        }
     }
 
     private File getOutputDirectory( Locale locale, Locale defaultLocale )

Added: 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=384800&view=auto
==============================================================================
--- 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/SiteRunMojo.java Fri Mar 10 06:20:04 2006
@@ -0,0 +1,198 @@
+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.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;
+import org.codehaus.plexus.util.IOUtil;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.NotFoundHandler;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Start the site up, rendering documents as requested for fast editing.
+ *
+ * @author <a href="mailto:brett@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ * @goal run
+ */
+public class SiteRunMojo
+    extends AbstractSiteMojo
+{
+    /**
+     * Where to create the dummy web application.
+     *
+     * @parameter expression="${project.build.directory}/site-webapp"
+     */
+    private File tempWebappDirectory;
+
+    /**
+     * The port to execute the HTTP server on.
+     *
+     * @parameter expression="${port}" default-value="8080"
+     */
+    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()
+        throws MojoExecutionException, MojoFailureException
+    {
+        Server server = new Server();
+        server.setStopAtShutdown( true );
+
+        Connector defaultConnector = getDefaultConnector();
+        server.setConnectors( new Connector[]{defaultConnector} );
+
+        WebAppContext webapp = createWebApplication();
+        webapp.setServer( server );
+
+        NotFoundHandler notFoundHandler = new NotFoundHandler();
+        notFoundHandler.setServer( server );
+
+        Handler[] handlers = new Handler[2];
+        handlers[0] = webapp;
+        handlers[1] = notFoundHandler;
+        server.setHandlers( handlers );
+
+        getLog().info( "Starting Jetty on http://localhost:8080/" );
+        try
+        {
+            server.start();
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Error executing Jetty", e );
+        }
+
+        // Watch it
+        try
+        {
+            server.getThreadPool().join();
+        }
+        catch ( InterruptedException e )
+        {
+            getLog().warn( "Jetty was interrupted", e );
+        }
+    }
+
+    private WebAppContext createWebApplication()
+        throws MojoExecutionException, MojoFailureException
+    {
+        File webXml = new File( tempWebappDirectory, "WEB-INF/web.xml" );
+        webXml.getParentFile().mkdirs();
+
+        InputStream inStream = null;
+        FileOutputStream outStream = null;
+        try
+        {
+            inStream = getClass().getResourceAsStream( "/webapp/web.xml" );
+            outStream = new FileOutputStream( webXml );
+            IOUtil.copy( inStream, outStream );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new MojoExecutionException( "Unable to construct temporary webapp for running site", e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Unable to construct temporary webapp for running site", e );
+        }
+        finally
+        {
+            IOUtil.close( outStream );
+            IOUtil.close( inStream );
+        }
+
+        WebAppContext webapp = new WebAppContext();
+        webapp.setContextPath( "/" );
+        webapp.setResourceBase( tempWebappDirectory.getAbsolutePath() );
+        webapp.setAttribute( "siteDirectory", siteDirectory );
+        webapp.setAttribute( "siteRenderer", siteRenderer );
+
+        // TODO fix
+        Map props = new HashMap();
+        props.put( "reports", "" );
+        props.put( "modules", "" );
+        DecorationModel decorationModel = getDecorationModel( project, Locale.getDefault(), props );
+
+        try
+        {
+            File skinArtifactFile = getSkinArtifactFile( decorationModel );
+
+            SiteRenderingContext context =
+                createSiteRenderingContext( skinArtifactFile, Locale.getDefault(), decorationModel );
+
+
+            copyResources( tempWebappDirectory, skinArtifactFile );
+
+            // Copy site resources
+            if ( resourcesDirectory != null && resourcesDirectory.exists() )
+            {
+                copyDirectory( resourcesDirectory, tempWebappDirectory );
+            }
+
+            webapp.setAttribute( "context", context );
+        }
+        catch ( IOException e )
+        {
+            // TODO
+        }
+        return webapp;
+    }
+
+    private Connector getDefaultConnector()
+    {
+        Connector connector = new SelectChannelConnector();
+        connector.setPort( port );
+        connector.setMaxIdleTime( MAX_IDLE_TIME );
+        return connector;
+    }
+
+    public void setTempWebappDirectory( File tempWebappDirectory )
+    {
+        this.tempWebappDirectory = tempWebappDirectory;
+    }
+
+    public void setPort( int port )
+    {
+        this.port = port;
+    }
+}

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

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

Added: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/DoxiaFilter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/DoxiaFilter.java?rev=384800&view=auto
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/DoxiaFilter.java (added)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/webapp/DoxiaFilter.java Fri Mar 10 06:20:04 2006
@@ -0,0 +1,133 @@
+package org.apache.maven.plugins.site.webapp;
+
+/*
+ * Copyright 2006 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.doxia.siterenderer.Renderer;
+import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Render a page as requested.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public class DoxiaFilter
+    implements Filter
+{
+    private File siteDirectory;
+
+    private Renderer siteRenderer;
+
+    private SiteRenderingContext context;
+
+    public void init( FilterConfig filterConfig )
+        throws ServletException
+    {
+        ServletContext servletContext = filterConfig.getServletContext();
+        siteDirectory = (File) servletContext.getAttribute( "siteDirectory" );
+        siteRenderer = (Renderer) servletContext.getAttribute( "siteRenderer" );
+        context = (SiteRenderingContext) servletContext.getAttribute( "context" );
+    }
+
+    public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain )
+        throws IOException, ServletException
+    {
+        HttpServletRequest req = (HttpServletRequest) servletRequest;
+        String path = req.getServletPath();
+
+        if ( "/index.html".equals( path ) )
+        {
+/*
+            // TODO
+            context.setLocale( req.getLocale() );
+
+            SiteRendererSink sink = null;
+            try
+            {
+                sink = siteRenderer.createSink( siteDirectory, "index.html" );
+            }
+            catch ( RendererException e )
+            {
+                // TODO
+            }
+
+            Locale locale = context.getLocale();
+            String title = i18n.getString( "site-plugin", locale, "report.index.title" ).trim() + " " + project.getName();
+            String title = "title";
+
+            sink.head();
+            sink.title();
+            sink.text( title );
+            sink.title_();
+            sink.head_();
+            sink.body();
+
+            sink.section1();
+            sink.sectionTitle1();
+            sink.text( title );
+            sink.sectionTitle1_();
+
+            sink.paragraph();
+
+            if ( project.getDescription() != null )
+            {
+                // TODO How to handle i18n?
+                sink.text( project.getDescription() );
+            }
+            else
+            {
+                sink.text( i18n.getString( "site-plugin", locale, "report.index.nodescription" ) );
+            }
+
+            sink.paragraph_();
+
+            sink.body_();
+
+            sink.flush();
+
+            sink.close();
+
+            try
+            {
+                siteRenderer.generateDocument( servletResponse.getWriter(), sink, context );
+            }
+            catch ( RendererException e )
+            {
+                throw new ServletException( e );
+            }
+*/
+        }
+        else
+        {
+            filterChain.doFilter( servletRequest, servletResponse );
+        }
+    }
+
+    public void destroy()
+    {
+    }
+}

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

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

Modified: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/site-plugin.properties
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/site-plugin.properties?rev=384800&r1=384789&r2=384800&view=diff
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/site-plugin.properties (original)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/site-plugin.properties Fri Mar 10 06:20:04 2006
@@ -17,23 +17,6 @@
 template.lastpublished=Last Published
 template.version=Version
 template.builtby=Built by
-report.project.title=Maven Generated Reports
-report.project.description1=This document provides an overview of the various reports that are automatically generated by
-report.project.description2=Each report is briefly described below.
-report.project.sectionTitle=Overview
-report.project.column.description=Description
-report.project.column.document=Document
-report.information.title=General Project Information
-report.information.description1=This document provides an overview of the various documents and links that are part of this project's general information. All of this content is automatically generated by
-report.information.description2=on behalf of the project.
-report.information.sectionTitle=Overview
-report.information.column.description=Description
-report.information.column.document=Document
 report.menu.projectdocumentation=Project Documentation
 report.menu.parentproject=Parent Project
 report.menu.projectmodules=Modules
-report.menu.about=About
-report.menu.projectinformation=Project Info
-report.menu.projectreports=Project Reports
-report.index.title=Welcome to
-report.index.nodescription=There is currently no description associated with this project.

Added: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml?rev=384800&view=auto
==============================================================================
--- maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml (added)
+++ maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml Fri Mar 10 06:20:04 2006
@@ -0,0 +1,23 @@
+<!DOCTYPE web-app PUBLIC
+    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+  <context-param>
+    <param-name>foo</param-name>
+    <param-value>bar</param-value>
+  </context-param>
+  <filter>
+    <filter-name>doxia</filter-name>
+    <filter-class>org.apache.maven.plugins.site.webapp.DoxiaFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>doxia</filter-name>
+    <url-pattern>*.html</url-pattern>
+  </filter-mapping>
+
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+</web-app>

Propchange: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/branches/site-refactor/maven-site-plugin/src/main/resources/webapp/web.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message