Coverage Report - org.apache.maven.project.artifact.ProjectArtifactMetadata
 
Classes in this File Line Coverage Branch Coverage Complexity
ProjectArtifactMetadata
0 %
0/32
0 %
0/8
1,4
 
 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 java.io.File;
 23  
 import java.io.IOException;
 24  
 
 25  
 import org.apache.maven.artifact.Artifact;
 26  
 import org.apache.maven.artifact.metadata.AbstractArtifactMetadata;
 27  
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 28  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 29  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
 30  
 import org.codehaus.plexus.util.FileUtils;
 31  
 
 32  
 /**
 33  
  * Attach a POM to an artifact.
 34  
  *
 35  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 36  
  * @version $Id: ProjectArtifactMetadata.java 745955 2009-02-19 18:39:09Z jdcasey $
 37  
  */
 38  
 public class ProjectArtifactMetadata
 39  
     extends AbstractArtifactMetadata
 40  
 {
 41  
     private File originalFile;
 42  
     
 43  
     private File transformedFile;
 44  
     
 45  0
     private boolean versionExpressionsResolved = false;
 46  
 
 47  
     public ProjectArtifactMetadata( Artifact artifact )
 48  
     {
 49  0
         this( artifact, null );
 50  0
     }
 51  
 
 52  
     public ProjectArtifactMetadata( Artifact artifact,
 53  
                                     File file )
 54  
     {
 55  0
         super( artifact );
 56  0
         this.originalFile = file;
 57  0
     }
 58  
 
 59  
     public String getRemoteFilename()
 60  
     {
 61  0
         return getFilename();
 62  
     }
 63  
 
 64  
     public String getLocalFilename( ArtifactRepository repository )
 65  
     {
 66  0
         return getFilename();
 67  
     }
 68  
 
 69  
     private String getFilename()
 70  
     {
 71  0
         return getArtifactId() + "-" + artifact.getVersion() + ".pom";
 72  
     }
 73  
 
 74  
     public void storeInLocalRepository( ArtifactRepository localRepository,
 75  
                                         ArtifactRepository remoteRepository )
 76  
         throws RepositoryMetadataStoreException
 77  
     {
 78  0
         File f = transformedFile == null ? originalFile : transformedFile;
 79  0
         if ( f == null )
 80  
         {
 81  0
             return;
 82  
         }
 83  
         
 84  0
         File destination = new File( localRepository.getBasedir(),
 85  
                                      localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
 86  
 
 87  
         // ----------------------------------------------------------------------------
 88  
         // I'm fully aware that the file could just be moved using File.rename but
 89  
         // there are bugs in various JVM that have problems doing this across
 90  
         // different filesystem. So we'll incur the small hit to actually copy
 91  
         // here and be safe. jvz.
 92  
         // ----------------------------------------------------------------------------
 93  
 
 94  
         try
 95  
         {
 96  0
             FileUtils.copyFile( f, destination );
 97  
         }
 98  0
         catch ( IOException e )
 99  
         {
 100  0
             throw new RepositoryMetadataStoreException( "Error copying POM to the local repository.", e );
 101  0
         }
 102  0
     }
 103  
 
 104  
     public String toString()
 105  
     {
 106  0
         return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
 107  
     }
 108  
 
 109  
     public boolean storedInArtifactVersionDirectory()
 110  
     {
 111  0
         return true;
 112  
     }
 113  
 
 114  
     public String getBaseVersion()
 115  
     {
 116  0
         return artifact.getBaseVersion();
 117  
     }
 118  
 
 119  
     public Object getKey()
 120  
     {
 121  0
         return "project " + artifact.getGroupId() + ":" + artifact.getArtifactId();
 122  
     }
 123  
 
 124  
     public void merge( ArtifactMetadata metadata )
 125  
     {
 126  0
         ProjectArtifactMetadata m = (ProjectArtifactMetadata) metadata;
 127  0
         if ( !m.originalFile.equals( originalFile ) )
 128  
         {
 129  0
             throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
 130  
         }
 131  0
     }
 132  
 
 133  
     public boolean isVersionExpressionsResolved()
 134  
     {
 135  0
         return versionExpressionsResolved;
 136  
     }
 137  
 
 138  
     public void setVersionExpressionsResolved( boolean versionExpressionsResolved )
 139  
     {
 140  0
         this.versionExpressionsResolved = versionExpressionsResolved;
 141  0
     }
 142  
     
 143  
     public void setFile( File file )
 144  
     {
 145  0
         this.transformedFile = file;
 146  0
     }
 147  
 
 148  
     public File getFile()
 149  
     {
 150  0
         return transformedFile == null ? originalFile : transformedFile;
 151  
     }
 152  
 }