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