1 | |
package org.apache.maven.plugin.dependency.fromConfiguration; |
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.plugin.MojoExecutionException; |
23 | |
import org.apache.maven.plugin.MojoFailureException; |
24 | |
import org.apache.maven.plugin.dependency.utils.filters.ArtifactItemFilter; |
25 | |
import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter; |
26 | |
import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler; |
27 | |
import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler; |
28 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
29 | |
import org.apache.maven.plugins.annotations.Mojo; |
30 | |
import org.apache.maven.plugins.annotations.Parameter; |
31 | |
import org.codehaus.plexus.util.StringUtils; |
32 | |
|
33 | |
import java.io.File; |
34 | |
import java.util.List; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@Mojo( name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true ) |
44 | 28 | public final class UnpackMojo |
45 | |
extends AbstractFromConfigurationMojo |
46 | |
{ |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
@Parameter( defaultValue = "${project.build.directory}/dependency-maven-plugin-markers" ) |
52 | |
private File markersDirectory; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Parameter( property = "mdep.unpack.includes" ) |
62 | |
private String includes; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
@Parameter( property = "mdep.unpack.excludes" ) |
72 | |
private String excludes; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
@SuppressWarnings( "unused" ) |
79 | |
@Parameter( property = "artifact" ) |
80 | |
private String artifact; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void execute() |
92 | |
throws MojoExecutionException, MojoFailureException |
93 | |
{ |
94 | 32 | if ( isSkip() ) |
95 | |
{ |
96 | 1 | return; |
97 | |
} |
98 | |
|
99 | 31 | verifyRequirements(); |
100 | |
|
101 | 31 | List<ArtifactItem> processedItems = getProcessedArtifactItems( false ); |
102 | 28 | for ( ArtifactItem artifactItem : processedItems ) |
103 | |
{ |
104 | 37 | if ( artifactItem.isNeedsProcessing() ) |
105 | |
{ |
106 | 33 | unpackArtifact( artifactItem ); |
107 | |
} |
108 | |
else |
109 | |
{ |
110 | 4 | this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." ); |
111 | |
} |
112 | |
} |
113 | 28 | } |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
private void unpackArtifact( ArtifactItem artifactItem ) |
124 | |
throws MojoExecutionException |
125 | |
{ |
126 | 33 | MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory ); |
127 | |
|
128 | 33 | unpack( artifactItem.getArtifact(), artifactItem.getOutputDirectory(), artifactItem.getIncludes(), |
129 | |
artifactItem.getExcludes() ); |
130 | 33 | handler.setMarker(); |
131 | 33 | } |
132 | |
|
133 | |
ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ) |
134 | |
{ |
135 | 39 | MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory ); |
136 | |
|
137 | 39 | return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(), |
138 | |
handler ); |
139 | |
} |
140 | |
|
141 | |
protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion ) |
142 | |
throws MojoExecutionException |
143 | |
{ |
144 | 34 | List<ArtifactItem> items = super.getProcessedArtifactItems( removeVersion ); |
145 | 30 | for ( ArtifactItem artifactItem : items ) |
146 | |
{ |
147 | 39 | if ( StringUtils.isEmpty( artifactItem.getIncludes() ) ) |
148 | |
{ |
149 | 32 | artifactItem.setIncludes( getIncludes() ); |
150 | |
} |
151 | 39 | if ( StringUtils.isEmpty( artifactItem.getExcludes() ) ) |
152 | |
{ |
153 | 38 | artifactItem.setExcludes( getExcludes() ); |
154 | |
} |
155 | |
} |
156 | 30 | return items; |
157 | |
} |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public File getMarkersDirectory() |
163 | |
{ |
164 | 21 | return this.markersDirectory; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public void setMarkersDirectory( File theMarkersDirectory ) |
171 | |
{ |
172 | 28 | this.markersDirectory = theMarkersDirectory; |
173 | 28 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
public String getExcludes() |
179 | |
{ |
180 | 38 | return this.excludes; |
181 | |
} |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public void setExcludes( String excludes ) |
187 | |
{ |
188 | 4 | this.excludes = excludes; |
189 | 4 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
public String getIncludes() |
195 | |
{ |
196 | 32 | return this.includes; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
public void setIncludes( String includes ) |
203 | |
{ |
204 | 4 | this.includes = includes; |
205 | 4 | } |
206 | |
} |