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