View Javadoc
1   package org.apache.maven.shared.transfer.artifact;
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  /**
23   * Common usage of an ArtifactCoordinate for a Mojo
24   * 
25   * <pre>
26   * &#64;Parameter
27   * private DefaultArtifactCoordinate[] artifacts;
28   * </pre>
29   * 
30   * and
31   * 
32   * <pre>
33   * private DefaultArtifactCoordinate artifact = new DefaultArtifactCoordinate();
34   * 
35   * &#64;Parameter( property = "groupId" )
36   * private String groupId;
37   * 
38   * &#64;Parameter( property = "artifactId" )
39   * private String artifactId;
40   * 
41   * &#64;Parameter( property = "version" )
42   * private String version;
43   * 
44   * &#64;Parameter( property = "classifier" )
45   * private String classifier;
46   * 
47   * &#64;Parameter( property = "type" )
48   * private String type;
49   * 
50   * public void setGroupId( String groupId )
51   * {
52   *     this.artifact.setGroupId( groupId );
53   * }
54   * 
55   * public void setArtifactId( String artifactId )
56   * {
57   *     this.artifact.setArtifactId( artifactId );
58   * }
59   * 
60   * public void setVersion( String version )
61   * {
62   *     this.artifact.setVersion( version );
63   * }
64   * 
65   * public void setClassifier( String classifier )
66   * {
67   *     this.artifact.setClassifier( classifier );
68   * }
69   * 
70   * public void setType( String type )
71   * {
72   *     this.artifact.setType( type );
73   * }
74   * </pre>
75   * 
76   * <strong>Note: </strong> type is not the same as extension! {@link org.apache.maven.artifact.handler.ArtifactHandler}s
77   * are used to map a type to an extension.
78   * 
79   * @author Robert Scholte
80   * @since 3.0
81   */
82  public class DefaultArtifactCoordinate
83      implements ArtifactCoordinate
84  {
85      private String groupId;
86  
87      private String artifactId;
88  
89      private String version;
90  
91      private String extension;
92  
93      private String classifier;
94  
95      @Override
96      public final String getGroupId()
97      {
98          return groupId;
99      }
100 
101     /**
102      * @param groupId The groupId to be used.
103      */
104     public final void setGroupId( String groupId )
105     {
106         this.groupId = groupId;
107     }
108 
109     @Override
110     public final String getArtifactId()
111     {
112         return artifactId;
113     }
114 
115     /**
116      * @param artifactId The artifactId to be used.
117      */
118     public final void setArtifactId( String artifactId )
119     {
120         this.artifactId = artifactId;
121     }
122 
123     @Override
124     public final String getVersion()
125     {
126         return version;
127     }
128 
129     /**
130      * @param version The version to be used.
131      */
132     public final void setVersion( String version )
133     {
134         this.version = version;
135     }
136 
137     @Override
138     public final String getExtension()
139     {
140         return extension != null ? extension : "jar";
141     }
142 
143     /**
144      * @param extension The extension to be used.
145      */
146     public final void setExtension( String extension )
147     {
148         this.extension = extension;
149     }
150 
151     @Override
152     public final String getClassifier()
153     {
154         return classifier;
155     }
156 
157     /**
158      * @param classifier The classifier to be used.
159      */
160     public final void setClassifier( String classifier )
161     {
162         this.classifier = classifier;
163     }
164 
165     /**
166      * @see org.apache.maven.artifact.DefaultArtifact#toString()
167      */
168     @Override
169     public String toString()
170     {
171         StringBuilder sb = new StringBuilder().append( groupId ).append( ':' )
172                         .append( artifactId ).append( ':' ).append( getExtension() );
173 
174         if ( classifier != null )
175         {
176             sb.append( ':' ).append( classifier );
177         }
178 
179         sb.append( ':' ).append( version );
180 
181         return sb.toString();
182     }
183 
184 }