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