mirror of https://github.com/apache/maven.git
Report generate directly xhtml file
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
040139d102
commit
1eb084ce3e
|
@ -22,12 +22,15 @@ import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.reporting.MavenReport;
|
import org.apache.maven.reporting.MavenReport;
|
||||||
import org.apache.maven.reporting.MavenReportConfiguration;
|
import org.apache.maven.reporting.MavenReportConfiguration;
|
||||||
|
import org.codehaus.doxia.module.xhtml.XhtmlSink;
|
||||||
import org.codehaus.doxia.site.renderer.SiteRenderer;
|
import org.codehaus.doxia.site.renderer.SiteRenderer;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.codehaus.plexus.util.StringInputStream;
|
import org.codehaus.plexus.util.StringInputStream;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -43,6 +46,12 @@ import java.util.Map;
|
||||||
public class DoxiaMojo
|
public class DoxiaMojo
|
||||||
extends AbstractMojo
|
extends AbstractMojo
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @parameter expression="${basedir}"
|
||||||
|
* @required
|
||||||
|
*/
|
||||||
|
private String basedir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${basedir}/src/site"
|
* @parameter expression="${basedir}/src/site"
|
||||||
* @required
|
* @required
|
||||||
|
@ -124,26 +133,16 @@ public class DoxiaMojo
|
||||||
|
|
||||||
report.setConfiguration( config );
|
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,
|
siteRenderer.render( siteDirectory, generatedSiteDirectory, outputDirectory, flavour,
|
||||||
siteDescriptorStream );
|
getSiteDescriptor() );
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
|
@ -151,6 +150,7 @@ public class DoxiaMojo
|
||||||
throw new MojoExecutionException( "Error during site generation", e );
|
throw new MojoExecutionException( "Error during site generation", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getReportsMenu()
|
private String getReportsMenu()
|
||||||
{
|
{
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
@ -168,4 +168,37 @@ public class DoxiaMojo
|
||||||
buffer.append( "</menu>\n" );
|
buffer.append( "</menu>\n" );
|
||||||
return buffer.toString();
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,19 @@ import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The basis for a Maven report.
|
||||||
|
*
|
||||||
|
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
|
||||||
|
* @version $Id: MavenReport.java 163376 2005-02-23 00:06:06Z brett $
|
||||||
|
*/
|
||||||
public abstract class AbstractMavenReport
|
public abstract class AbstractMavenReport
|
||||||
implements MavenReport
|
implements MavenReport
|
||||||
{
|
{
|
||||||
private MavenReportConfiguration config;
|
private MavenReportConfiguration config;
|
||||||
|
|
||||||
|
private Sink sink;
|
||||||
|
|
||||||
public MavenReportConfiguration getConfiguration()
|
public MavenReportConfiguration getConfiguration()
|
||||||
{
|
{
|
||||||
return config;
|
return config;
|
||||||
|
@ -38,7 +46,7 @@ public abstract class AbstractMavenReport
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generate()
|
public void generate( Sink sink )
|
||||||
throws MavenReportException
|
throws MavenReportException
|
||||||
{
|
{
|
||||||
if ( config == null )
|
if ( config == null )
|
||||||
|
@ -46,6 +54,15 @@ public abstract class AbstractMavenReport
|
||||||
throw new MavenReportException( "You must specify a report configuration." );
|
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();
|
execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,20 +72,6 @@ public abstract class AbstractMavenReport
|
||||||
public Sink getSink()
|
public Sink getSink()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return getSink( getOutputName() );
|
return sink;
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,14 +36,11 @@ public interface MavenReport
|
||||||
|
|
||||||
void setConfiguration( MavenReportConfiguration config );
|
void setConfiguration( MavenReportConfiguration config );
|
||||||
|
|
||||||
void generate()
|
void generate( Sink sink )
|
||||||
throws MavenReportException;
|
throws MavenReportException;
|
||||||
|
|
||||||
String getOutputName();
|
String getOutputName();
|
||||||
|
|
||||||
Sink getSink()
|
Sink getSink()
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
Sink getSink( String outputName )
|
|
||||||
throws IOException;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ public class MavenReportConfiguration
|
||||||
|
|
||||||
private File outputDirectory;
|
private File outputDirectory;
|
||||||
|
|
||||||
|
private File basedir;
|
||||||
|
|
||||||
public File getOutputDirectory()
|
public File getOutputDirectory()
|
||||||
{
|
{
|
||||||
return outputDirectory;
|
return outputDirectory;
|
||||||
|
@ -42,6 +44,16 @@ public class MavenReportConfiguration
|
||||||
this.outputDirectory = outputDirectory;
|
this.outputDirectory = outputDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getBasedir()
|
||||||
|
{
|
||||||
|
return basedir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasedir( File basedir )
|
||||||
|
{
|
||||||
|
this.basedir = basedir;
|
||||||
|
}
|
||||||
|
|
||||||
public Model getModel()
|
public Model getModel()
|
||||||
{
|
{
|
||||||
if ( model == null )
|
if ( model == null )
|
||||||
|
|
Loading…
Reference in New Issue