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 | 14 | { |
61 | 14 | this.outputFileDirectory = outputFileDirectory; |
62 | 14 | overWriteReleases = false; |
63 | 14 | overWriteIfNewer = false; |
64 | 14 | overWriteSnapshots = false; |
65 | 14 | useSubDirectoryPerArtifact = false; |
66 | 14 | useSubDirectoryPerType = false; |
67 | 14 | useSubDirectoryPerScope = false; |
68 | 14 | removeVersion = false; |
69 | 14 | } |
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 | 184 | { |
76 | 184 | this.overWriteReleases = overWriteReleases; |
77 | 184 | this.overWriteSnapshots = overWriteSnapshots; |
78 | 184 | this.overWriteIfNewer = overWriteIfNewer; |
79 | 184 | this.useSubDirectoryPerArtifact = useSubDirectoryPerArtifact; |
80 | 184 | this.useSubDirectoryPerType = useSubDirectoryPerType; |
81 | 184 | this.useSubDirectoryPerScope = useSubDirectoryPerScope; |
82 | 184 | this.useRepositoryLayout = useRepositoryLayout; |
83 | 184 | this.removeVersion = removeVersion; |
84 | 184 | this.outputFileDirectory = outputFileDirectory; |
85 | 184 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public Set filter( Set artifacts ) |
94 | |
throws ArtifactFilterException |
95 | |
{ |
96 | 136 | Set<Artifact> artifacts_ = artifacts; |
97 | 136 | Set<Artifact> result = new HashSet<Artifact>(); |
98 | |
|
99 | 136 | for ( Artifact artifact : artifacts_ ) |
100 | |
{ |
101 | 386 | if ( isArtifactIncluded( new ArtifactItem( artifact ) ) ) |
102 | |
{ |
103 | 370 | result.add( artifact ); |
104 | |
} |
105 | |
} |
106 | 136 | return result; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public boolean isOverWriteReleases() |
113 | |
{ |
114 | 4 | return this.overWriteReleases; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void setOverWriteReleases( boolean overWriteReleases ) |
122 | |
{ |
123 | 6 | this.overWriteReleases = overWriteReleases; |
124 | 6 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public boolean isOverWriteSnapshots() |
130 | |
{ |
131 | 4 | return this.overWriteSnapshots; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
public void setOverWriteSnapshots( boolean overWriteSnapshots ) |
139 | |
{ |
140 | 12 | this.overWriteSnapshots = overWriteSnapshots; |
141 | 12 | } |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public boolean isOverWriteIfNewer() |
147 | |
{ |
148 | 4 | return this.overWriteIfNewer; |
149 | |
} |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public void setOverWriteIfNewer( boolean overWriteIfNewer ) |
156 | |
{ |
157 | 6 | this.overWriteIfNewer = overWriteIfNewer; |
158 | 6 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public File getOutputFileDirectory() |
164 | |
{ |
165 | 4 | return this.outputFileDirectory; |
166 | |
} |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void setOutputFileDirectory( File outputFileDirectory ) |
173 | |
{ |
174 | 2 | this.outputFileDirectory = outputFileDirectory; |
175 | 2 | } |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public boolean isRemoveVersion() |
181 | |
{ |
182 | 4 | return this.removeVersion; |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public void setRemoveVersion( boolean removeVersion ) |
190 | |
{ |
191 | 6 | this.removeVersion = removeVersion; |
192 | 6 | } |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
public boolean isUseSubDirectoryPerArtifact() |
198 | |
{ |
199 | 4 | return this.useSubDirectoryPerArtifact; |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public void setUseSubDirectoryPerArtifact( boolean useSubDirectoryPerArtifact ) |
207 | |
{ |
208 | 6 | this.useSubDirectoryPerArtifact = useSubDirectoryPerArtifact; |
209 | 6 | } |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
public boolean isUseSubDirectoryPerType() |
215 | |
{ |
216 | 4 | return this.useSubDirectoryPerType; |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
public void setUseSubDirectoryPerType( boolean useSubDirectoryPerType ) |
224 | |
{ |
225 | 6 | this.useSubDirectoryPerType = useSubDirectoryPerType; |
226 | 6 | } |
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 | 470 | Artifact artifact = item.getArtifact(); |
250 | |
|
251 | 470 | boolean overWrite = |
252 | |
( artifact.isSnapshot() && this.overWriteSnapshots ) |
253 | |
|| ( !artifact.isSnapshot() && this.overWriteReleases ); |
254 | |
|
255 | 470 | File destFolder = item.getOutputDirectory(); |
256 | 470 | if ( destFolder == null ) |
257 | |
{ |
258 | 386 | destFolder = |
259 | |
DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType, |
260 | |
useSubDirectoryPerArtifact, useRepositoryLayout, |
261 | |
removeVersion, this.outputFileDirectory, artifact ); |
262 | |
} |
263 | |
|
264 | 470 | File destFile = null; |
265 | 470 | if ( StringUtils.isEmpty( item.getDestFileName() ) ) |
266 | |
{ |
267 | 386 | destFile = new File( destFolder, DependencyUtil.getFormattedFileName( artifact, this.removeVersion ) ); |
268 | |
} |
269 | |
else |
270 | |
{ |
271 | 84 | destFile = new File( destFolder, item.getDestFileName() ); |
272 | |
} |
273 | |
|
274 | 470 | return overWrite || !destFile.exists() |
275 | |
|| ( overWriteIfNewer && artifact.getFile().lastModified() > destFile.lastModified() ); |
276 | |
} |
277 | |
} |