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  
23  import java.util.List;
24  import java.util.Locale;
25  
26  import org.apache.commons.lang.StringUtils;
27  import org.apache.maven.doxia.sink.Sink;
28  import org.apache.maven.plugin.logging.Log;
29  import org.apache.maven.reporting.AbstractMavenReportRenderer;
30  import org.codehaus.mojo.gwt.GwtModule;
31  import org.codehaus.plexus.i18n.I18N;
32  
33  /**
34   * project compilation report renderer to display links to 
35   * all modules report
36   * @author <a href="mailto:olamy@apache.org">Olivier Lamy</a>
37   * @since 2.1.0-1
38   */
39  public class CompilationReportRenderer
40      extends AbstractMavenReportRenderer
41  {
42      private final List<GwtModule> gwtModules;
43      
44      private final Log log;
45      
46      private boolean reportsAvailable;
47      
48      private String compilerReportsPath;
49      
50      private boolean compilerReport;
51      
52      private final I18N i18n;
53      
54      private final Locale locale;
55      
56      public CompilationReportRenderer( final Sink sink, final List<GwtModule> gwtModules, Log log,
57                                        boolean reportsAvailable, String compilerReportsPath, boolean compilerReport,
58                                        I18N i18n, Locale locale )
59      {
60          super( sink );
61  
62          this.gwtModules = gwtModules;
63          this.log = log;
64          this.reportsAvailable = reportsAvailable;
65          this.compilerReportsPath = compilerReportsPath;
66          this.compilerReport = compilerReport;
67          this.i18n = i18n;
68          this.locale = locale;
69      }
70  
71      /**
72       * @see org.apache.maven.reporting.AbstractMavenReportRenderer#getTitle()
73       */
74      @Override
75      public String getTitle()
76      {
77          // TODO i18n
78          return "GWT Compilation Reports";
79      }
80  
81      /**
82       * @see org.apache.maven.reporting.AbstractMavenReportRenderer#renderBody()
83       */
84      @Override
85      protected void renderBody()
86      {
87          // TODO i18n and message for none
88          log.debug( "start renderBody" );
89          startSection( getI18nString( locale, "compiler.report.section.title" ) );
90          // display a specific warning message for SoycDashboard Report
91          if ( !compilerReport )
92          {
93              sink.paragraph();
94              sink.bold();
95              sink.text( getI18nString( locale, "soyc.report.warning" ) );
96              sink.bold_();
97              sink.paragraph_();
98  
99          }
100         if ( !this.reportsAvailable )
101         {
102             sink.paragraph();
103             sink.bold();
104             if ( compilerReport )
105             {
106                 sink.text( getI18nString( locale, "compiler.report.none.warning" ) );
107             }
108             else
109             {
110                 sink.text( getI18nString( locale, "compiler.report.soyc.warning" ) );
111             }
112             sink.bold_();
113             sink.paragraph_();
114         }
115         else
116         {
117             sink.list();
118             for ( GwtModule gwtModule : this.gwtModules )
119             {
120                 sink.listItem();
121                 if ( StringUtils.isNotBlank( compilerReportsPath ) )
122                 {
123                     sink.link( "./" + compilerReportsPath + "/" + gwtModule.getPath() + "/index.html" );
124                 }
125                 else
126                 {
127                     sink.link( "./" + gwtModule.getPath() + "/index.html" );
128                 }
129                 sink.text( gwtModule.getName() );
130                 sink.link_();
131                 sink.listItem_();
132             }
133             sink.list_();
134         }
135         endSection();
136         log.debug( "end renderBody" );
137     }
138     
139     protected String getI18nString( Locale locale, String key )
140     {
141         return i18n.getString( "compile-report", locale, key );
142     }
143 }