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