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