View Javadoc
1   package org.apache.maven.shared.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     public final void setGroupId( String groupId )
101     {
102         this.groupId = groupId;
103     }
104 
105     @Override
106     public final String getArtifactId()
107     {
108         return artifactId;
109     }
110 
111     public final void setArtifactId( String artifactId )
112     {
113         this.artifactId = artifactId;
114     }
115 
116     @Override
117     public final String getVersion()
118     {
119         return version;
120     }
121 
122     public final void setVersion( String version )
123     {
124         this.version = version;
125     }
126 
127     @Override
128     public final String getType()
129     {
130         return type != null ? type : "jar";
131     }
132 
133     public void setType( String type )
134     {
135         this.type = type;
136     }
137     
138     @Override
139     public final String getClassifier()
140     {
141         return classifier;
142     }
143 
144     public final void setClassifier( String classifier )
145     {
146         this.classifier = classifier;
147     }
148     
149     /**
150      * @see org.apache.maven.artifact.DefaultArtifact#toString()
151      */
152     @Override
153     public String toString()
154     {
155         StringBuilder sb =
156             new StringBuilder().append( groupId ).append( ':' ).append( artifactId ).append( ':' ).append( getType() );
157         
158         if ( classifier != null )
159         {
160             sb.append( ':' ).append( classifier );
161         }
162         
163         sb.append( ':' ).append( version );
164         
165         return sb.toString();
166     }
167     
168 }