You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2008/02/09 13:56:19 UTC
svn commit: r620103 - in /maven/sandbox/trunk/plugins/maven-pdf-plugin:
pom.xml src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
Author: vsiveton
Date: Sat Feb 9 04:56:17 2008
New Revision: 620103
URL: http://svn.apache.org/viewvc?rev=620103&view=rev
Log:
o generated a dynamic docDescriptor from pom if not specified
o updated dependencies
o improved readingness
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/PdfMojo.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=620103&r1=620102&r2=620103&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-pdf-plugin/pom.xml Sat Feb 9 04:56:17 2008
@@ -21,6 +21,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
@@ -60,20 +61,23 @@
</developers>
<dependencies>
+ <!-- maven -->
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
+ <artifactId>maven-project</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>1.4.5</version>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.4</version>
</dependency>
+
+ <!-- doxia -->
<dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-i18n</artifactId>
- <version>1.0-beta-7</version>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-core</artifactId>
+ <version>${doxia.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
@@ -88,7 +92,7 @@
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-doc-renderer</artifactId>
- <version>1.0-beta-1-SNAPSHOT</version>
+ <version>${doxia.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
@@ -100,10 +104,17 @@
</exclusion>
</exclusions>
</dependency>
+
+ <!-- plexus -->
<dependency>
- <groupId>org.apache.maven.doxia</groupId>
- <artifactId>doxia-core</artifactId>
- <version>1.0-beta-1-SNAPSHOT</version>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.4.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-i18n</artifactId>
+ <version>1.0-beta-7</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
@@ -115,6 +126,7 @@
</exclusion>
</exclusions>
</dependency>
+
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
@@ -136,6 +148,10 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <properties>
+ <doxia.version>1.0-beta-1-SNAPSHOT</doxia.version>
+ </properties>
<build>
<plugins>
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=620103&r1=620102&r2=620103&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 Sat Feb 9 04:56:17 2008
@@ -21,19 +21,29 @@
import java.io.File;
import java.io.IOException;
+import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.apache.maven.doxia.docrenderer.DocumentRenderer;
import org.apache.maven.doxia.docrenderer.DocumentRendererException;
+import org.apache.maven.doxia.document.DocumentMeta;
import org.apache.maven.doxia.document.DocumentModel;
+import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
/**
+ * Generates a PDF document for a project.
+ *
* @author ltheussl
* @version $Id$
*
@@ -42,6 +52,19 @@
public class PdfMojo
extends AbstractPdfMojo
{
+ // ----------------------------------------------------------------------
+ // Mojo Parameters
+ // ----------------------------------------------------------------------
+
+ /**
+ * The Maven Project Object.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
/**
* Directory containing source for apt, fml and xdoc docs.
*
@@ -62,8 +85,6 @@
* 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
*/
private File docDescriptor;
@@ -75,6 +96,10 @@
*/
private String implementation = "fo";
+ // ----------------------------------------------------------------------
+ // Mojo components
+ // ----------------------------------------------------------------------
+
/**
* FO Document Renderer.
*
@@ -89,12 +114,15 @@
*/
private DocumentRenderer itextRenderer;
-
/**
* Document Renderer.
*/
private DocumentRenderer docRenderer;
+ // ----------------------------------------------------------------------
+ // Public methods
+ // ----------------------------------------------------------------------
+
/** {@inheritDoc} */
public void execute()
throws MojoExecutionException, MojoFailureException
@@ -147,6 +175,10 @@
}
}
+ // ----------------------------------------------------------------------
+ // Private methods
+ // ----------------------------------------------------------------------
+
/**
* 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.
@@ -158,8 +190,14 @@
private DocumentModel getDocumentModel()
throws DocumentRendererException, IOException
{
- // TODO: check if exists, construct from pom if not
- return docRenderer.readDocumentModel( docDescriptor );
+ if ( docDescriptor.exists() )
+ {
+ return docRenderer.readDocumentModel( docDescriptor );
+ }
+
+ File tmp = generateDefaultDocDescriptor( project );
+
+ return docRenderer.readDocumentModel( tmp );
}
/**
@@ -172,18 +210,60 @@
*/
private File getOutputDirectory( Locale locale, Locale defaultLocale )
{
- File file;
-
if ( locale.getLanguage().equals( defaultLocale.getLanguage() ) )
{
- file = outputDirectory;
+ return outputDirectory;
}
- else
+
+ return new File( outputDirectory, locale.getLanguage() );
+ }
+
+ /**
+ * @param project not null
+ * @return Generate a default document descriptor from the Maven project
+ * @throws IOException if any
+ */
+ private static File generateDefaultDocDescriptor( MavenProject project )
+ throws IOException
+ {
+ File outputDir = new File( project.getBuild().getDirectory(), "pdf" );
+ if ( outputDir.exists() && outputDir.isFile() )
+ {
+ throw new IOException( "The file '" + outputDir + "' should be a dir." );
+ }
+ if ( !outputDir.exists() )
{
- file = new File( outputDirectory, locale.getLanguage() );
+ outputDir.mkdirs();
}
- return file;
- }
+ File doc = FileUtils.createTempFile( "pdf", ".xml", outputDir );
+ doc.deleteOnExit();
+ DocumentMeta meta = new DocumentMeta(); // TODO Improve metadata
+ meta.setAuthor( ( project.getOrganization() != null
+ && StringUtils.isNotEmpty( project.getOrganization().getName() ) ? project.getOrganization().getName()
+ : System.getProperty( "user.name" ) ) );
+ meta.setTitle( ( StringUtils.isEmpty( project.getName() ) ? project.getGroupId() + ":"
+ + project.getArtifactId() : project.getName() ) );
+
+ DocumentModel docModel = new DocumentModel();
+ docModel.setModelEncoding( ( StringUtils.isEmpty( project.getModel().getModelEncoding() ) ? "UTF-8" : project
+ .getModel().getModelEncoding() ) );
+ docModel.setOutputName( project.getArtifactId() + "-doc" );
+ docModel.setMeta( meta );
+
+ DocumentXpp3Writer xpp3 = new DocumentXpp3Writer();
+ Writer w = null;
+ try
+ {
+ w = WriterFactory.newPlatformWriter( doc );
+ xpp3.write( w, docModel );
+ }
+ finally
+ {
+ IOUtil.close( w );
+ }
+
+ return doc;
+ }
}