Coverage Report - org.apache.maven.plugin.gpg.AscArtifactMetadata
 
Classes in this File Line Coverage Branch Coverage Complexity
AscArtifactMetadata
0%
0/29
0%
0/10
1,6
 
 1  
 package org.apache.maven.plugin.gpg;
 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  
 public class AscArtifactMetadata
 33  
     extends AbstractArtifactMetadata
 34  
 {
 35  
 
 36  
     File file;
 37  
 
 38  
     boolean isPom;
 39  
 
 40  
     public AscArtifactMetadata( Artifact artifact, File file, boolean isPom )
 41  
     {
 42  0
         super( artifact );
 43  0
         this.file = file;
 44  0
         this.isPom = isPom;
 45  0
     }
 46  
 
 47  
     public String getBaseVersion()
 48  
     {
 49  0
         return artifact.getBaseVersion();
 50  
     }
 51  
 
 52  
     public Object getKey()
 53  
     {
 54  0
         return "gpg signature " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType()
 55  
             + ":" + artifact.getClassifier() + ( isPom ? ":pom" : "" );
 56  
     }
 57  
 
 58  
     private String getFilename()
 59  
     {
 60  0
         StringBuffer buf = new StringBuffer( getArtifactId() );
 61  0
         buf.append( "-" ).append( artifact.getVersion() );
 62  0
         if ( isPom )
 63  
         {
 64  0
             buf.append( ".pom" );
 65  
         }
 66  
         else
 67  
         {
 68  0
             if ( artifact.getClassifier() != null && !"".equals( artifact.getClassifier() ) )
 69  
             {
 70  0
                 buf.append( "-" ).append( artifact.getClassifier() );
 71  
             }
 72  0
             buf.append( "." ).append( artifact.getType() );
 73  
         }
 74  0
         buf.append( ".asc" );
 75  0
         return buf.toString();
 76  
     }
 77  
 
 78  
     public String getLocalFilename( ArtifactRepository repository )
 79  
     {
 80  0
         return getFilename();
 81  
     }
 82  
 
 83  
     public String getRemoteFilename()
 84  
     {
 85  0
         return getFilename();
 86  
     }
 87  
 
 88  
     public void merge( ArtifactMetadata metadata )
 89  
     {
 90  0
         AscArtifactMetadata m = (AscArtifactMetadata) metadata;
 91  0
         if ( !m.file.equals( file ) )
 92  
         {
 93  0
             throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
 94  
         }
 95  0
     }
 96  
 
 97  
     public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
 98  
         throws RepositoryMetadataStoreException
 99  
     {
 100  0
         File destination =
 101  
             new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( this,
 102  
                                                                                                    remoteRepository ) );
 103  
 
 104  
         try
 105  
         {
 106  0
             FileUtils.copyFile( file, destination );
 107  
         }
 108  0
         catch ( IOException e )
 109  
         {
 110  0
             throw new RepositoryMetadataStoreException( "Error copying ASC to the local repository.", e );
 111  0
         }
 112  0
     }
 113  
 
 114  
     public boolean storedInArtifactVersionDirectory()
 115  
     {
 116  0
         return true;
 117  
     }
 118  
 
 119  
     public String toString()
 120  
     {
 121  0
         return getFilename();
 122  
     }
 123  
 
 124  
 }