Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
JiraMojo |
|
| 1.8181818181818181;1,818 |
1 | package org.apache.maven.jira; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2006 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * 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, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | ||
19 | import org.apache.maven.doxia.siterenderer.Renderer; |
|
20 | import org.apache.maven.project.MavenProject; |
|
21 | import org.apache.maven.reporting.AbstractMavenReport; |
|
22 | import org.apache.maven.reporting.MavenReportException; |
|
23 | import org.apache.maven.settings.Settings; |
|
24 | ||
25 | import java.io.File; |
|
26 | import java.util.Locale; |
|
27 | import java.util.ResourceBundle; |
|
28 | ||
29 | /** |
|
30 | * Goal which downloads issues from the Issue Tracking System and generates a report. |
|
31 | * |
|
32 | * @goal jira-report |
|
33 | * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a> |
|
34 | * @version $Id: JiraMojo.java 422425 2006-07-16 10:09:16 +0000 (sö, 16 jul 2006) dennisl $ |
|
35 | */ |
|
36 | 0 | public class JiraMojo |
37 | 0 | extends AbstractMavenReport |
38 | { |
|
39 | /** |
|
40 | * Output Directory of the report. |
|
41 | * |
|
42 | * @parameter expression="${project.build.directory}/site " |
|
43 | * @required |
|
44 | * @readonly |
|
45 | */ |
|
46 | private String outputDirectory; |
|
47 | ||
48 | /** |
|
49 | * Path of the JIRA XML file to be parsed. |
|
50 | * |
|
51 | * @parameter expression="${project.build.directory}/jira-results.xml " |
|
52 | * @required |
|
53 | * @readonly |
|
54 | */ |
|
55 | private String jiraXmlPath; |
|
56 | ||
57 | /** |
|
58 | * Doxia Site Renderer. |
|
59 | * |
|
60 | * @parameter expression="${component.org.apache.maven.doxia.siterenderer.Renderer}" |
|
61 | * @required |
|
62 | * @readonly |
|
63 | */ |
|
64 | private Renderer siteRenderer; |
|
65 | ||
66 | /** |
|
67 | * The Maven Project. |
|
68 | * |
|
69 | * @parameter expression="${project}" |
|
70 | * @required |
|
71 | * @readonly |
|
72 | */ |
|
73 | private MavenProject project; |
|
74 | ||
75 | /** |
|
76 | * Settings XML configuration. |
|
77 | * |
|
78 | * @parameter expression="${settings}" |
|
79 | * @required |
|
80 | * @readonly |
|
81 | */ |
|
82 | private Settings settings; |
|
83 | ||
84 | /** |
|
85 | * Maximum number of entries to be displayed by the JIRA Report. |
|
86 | * |
|
87 | * @parameter default-value=100 |
|
88 | * |
|
89 | */ |
|
90 | private int maxEntries; |
|
91 | ||
92 | /** |
|
93 | * Defines the filter parameters to restrict the result issues from JIRA. |
|
94 | * The filter parameters property must use the same format of url parameters from the JIRA search. |
|
95 | * |
|
96 | * @parameter default-value="" |
|
97 | */ |
|
98 | private String filter; |
|
99 | ||
100 | /** |
|
101 | * Sets the status(es) of the project you want to limit your report to. |
|
102 | * Valid statuses are: Open, In Progress, Reopened, Resolved and Closed. Multiple values can be separated by commas. |
|
103 | * |
|
104 | * @parameter default-value="" |
|
105 | */ |
|
106 | private String statusIds; |
|
107 | ||
108 | /** |
|
109 | * Sets the resolution(s) of the project you want to limit your report to. |
|
110 | * Valid statuses are: Unresolved, Fixed, Won't Fix, Duplicate, Incomplete, Cannot Reproduce. |
|
111 | * Multiple values can be separated by commas. |
|
112 | * |
|
113 | * @parameter default-value="" |
|
114 | */ |
|
115 | private String resolutionIds; |
|
116 | ||
117 | /** |
|
118 | * Sets the priority(s) of the project you want to limit your report to. |
|
119 | * Valid statuses are: Blocker, Critical, Major, Minor, Trivial. Multiple values can be separated by commas. |
|
120 | * |
|
121 | * @parameter default-value="" |
|
122 | */ |
|
123 | private String priorityIds; |
|
124 | ||
125 | /** |
|
126 | * Sets the component(s) of the project you want to limit your report to. |
|
127 | * Multiple components can be separated by commas (such as 10011,10012). |
|
128 | * Default-value - empty, meaning all components. |
|
129 | * |
|
130 | * @parameter default-value="" |
|
131 | */ |
|
132 | private String component; |
|
133 | ||
134 | /** |
|
135 | * Defines the JIRA username for authentication into a private JIRA installation. |
|
136 | * |
|
137 | * @parameter default-value="" |
|
138 | */ |
|
139 | private String jiraUser; |
|
140 | ||
141 | /** |
|
142 | * Defines the JIRA password for authentication into a private JIRA installation. |
|
143 | * |
|
144 | * @parameter default-value="" |
|
145 | */ |
|
146 | private String jiraPassword; |
|
147 | ||
148 | /** |
|
149 | * Defines the http user for basic authentication into the JIRA webserver. |
|
150 | * |
|
151 | * @parameter default-value="" |
|
152 | */ |
|
153 | private String webUser; |
|
154 | ||
155 | /** |
|
156 | * Defines the http password for basic authentication into the JIRA webserver. |
|
157 | 0 | * |
158 | * @parameter default-value="" |
|
159 | 0 | */ |
160 | private String webPassword; |
|
161 | 0 | |
162 | /** |
|
163 | * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport() |
|
164 | */ |
|
165 | public boolean canGenerateReport() |
|
166 | 0 | { |
167 | 0 | return validateIfIssueManagementComplete(); |
168 | 0 | } |
169 | 0 | |
170 | 0 | public void executeReport( Locale locale ) |
171 | 0 | throws MavenReportException |
172 | { |
|
173 | 0 | JiraDownloader2 jira = new JiraDownloader2(); |
174 | 0 | |
175 | 0 | setJiraDownloaderParameter( jira ); |
176 | 0 | |
177 | JiraReportGenerator report; |
|
178 | 0 | |
179 | try |
|
180 | 0 | { |
181 | 0 | jira.doExecute(); |
182 | 0 | |
183 | 0 | if ( !( new File( jiraXmlPath ).exists() ) ) |
184 | 0 | { |
185 | 0 | return; |
186 | 0 | } |
187 | 0 | |
188 | 0 | report = new JiraReportGenerator( jiraXmlPath ); |
189 | 0 | |
190 | 0 | report.doGenerateReport( getBundle( locale ), getSink() ); |
191 | 0 | } |
192 | 0 | catch ( Exception e ) |
193 | 0 | { |
194 | 0 | e.printStackTrace(); |
195 | 0 | } |
196 | 0 | } |
197 | 0 | |
198 | 0 | public String getName( Locale locale ) |
199 | { |
|
200 | 0 | return getBundle( locale ).getString( "report.jira.name" ); |
201 | 0 | } |
202 | 0 | |
203 | 0 | public String getDescription( Locale locale ) |
204 | { |
|
205 | 0 | return getBundle( locale ).getString( "report.jira.description" ); |
206 | 0 | } |
207 | 0 | |
208 | 0 | protected Renderer getSiteRenderer() |
209 | { |
|
210 | 0 | return siteRenderer; |
211 | 0 | } |
212 | 0 | |
213 | 0 | protected MavenProject getProject() |
214 | { |
|
215 | 0 | return project; |
216 | 0 | } |
217 | 0 | |
218 | 0 | public String getOutputName() |
219 | { |
|
220 | 0 | return "jira-report"; |
221 | 0 | } |
222 | 0 | |
223 | 0 | protected String getOutputDirectory() |
224 | { |
|
225 | 0 | return outputDirectory; |
226 | 0 | } |
227 | 0 | |
228 | 0 | private ResourceBundle getBundle( Locale locale ) |
229 | { |
|
230 | 0 | return ResourceBundle.getBundle( "jira-report", locale, this.getClass().getClassLoader() ); |
231 | 0 | } |
232 | 0 | |
233 | private void setJiraDownloaderParameter( JiraDownloader2 jira ) |
|
234 | 0 | { |
235 | 0 | jira.setLog( getLog() ); |
236 | 0 | |
237 | 0 | jira.setMavenProject( project ); |
238 | 0 | |
239 | 0 | jira.setOutput( new File( jiraXmlPath ) ); |
240 | 0 | |
241 | 0 | jira.setNbEntries( maxEntries ); |
242 | 0 | |
243 | 0 | jira.setComponent( component ); |
244 | 0 | |
245 | 0 | jira.setStatusIds( statusIds ); |
246 | 0 | |
247 | 0 | jira.setResolutionIds( resolutionIds ); |
248 | 0 | |
249 | 0 | jira.setPriorityIds( priorityIds ); |
250 | 0 | |
251 | 0 | jira.setFilter( filter ); |
252 | 0 | |
253 | 0 | jira.setJiraUser( jiraUser ); |
254 | 0 | |
255 | 0 | jira.setJiraPassword( jiraPassword ); |
256 | 0 | |
257 | 0 | jira.setWebUser( webUser ); |
258 | 0 | |
259 | 0 | jira.setWebPassword( webPassword ); |
260 | 0 | |
261 | 0 | jira.setSettings( settings ); |
262 | 0 | } |
263 | 0 | |
264 | 0 | private boolean validateIfIssueManagementComplete() |
265 | 0 | { |
266 | 0 | if ( ( (MavenProject) project ).getIssueManagement() == null ) |
267 | 0 | { |
268 | 0 | getLog().error( "No Issue Management set. JIRA Report will not be generated." ); |
269 | 0 | |
270 | 0 | return false; |
271 | 0 | } |
272 | 0 | else if ( ( ( (MavenProject) project ).getIssueManagement().getUrl() == null ) |
273 | 0 | || ( ( (MavenProject) project ).getIssueManagement().getUrl().trim().equals( "" ) ) ) |
274 | 0 | { |
275 | 0 | getLog().error( "No URL set in Issue Management. JIRA Report will not be generated." ); |
276 | 0 | |
277 | 0 | return false; |
278 | 0 | } |
279 | 0 | else if ( ( ( (MavenProject) project ).getIssueManagement().getSystem() != null ) |
280 | 0 | && !( ( (MavenProject) project ).getIssueManagement().getSystem().equalsIgnoreCase( "jira" ) ) ) |
281 | 0 | { |
282 | 0 | getLog().error( "JIRA Report only supports JIRA. JIRA Report will not be generated." ); |
283 | 0 | |
284 | 0 | return false; |
285 | 0 | } |
286 | 0 | return true; |
287 | 0 | } |
288 | 0 | } |