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