1 package org.apache.maven.plugin.jira;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.maven.plugin.changes.AbstractChangesReport;
24 import org.apache.maven.plugin.changes.ProjectUtils;
25 import org.apache.maven.plugin.issues.Issue;
26 import org.apache.maven.plugin.issues.IssueUtils;
27 import org.apache.maven.plugin.issues.IssuesReportGenerator;
28 import org.apache.maven.plugin.issues.IssuesReportHelper;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.reporting.MavenReportException;
32 import org.apache.maven.settings.Settings;
33
34 import java.io.File;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.Map;
39 import java.util.ResourceBundle;
40
41
42
43
44
45
46
47 @Mojo( name = "jira-report", threadSafe = true )
48 public class JiraMojo
49 extends AbstractChangesReport
50 {
51
52
53
54 private static final Map<String, Integer> JIRA_COLUMNS = new HashMap<String, Integer>( 16 );
55
56 static
57 {
58 JIRA_COLUMNS.put( "Assignee", IssuesReportHelper.COLUMN_ASSIGNEE );
59 JIRA_COLUMNS.put( "Component", IssuesReportHelper.COLUMN_COMPONENT );
60 JIRA_COLUMNS.put( "Created", IssuesReportHelper.COLUMN_CREATED );
61 JIRA_COLUMNS.put( "Fix Version", IssuesReportHelper.COLUMN_FIX_VERSION );
62 JIRA_COLUMNS.put( "Id", IssuesReportHelper.COLUMN_ID );
63 JIRA_COLUMNS.put( "Key", IssuesReportHelper.COLUMN_KEY );
64 JIRA_COLUMNS.put( "Priority", IssuesReportHelper.COLUMN_PRIORITY );
65 JIRA_COLUMNS.put( "Reporter", IssuesReportHelper.COLUMN_REPORTER );
66 JIRA_COLUMNS.put( "Resolution", IssuesReportHelper.COLUMN_RESOLUTION );
67 JIRA_COLUMNS.put( "Status", IssuesReportHelper.COLUMN_STATUS );
68 JIRA_COLUMNS.put( "Summary", IssuesReportHelper.COLUMN_SUMMARY );
69 JIRA_COLUMNS.put( "Type", IssuesReportHelper.COLUMN_TYPE );
70 JIRA_COLUMNS.put( "Updated", IssuesReportHelper.COLUMN_UPDATED );
71 JIRA_COLUMNS.put( "Version", IssuesReportHelper.COLUMN_VERSION );
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 @Parameter( defaultValue = "Key,Summary,Status,Resolution,Assignee" )
89 private String columnNames;
90
91
92
93
94
95
96
97
98 @Parameter( property = "changes.useJql", defaultValue = "false" )
99 private boolean useJql;
100
101
102
103
104
105
106
107
108 @Parameter( defaultValue = "false" )
109 private boolean forceRss;
110
111
112
113
114
115
116 @Parameter( defaultValue = "" )
117 private String component;
118
119
120
121
122
123
124 @Parameter( defaultValue = "" )
125 private String filter;
126
127
128
129
130
131
132
133
134
135 @Parameter( defaultValue = "" )
136 private String fixVersionIds;
137
138
139
140
141
142
143
144 @Parameter( defaultValue = "EEE, d MMM yyyy HH:mm:ss Z" )
145 private String jiraDatePattern;
146
147
148
149
150 @Parameter( defaultValue = "" )
151 private String jiraPassword;
152
153
154
155
156 @Parameter( defaultValue = "" )
157 private String jiraUser;
158
159
160
161
162 @Parameter( defaultValue = "${project.build.directory}/jira-results.xml", required = true, readonly = true )
163 private File jiraXmlPath;
164
165
166
167
168 @Parameter( defaultValue = "100" )
169 private int maxEntries;
170
171
172
173
174
175
176
177
178 @Parameter( defaultValue = "false" )
179 private boolean onlyCurrentVersion;
180
181
182
183
184
185
186
187
188 @Parameter( defaultValue = "" )
189 private String priorityIds;
190
191
192
193
194
195
196
197
198
199
200
201
202 @Parameter( defaultValue = "Fixed" )
203 private String resolutionIds;
204
205
206
207
208 @Parameter( defaultValue = "${settings}", readonly = true, required = true )
209 private Settings settings;
210
211
212
213
214
215
216 @Parameter( property = "changes.jira.skip", defaultValue = "false" )
217 private boolean skip;
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 @Parameter( defaultValue = "Priority DESC, Created DESC" )
249 private String sortColumnNames;
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271 @Parameter( defaultValue = "Closed" )
272 private String statusIds;
273
274
275
276
277
278
279
280
281
282
283
284 @Parameter( defaultValue = "" )
285 private String typeIds;
286
287
288
289
290
291
292
293
294
295
296
297
298
299 @Parameter( defaultValue = "" )
300 private String versionPrefix;
301
302
303
304
305 @Parameter( defaultValue = "" )
306 private String webPassword;
307
308
309
310
311 @Parameter( defaultValue = "" )
312 private String webUser;
313
314
315
316
317 private AbstractJiraDownloader mockDownloader;
318
319
320
321
322
323
324
325
326 public boolean canGenerateReport()
327 {
328
329 if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
330 {
331 getLog().info( "Skipping the JIRA Report in this project because it's not the Execution Root" );
332 return false;
333 }
334 if ( skip )
335 {
336 return false;
337 }
338 if ( mockDownloader != null )
339 {
340 return true;
341 }
342 return ProjectUtils.validateIfIssueManagementComplete( project, "JIRA", "JIRA Report", getLog() );
343 }
344
345 public void executeReport( Locale locale )
346 throws MavenReportException
347 {
348
349 List<Integer> columnIds = IssuesReportHelper.getColumnIds( columnNames, JIRA_COLUMNS );
350 if ( columnIds.isEmpty() )
351 {
352
353 throw new MavenReportException(
354 "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." );
355 }
356
357 try
358 {
359
360 AbstractJiraDownloader issueDownloader;
361 if ( mockDownloader != null )
362 {
363 issueDownloader = mockDownloader;
364 }
365 else
366 {
367 AdaptiveJiraDownloader downloader = new AdaptiveJiraDownloader();
368 downloader.setForceClassic( forceRss );
369 issueDownloader = downloader;
370 }
371 configureIssueDownloader( issueDownloader );
372 issueDownloader.doExecute();
373
374 List<Issue> issueList = issueDownloader.getIssueList();
375
376 if ( StringUtils.isNotEmpty( versionPrefix ) )
377 {
378 int originalNumberOfIssues = issueList.size();
379 issueList = IssueUtils.filterIssuesWithVersionPrefix( issueList, versionPrefix );
380 getLog().debug( "Filtered out " + issueList.size() + " issues of " + originalNumberOfIssues
381 + " that matched the versionPrefix '" + versionPrefix + "'." );
382 }
383
384 if ( onlyCurrentVersion )
385 {
386 String version = ( versionPrefix == null ? "" : versionPrefix ) + project.getVersion();
387 issueList = IssueUtils.getIssuesForVersion( issueList, version );
388 getLog().info( "The JIRA Report will contain issues only for the current version." );
389 }
390
391
392 IssuesReportGenerator report = new IssuesReportGenerator( IssuesReportHelper.toIntArray( columnIds ) );
393
394 if ( issueList.isEmpty() )
395 {
396 report.doGenerateEmptyReport( getBundle( locale ), getSink() );
397 }
398 else
399 {
400 report.doGenerateReport( getBundle( locale ), getSink(), issueList );
401 }
402 }
403 catch ( Exception e )
404 {
405 getLog().warn( e );
406 }
407 }
408
409 public String getDescription( Locale locale )
410 {
411 return getBundle( locale ).getString( "report.issues.description" );
412 }
413
414 public String getName( Locale locale )
415 {
416 return getBundle( locale ).getString( "report.issues.name" );
417 }
418
419 public String getOutputName()
420 {
421 return "jira-report";
422 }
423
424
425
426
427
428 private ResourceBundle getBundle( Locale locale )
429 {
430 return ResourceBundle.getBundle( "jira-report", locale, this.getClass().getClassLoader() );
431 }
432
433 private void configureIssueDownloader( AbstractJiraDownloader issueDownloader )
434 {
435 issueDownloader.setLog( getLog() );
436
437 issueDownloader.setMavenProject( project );
438
439 issueDownloader.setOutput( jiraXmlPath );
440
441 issueDownloader.setNbEntries( maxEntries );
442
443 issueDownloader.setComponent( component );
444
445 issueDownloader.setFixVersionIds( fixVersionIds );
446
447 issueDownloader.setStatusIds( statusIds );
448
449 issueDownloader.setResolutionIds( resolutionIds );
450
451 issueDownloader.setPriorityIds( priorityIds );
452
453 issueDownloader.setSortColumnNames( sortColumnNames );
454
455 issueDownloader.setFilter( filter );
456
457 issueDownloader.setJiraDatePattern( jiraDatePattern );
458
459 issueDownloader.setJiraUser( jiraUser );
460
461 issueDownloader.setJiraPassword( jiraPassword );
462
463 issueDownloader.setTypeIds( typeIds );
464
465 issueDownloader.setWebUser( webUser );
466
467 issueDownloader.setWebPassword( webPassword );
468
469 issueDownloader.setSettings( settings );
470
471 issueDownloader.setUseJql( useJql );
472
473 issueDownloader.setOnlyCurrentVersion( onlyCurrentVersion );
474
475 issueDownloader.setVersionPrefix( versionPrefix );
476 }
477
478 public void setMockDownloader( AbstractJiraDownloader mockDownloader )
479 {
480 this.mockDownloader = mockDownloader;
481 }
482
483 public AbstractJiraDownloader getMockDownloader()
484 {
485 return mockDownloader;
486 }
487 }