Coverage Report - org.apache.maven.artifact.transform.ReleaseArtifactTransformation
 
Classes in this File Line Coverage Branch Coverage Complexity
ReleaseArtifactTransformation
58 %
14/24
33 %
2/6
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.metadata.ArtifactMetadata;
 24  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 25  
 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
 26  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
 27  
 import org.apache.maven.artifact.repository.metadata.Versioning;
 28  
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 29  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 30  
 
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * Change the version <code>RELEASE</code> to the appropriate release version from the remote repository.
 35  
  *
 36  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 37  
  * @version $Id: ReleaseArtifactTransformation.java 767322 2009-04-21 22:52:54Z jdcasey $
 38  
  */
 39  13
 public class ReleaseArtifactTransformation
 40  
     extends AbstractVersionTransformation
 41  
 {
 42  
     public void transformForResolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
 43  
         throws ArtifactResolutionException, ArtifactNotFoundException
 44  
     {
 45  16
         if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
 46  
         {
 47  
             try
 48  
             {
 49  0
                 String version = resolveVersion( artifact, localRepository, remoteRepositories );
 50  
 
 51  0
                 if ( Artifact.RELEASE_VERSION.equals( version ) )
 52  
                 {
 53  0
                     throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
 54  
                 }
 55  
 
 56  0
                 artifact.setBaseVersion( version );
 57  0
                 artifact.updateVersion( version, localRepository );
 58  
             }
 59  0
             catch ( RepositoryMetadataResolutionException e )
 60  
             {
 61  0
                 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
 62  0
             }
 63  
         }
 64  16
     }
 65  
 
 66  
     public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
 67  
     {
 68  1
         ArtifactMetadata metadata = createMetadata( artifact );
 69  
 
 70  1
         artifact.addMetadata( metadata );
 71  1
     }
 72  
 
 73  
     public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
 74  
                                         ArtifactRepository localRepository )
 75  
     {
 76  1
         ArtifactMetadata metadata = createMetadata( artifact );
 77  
 
 78  1
         artifact.addMetadata( metadata );
 79  1
     }
 80  
 
 81  
     private ArtifactMetadata createMetadata( Artifact artifact )
 82  
     {
 83  2
         Versioning versioning = new Versioning();
 84  2
         versioning.updateTimestamp();
 85  2
         versioning.addVersion( artifact.getVersion() );
 86  
 
 87  2
         if ( artifact.isRelease() )
 88  
         {
 89  0
             versioning.setRelease( artifact.getVersion() );
 90  
         }
 91  
 
 92  2
         return new ArtifactRepositoryMetadata( artifact, versioning );
 93  
     }
 94  
 
 95  
     protected String constructVersion( Versioning versioning, String baseVersion )
 96  
     {
 97  0
         return versioning.getRelease();
 98  
     }
 99  
 }