maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r780233 - in /maven/plugins/trunk/maven-pdf-plugin: ./ src/main/java/org/apache/maven/plugins/pdf/ src/test/java/org/apache/maven/plugins/pdf/stubs/ src/test/resources/unit/pdf/
Date Sat, 30 May 2009 10:59:11 GMT
Author: vsiveton
Date: Sat May 30 10:59:10 2009
New Revision: 780233

URL: http://svn.apache.org/viewvc?rev=780233&view=rev
Log:
MPDF-13: Copy resources from skin artifact

o added site renderer dependency to copy resources from skin jar
o updated test cases

Added:
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
  (with props)
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
  (with props)
Modified:
    maven/plugins/trunk/maven-pdf-plugin/pom.xml
    maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
    maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom.xml
    maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml

Modified: maven/plugins/trunk/maven-pdf-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/pom.xml?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/pom.xml Sat May 30 10:59:10 2009
@@ -114,7 +114,37 @@
     <dependency>
       <groupId>org.apache.maven.doxia</groupId>
       <artifactId>doxia-doc-renderer</artifactId>
-      <version>${doxia.version}</version>
+      <version>${doxiaSitetoolsVersion}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-component-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-decoration-model</artifactId>
+      <version>${doxiaSitetoolsVersion}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-component-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.doxia</groupId>
+      <artifactId>doxia-site-renderer</artifactId>
+      <version>${doxiaSitetoolsVersion}</version>
       <exclusions>
         <exclusion>
           <groupId>org.codehaus.plexus</groupId>
@@ -179,6 +209,7 @@
 
   <properties>
     <doxia.version>1.1.1-SNAPSHOT</doxia.version>
+    <doxiaSitetoolsVersion>1.1.1-SNAPSHOT</doxiaSitetoolsVersion>
     <maven.version>2.0.6</maven.version>
   </properties>
 

Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
(original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
Sat May 30 10:59:10 2009
@@ -35,6 +35,7 @@
 import java.util.Properties;
 import java.util.TimeZone;
 
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.docrenderer.DocumentRenderer;
 import org.apache.maven.doxia.docrenderer.DocumentRendererException;
 import org.apache.maven.doxia.docrenderer.pdf.PdfRenderer;
@@ -49,6 +50,8 @@
 import org.apache.maven.doxia.site.decoration.Menu;
 import org.apache.maven.doxia.site.decoration.MenuItem;
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.doxia.tools.SiteToolException;
 
 import org.apache.maven.plugin.MojoExecutionException;
@@ -126,6 +129,13 @@
      */
     private String implementation;
 
+    /**
+     * The local repository.
+     *
+     * @parameter expression="${localRepository}"
+     */
+    private ArtifactRepository localRepository;
+
     // ----------------------------------------------------------------------
     // Mojo components
     // ----------------------------------------------------------------------
@@ -145,6 +155,13 @@
     private PdfRenderer itextRenderer;
 
     /**
+     * Site renderer.
+     *
+     * @component
+     */
+    private Renderer siteRenderer;
+
+    /**
      * Document Renderer.
      */
     private DocumentRenderer docRenderer;
@@ -186,7 +203,6 @@
 
             // Default is first in the list
             Locale defaultLocale = (Locale) localesList.get( 0 );
-
             Locale.setDefault( defaultLocale );
 
             for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
@@ -196,12 +212,14 @@
                 File outputDir = getOutputDirectory( locale, defaultLocale );
 
                 File siteDirectoryFile = siteDirectory;
-
                 if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
                 {
                     siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
                 }
 
+                // Copy extra-resources
+                copyResources( locale );
+
                 docRenderer.render( siteDirectoryFile, outputDir, getDocumentModel() );
             }
         }
@@ -441,6 +459,61 @@
     }
 
     /**
+     * Parse the decoration model to find the skin artifact and copy its resources to the
output dir.
+     *
+     * @param locale not null
+     * @throws MojoExecutionException if any
+     * @see #getDefaultDecorationModel()
+     */
+    private void copyResources( Locale locale )
+        throws MojoExecutionException
+    {
+        DecorationModel decorationModel = getDefaultDecorationModel();
+
+        File skinFile;
+        try
+        {
+            skinFile =
+                getSiteTool().getSkinArtifactFromRepository( localRepository,
+                                                             project.getRemoteArtifactRepositories(),
+                                                             decorationModel ).getFile();
+        }
+        catch ( SiteToolException e )
+        {
+            throw new MojoExecutionException( "SiteToolException: " + e.getMessage(), e );
+        }
+
+        if ( skinFile == null )
+        {
+            return;
+        }
+
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "Copy resources from skin artifact: '" + skinFile + "'..." );
+        }
+
+        try
+        {
+            SiteRenderingContext context =
+                siteRenderer.createContextForSkin( skinFile, new HashMap(), decorationModel,
project.getName(),
+                                                   locale );
+            context.addSiteDirectory( new File( siteDirectory, locale.getLanguage() ) );
+
+            for ( Iterator i = context.getSiteDirectories().iterator(); i.hasNext(); )
+            {
+                File siteDirectoryFile = (File) i.next();
+
+                siteRenderer.copyResources( context, new File( siteDirectoryFile, "resources"
), outputDirectory );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "IOException: " + e.getMessage(), e );
+        }
+    }
+
+    /**
      * Read and filter the <code>docDescriptor</code> file.
      *
      * @param project not null

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
(original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/DefaultMavenProjectStub.java
Sat May 30 10:59:10 2009
@@ -21,9 +21,12 @@
 
 import java.io.File;
 import java.io.FileReader;
+import java.util.Collections;
 import java.util.List;
-import java.util.Properties;
 
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
@@ -40,7 +43,7 @@
         MavenXpp3Reader pomReader = new MavenXpp3Reader();
         try
         {
-            Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom_filtering.xml"
) ) );
+            Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom.xml"
) ) );
             setModel( model );
         }
         catch ( Exception e )
@@ -56,26 +59,18 @@
     }
 
     /** {@inheritDoc} */
