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