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.artifact.repository.ArtifactRepository; |
24 | |
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; |
25 | |
import org.apache.maven.artifact.resolver.ArtifactResolutionException; |
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.dependency.AbstractResolveMojo; |
28 | |
import org.apache.maven.plugin.dependency.utils.DependencyUtil; |
29 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
30 | |
import org.apache.maven.plugins.annotations.Mojo; |
31 | |
import org.apache.maven.plugins.annotations.Parameter; |
32 | |
import org.apache.maven.project.ProjectBuildingException; |
33 | |
import org.apache.maven.project.artifact.InvalidDependencyVersionException; |
34 | |
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; |
35 | |
import org.codehaus.plexus.util.IOUtil; |
36 | |
|
37 | |
import java.io.FileWriter; |
38 | |
import java.io.IOException; |
39 | |
import java.io.Writer; |
40 | |
import java.util.HashSet; |
41 | |
import java.util.List; |
42 | |
import java.util.Set; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Mojo( name = "resolve-plugins", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true ) |
52 | 0 | public class ResolvePluginsMojo |
53 | |
extends AbstractResolveMojo |
54 | |
{ |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true ) |
60 | |
private List<ArtifactRepository> remotePluginRepositories; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
@Parameter( property = "excludeTransitive", defaultValue = "false" ) |
66 | |
private boolean excludeTransitive; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
public void execute() |
75 | |
throws MojoExecutionException |
76 | |
{ |
77 | 0 | Writer outputWriter = null; |
78 | |
|
79 | |
try |
80 | |
{ |
81 | 0 | Set<Artifact> plugins = resolvePluginArtifacts(); |
82 | |
|
83 | 0 | if ( this.outputFile != null ) |
84 | |
{ |
85 | 0 | outputFile.getParentFile().mkdirs(); |
86 | |
|
87 | 0 | outputWriter = new FileWriter( outputFile ); |
88 | |
} |
89 | |
|
90 | 0 | for ( Artifact plugin : plugins ) |
91 | |
{ |
92 | 0 | String logStr = "Plugin Resolved: " + DependencyUtil.getFormattedFileName( plugin, false ); |
93 | 0 | if ( !silent ) |
94 | |
{ |
95 | 0 | this.getLog().info( logStr ); |
96 | |
} |
97 | |
|
98 | 0 | if ( outputWriter != null ) |
99 | |
{ |
100 | 0 | outputWriter.write( logStr ); |
101 | 0 | outputWriter.write( "\n" ); |
102 | |
} |
103 | |
|
104 | 0 | if ( !excludeTransitive ) |
105 | |
{ |
106 | 0 | for ( Artifact artifact : resolveArtifactDependencies( plugin ) ) |
107 | |
{ |
108 | 0 | logStr = |
109 | |
" Plugin Dependency Resolved: " + DependencyUtil.getFormattedFileName( artifact, false ); |
110 | |
|
111 | 0 | if ( !silent ) |
112 | |
{ |
113 | 0 | this.getLog().info( logStr ); |
114 | |
} |
115 | |
|
116 | 0 | if ( outputWriter != null ) |
117 | |
{ |
118 | 0 | outputWriter.write( logStr ); |
119 | 0 | outputWriter.write( "\n" ); |
120 | |
} |
121 | |
} |
122 | |
} |
123 | 0 | } |
124 | |
} |
125 | 0 | catch ( IOException e ) |
126 | |
{ |
127 | 0 | throw new MojoExecutionException( "Nested:", e ); |
128 | |
} |
129 | 0 | catch ( ArtifactResolutionException e ) |
130 | |
{ |
131 | 0 | throw new MojoExecutionException( "Nested:", e ); |
132 | |
} |
133 | 0 | catch ( ArtifactNotFoundException e ) |
134 | |
{ |
135 | 0 | throw new MojoExecutionException( "Nested:", e ); |
136 | |
} |
137 | 0 | catch ( ProjectBuildingException e ) |
138 | |
{ |
139 | 0 | throw new MojoExecutionException( "Nested:", e ); |
140 | |
} |
141 | 0 | catch ( InvalidDependencyVersionException e ) |
142 | |
{ |
143 | 0 | throw new MojoExecutionException( "Nested:", e ); |
144 | |
} |
145 | |
finally |
146 | |
{ |
147 | 0 | IOUtil.close( outputWriter ); |
148 | 0 | } |
149 | |
|
150 | 0 | } |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
protected Set<Artifact> resolvePluginArtifacts() |
160 | |
throws ArtifactResolutionException, ArtifactNotFoundException |
161 | |
{ |
162 | 0 | @SuppressWarnings( "unchecked" ) Set<Artifact> plugins = project.getPluginArtifacts(); |
163 | 0 | @SuppressWarnings( "unchecked" ) Set<Artifact> reports = project.getReportArtifacts(); |
164 | |
|
165 | 0 | Set<Artifact> artifacts = new HashSet<Artifact>(); |
166 | 0 | artifacts.addAll( reports ); |
167 | 0 | artifacts.addAll( plugins ); |
168 | |
|
169 | 0 | for ( Artifact artifact : artifacts ) |
170 | |
{ |
171 | |
|
172 | 0 | this.resolver.resolve( artifact, this.remotePluginRepositories, this.getLocal() ); |
173 | |
} |
174 | 0 | return artifacts; |
175 | |
} |
176 | |
|
177 | |
protected ArtifactsFilter getMarkedArtifactFilter() |
178 | |
{ |
179 | 0 | return null; |
180 | |
} |
181 | |
} |