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  
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.dependencies.DependableCoordinate;
28  import org.codehaus.plexus.util.StringUtils;
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   * @version $Id: ArtifactItem.java 1807877 2017-09-09 10:35:59Z khmarbaise $
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     public ArtifactItem()
125     {
126         // default constructor
127     }
128 
129     public ArtifactItem( Artifact artifact )
130     {
131         this.setArtifact( artifact );
132         this.setArtifactId( artifact.getArtifactId() );
133         this.setClassifier( artifact.getClassifier() );
134         this.setGroupId( artifact.getGroupId() );
135         this.setType( artifact.getType() );
136         this.setVersion( artifact.getVersion() );
137     }
138 
139     private String filterEmptyString( String in )
140     {
141         if ( "".equals( in ) )
142         {
143             return null;
144         }
145         return in;
146     }
147 
148     /**
149      * @return Returns the artifactId.
150      */
151     public String getArtifactId()
152     {
153         return artifactId;
154     }
155 
156     /**
157      * @param artifact The artifactId to set.
158      */
159     public void setArtifactId( String artifact )
160     {
161         this.artifactId = filterEmptyString( artifact );
162     }
163 
164     /**
165      * @return Returns the groupId.
166      */
167     public String getGroupId()
168     {
169         return groupId;
170     }
171 
172     /**
173      * @param groupId The groupId to set.
174      */
175     public void setGroupId( String groupId )
176     {
177         this.groupId = filterEmptyString( groupId );
178     }
179 
180     /**
181      * @return Returns the type.
182      */
183     public String getType()
184     {
185         return type;
186     }
187 
188     /**
189      * @param type The type to set.
190      */
191     public void setType( String type )
192     {
193         this.type = filterEmptyString( type );
194     }
195 
196     /**
197      * @return Returns the version.
198      */
199     public String getVersion()
200     {
201         return version;
202     }
203 
204     /**
205      * @param version The version to set.
206      */
207     public void setVersion( String version )
208     {
209         this.version = filterEmptyString( version );
210     }
211 
212     /**
213      * @return Returns the base version.
214      */
215     public String getBaseVersion()
216     {
217         return ArtifactUtils.toSnapshotVersion( version );
218     }
219 
220     /**
221      * @return Classifier.
222      */
223     public String getClassifier()
224     {
225         return classifier;
226     }
227 
228     /**
229      * @param classifier Classifier.
230      */
231     public void setClassifier( String classifier )
232     {
233         this.classifier = filterEmptyString( classifier );
234     }
235 
236     @Override
237     public String toString()
238     {
239         if ( this.classifier == null )
240         {
241             return groupId + ":" + artifactId + ":" + StringUtils.defaultString( version, "?" ) + ":" + type;
242         }
243         else
244         {
245             return groupId + ":" + artifactId + ":" + classifier + ":" + StringUtils.defaultString( version, "?" ) + ":"
246                 + type;
247         }
248     }
249 
250     /**
251      * @return Returns the location.
252      */
253     public File getOutputDirectory()
254     {
255         return outputDirectory;
256     }
257 
258     /**
259      * @param outputDirectory The outputDirectory to set.
260      */
261     public void setOutputDirectory( File outputDirectory )
262     {
263         this.outputDirectory = outputDirectory;
264     }
265 
266     /**
267      * @return Returns the location.
268      */
269     public String getDestFileName()
270     {
271         return destFileName;
272     }
273 
274     /**
275      * @param destFileName The destFileName to set.
276      */
277     public void setDestFileName( String destFileName )
278     {
279         this.destFileName = filterEmptyString( destFileName );
280     }
281 
282     /**
283      * @return Returns the needsProcessing.
284      */
285     public boolean isNeedsProcessing()
286     {
287         return this.needsProcessing;
288     }
289 
290     /**
291      * @param needsProcessing The needsProcessing to set.
292      */
293     public void setNeedsProcessing( boolean needsProcessing )
294     {
295         this.needsProcessing = needsProcessing;
296     }
297 
298     /**
299      * @return Returns the overWriteSnapshots.
300      */
301     public String getOverWrite()
302     {
303         return this.overWrite;
304     }
305 
306     /**
307      * @param overWrite The overWrite to set.
308      */
309     public void setOverWrite( String overWrite )
310     {
311         this.overWrite = overWrite;
312     }
313 
314     /**
315      * @return Returns the encoding.
316      * @since 3.0
317      */
318     public String getEncoding()
319     {
320         return this.encoding;
321     }
322 
323     /**
324      * @param encoding The encoding to set.
325      * @since 3.0
326      */
327     public void setEncoding( String encoding )
328     {
329         this.encoding = encoding;
330     }
331 
332     /**
333      * @return Returns the artifact.
334      */
335     public Artifact getArtifact()
336     {
337         return this.artifact;
338     }
339 
340     /**
341      * @param artifact The artifact to set.
342      */
343     public void setArtifact( Artifact artifact )
344     {
345         this.artifact = artifact;
346     }
347 
348     /**
349      * @return Returns a comma separated list of excluded items
350      */
351     public String getExcludes()
352     {
353         return DependencyUtil.cleanToBeTokenizedString( this.excludes );
354     }
355 
356     /**
357      * @param excludes A comma separated list of items to exclude i.e. <code>**\/*.xml, **\/*.properties</code>
358      */
359     public void setExcludes( String excludes )
360     {
361         this.excludes = excludes;
362     }
363 
364     /**
365      * @return Returns a comma separated list of included items
366      */
367     public String getIncludes()
368     {
369         return DependencyUtil.cleanToBeTokenizedString( this.includes );
370     }
371 
372     /**
373      * @param includes A comma separated list of items to include i.e. <code>**\/*.xml, **\/*.properties</code>
374      */
375     public void setIncludes( String includes )
376     {
377         this.includes = includes;
378     }
379 }