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   * @since 1.0
35   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
36   */
37  public class ArtifactItem implements DependableCoordinate {
38      /**
39       * Group Id of Artifact
40       *
41       */
42      @Parameter(required = true)
43      private String groupId;
44  
45      /**
46       * Name of Artifact
47       */
48      @Parameter(required = true)
49      private String artifactId;
50  
51      /**
52       * Version of Artifact
53       */
54      @Parameter
55      private String version = null;
56  
57      /**
58       * Type of Artifact (War,Jar,etc)
59       *
60       */
61      @Parameter(required = true)
62      private String type = "jar";
63  
64      /**
65       * Classifier for Artifact (tests,sources,etc)
66       */
67      @Parameter
68      private String classifier;
69  
70      /**
71       * Location to use for this Artifact. Overrides default location.
72       */
73      @Parameter
74      private File outputDirectory;
75  
76      /**
77       * Provides ability to change destination file name
78       */
79      @Parameter
80      private String destFileName;
81  
82      /**
83       * Force Overwrite..this is the one to set in pom
84       */
85      private String overWrite;
86  
87      /**
88       * Encoding of artifact. Overrides default encoding.
89       */
90      @Parameter
91      private String encoding;
92  
93      /**
94       *
95       */
96      private boolean needsProcessing;
97  
98      /**
99       * Artifact Item
100      */
101     private Artifact artifact;
102 
103     /**
104      * A comma separated list of file patterns to include when unpacking the artifact.
105      */
106     private String includes;
107 
108     /**
109      * A comma separated list of file patterns to exclude when unpacking the artifact.
110      */
111     private String excludes;
112 
113     /**
114      * {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting shall happen.
115      *
116      * @since 3.1.2
117      */
118     @Parameter
119     private FileMapper[] fileMappers;
120 
121     /**
122      * Default ctor.
123      */
124     public ArtifactItem() {
125         // default constructor
126     }
127 
128     /**
129      * @param artifact {@link Artifact}
130      */
131     public ArtifactItem(Artifact artifact) {
132         this.setArtifact(artifact);
133         this.setArtifactId(artifact.getArtifactId());
134         this.setClassifier(artifact.getClassifier());
135         this.setGroupId(artifact.getGroupId());
136         this.setType(artifact.getType());
137         this.setVersion(artifact.getVersion());
138     }
139 
140     private String filterEmptyString(String in) {
141         if ("".equals(in)) {
142             return null;
143         }
144         return in;
145     }
146 
147     /**
148      * @return Returns the artifactId.
149      */
150     public String getArtifactId() {
151         return artifactId;
152     }
153 
154     /**
155      * @param theArtifact The artifactId to set.
156      */
157     public void setArtifactId(String theArtifact) {
158         this.artifactId = filterEmptyString(theArtifact);
159     }
160 
161     /**
162      * @return Returns the groupId.
163      */
164     public String getGroupId() {
165         return groupId;
166     }
167 
168     /**
169      * @param groupId The groupId to set.
170      */
171     public void setGroupId(String groupId) {
172         this.groupId = filterEmptyString(groupId);
173     }
174 
175     /**
176      * @return Returns the type.
177      */
178     public String getType() {
179         return type;
180     }
181 
182     /**
183      * @param type The type to set.
184      */
185     public void setType(String type) {
186         this.type = filterEmptyString(type);
187     }
188 
189     /**
190      * @return Returns the version.
191      */
192     public String getVersion() {
193         return version;
194     }
195 
196     /**
197      * @param version The version to set.
198      */
199     public void setVersion(String version) {
200         this.version = filterEmptyString(version);
201     }
202 
203     /**
204      * @return Returns the base version.
205      */
206     public String getBaseVersion() {
207         return ArtifactUtils.toSnapshotVersion(version);
208     }
209 
210     /**
211      * @return Classifier.
212      */
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 destFileName 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 Returns 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 i.e. <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 included items
335      */
336     public String getIncludes() {
337         return DependencyUtil.cleanToBeTokenizedString(this.includes);
338     }
339 
340     /**
341      * @param includes A comma separated list of items to include i.e. <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      *
351      * @since 3.1.2
352      */
353     public FileMapper[] getFileMappers() {
354         return this.fileMappers;
355     }
356 
357     /**
358      * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no
359      * rewriting shall happen.
360      *
361      * @since 3.1.2
362      */
363     public void setFileMappers(FileMapper[] fileMappers) {
364         this.fileMappers = fileMappers;
365     }
366 }