1 |
|
package org.codehaus.mojo.exec; |
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.artifact.Artifact; |
23 |
|
import org.apache.maven.artifact.factory.ArtifactFactory; |
24 |
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; |
25 |
|
import org.apache.maven.artifact.repository.ArtifactRepository; |
26 |
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; |
27 |
|
import org.apache.maven.artifact.resolver.ArtifactResolver; |
28 |
|
import org.apache.maven.plugin.MojoExecutionException; |
29 |
|
import org.apache.maven.plugin.MojoFailureException; |
30 |
|
import org.apache.maven.project.MavenProject; |
31 |
|
import org.apache.maven.project.MavenProjectBuilder; |
32 |
|
import org.apache.maven.project.artifact.MavenMetadataSource; |
33 |
|
|
34 |
|
import java.io.File; |
35 |
|
import java.lang.reflect.Method; |
36 |
|
import java.net.MalformedURLException; |
37 |
|
import java.net.URL; |
38 |
|
import java.net.URLClassLoader; |
39 |
|
import java.util.ArrayList; |
40 |
|
import java.util.Collection; |
41 |
|
import java.util.Collections; |
42 |
|
import java.util.HashSet; |
43 |
|
import java.util.Iterator; |
44 |
|
import java.util.List; |
45 |
|
import java.util.Properties; |
46 |
|
import java.util.Set; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@author |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@since |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 266 (266) |
Complexity: 63 |
Complexity Density: 0.36 |
|
58 |
|
public class ExecJavaMojo |
59 |
|
extends AbstractExecMojo |
60 |
|
{ |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private ArtifactResolver artifactResolver; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
private ArtifactFactory artifactFactory; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
private ArtifactMetadataSource metadataSource; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@since |
81 |
|
|
82 |
|
private ArtifactRepository localRepository; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@since |
89 |
|
|
90 |
|
private List remoteRepositories; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@since |
95 |
|
|
96 |
|
private MavenProjectBuilder projectBuilder; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@since |
102 |
|
|
103 |
|
private List pluginDependencies; |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@since |
111 |
|
|
112 |
|
private String mainClass; |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@since |
119 |
|
|
120 |
|
private String[] arguments; |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
@since |
129 |
|
|
130 |
|
private Property[] systemProperties; |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
@deprecated |
138 |
|
@since |
139 |
|
|
140 |
|
private boolean keepAlive; |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@since |
148 |
|
|
149 |
|
private boolean includeProjectDependencies; |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@since |
162 |
|
|
163 |
|
private boolean includePluginDependencies; |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@since |
178 |
|
|
179 |
|
private ExecutableDependency executableDependency; |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@link |
190 |
|
@link |
191 |
|
|
192 |
|
|
193 |
|
@since |
194 |
|
|
195 |
|
private boolean cleanupDaemonThreads; |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
@link |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@since |
209 |
|
|
210 |
|
private long daemonThreadJoinTimeout; |
211 |
|
|
212 |
|
|
213 |
|
@link |
214 |
|
@link |
215 |
|
@link |
216 |
|
@link |
217 |
|
|
218 |
|
|
219 |
|
@link |
220 |
|
|
221 |
|
|
222 |
|
@since |
223 |
|
|
224 |
|
private boolean stopUnresponsiveDaemonThreads; |
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
@deprecated |
231 |
|
@since |
232 |
|
|
233 |
|
private long killAfter; |
234 |
|
|
235 |
|
private Properties originalSystemProperties; |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
@throws |
240 |
|
@throws |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 12 |
Complexity Density: 0.32 |
|
242 |
0
|
public void execute()... |
243 |
|
throws MojoExecutionException, MojoFailureException |
244 |
|
{ |
245 |
0
|
if ( isSkip() ) |
246 |
|
{ |
247 |
0
|
getLog().info( "skipping execute as per configuraion" ); |
248 |
0
|
return; |
249 |
|
} |
250 |
0
|
if ( killAfter != -1 ) |
251 |
|
{ |
252 |
0
|
getLog().warn( "Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6." ); |
253 |
|
} |
254 |
|
|
255 |
0
|
if ( null == arguments ) |
256 |
|
{ |
257 |
0
|
arguments = new String[0]; |
258 |
|
} |
259 |
|
|
260 |
0
|
if ( getLog().isDebugEnabled() ) |
261 |
|
{ |
262 |
0
|
StringBuffer msg = new StringBuffer( "Invoking : " ); |
263 |
0
|
msg.append( mainClass ); |
264 |
0
|
msg.append( ".main(" ); |
265 |
0
|
for ( int i = 0; i < arguments.length; i++ ) |
266 |
|
{ |
267 |
0
|
if ( i > 0 ) |
268 |
|
{ |
269 |
0
|
msg.append( ", " ); |
270 |
|
} |
271 |
0
|
msg.append( arguments[i] ); |
272 |
|
} |
273 |
0
|
msg.append( ")" ); |
274 |
0
|
getLog().debug( msg ); |
275 |
|
} |
276 |
|
|
277 |
0
|
IsolatedThreadGroup threadGroup = new IsolatedThreadGroup( mainClass ); |
278 |
0
|
Thread bootstrapThread = new Thread( threadGroup, new Runnable() |
279 |
|
{ |
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
280 |
0
|
public void run()... |
281 |
|
{ |
282 |
0
|
try |
283 |
|
{ |
284 |
0
|
Method main = Thread.currentThread().getContextClassLoader().loadClass( mainClass ) |
285 |
|
.getMethod( "main", new Class[]{ String[].class } ); |
286 |
0
|
if ( ! main.isAccessible() ) |
287 |
|
{ |
288 |
0
|
getLog().debug( "Setting accessibility to true in order to invoke main()." ); |
289 |
0
|
main.setAccessible( true ); |
290 |
|
} |
291 |
0
|
main.invoke( main, new Object[]{arguments} ); |
292 |
|
} |
293 |
|
catch ( NoSuchMethodException e ) |
294 |
|
{ |
295 |
0
|
Thread.currentThread().getThreadGroup().uncaughtException( Thread.currentThread(), |
296 |
|
new Exception( |
297 |
|
"The specified mainClass doesn't contain a main method with appropriate signature.", e |
298 |
|
) |
299 |
|
); |
300 |
|
} |
301 |
|
catch ( Exception e ) |
302 |
|
{ |
303 |
0
|
Thread.currentThread().getThreadGroup().uncaughtException( Thread.currentThread(), e ); |
304 |
|
} |
305 |
|
} |
306 |
|
}, mainClass + ".main()" ); |
307 |
0
|
bootstrapThread.setContextClassLoader( getClassLoader() ); |
308 |
0
|
setSystemProperties(); |
309 |
|
|
310 |
0
|
bootstrapThread.start(); |
311 |
0
|
joinNonDaemonThreads( threadGroup ); |
312 |
|
|
313 |
|
|
314 |
0
|
if ( keepAlive ) |
315 |
|
{ |
316 |
0
|
getLog().warn( |
317 |
|
"Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6." ); |
318 |
0
|
waitFor( 0 ); |
319 |
|
} |
320 |
|
|
321 |
0
|
if ( cleanupDaemonThreads ) |
322 |
|
{ |
323 |
|
|
324 |
0
|
terminateThreads( threadGroup ); |
325 |
|
|
326 |
0
|
try |
327 |
|
{ |
328 |
0
|
threadGroup.destroy(); |
329 |
|
} |
330 |
|
catch ( IllegalThreadStateException e ) |
331 |
|
{ |
332 |
0
|
getLog().warn( "Couldn't destroy threadgroup " + threadGroup, e ); |
333 |
|
} |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
0
|
if ( originalSystemProperties != null ) |
338 |
|
{ |
339 |
0
|
System.setProperties( originalSystemProperties ); |
340 |
|
} |
341 |
|
|
342 |
0
|
synchronized ( threadGroup ) |
343 |
|
{ |
344 |
0
|
if ( threadGroup.uncaughtException != null ) |
345 |
|
{ |
346 |
0
|
throw new MojoExecutionException( "An exception occured while executing the Java class. " |
347 |
|
+ threadGroup.uncaughtException.getMessage(), |
348 |
|
threadGroup.uncaughtException ); |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
0
|
registerSourceRoots(); |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
358 |
|
class IsolatedThreadGroup extends ThreadGroup |
359 |
|
{ |
360 |
|
private Throwable uncaughtException; |
361 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
362 |
0
|
public IsolatedThreadGroup( String name )... |
363 |
|
{ |
364 |
0
|
super( name ); |
365 |
|
} |
366 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
367 |
0
|
public void uncaughtException( Thread thread, Throwable throwable )... |
368 |
|
{ |
369 |
0
|
if ( throwable instanceof ThreadDeath ) |
370 |
|
{ |
371 |
0
|
return; |
372 |
|
} |
373 |
0
|
boolean doLog = false; |
374 |
0
|
synchronized ( this ) |
375 |
|
{ |
376 |
0
|
if ( uncaughtException == null ) |
377 |
|
{ |
378 |
0
|
uncaughtException = throwable; |
379 |
|
} |
380 |
|
else |
381 |
|
{ |
382 |
0
|
doLog = true; |
383 |
|
} |
384 |
|
} |
385 |
0
|
if ( doLog ) |
386 |
|
{ |
387 |
0
|
getLog().warn( "an additional exception was thrown", throwable ); |
388 |
|
} |
389 |
|
} |
390 |
|
} |
391 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
392 |
0
|
private void joinNonDaemonThreads( ThreadGroup threadGroup )... |
393 |
|
{ |
394 |
0
|
boolean foundNonDaemon; |
395 |
0
|
do |
396 |
|
{ |
397 |
0
|
foundNonDaemon = false; |
398 |
0
|
Collection threads = getActiveThreads( threadGroup ); |
399 |
0
|
for ( Iterator iter = threads.iterator(); iter.hasNext(); ) |
400 |
|
{ |
401 |
0
|
Thread thread = (Thread) iter.next(); |
402 |
0
|
if ( thread.isDaemon() ) |
403 |
|
{ |
404 |
0
|
continue; |
405 |
|
} |
406 |
0
|
foundNonDaemon = true; |
407 |
0
|
joinThread( thread, 0 ); |
408 |
|
} |
409 |
0
|
} while ( foundNonDaemon ); |
410 |
|
} |
411 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
412 |
0
|
private void joinThread( Thread thread, long timeoutMsecs )... |
413 |
|
{ |
414 |
0
|
try |
415 |
|
{ |
416 |
0
|
getLog().debug( "joining on thread " + thread ); |
417 |
0
|
thread.join( timeoutMsecs ); |
418 |
|
} |
419 |
|
catch ( InterruptedException e ) |
420 |
|
{ |
421 |
0
|
Thread.currentThread().interrupt(); |
422 |
0
|
getLog().warn( "interrupted while joining against thread " + thread, e ); |
423 |
|
} |
424 |
0
|
if ( thread.isAlive() ) |
425 |
|
{ |
426 |
0
|
getLog().warn( "thread " + thread + " was interrupted but is still alive after waiting at least " |
427 |
|
+ timeoutMsecs + "msecs" ); |
428 |
|
} |
429 |
|
} |
430 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 11 |
Complexity Density: 0.35 |
|
431 |
0
|
private void terminateThreads( ThreadGroup threadGroup )... |
432 |
|
{ |
433 |
0
|
long startTime = System.currentTimeMillis(); |
434 |
0
|
Set uncooperativeThreads = new HashSet(); |
435 |
0
|
for ( Collection threads = getActiveThreads( threadGroup ); !threads.isEmpty(); |
436 |
|
threads = getActiveThreads( threadGroup ), threads.removeAll( uncooperativeThreads ) ) |
437 |
|
{ |
438 |
|
|
439 |
|
|
440 |
0
|
for ( Iterator iter = threads.iterator(); iter.hasNext(); ) |
441 |
|
{ |
442 |
0
|
Thread thread = (Thread) iter.next(); |
443 |
0
|
getLog().debug( "interrupting thread " + thread ); |
444 |
0
|
thread.interrupt(); |
445 |
|
} |
446 |
|
|
447 |
0
|
for ( Iterator iter = threads.iterator(); iter.hasNext(); ) |
448 |
|
{ |
449 |
0
|
Thread thread = (Thread) iter.next(); |
450 |
0
|
if ( ! thread.isAlive() ) |
451 |
|
{ |
452 |
0
|
continue; |
453 |
|
} |
454 |
0
|
if ( daemonThreadJoinTimeout <= 0 ) |
455 |
|
{ |
456 |
0
|
joinThread( thread, 0 ); |
457 |
0
|
continue; |
458 |
|
} |
459 |
0
|
long timeout = daemonThreadJoinTimeout |
460 |
|
- ( System.currentTimeMillis() - startTime ); |
461 |
0
|
if ( timeout > 0 ) |
462 |
|
{ |
463 |
0
|
joinThread( thread, timeout ); |
464 |
|
} |
465 |
0
|
if ( ! thread.isAlive() ) |
466 |
|
{ |
467 |
0
|
continue; |
468 |
|
} |
469 |
0
|
uncooperativeThreads.add( thread ); |
470 |
0
|
if ( stopUnresponsiveDaemonThreads ) |
471 |
|
{ |
472 |
0
|
getLog().warn( "thread " + thread + " will be Thread.stop()'ed" ); |
473 |
0
|
thread.stop(); |
474 |
|
} |
475 |
|
else |
476 |
|
{ |
477 |
0
|
getLog().warn( "thread " + thread + " will linger despite being asked to die via interruption" ); |
478 |
|
} |
479 |
|
} |
480 |
|
} |
481 |
0
|
if ( ! uncooperativeThreads.isEmpty() ) |
482 |
|
{ |
483 |
0
|
getLog().warn( "NOTE: " + uncooperativeThreads.size() + " thread(s) did not finish despite being asked to " |
484 |
|
+ " via interruption. This is not a problem with exec:java, it is a problem with the running code." |
485 |
|
+ " Although not serious, it should be remedied." ); |
486 |
|
} |
487 |
|
else |
488 |
|
{ |
489 |
0
|
int activeCount = threadGroup.activeCount(); |
490 |
0
|
if ( activeCount != 0 ) |
491 |
|
{ |
492 |
|
|
493 |
0
|
Thread[] threadsArray = new Thread[1]; |
494 |
0
|
threadGroup.enumerate( threadsArray ); |
495 |
0
|
getLog().debug( "strange; " + activeCount |
496 |
|
+ " thread(s) still active in the group " + threadGroup + " such as " + threadsArray[0] ); |
497 |
|
} |
498 |
|
} |
499 |
|
} |
500 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
501 |
0
|
private Collection getActiveThreads( ThreadGroup threadGroup )... |
502 |
|
{ |
503 |
0
|
Thread[] threads = new Thread[ threadGroup.activeCount() ]; |
504 |
0
|
int numThreads = threadGroup.enumerate( threads ); |
505 |
0
|
Collection result = new ArrayList( numThreads ); |
506 |
0
|
for ( int i = 0; i < threads.length && threads[i] != null; i++ ) |
507 |
|
{ |
508 |
0
|
result.add( threads[i] ); |
509 |
|
} |
510 |
0
|
return result; |
511 |
|
} |
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
516 |
0
|
private void setSystemProperties()... |
517 |
|
{ |
518 |
0
|
if ( systemProperties != null ) |
519 |
|
{ |
520 |
0
|
originalSystemProperties = System.getProperties(); |
521 |
0
|
for ( int i = 0; i < systemProperties.length; i++ ) |
522 |
|
{ |
523 |
0
|
Property systemProperty = systemProperties[i]; |
524 |
0
|
String value = systemProperty.getValue(); |
525 |
0
|
System.setProperty( systemProperty.getKey(), value == null ? "" : value ); |
526 |
|
} |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
|
@return |
534 |
|
@throws |
535 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
536 |
0
|
private ClassLoader getClassLoader()... |
537 |
|
throws MojoExecutionException |
538 |
|
{ |
539 |
0
|
List classpathURLs = new ArrayList(); |
540 |
0
|
this.addRelevantPluginDependenciesToClasspath( classpathURLs ); |
541 |
0
|
this.addRelevantProjectDependenciesToClasspath( classpathURLs ); |
542 |
0
|
return new URLClassLoader( ( URL[] ) classpathURLs.toArray( new URL[ classpathURLs.size() ] ) ); |
543 |
|
} |
544 |
|
|
545 |
|
|
546 |
|
|
547 |
|
|
548 |
|
|
549 |
|
@param@link |
550 |
|
@throws |
551 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
552 |
0
|
private void addRelevantPluginDependenciesToClasspath( List path )... |
553 |
|
throws MojoExecutionException |
554 |
|
{ |
555 |
0
|
if ( hasCommandlineArgs() ) |
556 |
|
{ |
557 |
0
|
arguments = parseCommandlineArgs(); |
558 |
|
} |
559 |
|
|
560 |
0
|
try |
561 |
|
{ |
562 |
0
|
Iterator iter = this.determineRelevantPluginDependencies().iterator(); |
563 |
0
|
while ( iter.hasNext() ) |
564 |
|
{ |
565 |
0
|
Artifact classPathElement = (Artifact) iter.next(); |
566 |
0
|
getLog().debug( |
567 |
|
"Adding plugin dependency artifact: " + classPathElement.getArtifactId() + " to classpath" ); |
568 |
0
|
path.add( classPathElement.getFile().toURI().toURL() ); |
569 |
|
} |
570 |
|
} |
571 |
|
catch ( MalformedURLException e ) |
572 |
|
{ |
573 |
0
|
throw new MojoExecutionException( "Error during setting up classpath", e ); |
574 |
|
} |
575 |
|
|
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
@param@link |
583 |
|
@throws |
584 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 5 |
Complexity Density: 0.29 |
|
585 |
0
|
private void addRelevantProjectDependenciesToClasspath( List path )... |
586 |
|
throws MojoExecutionException |
587 |
|
{ |
588 |
0
|
if ( this.includeProjectDependencies ) |
589 |
|
{ |
590 |
0
|
try |
591 |
|
{ |
592 |
0
|
getLog().debug( "Project Dependencies will be included." ); |
593 |
|
|
594 |
0
|
List artifacts = new ArrayList(); |
595 |
0
|
List theClasspathFiles = new ArrayList(); |
596 |
|
|
597 |
0
|
collectProjectArtifactsAndClasspath( artifacts, theClasspathFiles ); |
598 |
|
|
599 |
0
|
for ( Iterator it = theClasspathFiles.iterator(); it.hasNext(); ) |
600 |
|
{ |
601 |
0
|
URL url = ( (File) it.next() ).toURI().toURL(); |
602 |
0
|
getLog().debug( "Adding to classpath : " + url ); |
603 |
0
|
path.add( url ); |
604 |
|
} |
605 |
|
|
606 |
0
|
Iterator iter = artifacts.iterator(); |
607 |
0
|
while ( iter.hasNext() ) |
608 |
|
{ |
609 |
0
|
Artifact classPathElement = (Artifact) iter.next(); |
610 |
0
|
getLog().debug( |
611 |
|
"Adding project dependency artifact: " + classPathElement.getArtifactId() + " to classpath" ); |
612 |
0
|
path.add( classPathElement.getFile().toURI().toURL() ); |
613 |
|
} |
614 |
|
|
615 |
|
} |
616 |
|
catch ( MalformedURLException e ) |
617 |
|
{ |
618 |
0
|
throw new MojoExecutionException( "Error during setting up classpath", e ); |
619 |
|
} |
620 |
|
} |
621 |
|
else |
622 |
|
{ |
623 |
0
|
getLog().debug( "Project Dependencies will be excluded." ); |
624 |
|
} |
625 |
|
|
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
@return |
633 |
|
|
634 |
|
@throws |
635 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
636 |
0
|
private Set determineRelevantPluginDependencies()... |
637 |
|
throws MojoExecutionException |
638 |
|
{ |
639 |
0
|
Set relevantDependencies; |
640 |
0
|
if ( this.includePluginDependencies ) |
641 |
|
{ |
642 |
0
|
if ( this.executableDependency == null ) |
643 |
|
{ |
644 |
0
|
getLog().debug( "All Plugin Dependencies will be included." ); |
645 |
0
|
relevantDependencies = new HashSet( this.pluginDependencies ); |
646 |
|
} |
647 |
|
else |
648 |
|
{ |
649 |
0
|
getLog().debug( "Selected plugin Dependencies will be included." ); |
650 |
0
|
Artifact executableArtifact = this.findExecutableArtifact(); |
651 |
0
|
Artifact executablePomArtifact = this.getExecutablePomArtifact( executableArtifact ); |
652 |
0
|
relevantDependencies = this.resolveExecutableDependencies( executablePomArtifact ); |
653 |
|
} |
654 |
|
} |
655 |
|
else |
656 |
|
{ |
657 |
0
|
relevantDependencies = Collections.EMPTY_SET; |
658 |
0
|
getLog().debug( "Plugin Dependencies will be excluded." ); |
659 |
|
} |
660 |
0
|
return relevantDependencies; |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
@param |
667 |
|
@return |
668 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
669 |
0
|
private Artifact getExecutablePomArtifact( Artifact executableArtifact )... |
670 |
|
{ |
671 |
0
|
return this.artifactFactory.createBuildArtifact( executableArtifact.getGroupId(), |
672 |
|
executableArtifact.getArtifactId(), |
673 |
|
executableArtifact.getVersion(), "pom" ); |
674 |
|
} |
675 |
|
|
676 |
|
|
677 |
|
|
678 |
|
|
679 |
|
@return |
680 |
|
@throws |
681 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
682 |
0
|
private Artifact findExecutableArtifact()... |
683 |
|
throws MojoExecutionException |
684 |
|
{ |
685 |
|
|
686 |
|
|
687 |
0
|
Artifact executableTool = null; |
688 |
0
|
for ( Iterator iter = this.pluginDependencies.iterator(); iter.hasNext(); ) |
689 |
|
{ |
690 |
0
|
Artifact pluginDep = (Artifact) iter.next(); |
691 |
0
|
if ( this.executableDependency.matches( pluginDep ) ) |
692 |
|
{ |
693 |
0
|
executableTool = pluginDep; |
694 |
0
|
break; |
695 |
|
} |
696 |
|
} |
697 |
|
|
698 |
0
|
if ( executableTool == null ) |
699 |
|
{ |
700 |
0
|
throw new MojoExecutionException( |
701 |
|
"No dependency of the plugin matches the specified executableDependency." |
702 |
|
+ " Specified executableToolAssembly is: " + executableDependency.toString() ); |
703 |
|
} |
704 |
|
|
705 |
0
|
return executableTool; |
706 |
|
} |
707 |
|
|
708 |
|
|
709 |
|
|
710 |
|
@param |
711 |
|
@return |
712 |
|
@throws |
713 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
714 |
0
|
private Set resolveExecutableDependencies( Artifact executablePomArtifact )... |
715 |
|
throws MojoExecutionException |
716 |
|
{ |
717 |
|
|
718 |
0
|
Set executableDependencies; |
719 |
0
|
try |
720 |
|
{ |
721 |
0
|
MavenProject executableProject = this.projectBuilder.buildFromRepository( executablePomArtifact, |
722 |
|
this.remoteRepositories, |
723 |
|
this.localRepository ); |
724 |
|
|
725 |
|
|
726 |
0
|
List dependencies = executableProject.getDependencies(); |
727 |
|
|
728 |
|
|
729 |
0
|
Set dependencyArtifacts = |
730 |
|
MavenMetadataSource.createArtifacts( this.artifactFactory, dependencies, null, null, null ); |
731 |
|
|
732 |
|
|
733 |
0
|
dependencyArtifacts.add( executableProject.getArtifact() ); |
734 |
|
|
735 |
|
|
736 |
0
|
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencyArtifacts, |
737 |
|
executablePomArtifact, |
738 |
|
Collections.EMPTY_MAP, |
739 |
|
this.localRepository, |
740 |
|
this.remoteRepositories, |
741 |
|
metadataSource, null, |
742 |
|
Collections.EMPTY_LIST ); |
743 |
0
|
executableDependencies = result.getArtifacts(); |
744 |
|
|
745 |
|
} |
746 |
|
catch ( Exception ex ) |
747 |
|
{ |
748 |
0
|
throw new MojoExecutionException( |
749 |
|
"Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", |
750 |
|
ex ); |
751 |
|
} |
752 |
|
|
753 |
0
|
return executableDependencies; |
754 |
|
} |
755 |
|
|
756 |
|
|
757 |
|
|
758 |
|
|
759 |
|
@param |
760 |
|
|
761 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
762 |
0
|
private void waitFor( long millis )... |
763 |
|
{ |
764 |
0
|
Object lock = new Object(); |
765 |
0
|
synchronized ( lock ) |
766 |
|
{ |
767 |
0
|
try |
768 |
|
{ |
769 |
0
|
lock.wait( millis ); |
770 |
|
} |
771 |
|
catch ( InterruptedException e ) |
772 |
|
{ |
773 |
0
|
Thread.currentThread().interrupt(); |
774 |
0
|
getLog().warn( "Spuriously interrupted while waiting for " + millis + "ms", e ); |
775 |
|
} |
776 |
|
} |
777 |
|
} |
778 |
|
|
779 |
|
} |