View Javadoc

1   package org.apache.maven.repository.metadata;
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.util.Collection;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.ArtifactScopeEnum;
26  
27  /**
28   * Artifact Metadata that is resolved independent of Artifact itself.
29   *
30   * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
31   */
32  public class ArtifactMetadata
33  {
34      /**
35       * standard glorified artifact coordinates
36       */
37      protected String groupId;
38      protected String artifactId;
39      protected String version;
40      protected String type;
41      protected ArtifactScopeEnum artifactScope;
42      protected String classifier;
43  
44      /**
45       * explanation: why this MD was chosen over it's siblings
46       * in the resulting structure (classpath for now)
47       */
48      protected String why;
49  
50      /** dependencies of the artifact behind this metadata */
51      protected Collection<ArtifactMetadata> dependencies;
52  
53      /** metadata URI */
54      protected String uri;
55  
56      /** is metadata found anywhere */
57      protected boolean resolved = false;
58  
59      /** does the actual artifact for this metadata exists */
60      protected boolean artifactExists = false;
61      /** artifact URI */
62      protected String artifactUri;
63  
64      /** error message  */
65      private String error;
66  
67      //------------------------------------------------------------------
68      /**
69       *
70       */
71      public ArtifactMetadata( String name )
72      {
73          if ( name == null )
74          {
75              return;
76          }
77          int ind1 = name.indexOf( ':' );
78          int ind2 = name.lastIndexOf( ':' );
79  
80          if ( ind1 == -1 || ind2 == -1 )
81          {
82              return;
83          }
84  
85          this.groupId = name.substring( 0, ind1 );
86          if ( ind1 == ind2 )
87          {
88              this.artifactId = name.substring( ind1 + 1 );
89          }
90          else
91          {
92              this.artifactId = name.substring( ind1 + 1, ind2 );
93              this.version = name.substring( ind2 + 1 );
94          }
95      }
96  
97      // ------------------------------------------------------------------
98      public ArtifactMetadata( String groupId, String name, String version )
99      {
100         this( groupId, name, version, null );
101     }
102     //------------------------------------------------------------------
103     public ArtifactMetadata( String groupId, String name, String version, String type )
104     {
105         this( groupId, name, version, type, null );
106     }
107 
108     //------------------------------------------------------------------
109     public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope )
110     {
111         this( groupId, name, version, type, artifactScope, null );
112     }
113 
114     //------------------------------------------------------------------
115     public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope,
116                              String classifier )
117     {
118         this( groupId, name, version, type, artifactScope, classifier, null );
119     }
120     //------------------------------------------------------------------
121     public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope,
122                              String classifier, String artifactUri )
123     {
124         this( groupId, name, version, type, artifactScope, classifier, artifactUri, null, true, null );
125     }
126     //------------------------------------------------------------------
127     public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope,
128                              String classifier, String artifactUri, String why, boolean resolved, String error )
129     {
130         this.groupId = groupId;
131         this.artifactId = name;
132         this.version = version;
133         this.type = type;
134         this.artifactScope = artifactScope;
135         this.classifier = classifier;
136         this.artifactUri = artifactUri;
137         this.why = why;
138         this.resolved = resolved;
139         this.error = error;
140     }
141     //------------------------------------------------------------------
142     public ArtifactMetadata( String groupId, String name, String version, String type, String scopeString,
143                              String classifier, String artifactUri, String why, boolean resolved, String error )
144     {
145         this( groupId, name, version, type,
146               scopeString == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scopeString ),
147               classifier, artifactUri, why, resolved, error );
148     }
149 
150     //------------------------------------------------------------------
151     public ArtifactMetadata( Artifact af )
152     {
153         /*
154         if ( af != null )
155         {
156             init( af );
157         }
158         */
159     }
160     //------------------------------------------------------------------
161 //    public void init( ArtifactMetadata af )
162 //    {
163 //        setGroupId( af.getGroupId() );
164 //        setArtifactId( af.getArtifactId() );
165 //        setVersion( af.getVersion() );
166 //        setType( af.getType() );
167 //        setScope( af.getScope() );
168 //        setClassifier( af.getClassifier() );
169 //        //setUri( af.getDownloadUrl() );
170 //
171 //        this.resolved = af.isResolved();
172 //    }
173 
174     //------------------------------------------------------------------
175     @Override
176     public String toString()
177     {
178         return groupId + ":" + artifactId + ":" + version;
179     }
180 
181     //------------------------------------------------------------------
182     public String toDomainString()
183     {
184         return groupId + ":" + artifactId;
185     }
186 
187     //------------------------------------------------------------------
188     public String getGroupId()
189     {
190         return groupId;
191     }
192 
193     public void setGroupId( String groupId )
194     {
195         this.groupId = groupId;
196     }
197 
198     public String getArtifactId()
199     {
200         return artifactId;
201     }
202 
203     public void setArtifactId( String name )
204     {
205         this.artifactId = name;
206     }
207 
208     public String getVersion()
209     {
210         return version;
211     }
212 
213     public void setVersion( String version )
214     {
215         this.version = version;
216     }
217 
218     public String getType()
219     {
220         return type;
221     }
222 
223     public String getCheckedType()
224     {
225         return type == null ? "jar" : type;
226     }
227 
228     public void setType( String type )
229     {
230         this.type = type;
231     }
232 
233     public ArtifactScopeEnum getArtifactScope()
234     {
235         return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
236     }
237 
238     public void setArtifactScope( ArtifactScopeEnum artifactScope )
239     {
240         this.artifactScope = artifactScope;
241     }
242 
243     public void setScope( String scope )
244     {
245         this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scope );
246     }
247 
248     public String getClassifier()
249     {
250         return classifier;
251     }
252 
253     public void setClassifier( String classifier )
254     {
255         this.classifier = classifier;
256     }
257 
258     public boolean isResolved()
259     {
260         return resolved;
261     }
262 
263     public void setResolved( boolean resolved )
264     {
265         this.resolved = resolved;
266     }
267 
268     public String getUri()
269     {
270         return uri;
271     }
272 
273     public void setUri( String uri )
274     {
275         this.uri = uri;
276     }
277 
278     public String getScope()
279     {
280         return getArtifactScope().getScope();
281     }
282 
283     public ArtifactScopeEnum getScopeAsEnum()
284     {
285         return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
286     }
287 
288     public boolean isArtifactExists()
289     {
290         return artifactExists;
291     }
292 
293     public void setArtifactExists( boolean artifactExists )
294     {
295         this.artifactExists = artifactExists;
296     }
297 
298 
299     public Collection<ArtifactMetadata> getDependencies()
300     {
301         return dependencies;
302     }
303 
304     public void setDependencies( Collection<ArtifactMetadata> dependencies )
305     {
306         this.dependencies = dependencies;
307     }
308 
309     public String getArtifactUri()
310     {
311         return artifactUri;
312     }
313 
314     public void setArtifactUri( String artifactUri )
315     {
316         this.artifactUri = artifactUri;
317     }
318 
319 
320     public String getWhy()
321     {
322         return why;
323     }
324 
325     public void setWhy( String why )
326     {
327         this.why = why;
328     }
329 
330     //-------------------------------------------------------------------
331     public String getError()
332     {
333         return error;
334     }
335 
336     public void setError( String error )
337     {
338         this.error = error;
339     }
340 
341     public boolean isError()
342     {
343         return error == null;
344     }
345 
346     //------------------------------------------------------------------
347     public String getDependencyConflictId()
348     {
349         return groupId + ":" + artifactId;
350     }
351     //------------------------------------------------------------------
352     //------------------------------------------------------------------
353 }