Coverage Report - org.apache.maven.artifact.ant.InstallWagonProviderTask
 
Classes in this File Line Coverage Branch Coverage Complexity
InstallWagonProviderTask
0%
0/36
0%
0/2
2.286
 
 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.ArtifactUtils;
 24  
 import org.apache.maven.artifact.factory.ArtifactFactory;
 25  
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 26  
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 27  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 28  
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 29  
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 30  
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 31  
 import org.apache.maven.artifact.versioning.VersionRange;
 32  
 import org.apache.maven.project.artifact.MavenMetadataSource;
 33  
 import org.apache.tools.ant.BuildException;
 34  
 import org.apache.tools.ant.Project;
 35  
 import org.codehaus.plexus.PlexusContainerException;
 36  
 
 37  
 import java.util.Collections;
 38  
 import java.util.Iterator;
 39  
 import java.util.List;
 40  
 
 41  
 /**
 42  
  * Ant Wrapper for wagon provider installation.
 43  
  *
 44  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 45  
  * @version $Id: InstallWagonProviderTask.java 649861 2008-04-19 23:03:55Z hboutemy $
 46  
  */
 47  0
 public class InstallWagonProviderTask
 48  
     extends AbstractArtifactWithRepositoryTask
 49  
 {
 50  0
     private String groupId = "org.apache.maven.wagon";
 51  
 
 52  
     private String artifactId;
 53  
 
 54  
     private String version;
 55  
 
 56  
     public String getGroupId()
 57  
     {
 58  0
         return groupId;
 59  
     }
 60  
     
 61  
     public void setGroupId( String groupId )
 62  
     {
 63  0
         this.groupId = groupId;
 64  0
     }
 65  
 
 66  
     public String getArtifactId()
 67  
     {
 68  0
         return artifactId;
 69  
     }
 70  
 
 71  
     public void setArtifactId( String artifactId )
 72  
     {
 73  0
         this.artifactId = artifactId;
 74  0
     }
 75  
 
 76  
     public String getVersion()
 77  
     {
 78  0
         return version;
 79  
     }
 80  
 
 81  
     public void setVersion( String version )
 82  
     {
 83  0
         this.version = version;
 84  0
     }
 85  
 
 86  
     public void doExecute()
 87  
     {
 88  
         VersionRange versionRange;
 89  
         try
 90  
         {
 91  0
             versionRange = VersionRange.createFromVersionSpec( version );
 92  
         }
 93  0
         catch ( InvalidVersionSpecificationException e )
 94  
         {
 95  0
             throw new BuildException( "Unable to get extension '"
 96  
                                       + ArtifactUtils.versionlessKey( groupId, artifactId ) + "' because version '"
 97  
                                       + version + " is invalid: " + e.getMessage(), e );
 98  0
         }
 99  
 
 100  0
         ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
 101  0
         Artifact providerArtifact = factory.createExtensionArtifact( groupId, artifactId, versionRange );
 102  
 
 103  0
         log( "Installing provider: " + providerArtifact );
 104  
 
 105  
         ArtifactResolutionResult result;
 106  
         try
 107  
         {
 108  0
             MavenMetadataSource metadataSource = (MavenMetadataSource) lookup( ArtifactMetadataSource.ROLE );
 109  0
             ArtifactResolver resolver = (ArtifactResolver) lookup( ArtifactResolver.ROLE );
 110  0
             List remoteRepositories = createRemoteArtifactRepositories();
 111  
 
 112  0
             result = resolver.resolveTransitively( Collections.singleton( providerArtifact ),
 113  
                                                    createDummyArtifact(), createLocalArtifactRepository(),
 114  
                                                    remoteRepositories, metadataSource, null );
 115  
         }
 116  0
         catch ( ArtifactResolutionException e )
 117  
         {
 118  0
             throw new BuildException( "Error downloading wagon provider from the remote repository: " + e.getMessage(),
 119  
                                       e );
 120  
         }
 121  0
         catch ( ArtifactNotFoundException e )
 122  
         {
 123  0
             throw new BuildException( "Unable to locate wagon provider in remote repository: " + e.getMessage(), e );
 124  0
         }
 125  
 
 126  
         try
 127  
         {
 128  0
             for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
 129  
             {
 130  0
                 Artifact a = (Artifact) i.next();
 131  
 
 132  0
                 getContainer().addJarResource( a.getFile() );
 133  0
             }
 134  
         }
 135  0
         catch ( PlexusContainerException e )
 136  
         {
 137  0
             throw new BuildException( "Unable to locate wagon provider in remote repository", e );
 138  0
         }
 139  
         
 140  0
         log( "Protocols now supported: " + getSupportedProtocolsAsString(), Project.MSG_VERBOSE );
 141  0
     }
 142  
 
 143  
 }