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