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.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.issues.Issue;
24 import org.apache.maven.plugin.issues.IssueUtils;
25 import org.apache.maven.plugin.logging.Log;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.settings.Proxy;
28 import org.apache.maven.settings.Settings;
29 import org.apache.maven.wagon.proxy.ProxyInfo;
30
31 import java.io.File;
32 import java.net.MalformedURLException;
33 import java.net.URL;
34 import java.util.List;
35
36
37
38
39
40
41
42
43
44 public abstract class AbstractJiraDownloader
45 {
46 protected static final String UTF_8 = "UTF-8";
47
48
49 protected Log log;
50
51 protected File output;
52
53 protected int nbEntriesMax;
54
55 protected String filter;
56
57 protected String fixVersionIds;
58
59 protected String statusIds;
60
61 protected String resolutionIds;
62
63 protected String priorityIds;
64
65 protected String component;
66
67 protected String typeIds;
68
69 protected String sortColumnNames;
70
71 protected String jiraUser;
72
73 protected String jiraPassword;
74
75 protected String webUser;
76
77 protected String webPassword;
78
79 protected MavenProject project;
80
81 protected Settings settings;
82
83
84
85 protected boolean useJql;
86
87 protected boolean onlyCurrentVersion;
88
89 protected String versionPrefix;
90
91 protected String jiraDatePattern;
92 protected String proxyHost;
93 protected int proxyPort;
94 protected String proxyUser;
95 protected String proxyPass;
96
97
98
99
100
101
102 public abstract void doExecute() throws Exception;
103
104
105
106
107
108
109
110 protected boolean isJiraAuthenticationConfigured()
111 {
112 return ( jiraUser != null ) && ( jiraUser.length() > 0 ) && ( jiraPassword != null );
113 }
114
115
116 protected void getProxyInfo( String jiraUrl )
117 {
118
119 Proxy proxy = null;
120
121 if ( project == null )
122 {
123 getLog().error( "No project set. No proxy info available." );
124
125 return;
126 }
127
128 if ( settings != null )
129 {
130 proxy = settings.getActiveProxy();
131 }
132
133 if ( proxy != null )
134 {
135
136 ProxyInfo proxyInfo = new ProxyInfo();
137 proxyInfo.setNonProxyHosts( proxy.getNonProxyHosts() );
138
139
140 URL url = null;
141 try
142 {
143 url = new URL( jiraUrl );
144 }
145 catch( MalformedURLException e )
146 {
147 getLog().error( "Invalid JIRA URL: " + jiraUrl + ". " + e.getMessage() );
148 }
149 String jiraHost = null;
150 if ( url != null )
151 {
152 jiraHost = url.getHost();
153 }
154
155
156
157
158
159 if ( JiraHelper.validateNonProxyHosts( proxyInfo, jiraHost ) )
160 {
161 return;
162 }
163
164 proxyHost = settings.getActiveProxy().getHost();
165 proxyPort = settings.getActiveProxy().getPort();
166 proxyUser = settings.getActiveProxy().getUsername();
167 proxyPass = settings.getActiveProxy().getPassword();
168 }
169 }
170
171
172
173
174
175
176 protected String getFixFor()
177 {
178 if ( onlyCurrentVersion && useJql )
179 {
180
181
182
183 String version = ( versionPrefix == null ? "" : versionPrefix ) + project.getVersion();
184
185
186 if ( version.endsWith( IssueUtils.SNAPSHOT_SUFFIX ) )
187 {
188 return version.substring( 0, version.length() - IssueUtils.SNAPSHOT_SUFFIX.length() );
189 }
190 else
191 {
192 return version;
193 }
194 }
195 else
196 {
197 return null;
198 }
199 }
200
201
202 public abstract List<Issue> getIssueList() throws MojoExecutionException;
203
204 public void setJiraDatePattern( String jiraDatePattern )
205 {
206 this.jiraDatePattern = jiraDatePattern;
207 }
208
209
210
211
212
213
214 public void setOutput( File thisOutput )
215 {
216 this.output = thisOutput;
217 }
218
219 public File getOutput()
220 {
221 return this.output;
222 }
223
224
225
226
227
228
229 public void setMavenProject( Object thisProject )
230 {
231 this.project = (MavenProject) thisProject;
232 }
233
234
235
236
237
238
239 public void setNbEntries( final int nbEntries )
240 {
241 nbEntriesMax = nbEntries;
242 }
243
244
245
246
247
248
249 public void setStatusIds( String thisStatusIds )
250 {
251 statusIds = thisStatusIds;
252 }
253
254
255
256
257
258
259 public void setPriorityIds( String thisPriorityIds )
260 {
261 priorityIds = thisPriorityIds;
262 }
263
264
265
266
267
268
269 public void setResolutionIds( String thisResolutionIds )
270 {
271 resolutionIds = thisResolutionIds;
272 }
273
274
275
276
277
278
279 public void setSortColumnNames( String thisSortColumnNames )
280 {
281 sortColumnNames = thisSortColumnNames;
282 }
283
284
285
286
287
288
289 public void setWebPassword( String thisWebPassword )
290 {
291 this.webPassword = thisWebPassword;
292 }
293
294
295
296
297
298
299 public void setWebUser( String thisWebUser )
300 {
301 this.webUser = thisWebUser;
302 }
303
304
305
306
307
308
309 public void setJiraPassword( final String thisJiraPassword )
310 {
311 this.jiraPassword = thisJiraPassword;
312 }
313
314
315
316
317
318
319 public void setJiraUser( String thisJiraUser )
320 {
321 this.jiraUser = thisJiraUser;
322 }
323
324
325
326
327
328
329 public void setFilter( String thisFilter )
330 {
331 this.filter = thisFilter;
332 }
333
334
335
336
337
338
339 public void setComponent( String theseComponents )
340 {
341 this.component = theseComponents;
342 }
343
344
345
346
347
348
349 public void setFixVersionIds( String theseFixVersionIds )
350 {
351 this.fixVersionIds = theseFixVersionIds;
352 }
353
354
355
356
357
358
359 public void setTypeIds( String theseTypeIds )
360 {
361 typeIds = theseTypeIds;
362 }
363
364 public void setLog( Log log )
365 {
366 this.log = log;
367 }
368
369 protected Log getLog()
370 {
371 return log;
372 }
373
374 public void setSettings( Settings settings )
375 {
376 this.settings = settings;
377 }
378
379 public boolean isUseJql()
380 {
381 return useJql;
382 }
383
384 public void setUseJql( boolean useJql )
385 {
386 this.useJql = useJql;
387 }
388
389 public boolean isOnlyCurrentVersion()
390 {
391 return onlyCurrentVersion;
392 }
393
394 public void setOnlyCurrentVersion( boolean onlyCurrentVersion )
395 {
396 this.onlyCurrentVersion = onlyCurrentVersion;
397 }
398
399 public String getVersionPrefix()
400 {
401 return versionPrefix;
402 }
403
404 public void setVersionPrefix( String versionPrefix )
405 {
406 this.versionPrefix = versionPrefix;
407 }
408 }