View Javadoc
1   package org.codehaus.mojo.gwt.reports;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * see http://code.google.com/webtoolkit/doc/latest/DevGuideCompileReport.html#Usage
46   * @author <a href="mailto:olamy@apache.org">Olivier Lamy</a>
47   * @since 2.1.0-1
48   */
49  @Mojo(name = "compile-report", threadSafe = true)
50  public class CompileReport
51      extends AbstractMavenReport
52  {
53  
54      /**
55       * The output directory of the gwt compiler reports.
56       */
57      @Parameter(defaultValue = "${project.reporting.outputDirectory}/gwtCompileReports", required = true, readonly = true)
58      protected File reportingOutputDirectory;
59  
60      /**
61       * The directory into which extra, non-deployed files will be written.
62       */
63      @Parameter(defaultValue = "${project.build.directory}/extra")
64      private File extra;
65  
66      /**
67       * Doxia Site Renderer component.
68       *
69       * @since 2.1.0-1
70       */
71      @Component
72      protected Renderer siteRenderer;
73  
74      /**
75       * The output directory for the report. Note that this parameter is only evaluated if the goal is run directly from
76       * the command line. If the goal is run indirectly as part of a site generation, the output directory configured in
77       * the Maven Site Plugin is used instead.
78       *
79       * @since 2.1.0-1
80       */
81      @Parameter(defaultValue = "${project.reporting.outputDirectory}", required = true)
82      protected File outputDirectory;
83  
84      /**
85       * The Maven Project.
86       *
87       * @since 2.1.0-1
88       */
89      @Parameter(defaultValue = "${project}", required = true, readonly = true)
90      protected MavenProject project;
91  
92      /**
93       * @since 2.1.0-1
94       */
95      @Component
96      protected ClasspathBuilder classpathBuilder;
97  
98      /**
99       * @since 2.1.0-1
100      */
101     @Parameter(defaultValue = "false", property = "gwt.compilerReport.skip")
102     private boolean skip;    
103     
104     /**
105      * Internationalization component.
106      *
107      * @since 2.1.0-1
108      */
109     @Component
110     protected I18N i18n;
111 
112     /**
113      * {@inheritDoc}
114      *
115      * @see org.apache.maven.reporting.MavenReport#canGenerateReport()
116      */
117     public boolean canGenerateReport()
118     {
119         // TODO check the compiler has created the raw xml soyc file
120         return true;
121     }
122 
123     /**
124      * {@inheritDoc}
125      *
126      * @see org.apache.maven.reporting.MavenReport#getCategoryName()
127      */
128     public String getCategoryName()
129     {
130         return CATEGORY_PROJECT_REPORTS;
131     }
132 
133     /**
134      * {@inheritDoc}
135      *
136      * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
137      */
138     public String getDescription( Locale locale )
139     {
140         return "GWT Compiler Report";
141     }
142 
143     /**
144      * {@inheritDoc}
145      *
146      * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
147      */
148     public String getName( Locale locale )
149     {
150         return "GWT Compiler Report";
151     }
152 
153     /**
154      * {@inheritDoc}
155      *
156      * @see org.apache.maven.reporting.MavenReport#getOutputName()
157      */
158     public String getOutputName()
159     {
160         return "gwt-compiler-reports";
161     }
162 
163     /**
164      * {@inheritDoc}
165      *
166      * @see org.apache.maven.reporting.MavenReport#isExternalReport()
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      * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
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         //compile-report
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             // add link in the page to all module reports
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 }