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