1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.plugins.dependency.fromConfiguration;
20
21 import java.io.File;
22 import java.util.Objects;
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.artifact.ArtifactUtils;
25 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
26 import org.apache.maven.shared.transfer.dependencies.DependableCoordinate;
27 import org.codehaus.plexus.components.io.filemappers.FileMapper;
28
29 /**
30 * ArtifactItem represents information specified in the plugin configuration section for each artifact.
31 *
32 * @since 1.0
33 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
34 */
35 public class ArtifactItem implements DependableCoordinate {
36 /**
37 * Group Id of Artifact
38 *
39 * @parameter
40 * @required
41 */
42 private String groupId;
43
44 /**
45 * Name of Artifact
46 *
47 * @parameter
48 * @required
49 */
50 private String artifactId;
51
52 /**
53 * Version of Artifact
54 *
55 * @parameter
56 */
57 private String version = null;
58
59 /**
60 * Type of Artifact (War,Jar,etc)
61 *
62 * @parameter
63 * @required
64 */
65 private String type = "jar";
66
67 /**
68 * Classifier for Artifact (tests,sources,etc)
69 *
70 * @parameter
71 */
72 private String classifier;
73
74 /**
75 * Location to use for this Artifact. Overrides default location.
76 *
77 * @parameter
78 */
79 private File outputDirectory;
80
81 /**
82 * Provides ability to change destination file name
83 *
84 * @parameter
85 */
86 private String destFileName;
87
88 /**
89 * Force Overwrite..this is the one to set in pom
90 */
91 private String overWrite;
92
93 /**
94 * Encoding of artifact. Overrides default encoding.
95 *
96 * @parameter
97 */
98 private String encoding;
99
100 /**
101 *
102 */
103 private boolean needsProcessing;
104
105 /**
106 * Artifact Item
107 */
108 private Artifact artifact;
109
110 /**
111 * A comma separated list of file patterns to include when unpacking the artifact.
112 */
113 private String includes;
114
115 /**
116 * A comma separated list of file patterns to exclude when unpacking the artifact.
117 */
118 private String excludes;
119
120 /**
121 * {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting shall happen.
122 *
123 * @since 3.1.2
124 *
125 * @parameter
126 */
127 private FileMapper[] fileMappers;
128
129 /**
130 * Default ctor.
131 */
132 public ArtifactItem() {
133 // default constructor
134 }
135
136 /**
137 * @param artifact {@link Artifact}
138 */
139 public ArtifactItem(Artifact artifact) {
140 this.setArtifact(artifact);
141 this.setArtifactId(artifact.getArtifactId());
142 this.setClassifier(artifact.getClassifier());
143 this.setGroupId(artifact.getGroupId());
144 this.setType(artifact.getType());
145 this.setVersion(artifact.getVersion());
146 }
147
148 private String filterEmptyString(String in) {
149 if ("".equals(in)) {
150 return null;
151 }
152 return in;
153 }
154
155 /**
156 * @return Returns the artifactId.
157 */
158 public String getArtifactId() {
159 return artifactId;
160 }
161
162 /**
163 * @param theArtifact The artifactId to set.
164 */
165 public void setArtifactId(String theArtifact) {
166 this.artifactId = filterEmptyString(theArtifact);
167 }
168
169 /**
170 * @return Returns the groupId.
171 */
172 public String getGroupId() {
173 return groupId;
174 }
175
176 /**
177 * @param groupId The groupId to set.
178 */
179 public void setGroupId(String groupId) {
180 this.groupId = filterEmptyString(groupId);
181 }
182
183 /**
184 * @return Returns the type.
185 */
186 public String getType() {
187 return type;
188 }
189
190 /**
191 * @param type The type to set.
192 */
193 public void setType(String type) {
194 this.type = filterEmptyString(type);
195 }
196
197 /**
198 * @return Returns the version.
199 */
200 public String getVersion() {
201 return version;
202 }
203
204 /**
205 * @param version The version to set.
206 */
207 public void setVersion(String version) {
208 this.version = filterEmptyString(version);
209 }
210
211 /**
212 * @return Returns the base version.
213 */
214 public String getBaseVersion() {
215 return ArtifactUtils.toSnapshotVersion(version);
216 }
217
218 /**
219 * @return Classifier.
220 */
221 public String getClassifier() {
222 return classifier;
223 }
224
225 /**
226 * @param classifier Classifier.
227 */
228 public void setClassifier(String classifier) {
229 this.classifier = filterEmptyString(classifier);
230 }
231
232 @Override
233 public String toString() {
234 if (this.classifier == null) {
235 return groupId + ":" + artifactId + ":" + Objects.toString(version, "?") + ":" + type;
236 } else {
237 return groupId + ":" + artifactId + ":" + classifier + ":" + Objects.toString(version, "?") + ":" + type;
238 }
239 }
240
241 /**
242 * @return Returns the location.
243 */
244 public File getOutputDirectory() {
245 return outputDirectory;
246 }
247
248 /**
249 * @param outputDirectory The outputDirectory to set.
250 */
251 public void setOutputDirectory(File outputDirectory) {
252 this.outputDirectory = outputDirectory;
253 }
254
255 /**
256 * @return Returns the location.
257 */
258 public String getDestFileName() {
259 return destFileName;
260 }
261
262 /**
263 * @param destFileName The destFileName to set.
264 */
265 public void setDestFileName(String destFileName) {
266 this.destFileName = filterEmptyString(destFileName);
267 }
268
269 /**
270 * @return Returns the needsProcessing.
271 */
272 public boolean isNeedsProcessing() {
273 return this.needsProcessing;
274 }
275
276 /**
277 * @param needsProcessing The needsProcessing to set.
278 */
279 public void setNeedsProcessing(boolean needsProcessing) {
280 this.needsProcessing = needsProcessing;
281 }
282
283 /**
284 * @return Returns the overWriteSnapshots.
285 */
286 public String getOverWrite() {
287 return this.overWrite;
288 }
289
290 /**
291 * @param overWrite The overWrite to set.
292 */
293 public void setOverWrite(String overWrite) {
294 this.overWrite = overWrite;
295 }
296
297 /**
298 * @return Returns the encoding.
299 * @since 3.0
300 */
301 public String getEncoding() {
302 return this.encoding;
303 }
304
305 /**
306 * @param encoding The encoding to set.
307 * @since 3.0
308 */
309 public void setEncoding(String encoding) {
310 this.encoding = encoding;
311 }
312
313 /**
314 * @return Returns the artifact.
315 */
316 public Artifact getArtifact() {
317 return this.artifact;
318 }
319
320 /**
321 * @param artifact The artifact to set.
322 */
323 public void setArtifact(Artifact artifact) {
324 this.artifact = artifact;
325 }
326
327 /**
328 * @return Returns a comma separated list of excluded items
329 */
330 public String getExcludes() {
331 return DependencyUtil.cleanToBeTokenizedString(this.excludes);
332 }
333
334 /**
335 * @param excludes A comma separated list of items to exclude i.e. <code>**\/*.xml, **\/*.properties</code>
336 */
337 public void setExcludes(String excludes) {
338 this.excludes = excludes;
339 }
340
341 /**
342 * @return Returns a comma separated list of included items
343 */
344 public String getIncludes() {
345 return DependencyUtil.cleanToBeTokenizedString(this.includes);
346 }
347
348 /**
349 * @param includes A comma separated list of items to include i.e. <code>**\/*.xml, **\/*.properties</code>
350 */
351 public void setIncludes(String includes) {
352 this.includes = includes;
353 }
354
355 /**
356 * @return {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting shall
357 * happen.
358 *
359 * @since 3.1.2
360 */
361 public FileMapper[] getFileMappers() {
362 return this.fileMappers;
363 }
364
365 /**
366 * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no
367 * rewriting shall happen.
368 *
369 * @since 3.1.2
370 */
371 public void setFileMappers(FileMapper[] fileMappers) {
372 this.fileMappers = fileMappers;
373 }
374 }