From 1eb084ce3eca5cca88492e92ae368f65f532575c Mon Sep 17 00:00:00 2001 From: Emmanuel Venisse Date: Sat, 7 May 2005 13:00:47 +0000 Subject: [PATCH] Report generate directly xhtml file git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169076 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/doxia/DoxiaMojo.java | 65 ++++++++++++++----- .../maven/reporting/AbstractMavenReport.java | 35 +++++----- .../apache/maven/reporting/MavenReport.java | 5 +- .../reporting/MavenReportConfiguration.java | 12 ++++ 4 files changed, 81 insertions(+), 36 deletions(-) diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java index 012370cf1f..1f72d97b09 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -22,12 +22,15 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReportConfiguration; +import org.codehaus.doxia.module.xhtml.XhtmlSink; import org.codehaus.doxia.site.renderer.SiteRenderer; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.StringInputStream; import org.codehaus.plexus.util.StringUtils; import java.io.File; +import java.io.InputStream; +import java.io.IOException; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -43,6 +46,12 @@ import java.util.Map; public class DoxiaMojo extends AbstractMojo { + /** + * @parameter expression="${basedir}" + * @required + */ + private String basedir; + /** * @parameter expression="${basedir}/src/site" * @required @@ -124,26 +133,16 @@ public class DoxiaMojo report.setConfiguration( config ); - report.generate(); + XhtmlSink sink = siteRenderer.createSink( new File( siteDirectory ), siteDirectory, + report.getOutputName() + ".html", + outputDirectory, getSiteDescriptor(), flavour ); + + report.generate( sink ); } } - File siteDescriptor = new File( siteDirectory, "site.xml" ); - if ( !siteDescriptor.exists() ) - { - throw new MojoExecutionException( "The site descriptor is not present!" ); - } - String siteDescriptorContent = FileUtils.fileRead( siteDescriptor ); - Map props = new HashMap(); - if ( reports != null ) - { - props.put( "reports", getReportsMenu() ); - } - siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props ); - StringInputStream siteDescriptorStream = new StringInputStream( siteDescriptorContent ); - siteRenderer.render( siteDirectory, generatedSiteDirectory, outputDirectory, flavour, - siteDescriptorStream ); + getSiteDescriptor() ); } catch ( Exception e ) { @@ -151,6 +150,7 @@ public class DoxiaMojo throw new MojoExecutionException( "Error during site generation", e ); } } + private String getReportsMenu() { StringBuffer buffer = new StringBuffer(); @@ -168,4 +168,37 @@ public class DoxiaMojo buffer.append( "\n" ); return buffer.toString(); } + + private InputStream getSiteDescriptor() + throws MojoExecutionException + { + File siteDescriptor = new File( siteDirectory, "site.xml" ); + + if ( !siteDescriptor.exists() ) + { + throw new MojoExecutionException( "The site descriptor is not present!" ); + } + + String siteDescriptorContent = ""; + + try + { + siteDescriptorContent = FileUtils.fileRead( siteDescriptor ); + } + catch( IOException e ) + { + throw new MojoExecutionException( "The site descriptor cannot be read!", e ); + } + + Map props = new HashMap(); + + if ( reports != null ) + { + props.put( "reports", getReportsMenu() ); + } + + siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props ); + + return new StringInputStream( siteDescriptorContent ); + } } diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java index ecbf148e9b..ec70decbf4 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java @@ -23,11 +23,19 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +/** + * The basis for a Maven report. + * + * @author Emmanuel Venisse + * @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $ + */ public abstract class AbstractMavenReport implements MavenReport { private MavenReportConfiguration config; + private Sink sink; + public MavenReportConfiguration getConfiguration() { return config; @@ -38,7 +46,7 @@ public abstract class AbstractMavenReport this.config = config; } - public void generate() + public void generate( Sink sink ) throws MavenReportException { if ( config == null ) @@ -46,6 +54,15 @@ public abstract class AbstractMavenReport throw new MavenReportException( "You must specify a report configuration." ); } + if ( sink == null ) + { + throw new MavenReportException( "You must specify a sink configuration." ); + } + else + { + this.sink = sink; + } + execute(); } @@ -55,20 +72,6 @@ public abstract class AbstractMavenReport public Sink getSink() throws IOException { - return getSink( getOutputName() ); - } - - public Sink getSink( String outputName ) - throws IOException - { - File outputDir = new File( config.getOutputDirectory(), "xdoc/" ); - - outputDir.mkdirs(); - - File outputFile = new File( outputDir, outputName + ".xml" ); - - FileWriter writer = new FileWriter( outputFile ); - - return new XdocSink( writer ); + return sink; } } \ No newline at end of file diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java index 760d7e3259..aac79e2919 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReport.java @@ -36,14 +36,11 @@ public interface MavenReport void setConfiguration( MavenReportConfiguration config ); - void generate() + void generate( Sink sink ) throws MavenReportException; String getOutputName(); Sink getSink() throws IOException; - - Sink getSink( String outputName ) - throws IOException; } diff --git a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java index 356c5aaba9..b838aa7d8d 100644 --- a/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java +++ b/maven-reporting/maven-reporting-api/src/main/java/org/apache/maven/reporting/MavenReportConfiguration.java @@ -32,6 +32,8 @@ public class MavenReportConfiguration private File outputDirectory; + private File basedir; + public File getOutputDirectory() { return outputDirectory; @@ -42,6 +44,16 @@ public class MavenReportConfiguration this.outputDirectory = outputDirectory; } + public File getBasedir() + { + return basedir; + } + + public void setBasedir( File basedir ) + { + this.basedir = basedir; + } + public Model getModel() { if ( model == null )