Hi,
I've just committed some changes WRT MNG-2410 which I've been sitting
on for weeks/months now.
I've just tested them out extensively, and they work fine.
I've had to change the maven-reporting-api and add a new 'generate' method.
I've done that in a new interface 'MavenMultiPageReport', so we can
retain backwards
compatibility.
There's just one problem: I had to update the dep in the
maven-site-plugin on
maven-reporting to 2.1-SNAPSHOT. This will block releases of the
maven-site-plugin.
This feature is planned for 2.1, but the reporting stuff is spread over
maven components,
doxia, and the site plugin. The site plugin has a different release
cycle, so it's impossible
to implement it without having the plugin depend on 2.1 (unless it's
backported to the 2.0.x branch
which we don't want since it's a new feature.)
Ideally I'd like to remove the reporting api/impl from the components
and put it in some shared
plugin space. Since reports are just mojo's we don't really need them in
core. The entire reporting
stuff is only used from the maven-site-plugin, so they're actually
plugins for the site plugin
(functionally seen).
I guess we're now seeing that plugins that depend on core api's can't
really have a totally separate
release cycle. Maybe we need 2 level versions for plugins (i.e. a branch
for plugins that operate on 2.0.x
and trunk that'll operate on 2.1.)
So, I've been waiting quite a while with this with little or no
feedback, and I just went along
and committed this. I'm sure there'll be a reaction now :-)
I really don't know how to solve the problem above, any feedback is
greatly appreciated!
-- Kenney
[EMAIL PROTECTED] wrote:
Author: kenney
Date: Thu Aug 10 10:20:32 2006
New Revision: 430446
URL: http://svn.apache.org/viewvc?rev=430446&view=rev
Log:
PR: 2410
Add support for multiple sinks for reports.
Update dep on maven-reporting to 2.1-SNAPSHOT to enable the new MavenReport API.
NOTE that the reporting api changes need to be merged to the 2.0.x branch
before a new site plugin can be released, and that the doxia deps on the 2.0.x
branch
need to be updated to 1.0-alpha-9 (currently SNAPSHOT).
Modified:
maven/plugins/trunk/maven-site-plugin/pom.xml
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java
Modified: maven/plugins/trunk/maven-site-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/pom.xml?rev=430446&r1=430445&r2=430446&view=diff
==============================================================================
--- maven/plugins/trunk/maven-site-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-site-plugin/pom.xml Thu Aug 10 10:20:32 2006
@@ -79,7 +79,7 @@
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
- <version>2.0.2</version>
+ <version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Modified:
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java?rev=430446&r1=430445&r2=430446&view=diff
==============================================================================
---
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java
(original)
+++
maven/plugins/trunk/maven-site-plugin/src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java
Thu Aug 10 10:20:32 2006
@@ -17,6 +17,8 @@
*/
import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkFactory;
import org.apache.maven.doxia.siterenderer.DocumentRenderer;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.doxia.siterenderer.RendererException;
@@ -24,11 +26,19 @@
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.reporting.MavenReport;
+import org.apache.maven.reporting.MavenMultiPageReport;
import org.apache.maven.reporting.MavenReportException;
+import org.apache.maven.reporting.MavenReport;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.Writer;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
import java.util.Locale;
+import java.util.List;
+import java.util.Iterator;
/**
* Renders a Maven report.
@@ -53,18 +63,84 @@
this.log = log;
}
+ private static class MySink extends SiteRendererSink
+ {
+ private File outputDir;
+
+ private String outputName;
+
+ public MySink( File outputDir, String outputName, RenderingContext ctx )
+ {
+ super( ctx );
+ this.outputName = outputName;
+ this.outputDir = outputDir;
(sorry for the indent!)
+ }
+
+ public String getOutputName()
+ {
+ return outputName;
+ }
+
+ public File getOutputDir()
+ {
+ return outputDir;
+ }
+
+ }
+
+ private static class MySinkFactory implements SinkFactory
+ {
+ private RenderingContext context;
+
+ private List sinks = new ArrayList();
+
+ public MySinkFactory( RenderingContext ctx )
+ {
+ this.context = ctx;
+ }
+
+ public Sink createSink( File outputDir, String outputName )
+ {
+ SiteRendererSink sink = new MySink( outputDir, outputName, context
);
+ sinks.add( sink );
+ return sink;
+ }
+
+ public List sinks()
+ {
+ return sinks;
+ }
+ }
+
+
public void renderDocument( Writer writer, Renderer renderer,
SiteRenderingContext siteRenderingContext )
throws RendererException, FileNotFoundException
{
Locale locale = siteRenderingContext.getLocale();
String localReportName = report.getName( locale );
- log.info( "Generate \"" + localReportName + "\" report." );
+ log.info( "Generating \"" + localReportName + "\" report." );
+
+ MySinkFactory sf = new MySinkFactory( renderingContext );
SiteRendererSink sink = new SiteRendererSink( renderingContext );
try
{
- report.generate( sink, locale );
+ if ( report instanceof MavenMultiPageReport )
+ {
+ ( (MavenMultiPageReport) report ).generate( sink, sf, locale );
+ }
+ else
+ {
+ try
+ {
+ report.generate( sink, locale );
+ }
+ catch ( NoSuchMethodError e )
+ {
+ throw new RendererException( "No method on " +
report.getClass(), e );
+ }
+ }
}
catch ( MavenReportException e )
{
@@ -73,6 +149,28 @@
if ( !report.isExternalReport() )
{
+ try
+ {
+ List sinks = sf.sinks();
+
+ log.debug( "Multipage report: " + sinks.size() + "
subreports");
+
+ for ( Iterator it = sinks.iterator(); it.hasNext(); )
+ {
+ MySink mySink = (MySink) it.next();
+
+ log.debug( " Rendering " + mySink.getOutputName() );
+
+ Writer out = new FileWriter( new File(
mySink.getOutputDir(), mySink.getOutputName() ) );
+
+ renderer.generateDocument( out, mySink,
siteRenderingContext );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new RendererException( "Cannot create writer", e );
+ }
+
renderer.generateDocument( writer, sink, siteRenderingContext );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]