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