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.dependency.utils.filters.ArtifactItemFilter;
24 import org.apache.maven.plugin.dependency.utils.filters.MarkerFileFilter;
25 import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler;
26 import org.apache.maven.plugin.dependency.utils.markers.UnpackFileMarkerHandler;
27 import org.apache.maven.plugins.annotations.LifecyclePhase;
28 import org.apache.maven.plugins.annotations.Mojo;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.io.File;
33 import java.util.List;
34
35
36
37
38
39
40
41
42 @Mojo( name = "unpack", defaultPhase = LifecyclePhase.PROCESS_SOURCES )
43 public final 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
79
80
81
82 public void execute()
83 throws MojoExecutionException
84 {
85 if ( isSkip() )
86 {
87 return;
88 }
89
90 List<ArtifactItem> processedItems = getProcessedArtifactItems( false );
91 for ( ArtifactItem artifactItem : processedItems )
92 {
93 if ( artifactItem.isNeedsProcessing() )
94 {
95 unpackArtifact( artifactItem );
96 }
97 else
98 {
99 this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." );
100 }
101 }
102 }
103
104
105
106
107
108
109
110
111
112 private void unpackArtifact( ArtifactItem artifactItem )
113 throws MojoExecutionException
114 {
115 MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory );
116
117 unpack( artifactItem.getArtifact().getFile(), artifactItem.getOutputDirectory(), artifactItem.getIncludes(),
118 artifactItem.getExcludes() );
119 handler.setMarker();
120 }
121
122 ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
123 {
124 MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory );
125
126 return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(), this.isOverWriteIfNewer(),
127 handler );
128 }
129
130 protected List<ArtifactItem> getProcessedArtifactItems( boolean removeVersion )
131 throws MojoExecutionException
132 {
133 List<ArtifactItem> items = super.getProcessedArtifactItems( removeVersion );
134 for ( ArtifactItem artifactItem : items )
135 {
136 if ( StringUtils.isEmpty( artifactItem.getIncludes() ) )
137 {
138 artifactItem.setIncludes( getIncludes() );
139 }
140 if ( StringUtils.isEmpty( artifactItem.getExcludes() ) )
141 {
142 artifactItem.setExcludes( getExcludes() );
143 }
144 }
145 return items;
146 }
147
148
149
150
151 public File getMarkersDirectory()
152 {
153 return this.markersDirectory;
154 }
155
156
157
158
159 public void setMarkersDirectory( File theMarkersDirectory )
160 {
161 this.markersDirectory = theMarkersDirectory;
162 }
163
164
165
166
167 public String getExcludes()
168 {
169 return this.excludes;
170 }
171
172
173
174
175 public void setExcludes( String excludes )
176 {
177 this.excludes = excludes;
178 }
179
180
181
182
183 public String getIncludes()
184 {
185 return this.includes;
186 }
187
188
189
190
191 public void setIncludes( String includes )
192 {
193 this.includes = includes;
194 }
195 }