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 org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
27 import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
28 import org.apache.maven.plugins.annotations.Component;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.plugins.annotations.ResolutionScope;
32 import org.apache.maven.project.MavenProject;
33 import org.codehaus.plexus.archiver.manager.ArchiverManager;
34 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
35
36 import java.io.File;
37 import java.util.LinkedHashSet;
38 import java.util.Set;
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 @Parameter( defaultValue = "${project}", readonly = true, required = true )
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 @SuppressWarnings( "ResultOfMethodCallIgnored" )
74 public void execute()
75 throws MojoExecutionException, MojoFailureException
76 {
77 final Set<Artifact> dependencies = new LinkedHashSet<Artifact>();
78
79 if ( project.getArtifact() != null && project.getArtifact().getFile() != null )
80 {
81 dependencies.add( project.getArtifact() );
82 }
83
84 @SuppressWarnings( "unchecked" ) final Set<Artifact> projectArtifacts = project.getArtifacts();
85 if ( projectArtifacts != null )
86 {
87 dependencies.addAll( projectArtifacts );
88 }
89
90 for ( final Artifact artifact : dependencies )
91 {
92 final String name = artifact.getFile().getName();
93
94 final File tempLocation = new File( workDirectory, name.substring( 0, name.lastIndexOf( '.' ) ) );
95 boolean process = false;
96 if ( !tempLocation.exists() )
97 {
98 tempLocation.mkdirs();
99 process = true;
100 }
101 else if ( artifact.getFile().lastModified() > tempLocation.lastModified() )
102 {
103 process = true;
104 }
105
106 if ( process )
107 {
108 final File file = artifact.getFile();
109 try
110 {
111 AssemblyFileUtils.unpack( file, tempLocation, archiverManager );
112 }
113 catch ( final NoSuchArchiverException e )
114 {
115 getLog().info( "Skip unpacking dependency file with unknown extension: " + file.getPath() );
116 }
117 catch ( final ArchiveExpansionException e )
118 {
119 throw new MojoExecutionException( "Error unpacking dependency file: " + file, e );
120 }
121 }
122 }
123 }
124
125 }