1 | |
package org.apache.maven.plugin.dependency.utils.filters; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.HashSet; |
24 | |
import java.util.Set; |
25 | |
|
26 | |
import org.apache.maven.artifact.Artifact; |
27 | |
import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; |
28 | |
import org.apache.maven.plugin.dependency.utils.DependencyUtil; |
29 | |
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter; |
30 | |
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; |
31 | |
import org.codehaus.plexus.util.StringUtils; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class DestFileFilter |
38 | |
extends AbstractArtifactsFilter |
39 | |
implements ArtifactItemFilter |
40 | |
{ |
41 | |
private boolean overWriteReleases; |
42 | |
|
43 | |
private boolean overWriteSnapshots; |
44 | |
|
45 | |
private boolean overWriteIfNewer; |
46 | |
|
47 | |
private boolean useSubDirectoryPerArtifact; |
48 | |
|
49 | |
private boolean useSubDirectoryPerType; |
50 | |
|
51 | |
private boolean useSubDirectoryPerScope; |
52 | |
|
53 | |
private boolean useRepositoryLayout; |
54 | |
|
55 | |
private boolean removeVersion; |
56 | |
|
57 | |
private File outputFileDirectory; |
58 | |
|
59 | |
public DestFileFilter( File outputFileDirectory ) |
60 | 7 | { |
61 | 7 | this.outputFileDirectory = outputFileDirectory; |
62 | 7 | overWriteReleases = false; |
63 | 7 | overWriteIfNewer = false; |
64 | 7 | overWriteSnapshots = false; |
65 | 7 | useSubDirectoryPerArtifact = false; |
66 | 7 | useSubDirectoryPerType = false; |
67 | 7 | useSubDirectoryPerScope = false; |
68 | 7 | removeVersion = false; |
69 | 7 | } |
70 | |
|
71 | |
public DestFileFilter( boolean overWriteReleases, boolean overWriteSnapshots, boolean overWriteIfNewer, |
72 | |
boolean useSubDirectoryPerArtifact, boolean useSubDirectoryPerType, |
73 | |
boolean useSubDirectoryPerScope, boolean useRepositoryLayout, boolean removeVersion, |
74 | |
File outputFileDirectory ) |
75 | 92 | { |
76 | 92 | this.overWriteReleases = overWriteReleases; |
77 | 92 | this.overWriteSnapshots = overWriteSnapshots; |
78 | 92 | this.overWriteIfNewer = overWriteIfNewer; |
79 | 92 | this.useSubDirectoryPerArtifact = useSubDirectoryPerArtifact; |
80 | 92 | this.useSubDirectoryPerType = useSubDirectoryPerType; |
81 | 92 | this.useSubDirectoryPerScope = useSubDirectoryPerScope; |
82 | 92 | this.useRepositoryLayout = useRepositoryLayout; |
83 | 92 | this.removeVersion = removeVersion; |
84 | 92 | this.outputFileDirectory = outputFileDirectory; |
85 | 92 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public Set filter( Set artifacts ) |
94 | |
throws ArtifactFilterException |
95 | |
{ |
96 | 68 | Set<Artifact> artifacts_ = artifacts; |
97 | 68 | Set<Artifact> result = new HashSet<Artifact>(); |
98 | |
|
99 | 68 | for ( Artifact artifact : artifacts_ ) |
100 | |
{ |
101 | 193 | if ( isArtifactIncluded( new ArtifactItem( artifact ) ) ) |
102 | |
{ |
103 | 185 | result.add( artifact ); |
104 | |
} |
105 | |
} |
106 | 68 | return result; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public boolean isOverWriteReleases() |
113 | |
{ |
114 | 2 | return this.overWriteReleases; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void setOverWriteReleases( boolean overWriteReleases ) |
122 | |
{ |
123 | 3 | this.overWriteReleases = overWriteReleases; |
124 | 3 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public boolean isOverWriteSnapshots() |
130 | |
{ |
131 | 2 | return this.overWriteSnapshots; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public void setOverWriteSnapshots( boolean overWriteSnapshots ) |
139 | |
{ |
140 | 6 | this.overWriteSnapshots = overWriteSnapshots; |
141 | 6 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public boolean isOverWriteIfNewer() |
147 | |
{ |
148 | 2 | return this.overWriteIfNewer; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public void setOverWriteIfNewer( boolean overWriteIfNewer ) |
156 | |
{ |
157 | 3 | this.overWriteIfNewer = overWriteIfNewer; |
158 | 3 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public File getOutputFileDirectory() |
164 | |
{ |
165 | 2 | return this.outputFileDirectory; |
166 | |
} |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void setOutputFileDirectory( File outputFileDirectory ) |
173 | |
{ |
174 | 1 | this.outputFileDirectory = outputFileDirectory; |
175 | 1 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public boolean isRemoveVersion() |
181 | |
{ |
182 | 2 | return this.removeVersion; |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public void setRemoveVersion( boolean removeVersion ) |
190 | |
{ |
191 | 3 | this.removeVersion = removeVersion; |
192 | 3 | } |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
public boolean isUseSubDirectoryPerArtifact() |
198 | |
{ |
199 | 2 | return this.useSubDirectoryPerArtifact; |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public void setUseSubDirectoryPerArtifact( boolean useSubDirectoryPerArtifact ) |
207 | |
{ |
208 | 3 | this.useSubDirectoryPerArtifact = useSubDirectoryPerArtifact; |
209 | 3 | } |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public boolean isUseSubDirectoryPerType() |
215 | |
{ |
216 | 2 | return this.useSubDirectoryPerType; |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
public void setUseSubDirectoryPerType( boolean useSubDirectoryPerType ) |
224 | |
{ |
225 | 3 | this.useSubDirectoryPerType = useSubDirectoryPerType; |
226 | 3 | } |
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
public boolean isUseRepositoryLayout() |
233 | |
{ |
234 | 0 | return useRepositoryLayout; |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
public void setUseRepositoryLayout( boolean useRepositoryLayout ) |
243 | |
{ |
244 | 0 | this.useRepositoryLayout = useRepositoryLayout; |
245 | 0 | } |
246 | |
|
247 | |
public boolean isArtifactIncluded( ArtifactItem item ) |
248 | |
{ |
249 | 235 | Artifact artifact = item.getArtifact(); |
250 | |
|
251 | 235 | boolean overWrite = |
252 | |
( artifact.isSnapshot() && this.overWriteSnapshots ) |
253 | |
|| ( !artifact.isSnapshot() && this.overWriteReleases ); |
254 | |
|
255 | 235 | File destFolder = item.getOutputDirectory(); |
256 | 235 | if ( destFolder == null ) |
257 | |
{ |
258 | 193 | destFolder = |
259 | |
DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, |
260 | |
useSubDirectoryPerArtifact, useRepositoryLayout, |
261 | |
removeVersion, this.outputFileDirectory, artifact ); |
262 | |
} |
263 | |
|
264 | 235 | File destFile = null; |
265 | 235 | if ( StringUtils.isEmpty( item.getDestFileName() ) ) |
266 | |
{ |
267 | 193 | destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, this.removeVersion ) ); |
268 | |
} |
269 | |
else |
270 | |
{ |
271 | 42 | destFile = new File( destFolder, item.getDestFileName() ); |
272 | |
} |
273 | |
|
274 | 235 | return overWrite || !destFile.exists() |
275 | |
|| ( overWriteIfNewer && artifact.getFile().lastModified() > destFile.lastModified() ); |
276 | |
} |
277 | |
} |