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 org.apache.maven.artifact.Artifact; |
23 | |
import org.apache.maven.plugin.MojoExecutionException; |
24 | |
import org.apache.maven.plugin.dependency.AbstractResolveMojo; |
25 | |
import org.apache.maven.plugin.dependency.utils.DependencyStatusSets; |
26 | |
import org.apache.maven.plugin.dependency.utils.DependencyUtil; |
27 | |
import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter; |
28 | |
import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler; |
29 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
30 | |
import org.apache.maven.plugins.annotations.Mojo; |
31 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
32 | |
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; |
33 | |
|
34 | |
import java.io.IOException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Mojo( name = "sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, |
44 | |
requiresDependencyResolution = ResolutionScope.TEST ) |
45 | 0 | public class ResolveDependencySourcesMojo |
46 | |
extends AbstractResolveMojo |
47 | |
{ |
48 | |
|
49 | |
private static final String SOURCE_TYPE = "java-source"; |
50 | |
|
51 | |
private static final String SOURCE_CLASSIFIER = "sources"; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
DependencyStatusSets results; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public void execute() |
65 | |
throws MojoExecutionException |
66 | |
{ |
67 | 0 | this.classifier = SOURCE_CLASSIFIER; |
68 | 0 | this.type = SOURCE_TYPE; |
69 | |
|
70 | 0 | results = this.getDependencySets( false ); |
71 | |
|
72 | 0 | SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler( this.markersDirectory ); |
73 | 0 | handler.setResolved( true ); |
74 | |
|
75 | 0 | for ( Artifact artifact : results.getResolvedDependencies() ) |
76 | |
{ |
77 | 0 | handler.setArtifact( artifact ); |
78 | 0 | handler.setMarker(); |
79 | |
} |
80 | |
|
81 | 0 | handler.setResolved( false ); |
82 | 0 | for ( Artifact artifact : results.getUnResolvedDependencies() ) |
83 | |
{ |
84 | 0 | handler.setArtifact( artifact ); |
85 | 0 | handler.setMarker(); |
86 | |
} |
87 | |
|
88 | 0 | String output = results.getOutput( outputAbsoluteArtifactFilename, false ); |
89 | |
try |
90 | |
{ |
91 | 0 | if ( outputFile == null ) |
92 | |
{ |
93 | 0 | DependencyUtil.log( output, getLog() ); |
94 | |
} |
95 | |
else |
96 | |
{ |
97 | 0 | DependencyUtil.write( output, outputFile, appendOutput, getLog() ); |
98 | |
} |
99 | |
} |
100 | 0 | catch ( IOException e ) |
101 | |
{ |
102 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
103 | 0 | } |
104 | 0 | } |
105 | |
|
106 | |
protected ArtifactsFilter getMarkedArtifactFilter() |
107 | |
{ |
108 | 0 | return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) ); |
109 | |
} |
110 | |
} |