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