Coverage Report - org.apache.maven.artifact.ant.InstallTask
 
Classes in this File Line Coverage Branch Coverage Complexity
InstallTask
0%
0/24
0%
0/16
0
 
 1  
 package org.apache.maven.artifact.ant;
 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.installer.ArtifactInstallationException;
 24  
 import org.apache.maven.artifact.installer.ArtifactInstaller;
 25  
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 26  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 27  
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 28  
 import org.apache.tools.ant.BuildException;
 29  
 
 30  
 /**
 31  
  * Install task, using maven-artifact.
 32  
  *
 33  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 34  
  * @version $Id: org.apache.maven.artifact.ant.InstallTask.html 806929 2012-03-01 18:57:40Z hboutemy $
 35  
  * @todo should be able to incorporate into the install mojo?
 36  
  */
 37  0
 public class InstallTask
 38  
     extends InstallDeployTaskSupport
 39  
 {
 40  
     protected void doExecute()
 41  
     {
 42  0
         if ( file == null && ( attachedArtifacts.size() == 0 ) )
 43  
         {
 44  0
             throw new BuildException( "You must specify a file and/or an attached artifact "
 45  
                 + "to install to the local repository." );
 46  
         }
 47  
 
 48  0
         ArtifactRepository localRepo = createLocalArtifactRepository();
 49  
 
 50  0
         Pom pom = initializePom( localRepo );
 51  
 
 52  0
         if ( pom == null )
 53  
         {
 54  0
             throw new BuildException( "A POM element is required to install to the local repository" );
 55  
         }
 56  
 
 57  0
         Artifact artifact = pom.getArtifact();
 58  
 
 59  0
         boolean isPomArtifact = "pom".equals( pom.getPackaging() );
 60  0
         if ( !isPomArtifact )
 61  
         {
 62  0
             ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom.getFile() );
 63  0
             artifact.addMetadata( metadata );
 64  
         }
 65  
 
 66  0
         ArtifactInstaller installer = (ArtifactInstaller) lookup( ArtifactInstaller.ROLE );
 67  
         try
 68  
         {
 69  0
             if ( file != null )
 70  
             {
 71  0
                 if ( !isPomArtifact )
 72  
                 {
 73  0
                     installer.install( file, artifact, localRepo );
 74  
                 }
 75  
                 else
 76  
                 {
 77  0
                     installer.install( pom.getFile(), artifact, localRepo );
 78  
                 }
 79  
             }
 80  
 
 81  
             // Install any attached artifacts
 82  0
             if ( attachedArtifacts != null )
 83  
             {
 84  0
                 for ( Artifact attachedArtifact : pom.getAttachedArtifacts() )
 85  
                 {
 86  0
                     installer.install( attachedArtifact.getFile(), attachedArtifact, localRepo );
 87  
                 }
 88  
             }
 89  
         }
 90  0
         catch ( ArtifactInstallationException e )
 91  
         {
 92  0
             throw new BuildException(
 93  
                 "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e );
 94  0
         }
 95  0
     }
 96  
 }