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