1 package org.codehaus.mojo.ounce;
2
3 import java.io.File;
4 import java.util.HashMap;
5 import java.util.Locale;
6 import java.util.ResourceBundle;
7
8 import org.apache.maven.doxia.siterenderer.Renderer;
9 import org.apache.maven.plugin.MojoExecutionException;
10 import org.apache.maven.plugin.MojoFailureException;
11 import org.apache.maven.project.MavenProject;
12 import org.apache.maven.reporting.MavenReport;
13 import org.apache.maven.reporting.MavenReportException;
14 import org.codehaus.doxia.sink.Sink;
15
16
17
18
19
20
21
22
23 public class ReportMojo
24 extends ScanMojo
25 implements MavenReport
26 {
27
28
29
30
31
32
33
34 private File reportOutputDirectory;
35
36
37
38
39
40
41
42 String existingAssessmentFile;
43
44
45
46
47
48
49
50 protected MavenProject project;
51
52
53
54
55
56
57
58
59 private Renderer siteRenderer;
60
61 protected Renderer getSiteRenderer()
62 {
63 return siteRenderer;
64 }
65
66 public String getDescription( Locale locale )
67 {
68 return getBundle( locale ).getString( "report.description" );
69 }
70
71 public String getName( Locale locale )
72 {
73 return getBundle( locale ).getString( "report.name" );
74 }
75
76 public String getOutputName()
77 {
78 return "Ounce-Analysis/index";
79 }
80
81
82
83
84 public boolean isExternalReport()
85 {
86 return true;
87 }
88
89 private ResourceBundle getBundle( Locale locale )
90 {
91 return ResourceBundle.getBundle( "ounce-report", locale, this.getClass().getClassLoader() );
92 }
93
94 public void execute()
95 throws MojoExecutionException, MojoFailureException
96 {
97 this.getLog().warn( "Generating..." );
98
99 if ( existingAssessmentFile != null )
100 {
101 if ( options == null )
102 {
103 options = new HashMap();
104 }
105 options.put( "existingAssessmentFile", existingAssessmentFile );
106 }
107
108 super.execute();
109 }
110
111 public boolean canGenerateReport()
112 {
113 return true;
114 }
115
116 public void generate( Sink sink, Locale locale )
117 throws MavenReportException
118 {
119 this.getLog().warn( "Generating..." );
120 this.waitForScan = true;
121 if ( this.reportType == null )
122 {
123 this.reportType = "Findings";
124 }
125 if ( this.reportOutputType == null )
126 {
127 this.reportOutputType = "html";
128 }
129 this.reportOutputPath = reportOutputDirectory + File.separator + getOutputName() + ".html";
130
131 try
132 {
133 super.execute();
134 }
135 catch ( MojoExecutionException e )
136 {
137 throw new MavenReportException( "Execption generating report:", e );
138 }
139 catch ( MojoFailureException e )
140 {
141 throw new MavenReportException( "Execption generating report:", e );
142 }
143 }
144
145
146
147
148 public String getCategoryName()
149 {
150 return CATEGORY_PROJECT_REPORTS;
151 }
152
153
154
155
156 public File getReportOutputDirectory()
157 {
158 return this.reportOutputDirectory;
159 }
160
161
162
163
164 public void setReportOutputDirectory( File outputDirectory )
165 {
166 reportOutputDirectory = outputDirectory;
167 }
168 }