1 package org.codehaus.mojo.gwt.reports;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27
28 import org.apache.maven.doxia.siterenderer.Renderer;
29 import org.apache.maven.plugins.annotations.Component;
30 import org.apache.maven.plugins.annotations.Mojo;
31 import org.apache.maven.plugins.annotations.Parameter;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.reporting.AbstractMavenReport;
34 import org.apache.maven.reporting.MavenReportException;
35 import org.codehaus.mojo.gwt.ClasspathBuilder;
36 import org.codehaus.mojo.gwt.GwtModule;
37 import org.codehaus.mojo.gwt.GwtModuleReader;
38 import org.codehaus.mojo.gwt.utils.DefaultGwtModuleReader;
39 import org.codehaus.mojo.gwt.utils.GwtModuleReaderException;
40 import org.codehaus.plexus.i18n.I18N;
41 import org.codehaus.plexus.util.DirectoryScanner;
42 import org.codehaus.plexus.util.FileUtils;
43
44
45
46
47
48
49 @Mojo(name = "compile-report", threadSafe = true)
50 public class CompileReport
51 extends AbstractMavenReport
52 {
53
54
55
56
57 @Parameter(defaultValue = "${project.reporting.outputDirectory}/gwtCompileReports", required = true, readonly = true)
58 protected File reportingOutputDirectory;
59
60
61
62
63 @Parameter(defaultValue = "${project.build.directory}/extra")
64 private File extra;
65
66
67
68
69
70
71 @Component
72 protected Renderer siteRenderer;
73
74
75
76
77
78
79
80
81 @Parameter(defaultValue = "${project.reporting.outputDirectory}", required = true)
82 protected File outputDirectory;
83
84
85
86
87
88
89 @Parameter(defaultValue = "${project}", required = true, readonly = true)
90 protected MavenProject project;
91
92
93
94
95 @Component
96 protected ClasspathBuilder classpathBuilder;
97
98
99
100
101 @Parameter(defaultValue = "false", property = "gwt.compilerReport.skip")
102 private boolean skip;
103
104
105
106
107
108
109 @Component
110 protected I18N i18n;
111
112
113
114
115
116
117 public boolean canGenerateReport()
118 {
119
120 return true;
121 }
122
123
124
125
126
127
128 public String getCategoryName()
129 {
130 return CATEGORY_PROJECT_REPORTS;
131 }
132
133
134
135
136
137
138 public String getDescription( Locale locale )
139 {
140 return "GWT Compiler Report";
141 }
142
143
144
145
146
147
148 public String getName( Locale locale )
149 {
150 return "GWT Compiler Report";
151 }
152
153
154
155
156
157
158 public String getOutputName()
159 {
160 return "gwt-compiler-reports";
161 }
162
163
164
165
166
167
168 public boolean isExternalReport()
169 {
170 return false;
171 }
172
173 @Override
174 protected Renderer getSiteRenderer()
175 {
176 return siteRenderer;
177 }
178
179 @Override
180 protected String getOutputDirectory()
181 {
182 return outputDirectory.getAbsolutePath();
183 }
184
185 @Override
186 protected MavenProject getProject()
187 {
188 return project;
189 }
190
191
192
193
194 @Override
195 protected void executeReport( Locale locale )
196 throws MavenReportException
197 {
198
199 if ( skip )
200 {
201 getLog().info( "Compiler Report is skipped" );
202 return;
203 }
204
205 if ( !reportingOutputDirectory.exists() )
206 {
207 reportingOutputDirectory.mkdirs();
208 }
209 boolean compileReports = true;
210
211
212 DirectoryScanner scanner = new DirectoryScanner();
213 scanner.setBasedir( extra );
214 scanner.setIncludes( new String[] { "**/soycReport/compile-report/index.html" } );
215
216 if (extra.exists())
217 {
218 scanner.scan();
219 } else
220 {
221 compileReports = false;
222 }
223
224 if (!compileReports || scanner.getIncludedFiles().length == 0 )
225 {
226 getLog().warn( "No compile reports found, did you compile with compileReport option set ?" );
227 compileReports = false;
228 }
229
230 String[] includeFiles = compileReports ? scanner.getIncludedFiles() : new String[0];
231
232 for ( String path : includeFiles )
233 {
234 String module = path.substring( 0, path.indexOf( File.separatorChar ) );
235 File dirTarget = new File( reportingOutputDirectory.getAbsolutePath() + File.separatorChar + module );
236 getLog().debug( "file in path " + path + " to target " + dirTarget.getAbsolutePath());
237 try
238 {
239 FileUtils.copyDirectoryStructure( new File(extra, path).getParentFile(), dirTarget );
240 }
241 catch ( IOException e )
242 {
243 throw new MavenReportException( e.getMessage(), e );
244 }
245 }
246
247 try
248 {
249
250 GwtModuleReader gwtModuleReader = new DefaultGwtModuleReader( this.project, getLog(), classpathBuilder );
251
252 List<GwtModule> gwtModules = new ArrayList<GwtModule>();
253 List<String> moduleNames = gwtModuleReader.getGwtModules();
254 for ( String name : moduleNames )
255 {
256 gwtModules.add( gwtModuleReader.readModule( name ) );
257 }
258
259 CompilationReportRenderer compilationReportRenderer = new CompilationReportRenderer( getSink(), gwtModules,
260 getLog(),
261 compileReports,
262 "gwtCompileReports",
263 true, i18n, locale );
264 compilationReportRenderer.render();
265 }
266 catch ( GwtModuleReaderException e )
267 {
268 throw new MavenReportException( e.getMessage(), e );
269 }
270
271 }
272
273
274
275 }