1 package org.apache.maven.plugin.assembly.mojos;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.LinkedHashSet;
24 import java.util.Set;
25
26 import org.apache.maven.artifact.Artifact;
27 import org.apache.maven.plugin.AbstractMojo;
28 import org.apache.maven.plugin.MojoExecutionException;
29 import org.apache.maven.plugin.MojoFailureException;
30 import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
31 import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
32 import org.apache.maven.plugins.annotations.Component;
33 import org.apache.maven.plugins.annotations.Mojo;
34 import org.apache.maven.plugins.annotations.Parameter;
35 import org.apache.maven.plugins.annotations.ResolutionScope;
36 import org.apache.maven.project.MavenProject;
37 import org.codehaus.plexus.archiver.manager.ArchiverManager;
38 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
39
40
41
42
43
44
45
46 @Mojo( name = "unpack", requiresDependencyResolution = ResolutionScope.TEST, inheritByDefault = false )
47 @Deprecated
48 public class UnpackMojo
49 extends AbstractMojo
50 {
51
52
53
54 @Component
55 private MavenProject project;
56
57
58
59 @Component
60 private ArchiverManager archiverManager;
61
62
63
64
65 @Parameter( defaultValue = "${project.build.directory}/assembly/work", required = true )
66 protected File workDirectory;
67
68
69
70
71
72
73 public void execute()
74 throws MojoExecutionException, MojoFailureException
75 {
76 final Set<Artifact> dependencies = new LinkedHashSet<Artifact>();
77
78 if ( project.getArtifact() != null && project.getArtifact().getFile() != null )
79 {
80 dependencies.add( project.getArtifact() );
81 }
82
83 @SuppressWarnings( "unchecked" )
84 final Set<Artifact> projectArtifacts = project.getArtifacts();
85 if ( projectArtifacts != null )
86 {
87 dependencies.addAll( projectArtifacts );
88 }
89
90 for (final Artifact artifact : dependencies) {
91 final String name = artifact.getFile().getName();
92
93 final File tempLocation = new File(workDirectory, name.substring(0, name.lastIndexOf('.')));
94 boolean process = false;
95 if (!tempLocation.exists()) {
96 tempLocation.mkdirs();
97 process = true;
98 } else if (artifact.getFile().lastModified() > tempLocation.lastModified()) {
99 process = true;
100 }
101
102 if (process) {
103 final File file = artifact.getFile();
104 try {
105 AssemblyFileUtils.unpack(file, tempLocation, archiverManager);
106 } catch (final NoSuchArchiverException e) {
107 getLog().info("Skip unpacking dependency file with unknown extension: " + file.getPath());
108 } catch (final ArchiveExpansionException e) {
109 throw new MojoExecutionException("Error unpacking dependency file: " + file, e);
110 }
111 }
112 }
113 }
114
115 }