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.project.MavenProject; |
29 | |
import org.codehaus.plexus.archiver.manager.ArchiverManager; |
30 | |
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; |
31 | |
|
32 | |
import java.io.File; |
33 | |
import java.util.Iterator; |
34 | |
import java.util.LinkedHashSet; |
35 | |
import java.util.Set; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
@Deprecated |
47 | 0 | public class UnpackMojo |
48 | |
extends AbstractMojo |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
private MavenProject project; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
private ArchiverManager archiverManager; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
protected File workDirectory; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public void execute() |
77 | |
throws MojoExecutionException, MojoFailureException |
78 | |
{ |
79 | 0 | final Set<Artifact> dependencies = new LinkedHashSet<Artifact>(); |
80 | |
|
81 | 0 | if ( project.getArtifact() != null && project.getArtifact() |
82 | |
.getFile() != null ) |
83 | |
{ |
84 | 0 | dependencies.add( project.getArtifact() ); |
85 | |
} |
86 | |
|
87 | |
@SuppressWarnings( "unchecked" ) |
88 | 0 | final Set<Artifact> projectArtifacts = project.getArtifacts(); |
89 | 0 | if ( projectArtifacts != null ) |
90 | |
{ |
91 | 0 | dependencies.addAll( projectArtifacts ); |
92 | |
} |
93 | |
|
94 | 0 | for ( final Iterator<Artifact> j = dependencies.iterator(); j.hasNext(); ) |
95 | |
{ |
96 | 0 | final Artifact artifact = j.next(); |
97 | |
|
98 | 0 | final String name = artifact.getFile() |
99 | |
.getName(); |
100 | |
|
101 | 0 | final File tempLocation = new File( workDirectory, name.substring( 0, name.lastIndexOf( '.' ) ) ); |
102 | 0 | boolean process = false; |
103 | 0 | if ( !tempLocation.exists() ) |
104 | |
{ |
105 | 0 | tempLocation.mkdirs(); |
106 | 0 | process = true; |
107 | |
} |
108 | 0 | else if ( artifact.getFile() |
109 | |
.lastModified() > tempLocation.lastModified() ) |
110 | |
{ |
111 | 0 | process = true; |
112 | |
} |
113 | |
|
114 | 0 | if ( process ) |
115 | |
{ |
116 | 0 | final File file = artifact.getFile(); |
117 | |
try |
118 | |
{ |
119 | 0 | AssemblyFileUtils.unpack( file, tempLocation, archiverManager ); |
120 | |
} |
121 | 0 | catch ( final NoSuchArchiverException e ) |
122 | |
{ |
123 | 0 | getLog().info( "Skip unpacking dependency file with unknown extension: " + file.getPath() ); |
124 | |
} |
125 | 0 | catch ( final ArchiveExpansionException e ) |
126 | |
{ |
127 | 0 | throw new MojoExecutionException( "Error unpacking dependency file: " + file, e ); |
128 | 0 | } |
129 | |
} |
130 | 0 | } |
131 | 0 | } |
132 | |
|
133 | |
} |