diff --git a/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportMojo.java b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportMojo.java index fa357b68d9..c756e9e506 100644 --- a/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportMojo.java +++ b/sandbox/maven-reports/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReportMojo.java @@ -22,10 +22,19 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReport; import org.apache.maven.reporting.MavenReportConfiguration; 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.FileWriter; +import java.io.InputStream; +import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; /** @@ -39,11 +48,35 @@ public class CheckstyleReportMojo 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 */ 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}" * @required @@ -66,11 +99,61 @@ public class CheckstyleReportMojo 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 ); } } + + private String getReportsMenu() + { + StringBuffer buffer = new StringBuffer(); + buffer.append( "\n" ); + buffer.append( " \n"); + buffer.append( " \n" ); + + buffer.append( " \n" ); + + buffer.append( " \n" ); + 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(); + + props.put( "reports", getReportsMenu() ); + + siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props ); + + return new StringInputStream( siteDescriptorContent ); + } }