View Javadoc

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