View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.changes.issues;
20  
21  import java.text.DateFormat;
22  import java.text.SimpleDateFormat;
23  import java.util.List;
24  import java.util.ResourceBundle;
25  
26  import org.apache.maven.doxia.sink.Sink;
27  
28  /**
29   * Generates a report on issues.
30   *
31   * @author Noriko Kinugasa
32   * @author Dennis Lundberg
33   * @version $Id$
34   * @since 2.4
35   */
36  public class IssuesReportRenderer extends AbstractIssuesReportRenderer {
37      /**
38       * Fallback value that is used if date field are not available.
39       */
40      private static final String NOT_AVAILABLE = "n/a";
41  
42      /**
43       * Holds the id:s for the columns to include in the report, in the order that they should appear in the report.
44       */
45      private final List<Integer> columns;
46  
47      private final List<Issue> issueList;
48  
49      /**
50       * @param includedColumns The id:s of the columns to include in the report
51       */
52      public IssuesReportRenderer(
53              Sink sink, ResourceBundle bundle, List<Integer> includedColumns, List<Issue> issueList) {
54          super(sink, bundle);
55          this.columns = includedColumns;
56          this.issueList = issueList;
57      }
58  
59      @Override
60      public void renderBody() {
61          if (issueList == null || issueList.isEmpty()) {
62              paragraph(bundle.getString("report.issues.error"));
63          } else {
64              startTable();
65              constructHeaderRow();
66              constructDetailRows();
67              endTable();
68          }
69      }
70  
71      private void constructHeaderRow() {
72  
73          sink.tableRow();
74  
75          for (int column : columns) {
76              switch (column) {
77                  case IssuesReportHelper.COLUMN_ASSIGNEE:
78                      tableHeaderCell(bundle.getString("report.issues.label.assignee"));
79                      break;
80  
81                  case IssuesReportHelper.COLUMN_COMPONENT:
82                      tableHeaderCell(bundle.getString("report.issues.label.component"));
83                      break;
84  
85                  case IssuesReportHelper.COLUMN_CREATED:
86                      tableHeaderCell(bundle.getString("report.issues.label.created"));
87                      break;
88  
89                  case IssuesReportHelper.COLUMN_FIX_VERSION:
90                      tableHeaderCell(bundle.getString("report.issues.label.fixVersion"));
91                      break;
92  
93                  case IssuesReportHelper.COLUMN_ID:
94                      tableHeaderCell(bundle.getString("report.issues.label.id"));
95                      break;
96  
97                  case IssuesReportHelper.COLUMN_KEY:
98                      tableHeaderCell(bundle.getString("report.issues.label.key"));
99                      break;
100 
101                 case IssuesReportHelper.COLUMN_PRIORITY:
102                     tableHeaderCell(bundle.getString("report.issues.label.priority"));
103                     break;
104 
105                 case IssuesReportHelper.COLUMN_REPORTER:
106                     tableHeaderCell(bundle.getString("report.issues.label.reporter"));
107                     break;
108 
109                 case IssuesReportHelper.COLUMN_RESOLUTION:
110                     tableHeaderCell(bundle.getString("report.issues.label.resolution"));
111                     break;
112 
113                 case IssuesReportHelper.COLUMN_STATUS:
114                     tableHeaderCell(bundle.getString("report.issues.label.status"));
115                     break;
116 
117                 case IssuesReportHelper.COLUMN_SUMMARY:
118                     tableHeaderCell(bundle.getString("report.issues.label.summary"));
119                     break;
120 
121                 case IssuesReportHelper.COLUMN_TYPE:
122                     tableHeaderCell(bundle.getString("report.issues.label.type"));
123                     break;
124 
125                 case IssuesReportHelper.COLUMN_UPDATED:
126                     tableHeaderCell(bundle.getString("report.issues.label.updated"));
127                     break;
128 
129                 case IssuesReportHelper.COLUMN_VERSION:
130                     tableHeaderCell(bundle.getString("report.issues.label.version"));
131                     break;
132 
133                 default:
134                     // Do not add a header for this column
135                     break;
136             }
137         }
138 
139         sink.tableRow_();
140     }
141 
142     private void constructDetailRows() {
143 
144         // Always use the international date format as recommended by the W3C:
145         // http://www.w3.org/QA/Tips/iso-date
146         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
147 
148         for (Issue issue : issueList) {
149 
150             sink.tableRow();
151 
152             for (int column : columns) {
153                 switch (column) {
154                     case IssuesReportHelper.COLUMN_ASSIGNEE:
155                         sinkCell(issue.getAssignee());
156                         break;
157 
158                     case IssuesReportHelper.COLUMN_COMPONENT:
159                         sinkCell(IssuesReportHelper.printValues(issue.getComponents()));
160                         break;
161 
162                     case IssuesReportHelper.COLUMN_CREATED:
163                         String created = NOT_AVAILABLE;
164                         if (issue.getCreated() != null) {
165                             created = df.format(issue.getCreated());
166                         }
167                         sinkCell(created);
168                         break;
169 
170                     case IssuesReportHelper.COLUMN_FIX_VERSION:
171                         sinkCell(IssuesReportHelper.printValues(issue.getFixVersions()));
172                         break;
173 
174                     case IssuesReportHelper.COLUMN_ID:
175                         sinkCellLink(issue.getId(), issue.getLink());
176                         break;
177 
178                     case IssuesReportHelper.COLUMN_KEY:
179                         sinkCellLink(issue.getKey(), issue.getLink());
180                         break;
181 
182                     case IssuesReportHelper.COLUMN_PRIORITY:
183                         sinkCell(issue.getPriority());
184                         break;
185 
186                     case IssuesReportHelper.COLUMN_REPORTER:
187                         sinkCell(issue.getReporter());
188                         break;
189 
190                     case IssuesReportHelper.COLUMN_RESOLUTION:
191                         sinkCell(issue.getResolution());
192                         break;
193 
194                     case IssuesReportHelper.COLUMN_STATUS:
195                         sinkCell(issue.getStatus());
196                         break;
197 
198                     case IssuesReportHelper.COLUMN_SUMMARY:
199                         sinkCell(issue.getSummary());
200                         break;
201 
202                     case IssuesReportHelper.COLUMN_TYPE:
203                         sinkCell(issue.getType());
204                         break;
205 
206                     case IssuesReportHelper.COLUMN_UPDATED:
207                         String updated = NOT_AVAILABLE;
208                         if (issue.getUpdated() != null) {
209                             updated = df.format(issue.getUpdated());
210                         }
211                         sinkCell(updated);
212                         break;
213 
214                     case IssuesReportHelper.COLUMN_VERSION:
215                         sinkCell(issue.getVersion());
216                         break;
217 
218                     default:
219                         // Do not add this column
220                         break;
221                 }
222             }
223 
224             sink.tableRow_();
225         }
226     }
227 }