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