1 package org.apache.maven.plugins.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.plugins.dependency.utils.filters.ArtifactItemFilter;
25 import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter;
26 import org.apache.maven.plugins.dependency.utils.markers.MarkerHandler;
27 import org.apache.maven.plugins.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.components.io.filemappers.FileMapper;
32 import org.codehaus.plexus.util.StringUtils;
33
34 import java.io.File;
35 import java.util.List;
36
37
38
39
40
41
42
43 @Mojo( name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES, requiresProject = false, threadSafe = true )
44 public 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
79 @Parameter( property = "mdep.unpack.filemappers" )
80 private FileMapper[] fileMappers;
81
82
83
84
85
86
87 @SuppressWarnings( "unused" )
88 @Parameter( property = "artifact" )
89 private String artifact;
90
91
92
93
94
95
96
97
98
99
100 @Override
101 protected void doExecute()
102 throws MojoExecutionException, MojoFailureException
103 {
104 if ( isSkip() )
105 {
106 return;
107 }
108
109 verifyRequirements();
110
111 List<ArtifactItem> processedItems = getProcessedArtifactItems( false );
112 for ( ArtifactItem artifactItem : processedItems )
113 {
114 if ( artifactItem.isNeedsProcessing() )
115 {
116 unpackArtifact( artifactItem );
117 }
118 else
119 {
120 this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." );
121 }
122 }
123 }
124
125
126
127
128
129
130
131
132 private void unpackArtifact( ArtifactItem artifactItem )
133 throws MojoExecutionException
134 {
135 MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
136
137 unpack( artifactItem.getArtifact(), artifactItem.getType(), artifactItem.getOutputDirectory(),
138 artifactItem.getIncludes(), artifactItem.getExcludes(), artifactItem.getEncoding(),
139 artifactItem.getFileMappers() );
140 handler.setMarker();
141 }
142
143 @Override
144 ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
145 {
146 MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory );
147
148 return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
149 handler );
150 }
151
152
153
154
155
156
157 protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion )
158 throws MojoExecutionException
159 {
160 List<ArtifactItem> items =
161 super.getProcessedArtifactItems( new ProcessArtifactItemsRequest( removeVersion, false, false, false ) );
162 for ( ArtifactItem artifactItem : items )
163 {
164 if ( StringUtils.isEmpty( artifactItem.getIncludes() ) )
165 {
166 artifactItem.setIncludes( getIncludes() );
167 }
168 if ( StringUtils.isEmpty( artifactItem.getExcludes() ) )
169 {
170 artifactItem.setExcludes( getExcludes() );
171 }
172 }
173 return items;
174 }
175
176
177
178
179 public File getMarkersDirectory()
180 {
181 return this.markersDirectory;
182 }
183
184
185
186
187 public void setMarkersDirectory( File theMarkersDirectory )
188 {
189 this.markersDirectory = theMarkersDirectory;
190 }
191
192
193
194
195 public String getExcludes()
196 {
197 return this.excludes;
198 }
199
200
201
202
203 public void setExcludes( String excludes )
204 {
205 this.excludes = excludes;
206 }
207
208
209
210
211 public String getIncludes()
212 {
213 return this.includes;
214 }
215
216
217
218
219 public void setIncludes( String includes )
220 {
221 this.includes = includes;
222 }
223
224
225
226
227
228
229
230 public FileMapper[] getFileMappers()
231 {
232 return this.fileMappers;
233 }
234
235
236
237
238
239
240
241 public void setFileMappers( FileMapper[] fileMappers )
242 {
243 this.fileMappers = fileMappers;
244 }
245 }