001 package org.apache.maven.repository.metadata;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.Collection;
023
024 import org.apache.maven.artifact.Artifact;
025 import org.apache.maven.artifact.ArtifactScopeEnum;
026
027 /**
028 * Artifact Metadata that is resolved independent of Artifact itself.
029 *
030 * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
031 */
032 public class ArtifactMetadata
033 {
034 /**
035 * standard glorified artifact coordinates
036 */
037 protected String groupId;
038 protected String artifactId;
039 protected String version;
040 protected String type;
041 protected ArtifactScopeEnum artifactScope;
042 protected String classifier;
043
044 /**
045 * explanation: why this MD was chosen over it's siblings
046 * in the resulting structure (classpath for now)
047 */
048 protected String why;
049
050 /** dependencies of the artifact behind this metadata */
051 protected Collection<ArtifactMetadata> dependencies;
052
053 /** metadata URI */
054 protected String uri;
055
056 /** is metadata found anywhere */
057 protected boolean resolved = false;
058
059 /** does the actual artifact for this metadata exists */
060 protected boolean artifactExists = false;
061 /** artifact URI */
062 protected String artifactUri;
063
064 /** error message */
065 private String error;
066
067 //------------------------------------------------------------------
068 /**
069 *
070 */
071 public ArtifactMetadata( String name )
072 {
073 if ( name == null )
074 {
075 return;
076 }
077 int ind1 = name.indexOf( ':' );
078 int ind2 = name.lastIndexOf( ':' );
079
080 if ( ind1 == -1 || ind2 == -1 )
081 {
082 return;
083 }
084
085 this.groupId = name.substring( 0, ind1 );
086 if ( ind1 == ind2 )
087 {
088 this.artifactId = name.substring( ind1 + 1 );
089 }
090 else
091 {
092 this.artifactId = name.substring( ind1 + 1, ind2 );
093 this.version = name.substring( ind2 + 1 );
094 }
095 }
096
097 // ------------------------------------------------------------------
098 public ArtifactMetadata( String groupId, String name, String version )
099 {
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 }