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.project.artifact;
20  
21  import java.io.File;
22  import java.util.Collection;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.handler.ArtifactHandler;
27  import org.apache.maven.artifact.metadata.ArtifactMetadata;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
30  import org.apache.maven.artifact.versioning.ArtifactVersion;
31  import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
32  import org.apache.maven.artifact.versioning.VersionRange;
33  import org.apache.maven.project.MavenProject;
34  
35  /**
36   * Wraps an active project instance to be able to receive updates from its artifact without affecting the original
37   * attributes of this artifact.
38   *
39   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
40   * TODO I think this exposes a design flaw in that the immutable and mutable parts of an artifact are in one class and
41   * should be split. ie scope, file, etc depend on the context of use, whereas everything else is immutable.
42   */
43  @Deprecated
44  public class ActiveProjectArtifact implements Artifact {
45      private final Artifact artifact;
46  
47      private final MavenProject project;
48  
49      public ActiveProjectArtifact(MavenProject project, Artifact artifact) {
50          this.artifact = artifact;
51          this.project = project;
52  
53          artifact.setFile(project.getArtifact().getFile());
54          artifact.setResolved(true);
55      }
56  
57      /** {@inheritDoc} */
58      public File getFile() {
59          // we need to get the latest file for the project, not the artifact that was created at one point in time
60          return project.getArtifact().getFile();
61      }
62  
63      /** {@inheritDoc} */
64      public String getGroupId() {
65          return artifact.getGroupId();
66      }
67  
68      /** {@inheritDoc} */
69      public String getArtifactId() {
70          return artifact.getArtifactId();
71      }
72  
73      /** {@inheritDoc} */
74      public String getVersion() {
75          return artifact.getVersion();
76      }
77  
78      /** {@inheritDoc} */
79      public void setVersion(String version) {
80          artifact.setVersion(version);
81      }
82  
83      /** {@inheritDoc} */
84      public String getScope() {
85          return artifact.getScope();
86      }
87  
88      /** {@inheritDoc} */
89      public String getType() {
90          return artifact.getType();
91      }
92  
93      /** {@inheritDoc} */
94      public String getClassifier() {
95          return artifact.getClassifier();
96      }
97  
98      /** {@inheritDoc} */
99      public boolean hasClassifier() {
100         return artifact.hasClassifier();
101     }
102 
103     /** {@inheritDoc} */
104     public void setFile(File destination) {
105         artifact.setFile(destination);
106         project.getArtifact().setFile(destination);
107     }
108 
109     /** {@inheritDoc} */
110     public String getBaseVersion() {
111         return artifact.getBaseVersion();
112     }
113 
114     /** {@inheritDoc} */
115     public void setBaseVersion(String baseVersion) {
116         artifact.setBaseVersion(baseVersion);
117     }
118 
119     /** {@inheritDoc} */
120     public String getId() {
121         return artifact.getId();
122     }
123 
124     /** {@inheritDoc} */
125     public String getDependencyConflictId() {
126         return artifact.getDependencyConflictId();
127     }
128 
129     /** {@inheritDoc} */
130     public void addMetadata(ArtifactMetadata metadata) {
131         artifact.addMetadata(metadata);
132     }
133 
134     /** {@inheritDoc} */
135     public Collection<ArtifactMetadata> getMetadataList() {
136         return artifact.getMetadataList();
137     }
138 
139     /** {@inheritDoc} */
140     public void setRepository(ArtifactRepository remoteRepository) {
141         artifact.setRepository(remoteRepository);
142     }
143 
144     /** {@inheritDoc} */
145     public ArtifactRepository getRepository() {
146         return artifact.getRepository();
147     }
148 
149     /** {@inheritDoc} */
150     public void updateVersion(String version, ArtifactRepository localRepository) {
151         artifact.updateVersion(version, localRepository);
152     }
153 
154     /** {@inheritDoc} */
155     public String getDownloadUrl() {
156         return artifact.getDownloadUrl();
157     }
158 
159     /** {@inheritDoc} */
160     public void setDownloadUrl(String downloadUrl) {
161         artifact.setDownloadUrl(downloadUrl);
162     }
163 
164     /** {@inheritDoc} */
165     public ArtifactFilter getDependencyFilter() {
166         return artifact.getDependencyFilter();
167     }
168 
169     /** {@inheritDoc} */
170     public void setDependencyFilter(ArtifactFilter artifactFilter) {
171         artifact.setDependencyFilter(artifactFilter);
172     }
173 
174     /** {@inheritDoc} */
175     public ArtifactHandler getArtifactHandler() {
176         return artifact.getArtifactHandler();
177     }
178 
179     /** {@inheritDoc} */
180     public List<String> getDependencyTrail() {
181         return artifact.getDependencyTrail();
182     }
183 
184     /** {@inheritDoc} */
185     public void setDependencyTrail(List<String> dependencyTrail) {
186         artifact.setDependencyTrail(dependencyTrail);
187     }
188 
189     /** {@inheritDoc} */
190     public void setScope(String scope) {
191         artifact.setScope(scope);
192     }
193 
194     /** {@inheritDoc} */
195     public VersionRange getVersionRange() {
196         return artifact.getVersionRange();
197     }
198 
199     /** {@inheritDoc} */
200     public void setVersionRange(VersionRange newRange) {
201         artifact.setVersionRange(newRange);
202     }
203 
204     /** {@inheritDoc} */
205     public void selectVersion(String version) {
206         artifact.selectVersion(version);
207     }
208 
209     /** {@inheritDoc} */
210     public void setGroupId(String groupId) {
211         artifact.setGroupId(groupId);
212     }
213 
214     /** {@inheritDoc} */
215     public void setArtifactId(String artifactId) {
216         artifact.setArtifactId(artifactId);
217     }
218 
219     /** {@inheritDoc} */
220     public boolean isSnapshot() {
221         return artifact.isSnapshot();
222     }
223 
224     /** {@inheritDoc} */
225     public int compareTo(Artifact a) {
226         return artifact.compareTo(a);
227     }
228 
229     /** {@inheritDoc} */
230     public void setResolved(boolean resolved) {
231         artifact.setResolved(resolved);
232     }
233 
234     /** {@inheritDoc} */
235     public boolean isResolved() {
236         return artifact.isResolved();
237     }
238 
239     /** {@inheritDoc} */
240     public void setResolvedVersion(String version) {
241         artifact.setResolvedVersion(version);
242     }
243 
244     /** {@inheritDoc} */
245     public void setArtifactHandler(ArtifactHandler handler) {
246         artifact.setArtifactHandler(handler);
247     }
248 
249     /** {@inheritDoc} */
250     public String toString() {
251         return "active project artifact[artifact: " + artifact + ", project: " + project + "]";
252     }
253 
254     /** {@inheritDoc} */
255     public boolean isRelease() {
256         return artifact.isRelease();
257     }
258 
259     /** {@inheritDoc} */
260     public void setRelease(boolean release) {
261         artifact.setRelease(release);
262     }
263 
264     /** {@inheritDoc} */
265     public List<ArtifactVersion> getAvailableVersions() {
266         return artifact.getAvailableVersions();
267     }
268 
269     /** {@inheritDoc} */
270     public void setAvailableVersions(List<ArtifactVersion> versions) {
271         artifact.setAvailableVersions(versions);
272     }
273 
274     /** {@inheritDoc} */
275     public boolean isOptional() {
276         return artifact.isOptional();
277     }
278 
279     /** {@inheritDoc} */
280     public ArtifactVersion getSelectedVersion() throws OverConstrainedVersionException {
281         return artifact.getSelectedVersion();
282     }
283 
284     /** {@inheritDoc} */
285     public boolean isSelectedVersionKnown() throws OverConstrainedVersionException {
286         return artifact.isSelectedVersionKnown();
287     }
288 
289     /** {@inheritDoc} */
290     public void setOptional(boolean optional) {
291         artifact.setOptional(optional);
292     }
293 
294     /** {@inheritDoc} */
295     public int hashCode() {
296         int result = 17;
297 
298         result = 37 * result + getGroupId().hashCode();
299         result = 37 * result + getArtifactId().hashCode();
300         result = 37 * result + getType().hashCode();
301         if (getVersion() != null) {
302             result = 37 * result + getVersion().hashCode();
303         }
304         result = 37 * result + (getClassifier() != null ? getClassifier().hashCode() : 0);
305 
306         return result;
307     }
308 
309     /** {@inheritDoc} */
310     public boolean equals(Object o) {
311         if (o == this) {
312             return true;
313         }
314 
315         if (!(o instanceof Artifact)) {
316             return false;
317         }
318 
319         Artifact a = (Artifact) o;
320 
321         if (!a.getGroupId().equals(getGroupId())) {
322             return false;
323         } else if (!a.getArtifactId().equals(getArtifactId())) {
324             return false;
325         } else if (!a.getVersion().equals(getVersion())) {
326             return false;
327         } else if (!a.getType().equals(getType())) {
328             return false;
329         } else {
330             return a.getClassifier() == null
331                     ? getClassifier() == null
332                     : a.getClassifier().equals(getClassifier());
333         }
334     }
335 }