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
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 @SuppressWarnings( "unused" )
80 @Parameter( property = "artifact" )
81 private String artifact;
82
83
84
85
86
87
88
89
90
91
92 @Override
93 protected void doExecute()
94 throws MojoExecutionException, MojoFailureException
95 {
96 if ( isSkip() )
97 {
98 return;
99 }
100
101 verifyRequirements();
102
103 List<ArtifactItem> processedItems = getProcessedArtifactItems( false );
104 for ( ArtifactItem artifactItem : processedItems )
105 {
106 if ( artifactItem.isNeedsProcessing() )
107 {
108 unpackArtifact( artifactItem );
109 }
110 else
111 {
112 this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." );
113 }
114 }
115 }
116
117
118
119
120
121
122
123
124 private void unpackArtifact( ArtifactItem artifactItem )
125 throws MojoExecutionException
126 {
127 MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
128
129 unpack( artifactItem.getArtifact(), artifactItem.getType(), artifactItem.getOutputDirectory(),
130 artifactItem.getIncludes(), artifactItem.getExcludes(), artifactItem.getEncoding() );
131 handler.setMarker();
132 }
133
134 @Override
135 ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
136 {
137 MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory );
138
139 return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
140 handler );
141 }
142
143 protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion )
144 throws MojoExecutionException
145 {
146 List<ArtifactItem> items =
147 super.getProcessedArtifactItems( new ProcessArtifactItemsRequest( removeVersion, false, false, false ) );
148 for ( ArtifactItem artifactItem : items )
149 {
150 if ( StringUtils.isEmpty( artifactItem.getIncludes() ) )
151 {
152 artifactItem.setIncludes( getIncludes() );
153 }
154 if ( StringUtils.isEmpty( artifactItem.getExcludes() ) )
155 {
156 artifactItem.setExcludes( getExcludes() );
157 }
158 }
159 return items;
160 }
161
162
163
164
165 public File getMarkersDirectory()
166 {
167 return this.markersDirectory;
168 }
169
170
171
172
173 public void setMarkersDirectory( File theMarkersDirectory )
174 {
175 this.markersDirectory = theMarkersDirectory;
176 }
177
178
179
180
181 public String getExcludes()
182 {
183 return this.excludes;
184 }
185
186
187
188
189 public void setExcludes( String excludes )
190 {
191 this.excludes = excludes;
192 }
193
194
195
196
197 public String getIncludes()
198 {
199 return this.includes;
200 }
201
202
203
204
205 public void setIncludes( String includes )
206 {
207 this.includes = includes;
208 }
209 }