-    public String getVersion()
-    {
-        return getModel().getVersion();
-    }
-
-    /** {@inheritDoc} */
     public File getBasedir()
     {
         return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
     }
 
     /** {@inheritDoc} */
-    public List getDevelopers()
+    public List getRemoteArtifactRepositories()
     {
-        return getModel().getDevelopers();
-    }
+        ArtifactRepository repository =
+            new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
+                                           new DefaultRepositoryLayout() );
 
-    /** {@inheritDoc} */
-    public Properties getProperties()
-    {
-        return getModel().getProperties();
+        return Collections.singletonList( repository );
     }
 }

Added: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java?rev=780233&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
(added)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
Sat May 30 10:59:10 2009
@@ -0,0 +1,95 @@
+package org.apache.maven.plugins.pdf.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class FilteringMavenProjectStub
+    extends MavenProjectStub
+{
+    public FilteringMavenProjectStub()
+    {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        try
+        {
+            Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom_filtering.xml"
) ) );
+            setModel( model );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getName()
+    {
+        return getModel().getName();
+    }
+
+    /** {@inheritDoc} */
+    public String getVersion()
+    {
+        return getModel().getVersion();
+    }
+
+    /** {@inheritDoc} */
+    public File getBasedir()
+    {
+        return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+    }
+
+    /** {@inheritDoc} */
+    public List getDevelopers()
+    {
+        return getModel().getDevelopers();
+    }
+
+    /** {@inheritDoc} */
+    public Properties getProperties()
+    {
+        return getModel().getProperties();
+    }
+
+    /** {@inheritDoc} */
+    public List getRemoteArtifactRepositories()
+    {
+        ArtifactRepository repository =
+            new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
+                                           new DefaultRepositoryLayout() );
+
+        return Collections.singletonList( repository );
+    }
+}

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java?rev=780233&view=auto
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
(added)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
Sat May 30 10:59:10 2009
@@ -0,0 +1,70 @@
+package org.apache.maven.plugins.pdf.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class ITextMavenProjectStub
+    extends MavenProjectStub
+{
+    public ITextMavenProjectStub()
+    {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        try
+        {
+            Model model = pomReader.read( new FileReader( new File( getBasedir() + "/iText_pom.xml"
) ) );
+            setModel( model );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
+    /** {@inheritDoc} */
+    public File getBasedir()
+    {
+        return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+    }
+
+    /** {@inheritDoc} */
+    public List getRemoteArtifactRepositories()
+    {
+        ArtifactRepository repository =
+            new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
+                                           new DefaultRepositoryLayout() );
+
+        return Collections.singletonList( repository );
+    }
+}

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml Sat May
30 10:59:10 2009
@@ -27,6 +27,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pdf-plugin</artifactId>
         <configuration>
+          <project implementation="org.apache.maven.plugins.pdf.stubs.ITextMavenProjectStub"/>
+          <localRepository>${localRepository}</localRepository>
           <docDescriptor>${basedir}/target/test-classes/unit/pdf/src/site/pdf.xml</docDescriptor>
           <siteDirectory>${basedir}/target/test-classes/unit/pdf/src/site/</siteDirectory>
           <outputDirectory>${basedir}/target/test-output/pdf</outputDirectory>

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom.xml?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom.xml Sat May 30 10:59:10
2009
@@ -27,6 +27,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pdf-plugin</artifactId>
         <configuration>
+          <project implementation="org.apache.maven.plugins.pdf.stubs.DefaultMavenProjectStub"/>
+          <localRepository>${localRepository}</localRepository>
           <docDescriptor>${basedir}/target/test-classes/unit/pdf/src/site/pdf.xml</docDescriptor>
           <siteDirectory>${basedir}/target/test-classes/unit/pdf/src/site/</siteDirectory>
           <outputDirectory>${basedir}/target/test-output/pdf</outputDirectory>

Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml?rev=780233&r1=780232&r2=780233&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/resources/unit/pdf/pom_filtering.xml Sat
May 30 10:59:10 2009
@@ -54,7 +54,8 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-pdf-plugin</artifactId>
         <configuration>
-          <project implementation="org.apache.maven.plugins.pdf.stubs.DefaultMavenProjectStub"/>
+          <project implementation="org.apache.maven.plugins.pdf.stubs.FilteringMavenProjectStub"/>
+          <localRepository>${localRepository}</localRepository>
           <docDescriptor>${basedir}/target/test-classes/unit/pdf/src/site/pdf_filtering.xml</docDescriptor>
           <siteDirectory>${basedir}/target/test-classes/unit/pdf/src/site/</siteDirectory>
           <outputDirectory>${basedir}/target/test-output/pdf</outputDirectory>



Mime
View raw message