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.fromConfiguration;
20
21 import javax.inject.Inject;
22
23 import java.io.File;
24 import java.util.List;
25
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.plugin.MojoFailureException;
30 import org.apache.maven.plugins.annotations.LifecyclePhase;
31 import org.apache.maven.plugins.annotations.Mojo;
32 import org.apache.maven.plugins.annotations.Parameter;
33 import org.apache.maven.plugins.dependency.utils.UnpackUtil;
34 import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter;
35 import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
36 import org.apache.maven.plugins.dependency.utils.markers.MarkerHandler;
37 import org.apache.maven.plugins.dependency.utils.markers.UnpackFileMarkerHandler;
38 import org.apache.maven.project.MavenProject;
39 import org.codehaus.plexus.components.io.filemappers.FileMapper;
40 import org.eclipse.aether.RepositorySystem;
41 import org.sonatype.plexus.build.incremental.BuildContext;
42
43
44
45
46
47
48
49 @Mojo(name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true)
50 public class UnpackMojo extends AbstractFromConfigurationMojo {
51
52 private final UnpackUtil unpackUtil;
53
54
55
56
57 @Parameter(
58 property = "markersDirectory",
59 defaultValue = "${project.build.directory}/dependency-maven-plugin-markers")
60 private File markersDirectory;
61
62
63
64
65
66
67
68
69 @Parameter(property = "mdep.unpack.includes")
70 private String includes;
71
72
73
74
75
76
77
78
79 @Parameter(property = "mdep.unpack.excludes")
80 private String excludes;
81
82
83
84
85
86
87 @Parameter(property = "dependency.ignorePermissions", defaultValue = "false")
88 private boolean ignorePermissions;
89
90
91
92
93
94
95 @Parameter(property = "mdep.unpack.filemappers")
96 private FileMapper[] fileMappers;
97
98
99
100
101
102
103 @SuppressWarnings("unused")
104 @Parameter(property = "artifact")
105 private String artifact;
106
107 @Inject
108 public UnpackMojo(
109 MavenSession session,
110 BuildContext buildContext,
111 MavenProject project,
112 ArtifactHandlerManager artifactHandlerManager,
113 UnpackUtil unpackUtil,
114 RepositorySystem repositorySystem) {
115 super(session, buildContext, project, artifactHandlerManager, repositorySystem);
116 this.unpackUtil = unpackUtil;
117 }
118
119
120
121
122
123
124
125
126
127
128 @Override
129 protected void doExecute() throws MojoExecutionException, MojoFailureException {
130 if (isSkip()) {
131 return;
132 }
133
134 verifyRequirements();
135
136 List<ArtifactItem> processedItems = getProcessedArtifactItems(false);
137 for (ArtifactItem artifactItem : processedItems) {
138 if (artifactItem.isNeedsProcessing()) {
139 unpackArtifact(artifactItem);
140 } else {
141 this.getLog().info(artifactItem.getArtifact().getFile().getName() + " already unpacked.");
142 }
143 }
144 }
145
146
147
148
149
150
151
152
153 private void unpackArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
154 MarkerHandler handler = new UnpackFileMarkerHandler(artifactItem, this.markersDirectory);
155
156 unpackUtil.unpack(
157 artifactItem.getArtifact().getFile(),
158 artifactItem.getType(),
159 artifactItem.getOutputDirectory(),
160 artifactItem.getIncludes(),
161 artifactItem.getExcludes(),
162 artifactItem.getEncoding(),
163 ignorePermissions,
164 artifactItem.getFileMappers(),
165 getLog());
166 handler.setMarker();
167 }
168
169 @Override
170 ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item) {
171 MarkerHandler handler = new UnpackFileMarkerHandler(item, this.markersDirectory);
172
173 return new MarkerFileFilter(
174 this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), handler);
175 }
176
177
178
179
180
181
182 protected List<ArtifactItem> getProcessedArtifactItems(boolean removeVersion) throws MojoExecutionException {
183 List<ArtifactItem> items =
184 super.getProcessedArtifactItems(new ProcessArtifactItemsRequest(removeVersion, false, false, false));
185 for (ArtifactItem artifactItem : items) {
186 if (artifactItem.getIncludes().isEmpty()) {
187 artifactItem.setIncludes(getIncludes());
188 }
189 if (artifactItem.getExcludes().isEmpty()) {
190 artifactItem.setExcludes(getExcludes());
191 }
192 }
193 return items;
194 }
195
196
197
198
199 public File getMarkersDirectory() {
200 return this.markersDirectory;
201 }
202
203
204
205
206 public void setMarkersDirectory(File theMarkersDirectory) {
207 this.markersDirectory = theMarkersDirectory;
208 }
209
210
211
212
213 public String getExcludes() {
214 return this.excludes;
215 }
216
217
218
219
220 public void setExcludes(String excludes) {
221 this.excludes = excludes;
222 }
223
224
225
226
227 public String getIncludes() {
228 return this.includes;
229 }
230
231
232
233
234 public void setIncludes(String includes) {
235 this.includes = includes;
236 }
237
238
239
240
241
242
243 public FileMapper[] getFileMappers() {
244 return this.fileMappers;
245 }
246
247
248
249
250
251
252 public void setFileMappers(FileMapper[] fileMappers) {
253 this.fileMappers = fileMappers;
254 }
255 }