Coverage Report - org.apache.maven.project.artifact.ProjectArtifactMetadata
 
Classes in this File Line Coverage Branch Coverage Complexity
ProjectArtifactMetadata
0%
0/22
0%
0/2
1.364
 
 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 534671 2007-05-03 01:04:15Z brianf $
 37  
  */
 38  
 public class ProjectArtifactMetadata
 39  
     extends AbstractArtifactMetadata
 40  
 {
 41  
     private final File file;
 42  
 
 43  
     public ProjectArtifactMetadata( Artifact artifact )
 44  
     {
 45  0
         this( artifact, null );
 46  0
     }
 47  
 
 48  
     public ProjectArtifactMetadata( Artifact artifact,
 49  
                                     File file )
 50  
     {
 51  0
         super( artifact );
 52  0
         this.file = file;
 53  0
     }
 54  
 
 55  
     public String getRemoteFilename()
 56  
     {
 57  0
         return getFilename();
 58  
     }
 59  
 
 60  
     public String getLocalFilename( ArtifactRepository repository )
 61  
     {
 62  0
         return getFilename();
 63  
     }
 64  
 
 65  
     private String getFilename()
 66  
     {
 67  0
         return getArtifactId() + "-" + artifact.getVersion() + ".pom";
 68  
     }
 69  
 
 70  
     public void storeInLocalRepository( ArtifactRepository localRepository,
 71  
                                         ArtifactRepository remoteRepository )
 72  
         throws RepositoryMetadataStoreException
 73  
     {
 74  0
         File destination = new File( localRepository.getBasedir(),
 75  
                                      localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
 76  
 
 77  
         // ----------------------------------------------------------------------------
 78  
         // I'm fully aware that the file could just be moved using File.rename but
 79  
         // there are bugs in various JVM that have problems doing this across
 80  
         // different filesystem. So we'll incur the small hit to actually copy
 81  
         // here and be safe. jvz.
 82  
         // ----------------------------------------------------------------------------
 83  
 
 84  
         try
 85  
         {
 86  0
             FileUtils.copyFile( file, destination );
 87  
         }
 88  0
         catch ( IOException e )
 89  
         {
 90  0
             throw new RepositoryMetadataStoreException( "Error copying POM to the local repository.", e );
 91  0
         }
 92  0
     }
 93  
 
 94  
     public String toString()
 95  
     {
 96  0
         return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
 97  
     }
 98  
 
 99  
     public boolean storedInArtifactVersionDirectory()
 100  
     {
 101  0
         return true;
 102  
     }
 103  
 
 104  
     public String getBaseVersion()
 105  
     {
 106  0
         return artifact.getBaseVersion();
 107  
     }
 108  
 
 109  
     public Object getKey()
 110  
     {
 111  0
         return "project " + artifact.getGroupId() + ":" + artifact.getArtifactId();
 112  
     }
 113  
 
 114  
     public void merge( ArtifactMetadata metadata )
 115  
     {
 116  0
         ProjectArtifactMetadata m = (ProjectArtifactMetadata) metadata;
 117  0
         if ( !m.file.equals( file ) )
 118  
         {
 119  0
             throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
 120  
         }
 121  0
     }
 122  
 }