1 package org.apache.maven.shared.downloader; 2 3 import org.apache.maven.artifact.Artifact; 4 import org.apache.maven.artifact.factory.ArtifactFactory; 5 import org.apache.maven.artifact.repository.ArtifactRepository; 6 import org.apache.maven.artifact.resolver.ArtifactNotFoundException; 7 import org.apache.maven.artifact.resolver.ArtifactResolutionException; 8 import org.apache.maven.artifact.resolver.ArtifactResolver; 9 10 import java.io.File; 11 import java.util.List; 12 13 /** 14 * @author Jason van Zyl 15 * @plexus.component 16 */ 17 public class DefaultDownloader 18 implements Downloader 19 { 20 /** 21 * @plexus.requirement 22 */ 23 private ArtifactResolver artifactResolver; 24 25 /** 26 * @plexus.requirement 27 */ 28 private ArtifactFactory artifactFactory; 29 30 public File download( String groupId, 31 String artifactId, 32 String version, 33 File localRepository, 34 String[] remoteRepositories ) 35 throws DownloadException, DownloadNotFoundException 36 37 { 38 return download( groupId, artifactId, version, localRepository, remoteRepositories ); 39 } 40 41 public File download( String groupId, 42 String artifactId, 43 String version, 44 ArtifactRepository localRepository, 45 List remoteRepositories ) 46 throws DownloadException, DownloadNotFoundException 47 48 { 49 Artifact artifact = 50 artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, "jar" ); 51 52 try 53 { 54 artifactResolver.resolve( artifact, remoteRepositories, localRepository ); 55 } 56 catch ( ArtifactResolutionException e ) 57 { 58 throw new DownloadException( "Error downloading.", e ); 59 } 60 catch ( ArtifactNotFoundException e ) 61 { 62 throw new DownloadNotFoundException( "Requested download does not exist.", e ); 63 } 64 65 return artifact.getFile(); 66 } 67 }