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.java 1368231 2012-08-01 20:10:06Z hboutemy $
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       * Type of Artifact (War,Jar,etc)
63       *
64       * @parameter
65       * @required
66       */
67      private String type = "jar";
68  
69      /**
70       * Classifier for Artifact (tests,sources,etc)
71       *
72       * @parameter
73       */
74      private String classifier;
75  
76      /**
77       * Location to use for this Artifact. Overrides default location.
78       *
79       * @parameter
80       */
81      private File outputDirectory;
82  
83      /**
84       * Provides ability to change destination file name
85       *
86       * @parameter
87       */
88      private String destFileName;
89  
90      /**
91       * Force Overwrite..this is the one to set in pom
92       */
93      private String overWrite;
94  
95      /**
96       *
97       */
98      private boolean needsProcessing;
99  
100     /**
101      * Artifact Item
102      */
103     private Artifact artifact;
104 
105     /**
106      * A comma separated list of file patterns to include when unpacking the
107      * artifact.
108      */
109     private String includes;
110 
111     /**
112      * A comma separated list of file patterns to exclude when unpacking the
113      * artifact.
114      */
115     private String excludes;
116 
117     public ArtifactItem()
118     {
119         // default constructor
120     }
121 
122     public ArtifactItem( Artifact artifact )
123     {
124         this.setArtifact( artifact );
125         this.setArtifactId( artifact.getArtifactId() );
126         this.setClassifier( artifact.getClassifier() );
127         this.setGroupId( artifact.getGroupId() );
128         this.setType( artifact.getType() );
129         this.setVersion( artifact.getVersion() );
130     }
131 
132     private String filterEmptyString( String in )
133     {
134         if ( "".equals( in ) )
135         {
136             return null;
137         }
138         return in;
139     }
140 
141     /**
142      * @return Returns the artifactId.
143      */
144     public String getArtifactId()
145     {
146         return artifactId;
147     }
148 
149     /**
150      * @param artifactId
151      *            The artifactId to set.
152      */
153     public void setArtifactId( String artifact )
154     {
155         this.artifactId = filterEmptyString( artifact );
156     }
157 
158     /**
159      * @return Returns the groupId.
160      */
161     public String getGroupId()
162     {
163         return groupId;
164     }
165 
166     /**
167      * @param groupId
168      *            The groupId to set.
169      */
170     public void setGroupId( String groupId )
171     {
172         this.groupId = filterEmptyString( groupId );
173     }
174 
175     /**
176      * @return Returns the type.
177      */
178     public String getType()
179     {
180         return type;
181     }
182 
183     /**
184      * @param type
185      *            The type to set.
186      */
187     public void setType( String type )
188     {
189         this.type = filterEmptyString( type );
190     }
191 
192     /**
193      * @return Returns the version.
194      */
195     public String getVersion()
196     {
197         return version;
198     }
199 
200     /**
201      * @param version
202      *            The version to set.
203      */
204     public void setVersion( String version )
205     {
206         this.version = filterEmptyString( version );
207     }
208 
209     /**
210      * @return Classifier.
211      */
212     public String getClassifier()
213     {
214         return classifier;
215     }
216 
217     /**
218      * @param classifier
219      *            Classifier.
220      */
221     public void setClassifier( String classifier )
222     {
223         this.classifier = filterEmptyString( classifier );
224     }
225 
226     public String toString()
227     {
228         if ( this.classifier == null )
229         {
230             return groupId + ":" + artifactId + ":" + StringUtils.defaultString( version, "?" ) + ":" + type;
231         }
232         else
233         {
234             return groupId + ":" + artifactId + ":" + classifier + ":" + StringUtils.defaultString( version, "?" )
235                 + ":" + type;
236         }
237     }
238 
239     /**
240      * @return Returns the location.
241      */
242     public File getOutputDirectory()
243     {
244         return outputDirectory;
245     }
246 
247     /**
248      * @param location
249      *            The location to set.
250      */
251     public void setOutputDirectory( File outputDirectory )
252     {
253         this.outputDirectory = outputDirectory;
254     }
255 
256     /**
257      * @return Returns the location.
258      */
259     public String getDestFileName()
260     {
261         return destFileName;
262     }
263 
264     /**
265      * @param destFileName
266      *            The destFileName to set.
267      */
268     public void setDestFileName( String destFileName )
269     {
270         this.destFileName = filterEmptyString( destFileName );
271     }
272 
273     /**
274      * @return Returns the needsProcessing.
275      */
276     public boolean isNeedsProcessing()
277     {
278         return this.needsProcessing;
279     }
280 
281     /**
282      * @param needsProcessing
283      *            The needsProcessing to set.
284      */
285     public void setNeedsProcessing( boolean needsProcessing )
286     {
287         this.needsProcessing = needsProcessing;
288     }
289 
290     /**
291      * @return Returns the overWriteSnapshots.
292      */
293     public String getOverWrite()
294     {
295         return this.overWrite;
296     }
297 
298     /**
299      * @param overWriteSnapshots
300      *            The overWriteSnapshots to set.
301      */
302     public void setOverWrite( String overWrite )
303     {
304         this.overWrite = overWrite;
305     }
306 
307     /**
308      * @return Returns the artifact.
309      */
310     public Artifact getArtifact()
311     {
312         return this.artifact;
313     }
314 
315     /**
316      * @param artifact
317      *            The artifact to set.
318      */
319     public void setArtifact( Artifact artifact )
320     {
321         this.artifact = artifact;
322     }
323 
324     /**
325      * @return Returns a comma separated list of excluded items
326      */
327     public String getExcludes ()
328     {
329         return DependencyUtil.cleanToBeTokenizedString( this.excludes );
330     }
331 
332     /**
333      * @param excludes A comma separated list of items to exclude i.e. <code>**\/*.xml, **\/*.properties</code>
334      */
335     public void setExcludes( String excludes )
336     {
337         this.excludes = excludes;
338     }
339 
340     /**
341      * @return Returns a comma separated list of included items
342      */
343     public String getIncludes()
344     {
345         return DependencyUtil.cleanToBeTokenizedString( this.includes );
346     }
347 
348     /**
349      * @param includes A comma separated list of items to include i.e. <code>**\/*.xml, **\/*.properties</code>
350      */
351     public void setIncludes ( String includes )
352     {
353         this.includes = includes;
354     }
355 }