Coverage Report - org.apache.maven.artifact.installer.DefaultArtifactInstaller
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultArtifactInstaller
59%
13/22
75%
3/4
4
 
 1  
 package org.apache.maven.artifact.installer;
 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.ArtifactMetadata;
 24  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 25  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataInstallationException;
 26  
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
 27  
 import org.apache.maven.artifact.transform.ArtifactTransformationManager;
 28  
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 29  
 import org.codehaus.plexus.util.FileUtils;
 30  
 
 31  
 import java.io.File;
 32  
 import java.io.IOException;
 33  
 import java.util.Iterator;
 34  
 
 35  1
 public class DefaultArtifactInstaller
 36  
     extends AbstractLogEnabled
 37  
     implements ArtifactInstaller
 38  
 {
 39  
     private ArtifactTransformationManager transformationManager;
 40  
 
 41  
     private RepositoryMetadataManager repositoryMetadataManager;
 42  
 
 43  
     /**
 44  
      * @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
 45  
      */
 46  
     public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
 47  
         throws ArtifactInstallationException
 48  
     {
 49  0
         String extension = artifact.getArtifactHandler().getExtension();
 50  0
         File source = new File( basedir, finalName + "." + extension );
 51  
 
 52  0
         install( source, artifact, localRepository );
 53  0
     }
 54  
 
 55  
     public void install( File source, Artifact artifact, ArtifactRepository localRepository )
 56  
         throws ArtifactInstallationException
 57  
     {
 58  
         try
 59  
         {
 60  1
             transformationManager.transformForInstall( artifact, localRepository );
 61  
 
 62  1
             String localPath = localRepository.pathOf( artifact );
 63  
 
 64  
             // TODO: use a file: wagon and the wagon manager?
 65  1
             File destination = new File( localRepository.getBasedir(), localPath );
 66  1
             if ( !destination.getParentFile().exists() )
 67  
             {
 68  0
                 destination.getParentFile().mkdirs();
 69  
             }
 70  
 
 71  1
             getLogger().info( "Installing " + source.getPath() + " to " + destination );
 72  
 
 73  1
             FileUtils.copyFile( source, destination );
 74  
 
 75  
             // must be after the artifact is installed
 76  1
             for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
 77  
             {
 78  1
                 ArtifactMetadata metadata = (ArtifactMetadata) i.next();
 79  1
                 repositoryMetadataManager.install( metadata, localRepository );
 80  1
             }
 81  
             // TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy transformation
 82  
             // This would avoid the need to merge and clear out the state during deployment
 83  
 //            artifact.getMetadataList().clear();
 84  
         }
 85  0
         catch ( IOException e )
 86  
         {
 87  0
             throw new ArtifactInstallationException( "Error installing artifact: " + e.getMessage(), e );
 88  
         }
 89  0
         catch ( RepositoryMetadataInstallationException e )
 90  
         {
 91  0
             throw new ArtifactInstallationException( "Error installing artifact's metadata: " + e.getMessage(), e );
 92  1
         }
 93  1
     }
 94  
 }