1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.changes.trac;
20
21 import java.net.MalformedURLException;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Locale;
25 import java.util.Map;
26 import java.util.ResourceBundle;
27
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.apache.maven.plugins.changes.AbstractChangesReport;
31 import org.apache.maven.plugins.changes.ProjectUtils;
32 import org.apache.maven.plugins.changes.issues.Issue;
33 import org.apache.maven.plugins.changes.issues.IssuesReportHelper;
34 import org.apache.maven.plugins.changes.issues.IssuesReportRenderer;
35 import org.apache.maven.reporting.MavenReportException;
36 import org.apache.xmlrpc.XmlRpcException;
37
38
39
40
41
42
43
44
45
46 @Deprecated
47 @Mojo(name = "trac-changes", threadSafe = true)
48 public class TracChangesReport extends AbstractChangesReport {
49
50
51
52
53 private static final Map<String, Integer> TRAC_COLUMNS = new HashMap<>();
54
55 static {
56 TRAC_COLUMNS.put("Assignee", IssuesReportHelper.COLUMN_ASSIGNEE);
57 TRAC_COLUMNS.put("Component", IssuesReportHelper.COLUMN_COMPONENT);
58 TRAC_COLUMNS.put("Created", IssuesReportHelper.COLUMN_CREATED);
59 TRAC_COLUMNS.put("Fix Version", IssuesReportHelper.COLUMN_FIX_VERSION);
60 TRAC_COLUMNS.put("Id", IssuesReportHelper.COLUMN_ID);
61 TRAC_COLUMNS.put("Priority", IssuesReportHelper.COLUMN_PRIORITY);
62 TRAC_COLUMNS.put("Reporter", IssuesReportHelper.COLUMN_REPORTER);
63 TRAC_COLUMNS.put("Resolution", IssuesReportHelper.COLUMN_RESOLUTION);
64 TRAC_COLUMNS.put("Status", IssuesReportHelper.COLUMN_STATUS);
65 TRAC_COLUMNS.put("Summary", IssuesReportHelper.COLUMN_SUMMARY);
66 TRAC_COLUMNS.put("Type", IssuesReportHelper.COLUMN_TYPE);
67 TRAC_COLUMNS.put("Updated", IssuesReportHelper.COLUMN_UPDATED);
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81 @Parameter(defaultValue = "Id,Type,Summary,Assignee,Reporter,Priority,Status,Resolution,Created,Updated")
82 private String columnNames;
83
84
85
86
87 @Parameter(defaultValue = "order=id")
88 private String query;
89
90
91
92
93 @Parameter
94 private String tracPassword;
95
96
97
98
99 @Parameter
100 private String tracUser;
101
102
103
104
105
106
107
108
109 @Override
110 public boolean canGenerateReport() {
111
112 if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
113 getLog().info("Skipping the Trac Report in this project because it's not the Execution Root");
114 return false;
115 }
116 String message = ProjectUtils.validateIssueManagement(project, "Trac", "Trac Report");
117 if (message != null) {
118 getLog().warn(message);
119 }
120 return message == null;
121 }
122
123 @Override
124 public void executeReport(Locale locale) throws MavenReportException {
125
126 List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, TRAC_COLUMNS);
127 if (columnIds.isEmpty()) {
128
129 throw new MavenReportException(
130 "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid.");
131 }
132
133 try {
134
135 TracDownloader issueDownloader = new TracDownloader();
136 configureIssueDownloader(issueDownloader);
137
138 List<Issue> issueList = issueDownloader.getIssueList();
139
140
141 IssuesReportRenderer report = new IssuesReportRenderer(getSink(), getBundle(locale), columnIds, issueList);
142 report.render();
143
144 } catch (MalformedURLException e) {
145
146 throw new MavenReportException("The Trac URL is incorrect.");
147 } catch (XmlRpcException e) {
148
149 throw new MavenReportException("XmlRpc Error.", e);
150 } catch (Exception e) {
151 throw new MavenReportException(e.getMessage(), e);
152 }
153 }
154
155 @Override
156 public String getDescription(Locale locale) {
157 return getBundle(locale).getString("report.issues.description");
158 }
159
160 @Override
161 public String getName(Locale locale) {
162 return getBundle(locale).getString("report.issues.name");
163 }
164
165 @Override
166 @Deprecated
167 public String getOutputName() {
168 return "trac-changes";
169 }
170
171
172
173
174
175 private ResourceBundle getBundle(Locale locale) {
176 return ResourceBundle.getBundle("trac-report", locale, this.getClass().getClassLoader());
177 }
178
179 private void configureIssueDownloader(TracDownloader issueDownloader) {
180 issueDownloader.setProject(project);
181 issueDownloader.setQuery(query);
182 issueDownloader.setTracPassword(tracPassword);
183 issueDownloader.setTracUser(tracUser);
184 }
185 }