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 | 28 | 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 | 32 | if ( isSkip() ) |
86 | |
{ |
87 | 1 | return; |
88 | |
} |
89 | |
|
90 | 31 | List<ArtifactItem> processedItems = getProcessedArtifactItems( false ); |
91 | 28 | for ( ArtifactItem artifactItem : processedItems ) |
92 | |
{ |
93 | 37 | if ( artifactItem.isNeedsProcessing() ) |
94 | |
{ |
95 | 33 | unpackArtifact( artifactItem ); |
96 | |
} |
97 | |
else |
98 | |
{ |
99 | 4 | this.getLog().info( artifactItem.getArtifact().getFile().getName() + " already unpacked." ); |
100 | |
} |
101 | |
} |
102 | 28 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
private void unpackArtifact( ArtifactItem artifactItem ) |
113 | |
throws MojoExecutionException |
114 | |
{ |
115 | 33 | MarkerHandler handler = new UnpackFileMarkerHandler( artifactItem, this.markersDirectory ); |
116 | |
|
117 | 33 | unpack( artifactItem.getArtifact().getFile(), artifactItem.getOutputDirectory(), artifactItem.getIncludes(), |
118 | |
artifactItem.getExcludes() ); |
119 | 33 | handler.setMarker(); |
120 | 33 | } |
121 | |
|
122 | |
ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item ) |
123 | |
{ |
124 | 39 | MarkerHandler handler = new UnpackFileMarkerHandler( item, this.markersDirectory ); |
125 | |
|
126 | 39 | 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 | 34 | List<ArtifactItem> items = super.getProcessedArtifactItems( removeVersion ); |
134 | 30 | for ( ArtifactItem artifactItem : items ) |
135 | |
{ |
136 | 39 | if ( StringUtils.isEmpty( artifactItem.getIncludes() ) ) |
137 | |
{ |
138 | 32 | artifactItem.setIncludes( getIncludes() ); |
139 | |
} |
140 | 39 | if ( StringUtils.isEmpty( artifactItem.getExcludes() ) ) |
141 | |
{ |
142 | 38 | artifactItem.setExcludes( getExcludes() ); |
143 | |
} |
144 | |
} |
145 | 30 | return items; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public File getMarkersDirectory() |
152 | |
{ |
153 | 21 | return this.markersDirectory; |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public void setMarkersDirectory( File theMarkersDirectory ) |
160 | |
{ |
161 | 28 | this.markersDirectory = theMarkersDirectory; |
162 | 28 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public String getExcludes() |
168 | |
{ |
169 | 38 | return this.excludes; |
170 | |
} |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
public void setExcludes( String excludes ) |
176 | |
{ |
177 | 4 | this.excludes = excludes; |
178 | 4 | } |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public String getIncludes() |
184 | |
{ |
185 | 32 | return this.includes; |
186 | |
} |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
public void setIncludes( String includes ) |
192 | |
{ |
193 | 4 | this.includes = includes; |
194 | 4 | } |
195 | |
} |