1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.maven.plugin.ide; |
20 | |
|
21 | |
import java.io.File; |
22 | |
import java.io.IOException; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Collections; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.HashSet; |
27 | |
import java.util.Iterator; |
28 | |
import java.util.List; |
29 | |
import java.util.Map; |
30 | |
import java.util.Set; |
31 | |
import java.util.TreeSet; |
32 | |
import java.util.jar.Attributes; |
33 | |
import java.util.jar.JarFile; |
34 | |
import java.util.jar.Manifest; |
35 | |
import java.util.zip.ZipFile; |
36 | |
|
37 | |
import org.apache.maven.artifact.Artifact; |
38 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
39 | |
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; |
40 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
41 | |
import org.apache.maven.artifact.resolver.ArtifactCollector; |
42 | |
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; |
43 | |
import org.apache.maven.artifact.resolver.ArtifactResolutionException; |
44 | |
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; |
45 | |
import org.apache.maven.artifact.resolver.ArtifactResolver; |
46 | |
import org.apache.maven.artifact.resolver.DebugResolutionListener; |
47 | |
import org.apache.maven.artifact.resolver.ResolutionNode; |
48 | |
import org.apache.maven.artifact.resolver.WarningResolutionListener; |
49 | |
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; |
50 | |
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; |
51 | |
import org.apache.maven.artifact.versioning.ArtifactVersion; |
52 | |
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; |
53 | |
import org.apache.maven.artifact.versioning.VersionRange; |
54 | |
import org.apache.maven.execution.RuntimeInformation; |
55 | |
import org.apache.maven.model.Dependency; |
56 | |
import org.apache.maven.model.DependencyManagement; |
57 | |
import org.apache.maven.model.Exclusion; |
58 | |
import org.apache.maven.plugin.AbstractMojo; |
59 | |
import org.apache.maven.plugin.MojoExecutionException; |
60 | |
import org.apache.maven.plugin.MojoFailureException; |
61 | |
import org.apache.maven.plugin.eclipse.Constants; |
62 | |
import org.apache.maven.plugin.eclipse.Messages; |
63 | |
import org.apache.maven.project.MavenProject; |
64 | |
import org.codehaus.plexus.logging.LogEnabled; |
65 | |
import org.codehaus.plexus.logging.Logger; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 20 | public abstract class AbstractIdeSupportMojo |
85 | |
extends AbstractMojo |
86 | |
implements LogEnabled |
87 | |
{ |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
protected MavenProject project; |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
protected MavenProject executedProject; |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
protected String packaging; |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
protected ArtifactFactory artifactFactory; |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
protected ArtifactResolver artifactResolver; |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
protected ArtifactCollector artifactCollector; |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
protected ArtifactMetadataSource artifactMetadataSource; |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
private RuntimeInformation runtimeInformation; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
protected List remoteArtifactRepositories; |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
protected ArtifactRepository localRepository; |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
protected List reactorProjects; |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
private boolean skip; |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
protected boolean downloadSources; |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
protected boolean downloadJavadocs; |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
protected boolean forceRecheck; |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
protected Logger logger; |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
public ArtifactMetadataSource getArtifactMetadataSource() |
227 | |
{ |
228 | 0 | return artifactMetadataSource; |
229 | |
} |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
public void setArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource ) |
237 | |
{ |
238 | 0 | this.artifactMetadataSource = artifactMetadataSource; |
239 | 0 | } |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
public MavenProject getProject() |
247 | |
{ |
248 | 0 | return project; |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
public void setProject( MavenProject project ) |
257 | |
{ |
258 | 0 | this.project = project; |
259 | 0 | } |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public List getReactorProjects() |
267 | |
{ |
268 | 0 | return reactorProjects; |
269 | |
} |
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
public void setReactorProjects( List reactorProjects ) |
277 | |
{ |
278 | 0 | this.reactorProjects = reactorProjects; |
279 | 0 | } |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
public List getRemoteArtifactRepositories() |
287 | |
{ |
288 | 0 | return remoteArtifactRepositories; |
289 | |
} |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
public void setRemoteArtifactRepositories( List remoteArtifactRepositories ) |
297 | |
{ |
298 | 0 | this.remoteArtifactRepositories = remoteArtifactRepositories; |
299 | 0 | } |
300 | |
|
301 | |
|
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
public ArtifactFactory getArtifactFactory() |
307 | |
{ |
308 | 0 | return artifactFactory; |
309 | |
} |
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
public void setArtifactFactory( ArtifactFactory artifactFactory ) |
317 | |
{ |
318 | 0 | this.artifactFactory = artifactFactory; |
319 | 0 | } |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
public ArtifactResolver getArtifactResolver() |
327 | |
{ |
328 | 0 | return artifactResolver; |
329 | |
} |
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
public void setArtifactResolver( ArtifactResolver artifactResolver ) |
337 | |
{ |
338 | 0 | this.artifactResolver = artifactResolver; |
339 | 0 | } |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
public MavenProject getExecutedProject() |
347 | |
{ |
348 | 0 | return executedProject; |
349 | |
} |
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
public void setExecutedProject( MavenProject executedProject ) |
357 | |
{ |
358 | 0 | this.executedProject = executedProject; |
359 | 0 | } |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
public ArtifactRepository getLocalRepository() |
367 | |
{ |
368 | 0 | return localRepository; |
369 | |
} |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
public void setLocalRepository( ArtifactRepository localRepository ) |
377 | |
{ |
378 | 0 | this.localRepository = localRepository; |
379 | 0 | } |
380 | |
|
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
public boolean getDownloadJavadocs() |
387 | |
{ |
388 | 0 | return downloadJavadocs; |
389 | |
} |
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
public void setDownloadJavadocs( boolean downloadJavadoc ) |
397 | |
{ |
398 | 0 | downloadJavadocs = downloadJavadoc; |
399 | 0 | } |
400 | |
|
401 | |
|
402 | |
|
403 | |
|
404 | |
|
405 | |
|
406 | |
public boolean getDownloadSources() |
407 | |
{ |
408 | 0 | return downloadSources; |
409 | |
} |
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
public void setDownloadSources( boolean downloadSources ) |
417 | |
{ |
418 | 0 | this.downloadSources = downloadSources; |
419 | 0 | } |
420 | |
|
421 | |
protected void setResolveDependencies( boolean resolveDependencies ) |
422 | |
{ |
423 | 0 | this.resolveDependencies = resolveDependencies; |
424 | 0 | } |
425 | |
|
426 | |
protected boolean isResolveDependencies() |
427 | |
{ |
428 | 0 | return resolveDependencies; |
429 | |
} |
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
protected abstract boolean getUseProjectReferences(); |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
protected abstract boolean setup() |
446 | |
throws MojoExecutionException; |
447 | |
|
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
protected abstract void writeConfiguration( IdeDependency[] deps ) |
455 | |
throws MojoExecutionException; |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | 20 | private List missingSourceDependencies = new ArrayList(); |
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | 20 | private List missingJavadocDependencies = new ArrayList(); |
467 | |
|
468 | |
|
469 | |
|
470 | |
|
471 | |
private IdeDependency[] ideDeps; |
472 | |
|
473 | |
|
474 | |
|
475 | |
|
476 | |
|
477 | 20 | private boolean resolveDependencies = true; |
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
public void enableLogging( Logger logger ) |
483 | |
{ |
484 | 0 | this.logger = logger; |
485 | 0 | } |
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
public final void execute() |
491 | |
throws MojoExecutionException, MojoFailureException |
492 | |
{ |
493 | 0 | if ( skip ) |
494 | |
{ |
495 | 0 | return; |
496 | |
} |
497 | |
|
498 | 0 | boolean processProject = setup(); |
499 | 0 | if ( !processProject ) |
500 | |
{ |
501 | 0 | return; |
502 | |
} |
503 | |
|
504 | |
|
505 | 0 | IdeDependency[] deps = doDependencyResolution(); |
506 | |
|
507 | 0 | resolveSourceAndJavadocArtifacts( deps ); |
508 | |
|
509 | 0 | writeConfiguration( deps ); |
510 | |
|
511 | 0 | reportMissingArtifacts(); |
512 | |
|
513 | 0 | } |
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
protected IdeDependency[] doDependencyResolution() |
524 | |
throws MojoExecutionException |
525 | |
{ |
526 | 0 | if ( ideDeps == null ) |
527 | |
{ |
528 | 0 | if ( resolveDependencies ) |
529 | |
{ |
530 | 0 | MavenProject project = getProject(); |
531 | 0 | ArtifactRepository localRepo = getLocalRepository(); |
532 | |
|
533 | 0 | List deps = getProject().getDependencies(); |
534 | |
|
535 | |
|
536 | 0 | List dependencies = new ArrayList(); |
537 | |
|
538 | 0 | if ( deps != null ) |
539 | |
{ |
540 | 0 | Map managedVersions = |
541 | |
createManagedVersionMap( getArtifactFactory(), project.getId(), |
542 | |
project.getDependencyManagement() ); |
543 | |
|
544 | 0 | ArtifactResolutionResult artifactResolutionResult = null; |
545 | |
|
546 | |
try |
547 | |
{ |
548 | |
|
549 | 0 | List listeners = new ArrayList(); |
550 | |
|
551 | 0 | if ( logger.isDebugEnabled() ) |
552 | |
{ |
553 | 0 | listeners.add( new DebugResolutionListener( logger ) ); |
554 | |
} |
555 | |
|
556 | 0 | listeners.add( new WarningResolutionListener( logger ) ); |
557 | |
|
558 | 0 | artifactResolutionResult = |
559 | |
artifactCollector.collect( getProjectArtifacts(), project.getArtifact(), managedVersions, |
560 | |
localRepo, project.getRemoteArtifactRepositories(), |
561 | |
getArtifactMetadataSource(), null, listeners ); |
562 | |
} |
563 | 0 | catch ( ArtifactResolutionException e ) |
564 | |
{ |
565 | 0 | getLog().debug( e.getMessage(), e ); |
566 | 0 | getLog().error( |
567 | |
Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { |
568 | |
e.getGroupId(), e.getArtifactId(), e.getVersion(), |
569 | |
e.getMessage() } ) ); |
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | 0 | return new IdeDependency[0]; |
576 | 0 | } |
577 | |
|
578 | |
|
579 | 0 | Set emittedReactorProjectId = new HashSet(); |
580 | |
|
581 | 0 | for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); ) |
582 | |
{ |
583 | |
|
584 | 0 | ResolutionNode node = (ResolutionNode) i.next(); |
585 | 0 | int dependencyDepth = node.getDepth(); |
586 | 0 | Artifact art = node.getArtifact(); |
587 | |
|
588 | 0 | if ( hasToResolveJar( art ) ) |
589 | |
{ |
590 | |
try |
591 | |
{ |
592 | 0 | artifactResolver.resolve( art, node.getRemoteRepositories(), localRepository ); |
593 | |
} |
594 | 0 | catch ( ArtifactNotFoundException e ) |
595 | |
{ |
596 | 0 | getLog().debug( e.getMessage(), e ); |
597 | 0 | getLog().warn( |
598 | |
Messages.getString( "AbstractIdeSupportMojo.artifactdownload", new Object[] { |
599 | |
e.getGroupId(), e.getArtifactId(), e.getVersion(), |
600 | |
e.getMessage() } ) ); |
601 | |
} |
602 | 0 | catch ( ArtifactResolutionException e ) |
603 | |
{ |
604 | 0 | getLog().debug( e.getMessage(), e ); |
605 | 0 | getLog().warn( |
606 | |
Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { |
607 | |
e.getGroupId(), e.getArtifactId(), e.getVersion(), |
608 | |
e.getMessage() } ) ); |
609 | 0 | } |
610 | |
} |
611 | |
|
612 | 0 | boolean includeArtifact = true; |
613 | 0 | if ( getExcludes() != null ) |
614 | |
{ |
615 | 0 | String artifactFullId = art.getGroupId() + ":" + art.getArtifactId(); |
616 | 0 | if ( getExcludes().contains( artifactFullId ) ) |
617 | |
{ |
618 | 0 | getLog().info( "excluded: " + artifactFullId ); |
619 | 0 | includeArtifact = false; |
620 | |
} |
621 | |
} |
622 | |
|
623 | 0 | if ( includeArtifact |
624 | |
&& ( !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) || emittedReactorProjectId.add( art.getGroupId() |
625 | |
+ '-' + art.getArtifactId() ) ) ) |
626 | |
{ |
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
|
640 | |
|
641 | 0 | boolean isOsgiBundle = false; |
642 | 0 | String osgiSymbolicName = null; |
643 | 0 | if ( art.getFile() != null ) |
644 | |
{ |
645 | 0 | JarFile jarFile = null; |
646 | |
try |
647 | |
{ |
648 | 0 | jarFile = new JarFile( art.getFile(), false, ZipFile.OPEN_READ ); |
649 | |
|
650 | 0 | Manifest manifest = jarFile.getManifest(); |
651 | 0 | if ( manifest != null ) |
652 | |
{ |
653 | 0 | osgiSymbolicName = |
654 | |
manifest.getMainAttributes().getValue( |
655 | |
new Attributes.Name( |
656 | |
"Bundle-SymbolicName" ) ); |
657 | |
} |
658 | 0 | } |
659 | 0 | catch ( IOException e ) |
660 | |
{ |
661 | 0 | getLog().info( "Unable to read jar manifest from " + art.getFile() ); |
662 | 0 | } |
663 | |
finally |
664 | |
{ |
665 | 0 | if ( jarFile != null ) |
666 | |
{ |
667 | |
try |
668 | |
{ |
669 | 0 | jarFile.close(); |
670 | |
} |
671 | 0 | catch ( IOException e ) |
672 | |
{ |
673 | |
|
674 | 0 | } |
675 | |
} |
676 | 0 | } |
677 | |
} |
678 | |
|
679 | 0 | isOsgiBundle = osgiSymbolicName != null; |
680 | |
|
681 | 0 | IdeDependency dep = |
682 | |
new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(), |
683 | |
art.getClassifier(), useProjectReference( art ), |
684 | |
Artifact.SCOPE_TEST.equals( art.getScope() ), |
685 | |
Artifact.SCOPE_SYSTEM.equals( art.getScope() ), |
686 | |
Artifact.SCOPE_PROVIDED.equals( art.getScope() ), |
687 | |
art.getArtifactHandler().isAddedToClasspath(), art.getFile(), |
688 | |
art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, |
689 | |
getProjectNameForArifact( art ) ); |
690 | |
|
691 | 0 | if ( !dependencies.contains( dep ) ) |
692 | |
{ |
693 | 0 | dependencies.add( dep ); |
694 | |
} |
695 | |
} |
696 | |
|
697 | |
} |
698 | |
|
699 | |
|
700 | |
|
701 | |
|
702 | |
} |
703 | |
|
704 | 0 | ideDeps = (IdeDependency[]) dependencies.toArray( new IdeDependency[dependencies.size()] ); |
705 | |
} |
706 | |
else |
707 | |
{ |
708 | 0 | ideDeps = new IdeDependency[0]; |
709 | |
} |
710 | |
} |
711 | |
|
712 | 0 | return ideDeps; |
713 | |
} |
714 | |
|
715 | |
|
716 | |
|
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
abstract public String getProjectNameForArifact( Artifact artifact ); |
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
|
727 | |
|
728 | |
|
729 | |
|
730 | |
private Set getProjectArtifacts() |
731 | |
throws MojoExecutionException |
732 | |
{ |
733 | |
|
734 | 0 | Set artifacts = new TreeSet(); |
735 | |
|
736 | 0 | for ( Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext(); ) |
737 | |
{ |
738 | 0 | Dependency dependency = (Dependency) dependencies.next(); |
739 | |
|
740 | 0 | String groupId = dependency.getGroupId(); |
741 | 0 | String artifactId = dependency.getArtifactId(); |
742 | |
VersionRange versionRange; |
743 | |
try |
744 | |
{ |
745 | 0 | versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); |
746 | |
} |
747 | 0 | catch ( InvalidVersionSpecificationException e ) |
748 | |
{ |
749 | 0 | throw new MojoExecutionException( |
750 | |
Messages.getString( |
751 | |
"AbstractIdeSupportMojo.unabletoparseversion", new Object[] { |
752 | |
dependency.getArtifactId(), |
753 | |
dependency.getVersion(), |
754 | |
dependency.getManagementKey(), e.getMessage() } ), |
755 | |
e ); |
756 | 0 | } |
757 | |
|
758 | 0 | String type = dependency.getType(); |
759 | 0 | if ( type == null ) |
760 | |
{ |
761 | 0 | type = Constants.PROJECT_PACKAGING_JAR; |
762 | |
} |
763 | 0 | String classifier = dependency.getClassifier(); |
764 | 0 | boolean optional = dependency.isOptional(); |
765 | 0 | String scope = dependency.getScope(); |
766 | 0 | if ( scope == null ) |
767 | |
{ |
768 | 0 | scope = Artifact.SCOPE_COMPILE; |
769 | |
} |
770 | |
|
771 | 0 | Artifact art = |
772 | |
getArtifactFactory().createDependencyArtifact( groupId, artifactId, versionRange, type, classifier, |
773 | |
scope, optional ); |
774 | |
|
775 | 0 | if ( scope.equalsIgnoreCase( Artifact.SCOPE_SYSTEM ) ) |
776 | |
{ |
777 | 0 | art.setFile( new File( dependency.getSystemPath() ) ); |
778 | |
} |
779 | |
|
780 | 0 | List exclusions = new ArrayList(); |
781 | 0 | for ( Iterator j = dependency.getExclusions().iterator(); j.hasNext(); ) |
782 | |
{ |
783 | 0 | Exclusion e = (Exclusion) j.next(); |
784 | 0 | exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); |
785 | |
} |
786 | |
|
787 | 0 | ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions ); |
788 | |
|
789 | 0 | art.setDependencyFilter( newFilter ); |
790 | |
|
791 | 0 | artifacts.add( art ); |
792 | |
} |
793 | |
|
794 | 0 | return artifacts; |
795 | |
} |
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
protected boolean isAvailableAsAReactorProject( Artifact artifact ) |
804 | |
{ |
805 | 0 | return getReactorProject( artifact ) != null; |
806 | |
} |
807 | |
|
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
protected MavenProject getReactorProject( Artifact artifact ) { |
815 | 0 | if ( reactorProjects != null ) |
816 | |
{ |
817 | 0 | for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); ) |
818 | |
{ |
819 | 0 | MavenProject reactorProject = (MavenProject) iter.next(); |
820 | |
|
821 | 0 | if ( reactorProject.getGroupId().equals( artifact.getGroupId() ) |
822 | |
&& reactorProject.getArtifactId().equals( artifact.getArtifactId() ) ) |
823 | |
{ |
824 | 0 | if ( reactorProject.getVersion().equals( artifact.getVersion() ) ) |
825 | |
{ |
826 | 0 | return reactorProject; |
827 | |
} |
828 | |
else |
829 | |
{ |
830 | 0 | getLog().info( |
831 | |
"Artifact " |
832 | |
+ artifact.getId() |
833 | |
+ " already available as a reactor project, but with different version. Expected: " |
834 | |
+ artifact.getVersion() + ", found: " + reactorProject.getVersion() ); |
835 | |
} |
836 | |
} |
837 | |
} |
838 | |
} |
839 | 0 | return null; |
840 | |
} |
841 | |
|
842 | |
|
843 | |
|
844 | |
|
845 | |
protected IdeDependency[] getWorkspaceArtefacts() |
846 | |
{ |
847 | 0 | return new IdeDependency[0]; |
848 | |
} |
849 | |
|
850 | |
private Map createManagedVersionMap( ArtifactFactory artifactFactory, String projectId, |
851 | |
DependencyManagement dependencyManagement ) |
852 | |
throws MojoExecutionException |
853 | |
{ |
854 | |
Map map; |
855 | 0 | if ( dependencyManagement != null && dependencyManagement.getDependencies() != null ) |
856 | |
{ |
857 | 0 | map = new HashMap(); |
858 | 0 | for ( Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext(); ) |
859 | |
{ |
860 | 0 | Dependency d = (Dependency) i.next(); |
861 | |
|
862 | |
try |
863 | |
{ |
864 | 0 | VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); |
865 | 0 | Artifact artifact = |
866 | |
artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, |
867 | |
d.getType(), d.getClassifier(), d.getScope(), |
868 | |
d.isOptional() ); |
869 | 0 | map.put( d.getManagementKey(), artifact ); |
870 | |
} |
871 | 0 | catch ( InvalidVersionSpecificationException e ) |
872 | |
{ |
873 | 0 | throw new MojoExecutionException( Messages.getString( "AbstractIdeSupportMojo.unabletoparseversion", new Object[] { |
874 | |
projectId, d.getVersion(), |
875 | |
d.getManagementKey(), e.getMessage() } ), |
876 | |
e ); |
877 | 0 | } |
878 | |
} |
879 | |
} |
880 | |
else |
881 | |
{ |
882 | 0 | map = Collections.EMPTY_MAP; |
883 | |
} |
884 | 0 | return map; |
885 | |
} |
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
|
895 | |
private void resolveSourceAndJavadocArtifacts( IdeDependency[] deps ) |
896 | |
{ |
897 | 0 | final List missingSources = |
898 | |
resolveDependenciesWithClassifier( deps, "sources", getDownloadSources() ); |
899 | 0 | missingSourceDependencies.addAll( missingSources ); |
900 | |
|
901 | 0 | final List missingJavadocs = |
902 | |
resolveDependenciesWithClassifier( deps, "javadoc", getDownloadJavadocs() ); |
903 | 0 | missingJavadocDependencies.addAll( missingJavadocs ); |
904 | 0 | } |
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | |
private List resolveDependenciesWithClassifier( IdeDependency[] deps, String inClassifier, |
916 | |
boolean includeRemoteRepositories ) |
917 | |
{ |
918 | 0 | List missingClassifierDependencies = new ArrayList(); |
919 | |
|
920 | |
|
921 | |
|
922 | 0 | List remoteRepos = includeRemoteRepositories ? getRemoteArtifactRepositories() : Collections.EMPTY_LIST; |
923 | |
|
924 | 0 | for ( int j = 0; j < deps.length; j++ ) |
925 | |
{ |
926 | 0 | IdeDependency dependency = deps[j]; |
927 | |
|
928 | 0 | if ( dependency.isReferencedProject() || dependency.isSystemScoped() ) |
929 | |
{ |
930 | |
|
931 | 0 | continue; |
932 | |
} |
933 | |
|
934 | 0 | if ( getLog().isDebugEnabled() ) |
935 | |
{ |
936 | 0 | getLog().debug( |
937 | |
"Searching for sources for " + dependency.getId() + ":" + dependency.getClassifier() |
938 | |
+ " at " + dependency.getId() + ":" + inClassifier ); |
939 | |
} |
940 | |
|
941 | 0 | Artifact baseArtifact = |
942 | |
artifactFactory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), |
943 | |
dependency.getVersion(), dependency.getType(), |
944 | |
dependency.getClassifier() ); |
945 | 0 | baseArtifact = |
946 | |
IdeUtils.resolveArtifact( artifactResolver, baseArtifact, remoteRepos, localRepository, getLog() ); |
947 | 0 | if (!baseArtifact.isResolved()) { |
948 | |
|
949 | 0 | continue; |
950 | |
} |
951 | |
|
952 | 0 | Artifact artifact = |
953 | |
IdeUtils.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), |
954 | |
dependency.getVersion(), dependency.getClassifier(), |
955 | |
inClassifier, artifactFactory ); |
956 | 0 | File notAvailableMarkerFile = IdeUtils.getNotAvailableMarkerFile( localRepository, artifact ); |
957 | |
|
958 | 0 | if (forceRecheck && notAvailableMarkerFile.exists()) { |
959 | 0 | if (!notAvailableMarkerFile.delete()) { |
960 | 0 | getLog().warn( Messages.getString( "AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile", notAvailableMarkerFile ) ); |
961 | |
} |
962 | |
} |
963 | |
|
964 | 0 | if ( !notAvailableMarkerFile.exists() ) |
965 | |
{ |
966 | 0 | artifact = |
967 | |
IdeUtils.resolveArtifact( artifactResolver, artifact, remoteRepos, localRepository, getLog() ); |
968 | 0 | if ( artifact.isResolved() ) |
969 | |
{ |
970 | 0 | if ( "sources".equals( inClassifier ) ) |
971 | |
{ |
972 | 0 | dependency.setSourceAttachment( artifact.getFile() ); |
973 | |
} |
974 | 0 | else if ( "javadoc".equals( inClassifier ) ) |
975 | |
{ |
976 | 0 | dependency.setJavadocAttachment( artifact.getFile() ); |
977 | |
} |
978 | |
} |
979 | |
else |
980 | |
{ |
981 | 0 | if ( includeRemoteRepositories ) |
982 | |
{ |
983 | |
try |
984 | |
{ |
985 | 0 | notAvailableMarkerFile.createNewFile(); |
986 | 0 | getLog().debug( Messages.getString( "AbstractIdeSupportMojo.creatednotavailablemarkerfile", notAvailableMarkerFile ) ); |
987 | |
} |
988 | 0 | catch ( IOException e ) |
989 | |
{ |
990 | 0 | getLog().warn( Messages.getString( "AbstractIdeSupportMojo.failedtocreatenotavailablemarkerfile", |
991 | |
notAvailableMarkerFile ) ); |
992 | 0 | } |
993 | |
} |
994 | |
|
995 | |
|
996 | |
|
997 | 0 | missingClassifierDependencies.add( dependency ); |
998 | |
} |
999 | |
} |
1000 | |
} |
1001 | |
|
1002 | |
|
1003 | |
|
1004 | 0 | return missingClassifierDependencies; |
1005 | |
|
1006 | |
} |
1007 | |
|
1008 | |
|
1009 | |
|
1010 | |
|
1011 | |
private void reportMissingArtifacts() |
1012 | |
{ |
1013 | 0 | StringBuffer msg = new StringBuffer(); |
1014 | |
|
1015 | 0 | if ( !missingSourceDependencies.isEmpty() ) |
1016 | |
{ |
1017 | 0 | if ( getDownloadSources() ) |
1018 | |
{ |
1019 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotavailable" ) ); |
1020 | |
} |
1021 | |
else |
1022 | |
{ |
1023 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotdownloaded" ) ); |
1024 | |
} |
1025 | |
|
1026 | 0 | for ( Iterator it = missingSourceDependencies.iterator(); it.hasNext(); ) |
1027 | |
{ |
1028 | 0 | IdeDependency art = (IdeDependency) it.next(); |
1029 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesmissingitem", art.getId() ) ); |
1030 | |
} |
1031 | 0 | msg.append( "\n" ); |
1032 | |
} |
1033 | |
|
1034 | 0 | if ( !missingJavadocDependencies.isEmpty() ) |
1035 | |
{ |
1036 | 0 | if ( getDownloadJavadocs() ) |
1037 | |
{ |
1038 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotavailable" ) ); |
1039 | |
} |
1040 | |
else |
1041 | |
{ |
1042 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotdownloaded" ) ); |
1043 | |
} |
1044 | |
|
1045 | 0 | for ( Iterator it = missingJavadocDependencies.iterator(); it.hasNext(); ) |
1046 | |
{ |
1047 | 0 | IdeDependency art = (IdeDependency) it.next(); |
1048 | 0 | msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocmissingitem", art.getId() ) ); |
1049 | |
} |
1050 | 0 | msg.append( "\n" ); |
1051 | |
} |
1052 | 0 | getLog().info( msg ); |
1053 | 0 | } |
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
|
1058 | |
|
1059 | |
public abstract List getExcludes(); |
1060 | |
|
1061 | |
|
1062 | |
|
1063 | |
|
1064 | |
|
1065 | |
|
1066 | |
|
1067 | |
protected boolean hasToResolveJar( Artifact art ) |
1068 | |
{ |
1069 | 0 | return !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ); |
1070 | |
} |
1071 | |
|
1072 | |
|
1073 | |
|
1074 | |
|
1075 | |
|
1076 | |
|
1077 | |
|
1078 | |
protected boolean useProjectReference( Artifact art ) |
1079 | |
{ |
1080 | 0 | return getUseProjectReferences() && isAvailableAsAReactorProject( art ); |
1081 | |
} |
1082 | |
|
1083 | |
|
1084 | |
|
1085 | |
|
1086 | |
|
1087 | |
|
1088 | |
|
1089 | |
|
1090 | |
protected boolean isMavenVersion( String version ) |
1091 | |
{ |
1092 | |
try |
1093 | |
{ |
1094 | 4 | VersionRange versionRange = VersionRange.createFromVersionSpec( version ); |
1095 | 4 | ArtifactVersion mavenVersion = runtimeInformation.getApplicationVersion(); |
1096 | 4 | return versionRange.containsVersion( mavenVersion ); |
1097 | |
} |
1098 | 0 | catch ( InvalidVersionSpecificationException e ) |
1099 | |
{ |
1100 | 0 | throw new IllegalArgumentException( e.getMessage() ); |
1101 | |
} |
1102 | |
} |
1103 | |
|
1104 | |
} |