001package org.apache.maven.project.artifact;
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
022import org.apache.maven.artifact.Artifact;
023import org.apache.maven.artifact.handler.ArtifactHandler;
024import org.apache.maven.artifact.metadata.ArtifactMetadata;
025import org.apache.maven.artifact.repository.ArtifactRepository;
026import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
027import org.apache.maven.artifact.versioning.ArtifactVersion;
028import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
029import org.apache.maven.artifact.versioning.VersionRange;
030import org.apache.maven.project.MavenProject;
031
032import java.io.File;
033import java.util.Collection;
034import java.util.List;
035
036/**
037 * Wraps an active project instance to be able to receive updates from its artifact without affecting the original
038 * attributes of this artifact.
039 *
040 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
041 * @todo I think this exposes a design flaw in that the immutable and mutable parts of an artifact are in one class and
042 * should be split. ie scope, file, etc depend on the context of use, whereas everything else is immutable.
043 */
044@Deprecated
045public class ActiveProjectArtifact
046    implements Artifact
047{
048    private final Artifact artifact;
049
050    private final MavenProject project;
051
052    public ActiveProjectArtifact( MavenProject project, Artifact artifact )
053    {
054        this.artifact = artifact;
055        this.project = project;
056
057        artifact.setFile( project.getArtifact().getFile() );
058        artifact.setResolved( true );
059    }
060
061    /** {@inheritDoc} */
062    public File getFile()
063    {
064        // we need to get the latest file for the project, not the artifact that was created at one point in time
065        return project.getArtifact().getFile();
066    }
067
068    /** {@inheritDoc} */
069    public String getGroupId()
070    {
071        return artifact.getGroupId();
072    }
073
074    /** {@inheritDoc} */
075    public String getArtifactId()
076    {
077        return artifact.getArtifactId();
078    }
079
080    /** {@inheritDoc} */
081    public String getVersion()
082    {
083        return artifact.getVersion();
084    }
085
086    /** {@inheritDoc} */
087    public void setVersion( String version )
088    {
089        artifact.setVersion( version );
090    }
091
092    /** {@inheritDoc} */
093    public String getScope()
094    {
095        return artifact.getScope();
096    }
097
098    /** {@inheritDoc} */
099    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}