Coverage Report - org.apache.maven.artifact.transform.AbstractVersionTransformation
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractVersionTransformation
5 %
1/22
0 %
0/16
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.manager.WagonManager;
 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.Metadata;
 27  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
 28  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
 29  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
 30  
 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
 31  
 import org.apache.maven.artifact.repository.metadata.Versioning;
 32  
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 33  
 
 34  
 import java.util.List;
 35  
 
 36  
 /**
 37  
  * Describes a version transformation during artifact resolution.
 38  
  *
 39  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 40  
  * @version $Id: AbstractVersionTransformation.java 767322 2009-04-21 22:52:54Z jdcasey $
 41  
  * @todo try and refactor to remove abstract methods - not particular happy about current design
 42  
  */
 43  39
 public abstract class AbstractVersionTransformation
 44  
     extends AbstractLogEnabled
 45  
     implements ArtifactTransformation
 46  
 {
 47  
     protected RepositoryMetadataManager repositoryMetadataManager;
 48  
 
 49  
     protected WagonManager wagonManager;
 50  
 
 51  
     protected String resolveVersion( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
 52  
         throws RepositoryMetadataResolutionException
 53  
     {
 54  
         RepositoryMetadata metadata;
 55  
         // Don't use snapshot metadata for LATEST (which isSnapshot returns true for)
 56  0
         if ( !artifact.isSnapshot() || Artifact.LATEST_VERSION.equals( artifact.getBaseVersion() ) )
 57  
         {
 58  0
             metadata = new ArtifactRepositoryMetadata( artifact );
 59  
         }
 60  
         else
 61  
         {
 62  0
             metadata = new SnapshotArtifactRepositoryMetadata( artifact );
 63  
         }
 64  
 
 65  0
         repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
 66  
 
 67  0
         artifact.addMetadata( metadata );
 68  
 
 69  0
         Metadata repoMetadata = metadata.getMetadata();
 70  0
         String version = null;
 71  0
         if ( repoMetadata != null && repoMetadata.getVersioning() != null )
 72  
         {
 73  0
             version = constructVersion( repoMetadata.getVersioning(), artifact.getBaseVersion() );
 74  
         }
 75  
 
 76  0
         if ( version == null )
 77  
         {
 78  
             // use the local copy, or if it doesn't exist - go to the remote repo for it
 79  0
             version = artifact.getBaseVersion();
 80  
         }
 81  
 
 82  
         // TODO: also do this logging for other metadata?
 83  
         // TODO: figure out way to avoid duplicated message
 84  0
         if ( getLogger().isDebugEnabled() )
 85  
         {
 86  0
             if ( !version.equals( artifact.getBaseVersion() ) )
 87  
             {
 88  0
                 String message = artifact.getArtifactId() + ": resolved to version " + version;
 89  0
                 if ( artifact.getRepository() != null )
 90  
                 {
 91  0
                     message += " from repository " + artifact.getRepository().getId();
 92  
                 }
 93  
                 else
 94  
                 {
 95  0
                     message += " from local repository";
 96  
                 }
 97  0
                 getLogger().debug( message );
 98  0
             }
 99  
             else
 100  
             {
 101  
                 // Locally installed file is newer, don't use the resolved version
 102  0
                 getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" );
 103  
             }
 104  
         }
 105  0
         return version;
 106  
     }
 107  
 
 108  
     protected abstract String constructVersion( Versioning versioning, String baseVersion );
 109  
 }