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