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