1 | |
package org.apache.maven.plugin.trac; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.net.MalformedURLException; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.List; |
25 | |
import java.util.Locale; |
26 | |
import java.util.Map; |
27 | |
import java.util.ResourceBundle; |
28 | |
|
29 | |
import org.apache.maven.plugin.changes.AbstractChangesReport; |
30 | |
import org.apache.maven.plugin.changes.ProjectUtils; |
31 | |
import org.apache.maven.plugin.issues.IssuesReportGenerator; |
32 | |
import org.apache.maven.plugin.issues.IssuesReportHelper; |
33 | |
import org.apache.maven.reporting.MavenReportException; |
34 | |
import org.apache.xmlrpc.XmlRpcException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class TracMojo |
47 | |
extends AbstractChangesReport |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | 0 | private static Map<String,Integer> DEPRECATED_TRAC_COLUMNS = new HashMap<String,Integer>(); |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | private static Map<String,Integer> TRAC_COLUMNS = new HashMap<String,Integer>(); |
58 | |
|
59 | |
static |
60 | |
{ |
61 | 0 | DEPRECATED_TRAC_COLUMNS.put( "changed", new Integer( IssuesReportHelper.COLUMN_UPDATED ) ); |
62 | 0 | DEPRECATED_TRAC_COLUMNS.put( "component", new Integer( IssuesReportHelper.COLUMN_COMPONENT ) ); |
63 | 0 | DEPRECATED_TRAC_COLUMNS.put( "created", new Integer( IssuesReportHelper.COLUMN_CREATED ) ); |
64 | 0 | DEPRECATED_TRAC_COLUMNS.put( "id", new Integer( IssuesReportHelper.COLUMN_ID ) ); |
65 | 0 | DEPRECATED_TRAC_COLUMNS.put( "milestone", new Integer( IssuesReportHelper.COLUMN_FIX_VERSION ) ); |
66 | 0 | DEPRECATED_TRAC_COLUMNS.put( "owner", new Integer( IssuesReportHelper.COLUMN_ASSIGNEE ) ); |
67 | 0 | DEPRECATED_TRAC_COLUMNS.put( "priority", new Integer( IssuesReportHelper.COLUMN_PRIORITY ) ); |
68 | 0 | DEPRECATED_TRAC_COLUMNS.put( "reporter", new Integer( IssuesReportHelper.COLUMN_REPORTER ) ); |
69 | 0 | DEPRECATED_TRAC_COLUMNS.put( "resolution", new Integer( IssuesReportHelper.COLUMN_RESOLUTION ) ); |
70 | 0 | DEPRECATED_TRAC_COLUMNS.put( "status", new Integer( IssuesReportHelper.COLUMN_STATUS ) ); |
71 | 0 | DEPRECATED_TRAC_COLUMNS.put( "summary", new Integer( IssuesReportHelper.COLUMN_SUMMARY ) ); |
72 | 0 | DEPRECATED_TRAC_COLUMNS.put( "type", new Integer( IssuesReportHelper.COLUMN_TYPE ) ); |
73 | |
|
74 | 0 | TRAC_COLUMNS.put( "Assignee", new Integer( IssuesReportHelper.COLUMN_ASSIGNEE ) ); |
75 | 0 | TRAC_COLUMNS.put( "Component", new Integer( IssuesReportHelper.COLUMN_COMPONENT ) ); |
76 | 0 | TRAC_COLUMNS.put( "Created", new Integer( IssuesReportHelper.COLUMN_CREATED ) ); |
77 | 0 | TRAC_COLUMNS.put( "Fix Version", new Integer( IssuesReportHelper.COLUMN_FIX_VERSION ) ); |
78 | 0 | TRAC_COLUMNS.put( "Id", new Integer( IssuesReportHelper.COLUMN_ID ) ); |
79 | 0 | TRAC_COLUMNS.put( "Priority", new Integer( IssuesReportHelper.COLUMN_PRIORITY ) ); |
80 | 0 | TRAC_COLUMNS.put( "Reporter", new Integer( IssuesReportHelper.COLUMN_REPORTER ) ); |
81 | 0 | TRAC_COLUMNS.put( "Resolution", new Integer( IssuesReportHelper.COLUMN_RESOLUTION ) ); |
82 | 0 | TRAC_COLUMNS.put( "Status", new Integer( IssuesReportHelper.COLUMN_STATUS ) ); |
83 | 0 | TRAC_COLUMNS.put( "Summary", new Integer( IssuesReportHelper.COLUMN_SUMMARY ) ); |
84 | 0 | TRAC_COLUMNS.put( "Type", new Integer( IssuesReportHelper.COLUMN_TYPE ) ); |
85 | 0 | TRAC_COLUMNS.put( "Updated", new Integer( IssuesReportHelper.COLUMN_UPDATED ) ); |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
private String columnNames; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
private String query; |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
private String tracPassword; |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
private String tracUser; |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public boolean canGenerateReport() |
136 | |
{ |
137 | 0 | return ProjectUtils.validateIfIssueManagementComplete( project, "Trac", "Trac Report", getLog() ); |
138 | |
} |
139 | |
|
140 | |
public void executeReport( Locale locale ) |
141 | |
throws MavenReportException |
142 | |
{ |
143 | |
|
144 | 0 | List<Integer> columnIds = IssuesReportHelper.getColumnIds( columnNames, TRAC_COLUMNS, DEPRECATED_TRAC_COLUMNS, |
145 | |
getLog() ); |
146 | 0 | if ( columnIds.size() == 0 ) |
147 | |
{ |
148 | |
|
149 | 0 | throw new MavenReportException( |
150 | |
"maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." ); |
151 | |
} |
152 | |
|
153 | |
try |
154 | |
{ |
155 | |
|
156 | 0 | TracDownloader issueDownloader = new TracDownloader(); |
157 | 0 | configureIssueDownloader( issueDownloader ); |
158 | |
|
159 | 0 | List issueList = issueDownloader.getIssueList(); |
160 | |
|
161 | |
|
162 | 0 | IssuesReportGenerator report = new IssuesReportGenerator( IssuesReportHelper.toIntArray( columnIds ) ); |
163 | |
|
164 | 0 | if ( issueList.isEmpty() ) |
165 | |
{ |
166 | 0 | report.doGenerateEmptyReport( getBundle( locale ), getSink() ); |
167 | 0 | getLog().warn( "No ticket has matched." ); |
168 | |
} |
169 | |
else |
170 | |
{ |
171 | 0 | report.doGenerateReport( getBundle( locale ), getSink(), issueList ); |
172 | |
} |
173 | |
} |
174 | 0 | catch ( MalformedURLException e ) |
175 | |
{ |
176 | |
|
177 | 0 | throw new MavenReportException( "The Trac URL is incorrect." ); |
178 | |
} |
179 | 0 | catch ( XmlRpcException e ) |
180 | |
{ |
181 | |
|
182 | 0 | throw new MavenReportException( "XmlRpc Error.", e ); |
183 | |
} |
184 | 0 | catch ( Exception e ) |
185 | |
{ |
186 | 0 | e.printStackTrace(); |
187 | 0 | } |
188 | 0 | } |
189 | |
|
190 | |
public String getDescription( Locale locale ) |
191 | |
{ |
192 | 0 | return getBundle( locale ).getString( "report.issues.description" ); |
193 | |
} |
194 | |
|
195 | |
public String getName( Locale locale ) |
196 | |
{ |
197 | 0 | return getBundle( locale ).getString( "report.issues.name" ); |
198 | |
} |
199 | |
|
200 | |
public String getOutputName() |
201 | |
{ |
202 | 0 | return "trac-report"; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
private ResourceBundle getBundle( Locale locale ) |
210 | |
{ |
211 | 0 | return ResourceBundle.getBundle( "trac-report", locale, this.getClass().getClassLoader() ); |
212 | |
} |
213 | |
|
214 | |
private void configureIssueDownloader( TracDownloader issueDownloader ) |
215 | |
{ |
216 | 0 | issueDownloader.setProject( project ); |
217 | |
|
218 | 0 | issueDownloader.setQuery( query ); |
219 | |
|
220 | 0 | issueDownloader.setTracPassword( tracPassword ); |
221 | |
|
222 | 0 | issueDownloader.setTracUser( tracUser ); |
223 | 0 | } |
224 | |
} |