20
20
21
21
import java .io .File ;
22
22
import java .io .IOException ;
23
- import java .lang .reflect .Field ;
24
23
import java .util .List ;
25
24
26
- import org .apache .commons .lang3 .StringUtils ;
27
- import org .apache .maven .artifact .Artifact ;
28
25
import org .apache .maven .artifact .repository .ArtifactRepository ;
29
26
import org .apache .maven .execution .MavenSession ;
30
27
import org .apache .maven .plugin .AbstractMojo ;
36
33
import org .apache .maven .project .DefaultProjectBuildingRequest ;
37
34
import org .apache .maven .project .MavenProject ;
38
35
import org .apache .maven .project .ProjectBuildingRequest ;
39
- import org .codehaus .plexus .archiver .ArchiverException ;
40
- import org .codehaus .plexus .archiver .UnArchiver ;
41
- import org .codehaus .plexus .archiver .manager .ArchiverManager ;
42
- import org .codehaus .plexus .archiver .manager .NoSuchArchiverException ;
43
- import org .codehaus .plexus .archiver .zip .ZipUnArchiver ;
44
- import org .codehaus .plexus .components .io .filemappers .FileMapper ;
45
- import org .codehaus .plexus .components .io .fileselectors .IncludeExcludeFileSelector ;
46
36
import org .codehaus .plexus .util .FileUtils ;
47
- import org .codehaus .plexus .util .ReflectionUtils ;
48
37
import org .sonatype .plexus .build .incremental .BuildContext ;
49
38
50
39
/**
51
40
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
52
41
*/
53
42
public abstract class AbstractDependencyMojo extends AbstractMojo {
54
- /**
55
- * To look up Archiver/UnArchiver implementations
56
- */
57
- @ Component
58
- private ArchiverManager archiverManager ;
59
43
60
44
/**
61
45
* For IDE build support
@@ -72,14 +56,6 @@ public abstract class AbstractDependencyMojo extends AbstractMojo {
72
56
@ Parameter (defaultValue = "false" )
73
57
private boolean skipDuringIncrementalBuild ;
74
58
75
- /**
76
- * ignore to set file permissions when unpacking a dependency
77
- *
78
- * @since 2.7
79
- */
80
- @ Parameter (property = "dependency.ignorePermissions" , defaultValue = "false" )
81
- private boolean ignorePermissions ;
82
-
83
59
/**
84
60
* POM
85
61
*/
@@ -155,13 +131,6 @@ public final void execute() throws MojoExecutionException, MojoFailureException
155
131
*/
156
132
protected abstract void doExecute () throws MojoExecutionException , MojoFailureException ;
157
133
158
- /**
159
- * @return Returns the archiverManager.
160
- */
161
- public ArchiverManager getArchiverManager () {
162
- return this .archiverManager ;
163
- }
164
-
165
134
/**
166
135
* Does the actual copy of the file and logging.
167
136
*
@@ -188,146 +157,6 @@ protected void copyFile(File artifact, File destFile) throws MojoExecutionExcept
188
157
}
189
158
}
190
159
191
- /**
192
- * @param artifact {@link Artifact}
193
- * @param location The location.
194
- * @param encoding The encoding.
195
- * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting
196
- * shall happen.
197
- * @throws MojoExecutionException in case of an error.
198
- */
199
- protected void unpack (Artifact artifact , File location , String encoding , FileMapper [] fileMappers )
200
- throws MojoExecutionException {
201
- unpack (artifact , location , null , null , encoding , fileMappers );
202
- }
203
-
204
- /**
205
- * Unpacks the archive file.
206
- *
207
- * @param artifact File to be unpacked.
208
- * @param location Location where to put the unpacked files.
209
- * @param includes Comma separated list of file patterns to include i.e. <code>**/.xml,
210
- * **/*.properties</code>
211
- * @param excludes Comma separated list of file patterns to exclude i.e. <code>**/*.xml,
212
- * **/*.properties</code>
213
- * @param encoding Encoding of artifact. Set {@code null} for default encoding.
214
- * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting
215
- * shall happen.
216
- * @throws MojoExecutionException In case of errors.
217
- */
218
- protected void unpack (
219
- Artifact artifact ,
220
- File location ,
221
- String includes ,
222
- String excludes ,
223
- String encoding ,
224
- FileMapper [] fileMappers )
225
- throws MojoExecutionException {
226
- unpack (artifact , artifact .getType (), location , includes , excludes , encoding , fileMappers );
227
- }
228
-
229
- /**
230
- * @param artifact {@link Artifact}
231
- * @param type The type.
232
- * @param location The location.
233
- * @param includes includes list.
234
- * @param excludes excludes list.
235
- * @param encoding the encoding.
236
- * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting
237
- * shall happen.
238
- * @throws MojoExecutionException in case of an error.
239
- */
240
- protected void unpack (
241
- Artifact artifact ,
242
- String type ,
243
- File location ,
244
- String includes ,
245
- String excludes ,
246
- String encoding ,
247
- FileMapper [] fileMappers )
248
- throws MojoExecutionException {
249
- File file = artifact .getFile ();
250
- try {
251
- logUnpack (file , location , includes , excludes );
252
-
253
- location .mkdirs ();
254
- if (!location .exists ()) {
255
- throw new MojoExecutionException (
256
- "Location to write unpacked files to could not be created: " + location );
257
- }
258
-
259
- if (file .isDirectory ()) {
260
- // usual case is a future jar packaging, but there are special cases: classifier and other packaging
261
- throw new MojoExecutionException ("Artifact has not been packaged yet. When used on reactor artifact, "
262
- + "unpack should be executed after packaging: see MDEP-98." );
263
- }
264
-
265
- UnArchiver unArchiver ;
266
-
267
- try {
268
- unArchiver = archiverManager .getUnArchiver (type );
269
- getLog ().debug ("Found unArchiver by type: " + unArchiver );
270
- } catch (NoSuchArchiverException e ) {
271
- unArchiver = archiverManager .getUnArchiver (file );
272
- getLog ().debug ("Found unArchiver by extension: " + unArchiver );
273
- }
274
-
275
- if (encoding != null && unArchiver instanceof ZipUnArchiver ) {
276
- ((ZipUnArchiver ) unArchiver ).setEncoding (encoding );
277
- getLog ().info ("Unpacks '" + type + "' with encoding '" + encoding + "'." );
278
- }
279
-
280
- unArchiver .setIgnorePermissions (ignorePermissions );
281
-
282
- unArchiver .setSourceFile (file );
283
-
284
- unArchiver .setDestDirectory (location );
285
-
286
- if (StringUtils .isNotEmpty (excludes ) || StringUtils .isNotEmpty (includes )) {
287
- // Create the selectors that will filter
288
- // based on include/exclude parameters
289
- // MDEP-47
290
- IncludeExcludeFileSelector [] selectors =
291
- new IncludeExcludeFileSelector [] {new IncludeExcludeFileSelector ()};
292
-
293
- if (StringUtils .isNotEmpty (excludes )) {
294
- selectors [0 ].setExcludes (excludes .split ("," ));
295
- }
296
-
297
- if (StringUtils .isNotEmpty (includes )) {
298
- selectors [0 ].setIncludes (includes .split ("," ));
299
- }
300
-
301
- unArchiver .setFileSelectors (selectors );
302
- }
303
- if (this .silent ) {
304
- silenceUnarchiver (unArchiver );
305
- }
306
-
307
- unArchiver .setFileMappers (fileMappers );
308
-
309
- unArchiver .extract ();
310
- } catch (NoSuchArchiverException e ) {
311
- throw new MojoExecutionException ("Unknown archiver type" , e );
312
- } catch (ArchiverException e ) {
313
- throw new MojoExecutionException ("Error unpacking file: " + file + " to: " + location , e );
314
- }
315
- buildContext .refresh (location );
316
- }
317
-
318
- private void silenceUnarchiver (UnArchiver unArchiver ) {
319
- // dangerous but handle any errors. It's the only way to silence the unArchiver.
320
- try {
321
- Field field = ReflectionUtils .getFieldByNameIncludingSuperclasses ("logger" , unArchiver .getClass ());
322
-
323
- field .setAccessible (true );
324
-
325
- field .set (unArchiver , this .getLog ());
326
- } catch (Exception e ) {
327
- // was a nice try. Don't bother logging because the log is silent.
328
- }
329
- }
330
-
331
160
/**
332
161
* @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
333
162
* repositories, used to resolve artifacts.
@@ -359,13 +188,6 @@ public MavenProject getProject() {
359
188
return this .project ;
360
189
}
361
190
362
- /**
363
- * @param archiverManager The archiverManager to set.
364
- */
365
- public void setArchiverManager (ArchiverManager archiverManager ) {
366
- this .archiverManager = archiverManager ;
367
- }
368
-
369
191
/**
370
192
* @return {@link #skip}
371
193
*/
@@ -399,34 +221,4 @@ public void setSilent(boolean silent) {
399
221
setLog (new DependencySilentLog ());
400
222
}
401
223
}
402
-
403
- private void logUnpack (File file , File location , String includes , String excludes ) {
404
- if (!getLog ().isInfoEnabled ()) {
405
- return ;
406
- }
407
-
408
- StringBuilder msg = new StringBuilder ();
409
- msg .append ("Unpacking " );
410
- msg .append (file );
411
- msg .append (" to " );
412
- msg .append (location );
413
-
414
- if (includes != null && excludes != null ) {
415
- msg .append (" with includes \" " );
416
- msg .append (includes );
417
- msg .append ("\" and excludes \" " );
418
- msg .append (excludes );
419
- msg .append ("\" " );
420
- } else if (includes != null ) {
421
- msg .append (" with includes \" " );
422
- msg .append (includes );
423
- msg .append ("\" " );
424
- } else if (excludes != null ) {
425
- msg .append (" with excludes \" " );
426
- msg .append (excludes );
427
- msg .append ("\" " );
428
- }
429
-
430
- getLog ().info (msg .toString ());
431
- }
432
224
}
0 commit comments