You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ke...@apache.org on 2006/08/10 19:20:33 UTC

svn commit: r430446 - in /maven/plugins/trunk/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java

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;
+        }
+        
+        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 );
         }
     }



Re: svn commit: r430446 - in /maven/plugins/trunk/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java

Posted by Brett Porter <br...@apache.org>.
Ok, I should have read lists in the other order :)

I think we should put the site plugin changes on the branch for now.

We can't move the reporting api to a shared space as the maven core 
requires it. I think it makes sense to keep the impl and api together 
and on the same release timelines.

I didn't check, but if sink-api changes were made this is the same deal.

I know we need to better decouple some of the implementations and apis 
in the maven-core. Ideally, only the things the maven-core needs from 
the other parts should be in the general API and that would be locked 
down. The plugins should have as few callbacks into that as possible. So 
I think we need to do a bit of redesigning of that, especially in this 
case as the Maven core really only needs the report interface, not even 
the methods I think.

Add it to the 2.1 list ;)

- Brett

On 11/08/2006 3:32 AM, Kenney Westerhof wrote:
> 
> 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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r430446 - in /maven/plugins/trunk/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java

Posted by Kenney Westerhof <fo...@gods.nl>.
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



kenney@apache.org 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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r430446 - in /maven/plugins/trunk/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java

Posted by Kenney Westerhof <fo...@gods.nl>.

Brett Porter wrote:
> On 11/08/2006 3:20 AM, kenney@apache.org wrote:
>> 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>
> 
> This will block a release of the site plugin until after Maven 2.1, 
> which is not desirable.

I know. I've posted a mail on this about 7 mails up in the dev list..


> 
> Two questions:
> a) does this change actually make it always require Maven 2.1, or is it 
> only if you use the multi page feature that will trigger the code?

Only the latter, actually. But at runtime it will still require the new 
code in the maven-reporting-api.

> b) can we create a branch for it anyway?

A branch for what, exactly?

> 
> I think the answer to a) is that it does, so it needs a <prerequisites> 
> element, and it also makes b) a must for now.

Please take a look at the full problem description in the other mail. 
Maybe we've got a bigger design issue here..

-- Kenney


> 
> Cheers,
> Brett
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: svn commit: r430446 - in /maven/plugins/trunk/maven-site-plugin: pom.xml src/main/java/org/apache/maven/plugins/site/ReportDocumentRenderer.java

Posted by Brett Porter <br...@apache.org>.
On 11/08/2006 3:20 AM, kenney@apache.org wrote:
> 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>

This will block a release of the site plugin until after Maven 2.1, 
which is not desirable.

Two questions:
a) does this change actually make it always require Maven 2.1, or is it 
only if you use the multi page feature that will trigger the code?
b) can we create a branch for it anyway?

I think the answer to a) is that it does, so it needs a <prerequisites> 
element, and it also makes b) a must for now.

Cheers,
Brett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org