You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by lt...@apache.org on 2007/10/09 22:25:08 UTC
svn commit: r583290 - in /maven/sandbox/trunk/plugins/maven-pdf-plugin: ./
src/main/java/org/apache/maven/plugins/pdf/
src/main/java/org/apache/maven/plugins/pdf/renderer/
src/main/resources/META-INF/plexus/
src/test/java/org/apache/maven/plugins/pdf/ ...
Author: ltheussl
Date: Tue Oct 9 13:25:08 2007
New Revision: 583290
URL: http://svn.apache.org/viewvc?rev=583290&view=rev
Log:
Adjust to changes in docrenderer. Use the PdfRenderer from there. Make it configurable whether to use fo or itext. There is a problem with the logger throwing a NPE when run from the cl, needs fixing.
Added:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml (with props)
Removed:
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/renderer/
Modified:
maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/resources/META-INF/plexus/components.xml
maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml?rev=583290&r1=583289&r2=583290&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml Tue Oct 9 13:25:08 2007
@@ -67,6 +67,11 @@
<version>1.4.5</version>
</dependency>
<dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-i18n</artifactId>
+ <version>1.0-beta-7</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-doc-renderer</artifactId>
<version>1.0-beta-1-SNAPSHOT</version>
Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java?rev=583290&r1=583289&r2=583290&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/AbstractPdfMojo.java Tue Oct 9 13:25:08 2007
@@ -57,7 +57,7 @@
*
* @component
*/
- protected I18N i18n;
+ private I18N i18n;
/**
* Init the <code>localesList</code> variable.
Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java?rev=583290&r1=583289&r2=583290&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java Tue Oct 9 13:25:08 2007
@@ -25,8 +25,9 @@
import java.util.List;
import java.util.Locale;
-import org.apache.maven.doxia.docrenderer.DocRenderer;
-import org.apache.maven.doxia.docrenderer.DocRendererException;
+import org.apache.maven.doxia.docrenderer.DocumentRenderer;
+import org.apache.maven.doxia.docrenderer.DocumentRendererException;
+import org.apache.maven.doxia.docrenderer.document.DocumentModel;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -47,7 +48,7 @@
* @parameter expression="${basedir}/src/site"
* @required
*/
- protected File siteDirectory;
+ private File siteDirectory;
/**
* Directory containing the generated project sites and report distributions.
@@ -55,33 +56,69 @@
* @parameter alias="workingDirectory" expression="${project.build.directory}/pdf"
* @required
*/
- protected File outputDirectory;
+ private File outputDirectory;
/**
* File that contains the DocumentModel of the PDF to generate.
*
* @parameter expression="src/site/pdf.xml"
* @required
+ * @todo shouldn't be required, construct info from pom
*/
- protected File docDescriptor;
+ private File docDescriptor;
/**
- * Document Renderer.
+ * Identifies the framework to use for pdf generation: either "fo" (default) or "itext".
+ *
+ * @parameter expression="fo"
+ * @required
+ */
+ private String implementation = "fo";
+
+ /**
+ * FO Document Renderer.
+ *
+ * @component role-hint="fo"
+ */
+ private DocumentRenderer foRenderer;
+
+ /**
+ * IText Document Renderer.
*
- * @component
+ * @component role-hint="itext"
+ */
+ private DocumentRenderer itextRenderer;
+
+
+ /**
+ * Document Renderer.
*/
- private DocRenderer docRenderer;
+ private DocumentRenderer docRenderer;
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException, MojoFailureException
{
+ if ( "fo".equals( implementation ) )
+ {
+ this.docRenderer = foRenderer;
+ }
+ else if ( "itext".equals( implementation ) )
+ {
+ this.docRenderer = itextRenderer;
+ }
+ else
+ {
+ throw new MojoFailureException( "Not a valid implementation: " + implementation );
+ }
+
try
{
List localesList = initLocalesList();
// Default is first in the list
Locale defaultLocale = (Locale) localesList.get( 0 );
+
Locale.setDefault( defaultLocale );
for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
@@ -90,7 +127,6 @@
File outputDir = getOutputDirectory( locale, defaultLocale );
- // Generate static site
File siteDirectoryFile = siteDirectory;
if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
@@ -98,10 +134,10 @@
siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
}
- docRenderer.render( siteDirectoryFile, outputDir, docDescriptor );
+ docRenderer.render( siteDirectoryFile, outputDir, getDocumentModel() );
}
}
- catch ( DocRendererException e )
+ catch ( DocumentRendererException e )
{
throw new MojoExecutionException( "Error during document generation", e );
}
@@ -111,7 +147,29 @@
}
}
- // TODO: can be re-used
+ /**
+ * Constructs a DocumentModel for the current project. The model is either read from
+ * a descriptor file, if it exists, or constructed from information in the pom and site.xml.
+ *
+ * @return DocumentModel.
+ * @throws DocumentRendererException if any.
+ * @throws IOException if any.
+ */
+ private DocumentModel getDocumentModel()
+ throws DocumentRendererException, IOException
+ {
+ // TODO: check if exists, construct from pom if not
+ return docRenderer.readDocumentModel( docDescriptor );
+ }
+
+ /**
+ * Return the output directory for a given Locale and the current default Locale.
+ *
+ * @param locale a Locale.
+ * @param defaultLocale the current default Locale.
+ * @return File.
+ * @todo can be re-used
+ */
private File getOutputDirectory( Locale locale, Locale defaultLocale )
{
File file;
Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/resources/META-INF/plexus/components.xml?rev=583290&r1=583289&r2=583290&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/main/resources/META-INF/plexus/components.xml Tue Oct 9 13:25:08 2007
@@ -3,8 +3,25 @@
<components>
<component>
- <role>org.apache.maven.doxia.docrenderer.DocRenderer</role>
- <implementation>org.apache.maven.plugins.pdf.renderer.DefaultPdfRenderer</implementation>
+ <role>org.apache.maven.doxia.docrenderer.DocumentRenderer</role>
+ <role-hint>fo</role-hint>
+ <implementation>org.apache.maven.doxia.docrenderer.pdf.fo.FoPdfRenderer</implementation>
+ <requirements>
+ <requirement>
+ <role>org.apache.maven.doxia.module.site.manager.SiteModuleManager</role>
+ <field-name>siteModuleManager</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.doxia.Doxia</role>
+ <field-name>doxia</field-name>
+ </requirement>
+ </requirements>
+ </component>
+
+ <component>
+ <role>org.apache.maven.doxia.docrenderer.DocumentRenderer</role>
+ <role-hint>itext</role-hint>
+ <implementation>org.apache.maven.doxia.docrenderer.pdf.itext.ITextPdfRenderer</implementation>
<requirements>
<requirement>
<role>org.apache.maven.doxia.module.site.manager.SiteModuleManager</role>
Modified: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java?rev=583290&r1=583289&r2=583290&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/PdfMojoTest.java Tue Oct 9 13:25:08 2007
@@ -38,7 +38,7 @@
}
/**
- * Tests the basic functioning of the pdf generation.
+ * Tests the basic functioning of the pdf generation using the FO implementation.
*
* @throws Exception if any.
*/
@@ -65,4 +65,40 @@
assertTrue( "Pdf file has no content!", pdfFile.length() > 0 );
}
+
+ /**
+ * Tests the basic functioning of the pdf generation with iText.
+ *
+ * @throws Exception if any.
+ */
+ public void testITextImpl() throws Exception
+ {
+ File testPom = new File( getBasedir(), "/target/test-classes/unit/pdf/iText_pom.xml" );
+
+ assertTrue( "testPom does not exist!", testPom.exists() );
+
+ PdfMojo mojo = (PdfMojo) lookupMojo( "pdf", testPom );
+
+ assertNotNull( "pdf mojo not found!", mojo );
+
+ // TODO
+/*
+ File pdfFile = new File( getBasedir(), "/target/test-output/pdf/maven-pdf-plugin-doc.pdf" );
+
+ if ( pdfFile.exists() )
+ {
+ pdfFile.delete();
+ }
+ */
+
+ mojo.execute();
+
+/*
+ assertTrue( "Pdf file not created!", pdfFile.exists() );
+
+ assertTrue( "Pdf file has no content!", pdfFile.length() > 0 );
+ */
+ }
+
+
}
Added: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml?rev=583290&view=auto
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml (added)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml Tue Oct 9 13:25:08 2007
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pdf-plugin</artifactId>
+ <configuration>
+ <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>
+ <implementation>itext</implementation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/sandbox/trunk/plugins/maven-pdf-plugin/src/test/resources/unit/pdf/iText_pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"