1 package org.apache.maven.reporting; 2 3 18 19 import org.apache.maven.doxia.sink.Sink; 20 import org.apache.maven.doxia.siterenderer.Renderer; 21 import org.apache.maven.doxia.siterenderer.RendererException; 22 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink; 23 import org.apache.maven.plugin.AbstractMojo; 24 import org.apache.maven.plugin.MojoExecutionException; 25 import org.apache.maven.project.MavenProject; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.util.Locale ; 30 31 37 public abstract class AbstractMavenReport 38 extends AbstractMojo 39 implements MavenReport 40 { 41 private Sink sink; 42 43 private Locale locale = Locale.ENGLISH; 44 45 protected abstract Renderer getSiteRenderer(); 46 47 protected abstract String getOutputDirectory(); 48 49 protected abstract MavenProject getProject(); 50 51 private File reportOutputDirectory; 52 53 56 public void execute() 57 throws MojoExecutionException 58 { 59 try 60 { 61 String outputDirectory = getOutputDirectory(); 62 63 SiteRendererSink sink = 64 getSiteRenderer().createSink( new File ( outputDirectory ), getOutputName() + ".html" ); 65 66 generate( sink, Locale.getDefault() ); 67 68 } 71 catch ( RendererException e ) 72 { 73 throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.", 74 e ); 75 } 76 catch ( IOException e ) 77 { 78 throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.", 79 e ); 80 } 81 catch ( MavenReportException e ) 82 { 83 throw new MojoExecutionException( "An error has occurred in " + getName( locale ) + " report generation.", 84 e ); 85 } 86 } 87 88 91 public void generate( org.codehaus.doxia.sink.Sink sink, Locale locale ) 92 throws MavenReportException 93 { 94 if ( sink == null ) 95 { 96 throw new MavenReportException( "You must specify a sink." ); 97 } 98 99 this.sink = sink; 100 101 executeReport( locale ); 102 103 closeReport(); 104 } 105 106 protected abstract void executeReport( Locale locale ) 107 throws MavenReportException; 108 109 protected void closeReport() 110 { 111 } 112 113 public String getCategoryName() 114 { 115 return CATEGORY_PROJECT_REPORTS; 116 } 117 118 public File getReportOutputDirectory() 119 { 120 if ( reportOutputDirectory == null ) 121 { 122 reportOutputDirectory = new File ( getOutputDirectory() ); 123 } 124 return reportOutputDirectory; 125 } 126 127 public void setReportOutputDirectory( File reportOutputDirectory ) 128 { 129 this.reportOutputDirectory = reportOutputDirectory; 130 } 131 132 public Sink getSink() 133 { 134 return sink; 135 } 136 137 public boolean isExternalReport() 138 { 139 return false; 140 } 141 142 public boolean canGenerateReport() 143 { 144 return true; 145 } 146 } 147 | Popular Tags |