1 | |
package org.apache.maven.plugin.dependency.resolvers; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.IOException; |
23 | |
import java.util.Iterator; |
24 | |
|
25 | |
import org.apache.maven.artifact.Artifact; |
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.dependency.AbstractResolveMojo; |
28 | |
import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; |
29 | |
import org.apache.maven.plugin.dependency.utils.DependencyUtil; |
30 | |
import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter; |
31 | |
import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler; |
32 | |
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ResolveDependencySourcesMojo |
45 | |
extends AbstractResolveMojo |
46 | |
{ |
47 | |
|
48 | |
private static final String SOURCE_TYPE = "java-source"; |
49 | |
|
50 | |
private static final String SOURCE_CLASSIFIER = "sources"; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
DependencyStatusSets results; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void execute() |
66 | |
throws MojoExecutionException |
67 | |
{ |
68 | 0 | this.classifier = SOURCE_CLASSIFIER; |
69 | 0 | this.type = SOURCE_TYPE; |
70 | |
|
71 | 0 | results = this.getDependencySets( false ); |
72 | |
|
73 | 0 | SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(this.markersDirectory); |
74 | 0 | handler.setResolved( true ); |
75 | |
|
76 | 0 | Iterator iter = results.getResolvedDependencies().iterator(); |
77 | 0 | while (iter.hasNext()) |
78 | |
{ |
79 | 0 | Artifact artifact = (Artifact) iter.next(); |
80 | 0 | handler.setArtifact( artifact ); |
81 | 0 | handler.setMarker(); |
82 | 0 | } |
83 | |
|
84 | 0 | handler.setResolved( false ); |
85 | 0 | iter = results.getUnResolvedDependencies().iterator(); |
86 | 0 | while (iter.hasNext()) |
87 | |
{ |
88 | 0 | Artifact artifact = (Artifact) iter.next(); |
89 | 0 | handler.setArtifact( artifact ); |
90 | 0 | handler.setMarker(); |
91 | 0 | } |
92 | |
|
93 | 0 | String output = results.getOutput( outputAbsoluteArtifactFilename, false ); |
94 | |
try |
95 | |
{ |
96 | 0 | if ( outputFile == null ) |
97 | |
{ |
98 | 0 | DependencyUtil.log( output, getLog() ); |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | 0 | DependencyUtil.write( output, outputFile, getLog() ); |
103 | |
} |
104 | |
} |
105 | 0 | catch ( IOException e ) |
106 | |
{ |
107 | 0 | throw new MojoExecutionException(e.getMessage(),e); |
108 | 0 | } |
109 | 0 | } |
110 | |
|
111 | |
protected ArtifactsFilter getMarkedArtifactFilter() |
112 | |
{ |
113 | 0 | return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) ); |
114 | |
} |
115 | |
} |