Coverage Report - org.apache.maven.plugins.site.SiteDescriptorArtifactMetadata
 
Classes in this File Line Coverage Branch Coverage Complexity
SiteDescriptorArtifactMetadata
0%
0/25
0%
0/2
1,4
 
 1  
 package org.apache.maven.plugins.site;
 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.AbstractArtifactMetadata;
 24  
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 25  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 26  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException;
 27  
 import org.apache.maven.doxia.site.decoration.DecorationModel;
 28  
 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Writer;
 29  
 import org.codehaus.plexus.util.IOUtil;
 30  
 import org.codehaus.plexus.util.WriterFactory;
 31  
 
 32  
 import java.io.File;
 33  
 import java.io.IOException;
 34  
 import java.io.Writer;
 35  
 
 36  
 /**
 37  
  * Attach a POM to an artifact.
 38  
  *
 39  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 40  
  * @version $Id: org.apache.maven.plugins.site.SiteDescriptorArtifactMetadata.html 816550 2012-05-08 11:52:49Z hboutemy $
 41  
  */
 42  
 public class SiteDescriptorArtifactMetadata
 43  
     extends AbstractArtifactMetadata
 44  
 {
 45  
     private final DecorationModel decoration;
 46  
 
 47  
     private final File file;
 48  
 
 49  
     public SiteDescriptorArtifactMetadata( Artifact artifact, DecorationModel decoration, File file )
 50  
     {
 51  0
         super( artifact );
 52  
 
 53  0
         this.file = file;
 54  0
         this.decoration = decoration;
 55  0
     }
 56  
 
 57  
     public String getRemoteFilename()
 58  
     {
 59  0
         return getFilename();
 60  
     }
 61  
 
 62  
     public String getLocalFilename( ArtifactRepository repository )
 63  
     {
 64  0
         return getFilename();
 65  
     }
 66  
 
 67  
     private String getFilename()
 68  
     {
 69  0
         return getArtifactId() + "-" + artifact.getVersion() + "-" + file.getName();
 70  
     }
 71  
 
 72  
     public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
 73  
         throws RepositoryMetadataStoreException
 74  
     {
 75  0
         File destination = new File( localRepository.getBasedir(),
 76  
                                      localRepository.pathOfLocalRepositoryMetadata( this, remoteRepository ) );
 77  
 
 78  0
         destination.getParentFile().mkdirs();
 79  
 
 80  0
         Writer writer = null;
 81  
         try
 82  
         {
 83  0
             writer = WriterFactory.newXmlWriter( destination );
 84  0
             new DecorationXpp3Writer().write( writer, decoration );
 85  
         }
 86  0
         catch ( IOException e )
 87  
         {
 88  0
             throw new RepositoryMetadataStoreException( "Error saving in local repository", e );
 89  
         }
 90  
         finally
 91  
         {
 92  0
             IOUtil.close( writer );
 93  0
         }
 94  0
     }
 95  
 
 96  
     public String toString()
 97  
     {
 98  0
         return "site descriptor for " + artifact.getArtifactId() + " " + artifact.getVersion() + " " + file.getName();
 99  
     }
 100  
 
 101  
     public boolean storedInArtifactVersionDirectory()
 102  
     {
 103  0
         return true;
 104  
     }
 105  
 
 106  
     public String getBaseVersion()
 107  
     {
 108  0
         return artifact.getBaseVersion();
 109  
     }
 110  
 
 111  
     public Object getKey()
 112  
     {
 113  0
         return "site descriptor " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " " + file.getName();
 114  
     }
 115  
 
 116  
     public void merge( ArtifactMetadata metadata )
 117  
     {
 118  0
         SiteDescriptorArtifactMetadata m = (SiteDescriptorArtifactMetadata) metadata;
 119  0
         if ( !m.file.equals( file ) )
 120  
         {
 121  0
             throw new IllegalStateException( "Cannot add two different pieces of metadata for: " + getKey() );
 122  
         }
 123  0
     }
 124  
 }