mirror of https://github.com/apache/maven.git
Update to new reporting-api
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169078 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd4c6fb600
commit
dd5f4fed12
|
@ -22,10 +22,19 @@ 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.apache.maven.reporting.MavenReportException;
|
import org.apache.maven.reporting.MavenReportException;
|
||||||
|
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.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,11 +48,35 @@ public class CheckstyleReportMojo
|
||||||
extends AbstractMojo
|
extends AbstractMojo
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @parameter alias="workingDirectory" expression="${project.build.directory}/site-generated"
|
* @parameter expression="${basedir}"
|
||||||
|
* @required
|
||||||
|
*/
|
||||||
|
private String basedir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter expression="${basedir}/src/site"
|
||||||
|
* @required
|
||||||
|
*/
|
||||||
|
private String siteDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter expression="${project.build.directory}/site"
|
||||||
* @required
|
* @required
|
||||||
*/
|
*/
|
||||||
private String outputDirectory;
|
private String outputDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter alias="flavor"
|
||||||
|
*/
|
||||||
|
private String flavour = "maven";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
|
||||||
|
* @required
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private SiteRenderer siteRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${project}"
|
* @parameter expression="${project}"
|
||||||
* @required
|
* @required
|
||||||
|
@ -66,11 +99,61 @@ public class CheckstyleReportMojo
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
report.generate();
|
XhtmlSink sink = siteRenderer.createSink( new File( siteDirectory ), siteDirectory,
|
||||||
|
report.getOutputName() + ".html",
|
||||||
|
outputDirectory, getSiteDescriptor(), flavour );
|
||||||
|
|
||||||
|
siteRenderer.copyResources( siteDirectory, outputDirectory, flavour );
|
||||||
|
|
||||||
|
report.generate( sink );
|
||||||
}
|
}
|
||||||
catch ( MavenReportException e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "An error is occurred in the Checkstyle report generation.", e );
|
throw new MojoExecutionException( "An error is occurred in the Checkstyle report generation.", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getReportsMenu()
|
||||||
|
{
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append( "<menu name=\"Project Documentation\">\n" );
|
||||||
|
buffer.append( " <item name=\"About " + project.getName() + "\" href=\"/index.html\"/>\n");
|
||||||
|
buffer.append( " <item name=\"Project reports\" href=\"/maven-reports.html\" collapse=\"true\">\n" );
|
||||||
|
|
||||||
|
buffer.append( " <item name=\"Checkstyle\" href=\"/checkstyle.html\"/>\n" );
|
||||||
|
|
||||||
|
buffer.append( " </item>\n" );
|
||||||
|
buffer.append( "</menu>\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();
|
||||||
|
|
||||||
|
props.put( "reports", getReportsMenu() );
|
||||||
|
|
||||||
|
siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props );
|
||||||
|
|
||||||
|
return new StringInputStream( siteDescriptorContent );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue