View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.metadata;
20  
21  import java.util.Collection;
22  
23  import org.apache.maven.artifact.Artifact;
24  import org.apache.maven.artifact.ArtifactScopeEnum;
25  
26  /**
27   * Artifact Metadata that is resolved independent of Artifact itself.
28   *
29   */
30  @Deprecated
31  public class ArtifactMetadata {
32      /**
33       * standard glorified artifact coordinates
34       */
35      protected String groupId;
36  
37      protected String artifactId;
38      protected String version;
39      protected String type;
40      protected ArtifactScopeEnum artifactScope;
41      protected String classifier;
42  
43      /**
44       * explanation: why this MD was chosen over its siblings
45       * in the resulting structure (classpath for now)
46       */
47      protected String why;
48  
49      /** dependencies of the artifact behind this metadata */
50      protected Collection<ArtifactMetadata> dependencies;
51  
52      /** metadata URI */
53      protected String uri;
54  
55      /** is metadata found anywhere */
56      protected boolean resolved = false;
57  
58      /** does the actual artifact for this metadata exists */
59      protected boolean artifactExists = false;
60      /** artifact URI */
61      protected String artifactUri;
62  
63      /** error message  */
64      private String error;
65  
66      // ------------------------------------------------------------------
67      /**
68       *
69       */
70      public ArtifactMetadata(String name) {
71          if (name == null) {
72              return;
73          }
74          int ind1 = name.indexOf(':');
75          int ind2 = name.lastIndexOf(':');
76  
77          if (ind1 == -1 || ind2 == -1) {
78              return;
79          }
80  
81          this.groupId = name.substring(0, ind1);
82          if (ind1 == ind2) {
83              this.artifactId = name.substring(ind1 + 1);
84          } else {
85              this.artifactId = name.substring(ind1 + 1, ind2);
86              this.version = name.substring(ind2 + 1);
87          }
88      }
89  
90      public ArtifactMetadata(String groupId, String name, String version) {
91          this(groupId, name, version, null);
92      }
93  
94      public ArtifactMetadata(String groupId, String name, String version, String type) {
95          this(groupId, name, version, type, null);
96      }
97  
98      public ArtifactMetadata(String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope) {
99          this(groupId, name, version, type, artifactScope, null);
100     }
101 
102     public ArtifactMetadata(
103             String groupId,
104             String name,
105             String version,
106             String type,
107             ArtifactScopeEnum artifactScope,
108             String classifier) {
109         this(groupId, name, version, type, artifactScope, classifier, null);
110     }
111 
112     public ArtifactMetadata(
113             String groupId,
114             String name,
115             String version,
116             String type,
117             ArtifactScopeEnum artifactScope,
118             String classifier,
119             String artifactUri) {
120         this(groupId, name, version, type, artifactScope, classifier, artifactUri, null, true, null);
121     }
122 
123     @SuppressWarnings("checkstyle:parameternumber")
124     public ArtifactMetadata(
125             String groupId,
126             String name,
127             String version,
128             String type,
129             ArtifactScopeEnum artifactScope,
130             String classifier,
131             String artifactUri,
132             String why,
133             boolean resolved,
134             String error) {
135         this.groupId = groupId;
136         this.artifactId = name;
137         this.version = version;
138         this.type = type;
139         this.artifactScope = artifactScope;
140         this.classifier = classifier;
141         this.artifactUri = artifactUri;
142         this.why = why;
143         this.resolved = resolved;
144         this.error = error;
145     }
146 
147     @SuppressWarnings("checkstyle:parameternumber")
148     public ArtifactMetadata(
149             String groupId,
150             String name,
151             String version,
152             String type,
153             String scopeString,
154             String classifier,
155             String artifactUri,
156             String why,
157             boolean resolved,
158             String error) {
159         this(
160                 groupId,
161                 name,
162                 version,
163                 type,
164                 scopeString == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf(scopeString),
165                 classifier,
166                 artifactUri,
167                 why,
168                 resolved,
169                 error);
170     }
171 
172     public ArtifactMetadata(Artifact af) {}
173 
174     @Override
175     public String toString() {
176         return groupId + ":" + artifactId + ":" + version;
177     }
178 
179     public String toDomainString() {
180         return groupId + ":" + artifactId;
181     }
182 
183     public String getGroupId() {
184         return groupId;
185     }
186 
187     public void setGroupId(String groupId) {
188         this.groupId = groupId;
189     }
190 
191     public String getArtifactId() {
192         return artifactId;
193     }
194 
195     public void setArtifactId(String name) {
196         this.artifactId = name;
197     }
198 
199     public String getVersion() {
200         return version;
201     }
202 
203     public void setVersion(String version) {
204         this.version = version;
205     }
206 
207     public String getType() {
208         return type;
209     }
210 
211     public String getCheckedType() {
212         return type == null ? "jar" : type;
213     }
214 
215     public void setType(String type) {
216         this.type = type;
217     }
218 
219     public ArtifactScopeEnum getArtifactScope() {
220         return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
221     }
222 
223     public void setArtifactScope(ArtifactScopeEnum artifactScope) {
224         this.artifactScope = artifactScope;
225     }
226 
227     public void setScope(String scope) {
228         this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf(scope);
229     }
230 
231     public String getClassifier() {
232         return classifier;
233     }
234 
235     public void setClassifier(String classifier) {
236         this.classifier = classifier;
237     }
238 
239     public boolean isResolved() {
240         return resolved;
241     }
242 
243     public void setResolved(boolean resolved) {
244         this.resolved = resolved;
245     }
246 
247     public String getUri() {
248         return uri;
249     }
250 
251     public void setUri(String uri) {
252         this.uri = uri;
253     }
254 
255     public String getScope() {
256         return getArtifactScope().getScope();
257     }
258 
259     public ArtifactScopeEnum getScopeAsEnum() {
260         return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
261     }
262 
263     public boolean isArtifactExists() {
264         return artifactExists;
265     }
266 
267     public void setArtifactExists(boolean artifactExists) {
268         this.artifactExists = artifactExists;
269     }
270 
271     public Collection<ArtifactMetadata> getDependencies() {
272         return dependencies;
273     }
274 
275     public void setDependencies(Collection<ArtifactMetadata> dependencies) {
276         this.dependencies = dependencies;
277     }
278 
279     public String getArtifactUri() {
280         return artifactUri;
281     }
282 
283     public void setArtifactUri(String artifactUri) {
284         this.artifactUri = artifactUri;
285     }
286 
287     public String getWhy() {
288         return why;
289     }
290 
291     public void setWhy(String why) {
292         this.why = why;
293     }
294 
295     public String getError() {
296         return error;
297     }
298 
299     public void setError(String error) {
300         this.error = error;
301     }
302 
303     public boolean isError() {
304         return error == null;
305     }
306 
307     public String getDependencyConflictId() {
308         return groupId + ":" + artifactId;
309     }
310 }