Coverage Report - org.apache.maven.artifact.transform.LatestArtifactTransformation
 
Classes in this File Line Coverage Branch Coverage Complexity
LatestArtifactTransformation
36 %
5/14
25 %
1/4
0
 
 1  
 package org.apache.maven.artifact.transform;
 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.repository.ArtifactRepository;
 24  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
 25  
 import org.apache.maven.artifact.repository.metadata.Versioning;
 26  
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 27  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 28  
 
 29  
 import java.util.List;
 30  
 
 31  13
 public class LatestArtifactTransformation
 32  
     extends AbstractVersionTransformation
 33  
 {
 34  
     public void transformForResolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
 35  
         throws ArtifactResolutionException, ArtifactNotFoundException
 36  
     {
 37  16
         if ( Artifact.LATEST_VERSION.equals( artifact.getVersion() ) )
 38  
         {
 39  
             try
 40  
             {
 41  0
                 String version = resolveVersion( artifact, localRepository, remoteRepositories );
 42  0
                 if ( Artifact.LATEST_VERSION.equals( version ) )
 43  
                 {
 44  0
                     throw new ArtifactNotFoundException( "Unable to determine the latest version", artifact );
 45  
                 }
 46  
 
 47  0
                 artifact.setBaseVersion( version );
 48  0
                 artifact.updateVersion( version, localRepository );
 49  
             }
 50  0
             catch ( RepositoryMetadataResolutionException e )
 51  
             {
 52  0
                 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
 53  0
             }
 54  
         }
 55  16
     }
 56  
 
 57  
     public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
 58  
     {
 59  
         // metadata is added via addPluginArtifactMetadata
 60  1
     }
 61  
 
 62  
     public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
 63  
                                         ArtifactRepository localRepository )
 64  
     {
 65  
         // metadata is added via addPluginArtifactMetadata
 66  1
     }
 67  
 
 68  
     protected String constructVersion( Versioning versioning, String baseVersion )
 69  
     {
 70  0
         return versioning.getLatest();
 71  
     }
 72  
 }