1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency.fromDependencies;
20
21 import javax.inject.Inject;
22
23 import java.io.File;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
27 import org.apache.maven.execution.MavenSession;
28 import org.apache.maven.plugin.MojoExecutionException;
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.plugins.annotations.ResolutionScope;
33 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
34 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
35 import org.apache.maven.plugins.dependency.utils.ResolverUtil;
36 import org.apache.maven.plugins.dependency.utils.UnpackUtil;
37 import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
38 import org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler;
39 import org.apache.maven.project.MavenProject;
40 import org.apache.maven.project.ProjectBuilder;
41 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
42 import org.codehaus.plexus.components.io.filemappers.FileMapper;
43 import org.sonatype.plexus.build.incremental.BuildContext;
44
45
46
47
48
49
50
51
52 @Mojo(
53 name = "unpack-dependencies",
54 requiresDependencyResolution = ResolutionScope.TEST,
55 defaultPhase = LifecyclePhase.PROCESS_SOURCES,
56 threadSafe = true)
57
58 public class UnpackDependenciesMojo extends AbstractFromDependenciesMojo {
59
60
61
62
63
64
65
66
67 @Parameter(property = "mdep.unpack.includes")
68 private String includes;
69
70
71
72
73
74
75
76
77 @Parameter(property = "mdep.unpack.excludes")
78 private String excludes;
79
80
81
82
83
84
85 @Parameter(property = "dependency.ignorePermissions", defaultValue = "false")
86 private boolean ignorePermissions;
87
88
89
90
91
92
93 @Parameter(property = "mdep.unpack.encoding")
94 private String encoding;
95
96
97
98
99
100
101 @Parameter(property = "mdep.unpack.filemappers")
102 private FileMapper[] fileMappers;
103
104 private final UnpackUtil unpackUtil;
105
106 @Inject
107 public UnpackDependenciesMojo(
108 MavenSession session,
109 BuildContext buildContext,
110 MavenProject project,
111 ResolverUtil resolverUtil,
112 ProjectBuilder projectBuilder,
113 ArtifactHandlerManager artifactHandlerManager,
114 UnpackUtil unpackUtil) {
115 super(session, buildContext, project, resolverUtil, projectBuilder, artifactHandlerManager);
116 this.unpackUtil = unpackUtil;
117 }
118
119
120
121
122
123
124
125
126 @Override
127 protected void doExecute() throws MojoExecutionException {
128 DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact);
129
130 for (Artifact artifact : dss.getResolvedDependencies()) {
131 File destDir = DependencyUtil.getFormattedOutputDirectory(
132 useSubDirectoryPerScope,
133 useSubDirectoryPerType,
134 useSubDirectoryPerArtifact,
135 useRepositoryLayout,
136 stripVersion,
137 stripType,
138 outputDirectory,
139 artifact);
140 unpackUtil.unpack(
141 artifact.getFile(),
142 artifact.getType(),
143 destDir,
144 getIncludes(),
145 getExcludes(),
146 getEncoding(),
147 ignorePermissions,
148 getFileMappers(),
149 getLog());
150 DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory);
151 handler.setMarker();
152 }
153
154 for (Artifact artifact : dss.getSkippedDependencies()) {
155 getLog().info(artifact.getId() + " already exists in destination.");
156 }
157 }
158
159 @Override
160 protected ArtifactsFilter getMarkedArtifactFilter() {
161 return new MarkerFileFilter(
162 this.overWriteReleases,
163 this.overWriteSnapshots,
164 this.overWriteIfNewer,
165 new DefaultFileMarkerHandler(this.markersDirectory));
166 }
167
168
169
170
171 public String getExcludes() {
172 return DependencyUtil.cleanToBeTokenizedString(this.excludes);
173 }
174
175
176
177
178 public void setExcludes(String excludes) {
179 this.excludes = excludes;
180 }
181
182
183
184
185 public String getIncludes() {
186 return DependencyUtil.cleanToBeTokenizedString(this.includes);
187 }
188
189
190
191
192 public void setIncludes(String includes) {
193 this.includes = includes;
194 }
195
196
197
198
199
200 public void setEncoding(String encoding) {
201 this.encoding = encoding;
202 }
203
204
205
206
207
208 public String getEncoding() {
209 return this.encoding;
210 }
211
212
213
214
215
216
217 public FileMapper[] getFileMappers() {
218 return this.fileMappers;
219 }
220
221
222
223
224
225
226 public void setFileMappers(FileMapper[] fileMappers) {
227 this.fileMappers = fileMappers;
228 }
229 }