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 2009/08/11 15:14:33 UTC
svn commit: r803108 - in /maven/plugins/trunk/maven-pdf-plugin: ./
src/main/java/org/apache/maven/plugins/pdf/ src/main/resources/
src/test/java/org/apache/maven/plugins/pdf/stubs/
Author: vsiveton
Date: Tue Aug 11 13:14:33 2009
New Revision: 803108
URL: http://svn.apache.org/viewvc?rev=803108&view=rev
Log:
MPDF-26: Add report generation in PDF
o added 2.1.0 as Maven prerequisites due to LinkageError with mvn 2.0.x
o added new parameter to include Maven reports or not
o updated i18n
o fixed tests to take care of encoding and added workaround for MNG-4289
Modified:
maven/plugins/trunk/maven-pdf-plugin/pom.xml
maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java
maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/PdfMojo.java
maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin.properties
maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_de.properties
maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_fr.properties
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/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java
maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java
maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ModelBuilderMavenProjectStub.java
Modified: maven/plugins/trunk/maven-pdf-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/pom.xml?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-pdf-plugin/pom.xml Tue Aug 11 13:14:33 2009
@@ -59,7 +59,7 @@
</developers>
<prerequisites>
- <maven>2.0.6</maven>
+ <maven>2.1.0</maven>
</prerequisites>
<scm>
@@ -74,7 +74,7 @@
<properties>
<doxiaVersion>1.1.2-SNAPSHOT</doxiaVersion>
- <mavenVersion>2.0.9</mavenVersion>
+ <mavenVersion>2.1.0</mavenVersion>
</properties>
<dependencies>
@@ -91,6 +91,11 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${mavenVersion}</version>
</dependency>
@@ -101,6 +106,11 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-descriptor</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${mavenVersion}</version>
</dependency>
@@ -110,6 +120,16 @@
<version>${mavenVersion}</version>
</dependency>
<dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ <version>2.0.4.2</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-doxia-tools</artifactId>
<version>1.0.2</version>
@@ -118,6 +138,16 @@
<!-- doxia -->
<dependency>
<groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-sink-api</artifactId>
+ <version>${doxiaVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-module-xdoc</artifactId>
+ <version>${doxiaVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>${doxiaVersion}</version>
<exclusions>
@@ -265,36 +295,37 @@
</executions>
</plugin>
<!-- END SNIPPET: configuration -->
- <!-- Backward compatibility with Maven 2.0.x, see MNG-3402 -->
+ <!-- Backward compatibility with Maven 2.0.x, see MNG-3402
+ TODO to be removed. Leaving there only to try to be backward compatible with 2.0.x MPDF-26
<plugin>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <finalName>${project.build.finalName}</finalName>
- <createDependencyReducedPom>
- false
- </createDependencyReducedPom>
- <keepDependenciesWithProvidedScope>
- true
- </keepDependenciesWithProvidedScope>
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
- </transformers>
- <artifactSet>
- <includes>
- <include>org.apache.maven.doxia:doxia-sink-api</include>
- <include>org.apache.maven.doxia:doxia-logging-api</include>
- </includes>
- </artifactSet>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <finalName>${project.build.finalName}</finalName>
+ <createDependencyReducedPom>
+ false
+ </createDependencyReducedPom>
+ <keepDependenciesWithProvidedScope>
+ true
+ </keepDependenciesWithProvidedScope>
+ <transformers>
+ <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
+ </transformers>
+ <artifactSet>
+ <includes>
+ <include>org.apache.maven.doxia:doxia-sink-api</include>
+ <include>org.apache.maven.doxia:doxia-logging-api</include>
+ </includes>
+ </artifactSet>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin> -->
</plugins>
</build>
Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/java/org/apache/maven/plugins/pdf/DocumentModelBuilder.java Tue Aug 11 13:14:33 2009
@@ -20,6 +20,7 @@
*/
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -36,8 +37,10 @@
import org.apache.maven.doxia.site.decoration.MenuItem;
import org.apache.maven.model.Developer;
import org.apache.maven.project.MavenProject;
-
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
/**
* Construct a DocumentModel from a MavenProject and related information.
@@ -313,11 +316,28 @@
return null;
}
- if ( StringUtils.isEmpty( project.getModel().getModelEncoding() ) )
+ String encoding = project.getModel().getModelEncoding();
+ // Workaround for MNG-4289
+ XmlStreamReader reader = null;
+ try
+ {
+ reader = ReaderFactory.newXmlReader( project.getFile() );
+ encoding = reader.getEncoding();
+ }
+ catch ( IOException e )
+ {
+ // nop
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ if ( StringUtils.isEmpty( encoding ) )
{
return "UTF-8";
}
- return project.getModel().getModelEncoding();
+ return encoding;
}
}
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=803108&r1=803107&r2=803108&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 Tue Aug 11 13:14:33 2009
@@ -21,34 +21,69 @@
import java.io.File;
import java.io.IOException;
+import java.io.Reader;
import java.io.StringReader;
+import java.io.StringWriter;
import java.io.Writer;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+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.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.doxia.Doxia;
import org.apache.maven.doxia.docrenderer.AbstractDocumentRenderer;
import org.apache.maven.doxia.docrenderer.DocumentRenderer;
import org.apache.maven.doxia.docrenderer.DocumentRendererContext;
import org.apache.maven.doxia.docrenderer.DocumentRendererException;
import org.apache.maven.doxia.docrenderer.pdf.PdfRenderer;
import org.apache.maven.doxia.document.DocumentModel;
+import org.apache.maven.doxia.document.DocumentTOCItem;
import org.apache.maven.doxia.document.io.xpp3.DocumentXpp3Writer;
+import org.apache.maven.doxia.markup.HtmlMarkup;
+import org.apache.maven.doxia.module.xdoc.XdocSink;
+import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkAdapter;
import org.apache.maven.doxia.site.decoration.DecorationModel;
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.SiteTool;
import org.apache.maven.doxia.tools.SiteToolException;
-
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.MailingList;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.ReportSet;
import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.InvalidPluginException;
+import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.PluginConfigurationException;
+import org.apache.maven.plugin.PluginManager;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.plugin.version.PluginVersionNotFoundException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.AbstractMavenReportRenderer;
+import org.apache.maven.reporting.MavenReport;
+import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.settings.Settings;
-
+import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
@@ -116,6 +151,38 @@
*/
private SiteTool siteTool;
+ /**
+ * The Plugin manager instance used to resolve Plugin descriptors.
+ *
+ * @component role="org.apache.maven.plugin.PluginManager"
+ * @since 1.1
+ */
+ private PluginManager pluginManager;
+
+ /**
+ * Doxia.
+ *
+ * @component
+ * @since 1.1
+ */
+ private Doxia doxia;
+
+ /**
+ * Factory for creating artifact objects.
+ *
+ * @component
+ * @since 1.1
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * Project builder.
+ *
+ * @component
+ * @since 1.1
+ */
+ private MavenProjectBuilder mavenProjectBuilder;
+
// ----------------------------------------------------------------------
// Mojo Parameters
// ----------------------------------------------------------------------
@@ -140,6 +207,16 @@
private Settings settings;
/**
+ * The current build session instance.
+ *
+ * @parameter expression="${session}"
+ * @required
+ * @readonly
+ * @since 1.1
+ */
+ private MavenSession session;
+
+ /**
* Directory containing source for apt, fml and xdoc docs.
*
* @parameter default-value="${basedir}/src/site"
@@ -197,6 +274,14 @@
private ArtifactRepository localRepository;
/**
+ * The remote repositories where artifacts are located.
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @since 1.1
+ */
+ private List remoteRepositories;
+
+ /**
* If <code>true</false>, aggregate all source documents in one pdf, otherwise generate one pdf for each
* source document.
*
@@ -212,34 +297,61 @@
*/
private String pluginVersion;
+ /**
+ * If <code>true</false>, generate all Maven reports defined in <code>${project.reporting}</code> and append
+ * them as a new entry in the Table Of Contents.
+ * <b>Note</b>: Including the report generation could fail the PDF generation.
+ *
+ * @parameter default-value="true"
+ * @since 1.1
+ */
+ private boolean includeReports;
+
// ----------------------------------------------------------------------
// Instance fields
// ----------------------------------------------------------------------
/**
- * Lazy instantiation for document Renderer.
+ * The current document Renderer.
+ * @see #implementation
*/
private DocumentRenderer docRenderer;
/**
- * Lazy instantiation for default locale.
+ * The default locale.
*/
private Locale defaultLocale;
/**
- * Lazy instantiation for available locales list.
+ * The available locales list.
*/
private List localesList;
/**
- * Lazy instantiation for decoration model.
+ * The default decoration model.
*/
private DecorationModel defaultDecorationModel;
/**
- * Lazy instantiation for tmpSite dir to have all site and generated-site files.
+ * The temp Site dir to have all site and generated-site files.
+ *
+ * @since 1.1
+ */
+ private File siteDirectoryTmp;
+
+ /**
+ * The temp Generated Site dir to have generated reports by this plugin.
+ *
+ * @since 1.1
+ */
+ private File generatedSiteDirectoryTmp;
+
+ /**
+ * The generated MavenReport list.
+ *
+ * @since 1.1
*/
- private File tmpSiteDirectory;
+ private List generatedMavenReports;
// ----------------------------------------------------------------------
// Public methods
@@ -249,17 +361,18 @@
public void execute()
throws MojoExecutionException, MojoFailureException
{
- if ( "fo".equals( implementation ) )
+ if ( "fo".equalsIgnoreCase( implementation ) )
{
this.docRenderer = foRenderer;
}
- else if ( "itext".equals( implementation ) )
+ else if ( "itext".equalsIgnoreCase( implementation ) )
{
this.docRenderer = itextRenderer;
}
else
{
- throw new MojoFailureException( "Not a valid implementation: " + implementation );
+ throw new MojoFailureException( "Not a valid implementation: '" + implementation
+ + "'. Should be 'fo' or 'itext'." );
}
try
@@ -276,10 +389,10 @@
if ( !outputDirectory.getCanonicalPath().equals( workingDirectory.getCanonicalPath() ) )
{
String outputName = getDocumentModel( getDefaultLocale() ).getOutputName();
- if ( StringUtils.isNotEmpty( FileUtils.getExtension( outputName ) ) )
+ final String extension = FileUtils.getExtension( outputName );
+ if ( StringUtils.isNotEmpty( extension ) )
{
- outputName =
- outputName.substring( 0, outputName.indexOf( FileUtils.getExtension( outputName ) ) - 1 );
+ outputName = outputName.substring( 0, outputName.indexOf( extension ) - 1 );
}
final List pdfs = FileUtils.getFiles( workingDirectory, "**/" + outputName + ".pdf", null );
@@ -296,13 +409,6 @@
{
throw new MojoExecutionException( "Error copying generated PDF: " + e.getMessage(), e );
}
-
- // safety release instance fields
- docRenderer = null;
- defaultLocale = null;
- localesList = null;
- defaultDecorationModel = null;
- tmpSiteDirectory = null;
}
// ----------------------------------------------------------------------
@@ -327,15 +433,18 @@
final File workingDir = getWorkingDirectory( locale );
- File siteDirectoryFile = getTmpSiteDirectory();
+ File siteDirectoryFile = getSiteDirectoryTmp();
if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
{
- siteDirectoryFile = new File( getTmpSiteDirectory(), locale.getLanguage() );
+ siteDirectoryFile = new File( getSiteDirectoryTmp(), locale.getLanguage() );
}
// Copy extra-resources
copyResources( locale );
+ // generate reports
+ generateMavenReports( locale );
+
DocumentRendererContext context = new DocumentRendererContext();
context.put( "project", project );
context.put( "settings", settings );
@@ -360,7 +469,12 @@
}
catch ( DocumentRendererException e )
{
- throw new MojoExecutionException( "Error during document generation", e );
+ if ( getLog().isDebugEnabled() )
+ {
+ throw new MojoExecutionException( "Error during document generation: " + e.getMessage(), e );
+ }
+
+ throw new MojoExecutionException( "Error during document generation: " + e.getMessage() );
}
}
}
@@ -368,19 +482,34 @@
/**
* @return the default tmpSiteDirectory.
* @throws IOException if any
+ * @since 1.1
*/
- private File getTmpSiteDirectory()
+ private File getSiteDirectoryTmp()
throws IOException
{
- if ( this.tmpSiteDirectory == null )
+ if ( this.siteDirectoryTmp == null )
{
- final File tmpSiteDir = new File( workingDirectory, "tmpsite" );
+ final File tmpSiteDir = new File( workingDirectory, "site.tmp" );
prepareTempSiteDirectory( tmpSiteDir );
- this.tmpSiteDirectory = tmpSiteDir;
+ this.siteDirectoryTmp = tmpSiteDir;
+ }
+
+ return this.siteDirectoryTmp;
+ }
+
+ /**
+ * @return the default tmpGeneratedSiteDirectory when report will be created.
+ * @since 1.1
+ */
+ private File getGeneratedSiteDirectoryTmp()
+ {
+ if ( this.generatedSiteDirectoryTmp == null )
+ {
+ this.generatedSiteDirectoryTmp = new File( workingDirectory, "generated-site.tmp" );
}
- return this.tmpSiteDirectory;
+ return this.generatedSiteDirectoryTmp;
}
/**
@@ -391,6 +520,7 @@
*
* @param tmpSiteDir not null
* @throws IOException if any
+ * @since 1.1
*/
private void prepareTempSiteDirectory( final File tmpSiteDir )
throws IOException
@@ -404,9 +534,9 @@
List files =
FileUtils.getFileAndDirectoryNames( tmpSiteDir, FileUtils.getDefaultExcludesAsString(), null, true,
true, true, true );
- for ( Iterator it = files.iterator(); it.hasNext(); )
+ for ( final Iterator it = files.iterator(); it.hasNext(); )
{
- File file = new File( it.next().toString() );
+ final File file = new File( it.next().toString() );
if ( file.isDirectory() )
{
@@ -418,59 +548,71 @@
}
}
+ copySiteDir( generatedSiteDirectory, tmpSiteDir );
+ }
+
+ /**
+ * Copy the from site dir to the to dir.
+ *
+ * @param from not null
+ * @param to not null
+ * @throws IOException if any
+ * @since 1.1
+ */
+ private void copySiteDir( final File from, final File to )
+ throws IOException
+ {
+ if ( from == null || !from.exists() )
+ {
+ return;
+ }
+
// copy generated-site
- if ( generatedSiteDirectory != null && generatedSiteDirectory.exists() )
+ for ( final Iterator iterator = getAvailableLocales().iterator(); iterator.hasNext(); )
{
- for ( final Iterator iterator = getAvailableLocales().iterator(); iterator.hasNext(); )
+ final Locale locale = (Locale) iterator.next();
+
+ String excludes = getDefaultExcludesWithLocales( getAvailableLocales(), getDefaultLocale() );
+ List siteFiles = FileUtils.getFileNames( siteDirectory, "**/*", excludes, false );
+ if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
{
- final Locale locale = (Locale) iterator.next();
+ siteFiles =
+ FileUtils.getFileNames( new File( siteDirectory, locale.getLanguage() ), "**/*", excludes,
+ false );
+ }
- List siteFiles =
- FileUtils.getFileNames( siteDirectory, "**/*", FileUtils.getDefaultExcludesAsString(), false );
- if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
+ List generatedSiteFiles = FileUtils.getFileNames( from, "**/*", excludes, false );
+ if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
+ {
+ generatedSiteFiles =
+ FileUtils.getFileNames( new File( from, locale.getLanguage() ), "**/*", excludes, false );
+ }
+
+ for ( final Iterator it = generatedSiteFiles.iterator(); it.hasNext(); )
+ {
+ final String generatedSiteFile = it.next().toString();
+
+ if ( siteFiles.contains( generatedSiteFile ) )
{
- siteFiles =
- FileUtils.getFileNames( new File( siteDirectory, locale.getLanguage() ), "**/*",
- FileUtils.getDefaultExcludesAsString(), false );
+ getLog().warn(
+ "Generated-site already contains a file in site: " + generatedSiteFile
+ + ". Ignoring copying it!" );
+ continue;
}
- List generatedSiteFiles =
- FileUtils.getFileNames( generatedSiteDirectory, "**/*",
- FileUtils.getDefaultExcludesAsString(), false );
if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
{
- generatedSiteFiles =
- FileUtils.getFileNames( new File( generatedSiteDirectory, locale.getLanguage() ), "**/*",
- FileUtils.getDefaultExcludesAsString(), false );
+ File in = new File( new File( from, locale.getLanguage() ), generatedSiteFile );
+ File out = new File( new File( to, locale.getLanguage() ), generatedSiteFile );
+ out.getParentFile().mkdirs();
+ FileUtils.copyFile( in, out );
}
-
- for ( final Iterator it = generatedSiteFiles.iterator(); it.hasNext(); )
+ else
{
- String generatedSiteFile = it.next().toString();
-
- if ( siteFiles.contains( generatedSiteFile ) )
- {
- getLog().warn(
- "Generated-site already contains a file in site: " + generatedSiteFile
- + ". Ignoring copying it!" );
- continue;
- }
-
- if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
- {
- File in =
- new File( new File( generatedSiteDirectory, locale.getLanguage() ), generatedSiteFile );
- File out = new File( new File( tmpSiteDir, locale.getLanguage() ), generatedSiteFile );
- out.getParentFile().mkdirs();
- FileUtils.copyFile( in, out );
- }
- else
- {
- File in = new File( generatedSiteDirectory, generatedSiteFile );
- File out = new File( tmpSiteDir, generatedSiteFile );
- out.getParentFile().mkdirs();
- FileUtils.copyFile( in, out );
- }
+ File in = new File( from, generatedSiteFile );
+ File out = new File( to, generatedSiteFile );
+ out.getParentFile().mkdirs();
+ FileUtils.copyFile( in, out );
}
}
}
@@ -483,7 +625,7 @@
* @param locale not null
* @return DocumentModel.
* @throws MojoExecutionException if any
- * @see #readAndFilterDocumentDescriptor(MavenProject, File, Log)
+ * @see #appendGeneratedReports(DocumentModel, Locale)
*/
private DocumentModel getDocumentModel( Locale locale )
throws MojoExecutionException
@@ -493,6 +635,8 @@
DocumentModel doc = getDocumentModelFromDescriptor( locale );
// TODO: descriptor model should get merged into default model, see MODELLO-63
+ appendGeneratedReports( doc, locale );
+
return doc;
}
@@ -503,6 +647,8 @@
model.getCover().setCoverType( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.type" ) );
model.getToc().setName( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.title" ) );
+ appendGeneratedReports( model, locale );
+
debugLogGeneratedModel( model );
return model;
@@ -615,12 +761,12 @@
try
{
reader = ReaderFactory.newXmlReader( descriptorFile );
- String siteDescriptorContent = IOUtil.toString( reader );
+ String enc = reader.getEncoding();
+ String siteDescriptorContent = IOUtil.toString( reader );
siteDescriptorContent =
siteTool.getInterpolatedSiteDescriptorContent( new HashMap(), project,
- siteDescriptorContent,
- reader.getEncoding(), reader.getEncoding() );
+ siteDescriptorContent, enc, enc );
decoration = new DecorationXpp3Reader().read( new StringReader( siteDescriptorContent ) );
}
@@ -659,14 +805,12 @@
throws MojoExecutionException
{
final DecorationModel decorationModel = getDefaultDecorationModel();
-
if ( decorationModel == null )
{
return;
}
File skinFile;
-
try
{
skinFile =
@@ -738,7 +882,6 @@
final DocumentXpp3Writer xpp3 = new DocumentXpp3Writer();
Writer w = null;
-
try
{
w = WriterFactory.newXmlWriter( doc );
@@ -755,4 +898,832 @@
}
}
}
+
+ /**
+ * Generate all Maven reports defined in <code>${project.reporting}</code> part only if <code>generateReports</code> is
+ * enabled.
+ *
+ * @param locale not null
+ * @throws MojoExecutionException if any
+ * @throws IOException if any
+ * @since 1.1
+ */
+ private void generateMavenReports( Locale locale )
+ throws MojoExecutionException, IOException
+ {
+ if ( !includeReports )
+ {
+ getLog().info( "Skipped report generation." );
+ return;
+ }
+
+ if ( project.getReporting() == null )
+ {
+ getLog().info( "No report was specified." );
+ return;
+ }
+
+ for ( final Iterator it = project.getReporting().getPlugins().iterator(); it.hasNext(); )
+ {
+ final ReportPlugin reportPlugin = (ReportPlugin) it.next();
+
+ final PluginDescriptor pluginDescriptor = getPluginDescriptor( reportPlugin );
+
+ List goals = new ArrayList();
+ for ( final Iterator it2 = reportPlugin.getReportSets().iterator(); it2.hasNext(); )
+ {
+ final ReportSet reportSet = (ReportSet) it2.next();
+
+ for ( final Iterator it3 = reportSet.getReports().iterator(); it3.hasNext(); )
+ {
+ goals.add( it3.next().toString() );
+ }
+ }
+
+ List mojoDescriptors = pluginDescriptor.getMojos();
+ for ( final Iterator it2 = mojoDescriptors.iterator(); it2.hasNext(); )
+ {
+ final MojoDescriptor mojoDescriptor = (MojoDescriptor) it2.next();
+
+ if ( goals.isEmpty() || ( !goals.isEmpty() && goals.contains( mojoDescriptor.getGoal() ) ) )
+ {
+ MavenReport report = getMavenReport( mojoDescriptor );
+
+ generateMavenReport( mojoDescriptor, report, locale );
+ }
+ }
+ }
+
+ // generate project-info report
+ if ( !getGeneratedMavenReports().isEmpty() )
+ {
+ File outDir = new File( getGeneratedSiteDirectoryTmp(), "xdoc" );
+ if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
+ {
+ outDir = new File( new File( getGeneratedSiteDirectoryTmp(), locale.getLanguage() ), "xdoc" );
+ }
+ outDir.mkdirs();
+
+ File piReport = new File( outDir, "project-info.xml" );
+
+ StringWriter sw = new StringWriter();
+
+ PdfSink sink = new PdfSink( sw );
+ ProjectInfoRenderer r = new ProjectInfoRenderer( sink, getGeneratedMavenReports(), i18n, locale );
+ r.render();
+
+ writeGeneratedReport( sw.toString(), piReport );
+ }
+
+ // copy generated site
+ copySiteDir( getGeneratedSiteDirectoryTmp(), getSiteDirectoryTmp() );
+ copySiteDir( generatedSiteDirectory, getSiteDirectoryTmp() );
+ }
+
+ /**
+ * @param reportPlugin not null
+ * @return the PluginDescriptor instance for the given reportPlugin.
+ * @throws MojoExecutionException if any
+ * @since 1.1
+ */
+ private PluginDescriptor getPluginDescriptor( ReportPlugin reportPlugin )
+ throws MojoExecutionException
+ {
+ try
+ {
+ return pluginManager.verifyReportPlugin( reportPlugin, project, session );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new MojoExecutionException( "ArtifactResolutionException: " + e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( "ArtifactNotFoundException: " + e.getMessage(), e );
+ }
+ catch ( PluginNotFoundException e )
+ {
+ throw new MojoExecutionException( "PluginNotFoundException: " + e.getMessage(), e );
+ }
+ catch ( PluginVersionResolutionException e )
+ {
+ throw new MojoExecutionException( "PluginVersionResolutionException: " + e.getMessage(), e );
+ }
+ catch ( InvalidVersionSpecificationException e )
+ {
+ throw new MojoExecutionException( "InvalidVersionSpecificationException: " + e.getMessage(), e );
+ }
+ catch ( InvalidPluginException e )
+ {
+ throw new MojoExecutionException( "InvalidPluginException: " + e.getMessage(), e );
+ }
+ catch ( PluginManagerException e )
+ {
+ throw new MojoExecutionException( "PluginManagerException: " + e.getMessage(), e );
+ }
+ catch ( PluginVersionNotFoundException e )
+ {
+ throw new MojoExecutionException( "PluginVersionNotFoundException: " + e.getMessage(), e );
+ }
+ }
+
+ /**
+ * @param mojoDescriptor not null
+ * @return the MavenReport instance for the given mojoDescriptor.
+ * @throws MojoExecutionException if any
+ * @since 1.1
+ */
+ private MavenReport getMavenReport( MojoDescriptor mojoDescriptor )
+ throws MojoExecutionException
+ {
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(
+ mojoDescriptor.getPluginDescriptor().getClassRealm()
+ .getClassLoader() );
+
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
+
+ return pluginManager.getReport( project, mojoExecution, session );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ throw new MojoExecutionException( "ArtifactNotFoundException: " + e.getMessage(), e );
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new MojoExecutionException( "ArtifactResolutionException: " + e.getMessage(), e );
+ }
+ catch ( PluginConfigurationException e )
+ {
+ throw new MojoExecutionException( "PluginConfigurationException: " + e.getMessage(), e );
+ }
+ catch ( PluginManagerException e )
+ {
+ throw new MojoExecutionException( "PluginManagerException: " + e.getMessage(), e );
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader( oldClassLoader );
+ }
+ }
+
+ /**
+ * Generate the given Maven report only if it is not an external report and the report could be generated.
+ *
+ * @param mojoDescriptor not null, to catch linkage error
+ * @param report could be null
+ * @param locale not null
+ * @throws IOException if any
+ * @throws MojoExecutionException if any
+ * @see #isValidGeneratedReport(MojoDescriptor, File, String)
+ * @since 1.1
+ */
+ private void generateMavenReport( MojoDescriptor mojoDescriptor, MavenReport report, Locale locale )
+ throws IOException, MojoExecutionException
+ {
+ if ( report == null || !report.canGenerateReport() || report.isExternalReport() )
+ {
+ return;
+ }
+
+ File outDir = new File( getGeneratedSiteDirectoryTmp(), "xdoc" );
+ if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
+ {
+ outDir = new File( new File( getGeneratedSiteDirectoryTmp(), locale.getLanguage() ), "xdoc" );
+ }
+ outDir.mkdirs();
+
+ File generatedReport = new File( outDir, report.getOutputName() + ".xml" );
+
+ String excludes = getDefaultExcludesWithLocales( getAvailableLocales(), getDefaultLocale() );
+ List files = FileUtils.getFileNames( siteDirectory, "*/" + report.getOutputName() + ".*", excludes, false );
+ if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
+ {
+ files =
+ FileUtils.getFileNames( new File( siteDirectory, locale.getLanguage() ), "*/"
+ + report.getOutputName() + ".*", excludes, false );
+ }
+
+ if ( files.size() != 0 )
+ {
+ String displayLanguage = locale.getDisplayLanguage( Locale.ENGLISH );
+
+ getLog().info(
+ "Skipped \"" + report.getName( locale ) + "\" report, file \"" + report.getOutputName()
+ + "\" already exists for the " + displayLanguage + " version." );
+ return;
+ }
+
+ String localReportName = report.getName( locale );
+ getLog().info( "Generating \"" + localReportName + "\" report." );
+
+ StringWriter sw = new StringWriter();
+
+ PdfSink sink = new PdfSink( sw );
+ try
+ {
+ report.generate( sink, locale );
+ }
+ catch ( MavenReportException e )
+ {
+ throw new MojoExecutionException( "MavenReportException: " + e.getMessage(), e );
+ }
+ catch ( LinkageError e )
+ {
+ if ( getLog().isErrorEnabled() )
+ {
+ getLog().error(
+ report.getClass().getName() + "#generate(...) caused a linkage error ("
+ + e.getClass().getName() + ") and may be out-of-date. Check the realms:" );
+
+ ClassRealm reportPluginRealm = mojoDescriptor.getPluginDescriptor().getClassRealm();
+ StringBuilder sb = new StringBuilder();
+ sb.append( "Maven Report Plugin realm = " + reportPluginRealm.getId() ).append( '\n' );
+ for ( int i = 0; i < reportPluginRealm.getConstituents().length; i++ )
+ {
+ sb.append( "urls[" + i + "] = " + reportPluginRealm.getConstituents()[i] );
+ if ( i != ( reportPluginRealm.getConstituents().length - 1 ) )
+ {
+ sb.append( '\n' );
+ }
+ }
+ getLog().error( sb.toString() );
+ }
+
+ throw e;
+ }
+ finally
+ {
+ sink.close();
+ }
+
+ writeGeneratedReport( sw.toString(), generatedReport );
+
+ if ( isValidGeneratedReport( mojoDescriptor, generatedReport, localReportName ) )
+ {
+ getGeneratedMavenReports().add( report );
+ }
+ }
+
+ /**
+ * @return the generated reports
+ * @see #generateMavenReport(MojoDescriptor, MavenReport, Locale)
+ * @see #isValidGeneratedReport(MojoDescriptor, File, String)
+ * @since 1.1
+ */
+ private List getGeneratedMavenReports()
+ {
+ if ( this.generatedMavenReports == null )
+ {
+ this.generatedMavenReports = new ArrayList();
+ }
+
+ return this.generatedMavenReports;
+ }
+
+ /**
+ * Append generated reports to the toc only if <code>generateReports</code> is enabled, for instance:
+ * <pre>
+ * <item name="Project Reports" ref="/project-info">
+ * <item name="Project License" ref="/license" />
+ * <item name="Project Team" ref="/team-list" />
+ * <item name="Continuous Integration" ref="/integration" />
+ * ...
+ * </item>
+ * </pre>
+ *
+ * @param model not null
+ * @param locale not null
+ * @see #generateMavenReports(Locale)
+ * @since 1.1
+ */
+ private void appendGeneratedReports( DocumentModel model, Locale locale )
+ {
+ if ( !includeReports )
+ {
+ return;
+ }
+ if ( getGeneratedMavenReports().isEmpty() )
+ {
+ return;
+ }
+
+ final DocumentTOCItem documentTOCItem = new DocumentTOCItem();
+ documentTOCItem.setName( i18n.getString( "pdf-plugin", getDefaultLocale(), "toc.project-info.item" ) );
+ documentTOCItem.setRef( "/project-info" ); // see #generateMavenReports(Locale)
+
+ List addedRef = new ArrayList();
+
+ List items = new ArrayList();
+
+ // append generated report defined as MavenReport
+ for ( final Iterator it = getGeneratedMavenReports().iterator(); it.hasNext(); )
+ {
+ final MavenReport report = (MavenReport) it.next();
+
+ final DocumentTOCItem reportItem = new DocumentTOCItem();
+ reportItem.setName( report.getName( locale ) );
+ reportItem.setRef( "/" + report.getOutputName() );
+
+ items.add( reportItem );
+
+ addedRef.add( report.getOutputName() );
+ }
+
+ // append all generated reports from generated-site
+ try
+ {
+ String excludes = getDefaultExcludesWithLocales( getAvailableLocales(), getDefaultLocale() );
+ List generatedDirs = FileUtils.getDirectoryNames( generatedSiteDirectory, "*", excludes, true );
+ if ( !locale.getLanguage().equals( getDefaultLocale().getLanguage() ) )
+ {
+ generatedDirs =
+ FileUtils.getFileNames( new File( generatedSiteDirectory, locale.getLanguage() ), "*",
+ excludes, true );
+ }
+
+ for ( final Iterator it = generatedDirs.iterator(); it.hasNext(); )
+ {
+ final String generatedDir = it.next().toString();
+
+ List generatedFiles = FileUtils.getFileNames( new File( generatedDir ), "**.*", excludes, false );
+
+ for ( final Iterator it2 = generatedFiles.iterator(); it2.hasNext(); )
+ {
+ final String generatedFile = it2.next().toString();
+ final String ref = generatedFile.substring( 0, generatedFile.lastIndexOf( "." ) );
+
+ if ( !addedRef.contains( ref ) )
+ {
+ final String title = getGeneratedDocumentTitle( new File( generatedDir, generatedFile ) );
+
+ if ( title != null )
+ {
+ final DocumentTOCItem reportItem = new DocumentTOCItem();
+ reportItem.setName( title );
+ reportItem.setRef( "/" + ref );
+
+ items.add( reportItem );
+ }
+ }
+ }
+ }
+ }
+ catch ( IOException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "IOException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "IOException: " + e.getMessage() );
+ }
+ }
+
+ // append to Toc
+ documentTOCItem.setItems( items );
+ model.getToc().addItem( documentTOCItem );
+ }
+
+ /**
+ * Parse a generated Doxia file and returns its title.
+ *
+ * @param f not null
+ * @return the xdoc file title or null if an error occurs.
+ * @throws IOException if any
+ * @see TitleSink
+ * @since 1.1
+ */
+ private String getGeneratedDocumentTitle( File f )
+ throws IOException
+ {
+ TitleSink titleSink = new TitleSink();
+
+ Reader reader = null;
+ try
+ {
+ reader = ReaderFactory.newXmlReader( f );
+
+ doxia.parse( reader, f.getParentFile().getName(), titleSink );
+ }
+ catch ( ParseException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "ParseException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "ParseException: " + e.getMessage() );
+ }
+ return null;
+ }
+ catch ( ParserNotFoundException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "ParserNotFoundException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "ParserNotFoundException: " + e.getMessage() );
+ }
+ return null;
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return titleSink.getTitle();
+ }
+
+ /**
+ * Parsing the generated report to see if it is correct or not. Log the error for the user.
+ *
+ * @param mojoDescriptor not null
+ * @param generatedReport not null
+ * @param localReportName not null
+ * @return <code>true</code> if Doxia is able to parse the generated report, <code>false</code> otherwise.
+ * @since 1.1
+ */
+ private boolean isValidGeneratedReport( MojoDescriptor mojoDescriptor, File generatedReport,
+ String localReportName )
+ {
+ SinkAdapter sinkAdapter = new SinkAdapter();
+ Reader reader = null;
+ try
+ {
+ reader = ReaderFactory.newXmlReader( generatedReport );
+
+ doxia.parse( reader, generatedReport.getParentFile().getName(), sinkAdapter );
+ }
+ catch ( ParseException e )
+ {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "\n" ).append( "\n" );
+ sb.append( "Error when parsing the generated report: " ).append( generatedReport.getAbsolutePath() );
+ sb.append( "\n" );
+ sb.append( e.getMessage() );
+ sb.append( "\n" ).append( "\n" );
+
+ sb.append( "You could:\n" );
+ sb.append( " * exlcude all reports using -DincludeReports=false\n" );
+ sb.append( " * remove the " );
+ sb.append( mojoDescriptor.getPluginDescriptor().getGroupId() );
+ sb.append( ":" );
+ sb.append( mojoDescriptor.getPluginDescriptor().getArtifactId() );
+ sb.append( ":" );
+ sb.append( mojoDescriptor.getPluginDescriptor().getVersion() );
+ sb.append( " from the <reporting/> part. To not affect the site generation, " );
+ sb.append( "you could create a PDF profile.\n" );
+ sb.append( "\n" );
+
+ MavenProject pluginProject = getReportPluginProject( mojoDescriptor.getPluginDescriptor() );
+
+ if ( pluginProject == null )
+ {
+ sb.append( "You could also have to contact the Plugin team.\n" );
+ }
+ else
+ {
+ sb.append( "You could also have to contact the Plugin team:\n" );
+ if ( pluginProject.getMailingLists() != null && pluginProject.getMailingLists().size() != 0 )
+ {
+ boolean appended = false;
+ for ( Iterator i = pluginProject.getMailingLists().iterator(); i.hasNext(); )
+ {
+ MailingList mailingList = (MailingList) i.next();
+
+ if ( StringUtils.isNotEmpty( mailingList.getName() )
+ && StringUtils.isNotEmpty( mailingList.getPost() ) )
+ {
+ if ( !appended )
+ {
+ sb.append( " Mailing Lists:\n" );
+ appended = true;
+ }
+ sb.append( " " ).append( mailingList.getName() );
+ sb.append( ": " ).append( mailingList.getPost() );
+ sb.append( "\n" );
+ }
+ }
+ }
+ if ( StringUtils.isNotEmpty( pluginProject.getUrl() ) )
+ {
+ sb.append( " Web Site:\n" );
+ sb.append( " " ).append( pluginProject.getUrl() );
+ sb.append( "\n" );
+ }
+ if ( pluginProject.getIssueManagement() != null
+ && StringUtils.isNotEmpty( pluginProject.getIssueManagement().getUrl() ) )
+ {
+ sb.append( " Issue Tracking:\n" );
+ sb.append( " " ).append( pluginProject.getIssueManagement().getUrl() );
+ sb.append( "\n" );
+ }
+ }
+
+ sb.append( "\nIgnoring the \"" + localReportName + "\" report.\n" );
+
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( sb.toString(), e );
+ }
+ else
+ {
+ getLog().error( sb.toString() );
+ }
+
+ return false;
+ }
+ catch ( ParserNotFoundException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "ParserNotFoundException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "ParserNotFoundException: " + e.getMessage() );
+ }
+
+ return false;
+ }
+ catch ( IOException e )
+ {
+ if ( getLog().isDebugEnabled() )
+ {
+ getLog().error( "IOException: " + e.getMessage(), e );
+ }
+ else
+ {
+ getLog().error( "IOException: " + e.getMessage() );
+ }
+
+ return false;
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ return true;
+ }
+
+ /**
+ * @param pluginDescriptor not null
+ * @return the MavenProject for the current plugin descriptor or null if an error occurred.
+ * @since 1.1
+ */
+ private MavenProject getReportPluginProject( PluginDescriptor pluginDescriptor )
+ {
+ Artifact artifact =
+ artifactFactory.createProjectArtifact( pluginDescriptor.getGroupId(),
+ pluginDescriptor.getArtifactId(),
+ pluginDescriptor.getVersion(), Artifact.SCOPE_COMPILE );
+ try
+ {
+ return mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository );
+ }
+ catch ( ProjectBuildingException e )
+ {
+ getLog().debug( e.getMessage(), e );
+ }
+
+ return null;
+ }
+
+ // ----------------------------------------------------------------------
+ // static methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Write the given content to the given file.
+ * <br/>
+ * <b>Note</b>: try also to fix the content due to some issues in the {@link AbstractMavenReport}.
+ *
+ * @param content the given content
+ * @param toFile the report file
+ * @throws IOException if any
+ * @since 1.1
+ */
+ private static void writeGeneratedReport( String content, File toFile )
+ throws IOException
+ {
+ if ( StringUtils.isEmpty( content ) )
+ {
+ return;
+ }
+
+ content = StringUtils.replace( content, "<table><table", "<table" );
+ Writer writer = null;
+ try
+ {
+ writer = WriterFactory.newXmlWriter( toFile );
+ writer.write( content );
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
+ }
+
+ /**
+ * @param locales the list of locales dir to exclude
+ * @param defaultLocale the default locale.
+ * @return the comma separated list of default excludes and locales dir.
+ * @see FileUtils#getDefaultExcludesAsString()
+ * @since 1.1
+ */
+ private static String getDefaultExcludesWithLocales( List locales, Locale defaultLocale )
+ {
+ String excludesLocales = FileUtils.getDefaultExcludesAsString();
+ for ( final Iterator it = locales.iterator(); it.hasNext(); )
+ {
+ final Locale locale = (Locale) it.next();
+
+ if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
+ {
+ excludesLocales = excludesLocales + ",**/" + locale.getLanguage() + "/*";
+ }
+ }
+
+ return excludesLocales;
+ }
+
+ // ----------------------------------------------------------------------
+ // Inner class
+ // ----------------------------------------------------------------------
+
+ /**
+ * A sink to generate Maven report as xdoc.
+ *
+ * @since 1.1
+ */
+ private static class PdfSink
+ extends XdocSink
+ implements org.codehaus.doxia.sink.Sink
+ {
+ protected PdfSink( Writer writer )
+ {
+ super( writer );
+ }
+
+ /** {@inheritDoc} */
+ public void table()
+ {
+ // workaround to fix reporting-impl issue
+ writeStartTag( HtmlMarkup.TABLE );
+ }
+ }
+
+ /**
+ * Renderer Maven report similar to org.apache.maven.plugins.site.CategorySummaryDocumentRenderer
+ *
+ * @since 1.1
+ */
+ private static class ProjectInfoRenderer
+ extends AbstractMavenReportRenderer
+ {
+ private final List generatedReports;
+
+ private final I18N i18n;
+
+ private final Locale locale;
+
+ public ProjectInfoRenderer( Sink sink, List generatedReports, I18N i18n, Locale locale )
+ {
+ super( sink );
+
+ this.generatedReports = generatedReports;
+ this.i18n = i18n;
+ this.locale = locale;
+ }
+
+ /** {@inheritDoc} */
+ public String getTitle()
+ {
+ return i18n.getString( "pdf-plugin", locale, "report.project-info.title" );
+ }
+
+ /** {@inheritDoc} */
+ public void renderBody()
+ {
+ sink.section1();
+ sink.sectionTitle1();
+ sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.title" ) );
+ sink.sectionTitle1_();
+
+ sink.paragraph();
+ sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.description1" ) + " " );
+ sink.link( "http://maven.apache.org" );
+ sink.text( "Maven" );
+ sink.link_();
+ sink.text( " " + i18n.getString( "pdf-plugin", locale, "report.project-info.description2" ) );
+ sink.paragraph_();
+
+ sink.section2();
+ sink.sectionTitle2();
+ sink.text( i18n.getString( "pdf-plugin", locale, "report.project-info.sectionTitle" ) );
+ sink.sectionTitle2_();
+
+ sink.table();
+
+ sink.tableRows( new int[] { Sink.JUSTIFY_LEFT, Sink.JUSTIFY_LEFT }, false );
+
+ String name = i18n.getString( "pdf-plugin", locale, "report.project-info.column.document" );
+ String description = i18n.getString( "pdf-plugin", locale, "report.project-info.column.description" );
+
+ sink.tableRow();
+
+ sink.tableHeaderCell();
+
+ sink.text( name );
+
+ sink.tableHeaderCell_();
+
+ sink.tableHeaderCell();
+
+ sink.text( description );
+
+ sink.tableHeaderCell_();
+
+ sink.tableRow_();
+
+ if ( generatedReports != null )
+ {
+ for ( final Iterator it = generatedReports.iterator(); it.hasNext(); )
+ {
+ final MavenReport report = (MavenReport) it.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.tableRows_();
+
+ sink.table_();
+
+ sink.section2_();
+
+ sink.section1_();
+ }
+ }
+
+ /**
+ * A Sink class to get the Document title when parsing Doxia files.
+ *
+ * @see PdfMojo#getGeneratedDocumentTitle(File)
+ * @since 1.1
+ */
+ private static class TitleSink
+ extends SinkAdapter
+ {
+ String title;
+
+ boolean isTitle;
+
+ /** {@inheritDoc} */
+ public void title()
+ {
+ isTitle = true;
+ }
+
+ /** {@inheritDoc} */
+ public void title_()
+ {
+ isTitle = false;
+ }
+
+ /** {@inheritDoc} */
+ public void text( String text )
+ {
+ if ( isTitle )
+ {
+ title = text;
+ }
+ }
+
+ /**
+ * @return the found title or null.
+ */
+ public String getTitle()
+ {
+ return title;
+ }
+ }
}
Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin.properties?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin.properties (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin.properties Tue Aug 11 13:14:33 2009
@@ -15,5 +15,13 @@
# specific language governing permissions and limitations
# under the License.
-toc.title = Table Of Content
-toc.type=Project Documentation
+toc.title = Table Of Content
+toc.type = Project Documentation
+toc.project-info.item = Project Reports
+
+report.project-info.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.project-info.description2 = on behalf of the project.
+report.project-info.title = Project Information
+report.project-info.sectionTitle = Overview
+report.project-info.column.description = Description
+report.project-info.column.document = Document
Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_de.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_de.properties?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_de.properties (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_de.properties Tue Aug 11 13:14:33 2009
@@ -15,5 +15,13 @@
# specific language governing permissions and limitations
# under the License.
-toc.title = Inhaltsverzeichnis
-toc.type = Projekt-Dokumentation
+toc.title = Inhaltsverzeichnis
+toc.type = Projekt-Dokumentation
+toc.project-info.item = Allgemeine Projektinformation
+
+report.project-info.column.description = Beschreibung
+report.project-info.column.document = Dokument
+report.project-info.sectionTitle = \u00dcbersicht
+report.project-info.description1 = \u00dcbersicht der allgemeinen Projektinformationen. Der Inhalt dieser Dokumente wurde automatisch von
+report.project-info.description2 = f\u00fcr dieses Projekt erstellt.
+report.project-info.title = Allgemeine Projektinformation
Modified: maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_fr.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_fr.properties?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_fr.properties (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/main/resources/pdf-plugin_fr.properties Tue Aug 11 13:14:33 2009
@@ -15,5 +15,13 @@
# specific language governing permissions and limitations
# under the License.
-toc.title=Table des mati\u00e8res
-toc.type=Documentation du projet
+toc.title = Table des mati\u00e8res
+toc.type = Documentation du projet
+toc.project-info.item = Rapports Projet
+
+report.project-info.column.description = Description
+report.project-info.column.document = Document
+report.project-info.sectionTitle = Vue d'ensemble
+report.project-info.description1 = Ce document fournit une vue d'ensemble des divers documents et liens qui font partis des informations g\u00e9n\u00e9rales du projet. Tous ces contenus sont g\u00e9n\u00e9r\u00e9s automatiquement par
+report.project-info.description2 = le projet lui-m\u00eame.
+report.project-info.title = Information g\u00e9n\u00e9rale du projet
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=803108&r1=803107&r2=803108&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 Tue Aug 11 13:14:33 2009
@@ -20,7 +20,7 @@
*/
import java.io.File;
-import java.io.FileReader;
+import java.io.Reader;
import java.util.Collections;
import java.util.List;
@@ -30,6 +30,8 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
@@ -41,15 +43,21 @@
public DefaultMavenProjectStub()
{
MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Reader reader = null;
try
{
- Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom.xml" ) ) );
+ reader = ReaderFactory.newXmlReader( getFile() );
+ Model model = pomReader.read( reader );
setModel( model );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
/** {@inheritDoc} */
@@ -61,7 +69,7 @@
/** {@inheritDoc} */
public File getBasedir()
{
- return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+ return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
}
/** {@inheritDoc} */
@@ -73,4 +81,10 @@
return Collections.singletonList( repository );
}
+
+ /** {@inheritDoc} */
+ public File getFile()
+ {
+ return new File( getBasedir(), "pom.xml" );
+ }
}
Modified: 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=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/FilteringMavenProjectStub.java Tue Aug 11 13:14:33 2009
@@ -20,7 +20,7 @@
*/
import java.io.File;
-import java.io.FileReader;
+import java.io.Reader;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -31,6 +31,8 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
@@ -42,15 +44,21 @@
public FilteringMavenProjectStub()
{
MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Reader reader = null;
try
{
- Model model = pomReader.read( new FileReader( new File( getBasedir() + "/pom_filtering.xml" ) ) );
+ reader = ReaderFactory.newXmlReader( getFile() );
+ Model model = pomReader.read( reader );
setModel( model );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
/** {@inheritDoc} */
@@ -68,7 +76,7 @@
/** {@inheritDoc} */
public File getBasedir()
{
- return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+ return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
}
/** {@inheritDoc} */
@@ -92,4 +100,10 @@
return Collections.singletonList( repository );
}
+
+ /** {@inheritDoc} */
+ public File getFile()
+ {
+ return new File( getBasedir(), "pom_filtering.xml" );
+ }
}
Modified: 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=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ITextMavenProjectStub.java Tue Aug 11 13:14:33 2009
@@ -20,7 +20,7 @@
*/
import java.io.File;
-import java.io.FileReader;
+import java.io.Reader;
import java.util.Collections;
import java.util.List;
@@ -30,6 +30,8 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
@@ -41,21 +43,27 @@
public ITextMavenProjectStub()
{
MavenXpp3Reader pomReader = new MavenXpp3Reader();
+ Reader reader = null;
try
{
- Model model = pomReader.read( new FileReader( new File( getBasedir() + "/iText_pom.xml" ) ) );
+ reader = ReaderFactory.newXmlReader( getFile() );
+ Model model = pomReader.read( reader );
setModel( model );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
/** {@inheritDoc} */
public File getBasedir()
{
- return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+ return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
}
/** {@inheritDoc} */
@@ -67,4 +75,10 @@
return Collections.singletonList( repository );
}
+
+ /** {@inheritDoc} */
+ public File getFile()
+ {
+ return new File( getBasedir(), "iText_pom.xml" );
+ }
}
Modified: maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ModelBuilderMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ModelBuilderMavenProjectStub.java?rev=803108&r1=803107&r2=803108&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ModelBuilderMavenProjectStub.java (original)
+++ maven/plugins/trunk/maven-pdf-plugin/src/test/java/org/apache/maven/plugins/pdf/stubs/ModelBuilderMavenProjectStub.java Tue Aug 11 13:14:33 2009
@@ -20,7 +20,6 @@
*/
import java.io.File;
-import java.io.FileReader;
import java.util.List;
import org.apache.maven.model.Developer;
@@ -28,6 +27,9 @@
import org.apache.maven.model.Organization;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
/**
* @author ltheussl
@@ -41,10 +43,12 @@
*/
public ModelBuilderMavenProjectStub()
{
+ XmlStreamReader reader = null;
try
{
- Model model = new MavenXpp3Reader().read(
- new FileReader( new File( getBasedir() + "/pom_model_builder.xml" ) ) );
+ reader = ReaderFactory.newXmlReader( getFile() );
+
+ Model model = new MavenXpp3Reader().read( reader );
setModel( model );
setGroupId( model.getGroupId() );
@@ -59,53 +63,51 @@
{
throw new RuntimeException( e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
- /** {@inheritDoc}
- * @return the test base dir: "/target/test-classes/unit/pdf/".
- */
+ /** {@inheritDoc} */
public File getBasedir()
{
- return new File( super.getBasedir() + "/target/test-classes/unit/pdf/" );
+ return new File( super.getBasedir(), "target/test-classes/unit/pdf/" );
}
- /** {@inheritDoc}
- * @param developer
- */
+ /** {@inheritDoc} */
public void addDeveloper( Developer developer )
{
getModel().addDeveloper( developer );
}
- /** {@inheritDoc}
- * @return
- */
+ /** {@inheritDoc} */
public List getDevelopers()
{
return getModel().getDevelopers();
}
- /** {@inheritDoc}
- * @return
- */
+ /** {@inheritDoc} */
public Organization getOrganization()
{
return getModel().getOrganization();
}
- /** {@inheritDoc}
- * @param list
- */
+ /** {@inheritDoc} */
public void setDevelopers( List list )
{
getModel().setDevelopers( list );
}
- /** {@inheritDoc}
- * @param organization
- */
+ /** {@inheritDoc} */
public void setOrganization( Organization organization )
{
getModel().setOrganization( organization );
}
+
+ /** {@inheritDoc} */
+ public File getFile()
+ {
+ return new File( getBasedir(), "pom_model_builder.xml" );
+ }
}