Download the artifact from the download repository.
@param artifactReference
@param config
@return the downloaded file
@throws IOException
541893
private File downloadArtifact(
            ElasticsearchArtifact artifactReference,
            ClusterConfiguration config)
            throws IOException
    {
        String filename = Joiner.on("-").skipNulls()
                .join(
                        artifactReference.getArtifactId(),
                        artifactReference.getVersion(),
                        artifactReference.getClassifier() // May be null
                )
                + "." + artifactReference.getType();

        File tempFile = new File(FilesystemUtil.getTempDirectory(), filename);
        tempFile.deleteOnExit();
        FileUtils.deleteQuietly(tempFile);

        URL downloadUrl = new URL(
                StringUtils.isBlank(config.getDownloadUrl())
                        ? String.format(ELASTICSEARCH_DOWNLOAD_URL, filename)
                        : config.getDownloadUrl());

        config.getLog().debug("Downloading " + downloadUrl + " to " + tempFile);
        FileUtils.copyURLToFile(downloadUrl, tempFile);
        
        return tempFile;
    }
49466
public void deployArtifact(DeployArtifact deployArtifact) throws DeployException {
        log.debug("deploy artifact: {} ", deployArtifact.getNotation());
        
        RepositoryClient repoClient = new RepositoryClient(this.getLocalRepoPath());
        
        DeployRequest deployRequest = new DeployRequest();
        deployRequest.addArtifact(deployArtifact.getJarArtifact());
        if (deployArtifact.getPomArtifact() != null) {
            deployRequest.addArtifact(deployArtifact.getPomArtifact());
        }
        deployRequest.setRepository(deployArtifact.getRemoteRepo());

        log.debug("deploying artifact {}", deployArtifact.getNotation());
        try {
            repoClient.deploy(deployRequest);
        } catch (DeploymentException e) {
            log.error("Failed to deploy artifact", e);
            throw new DeployException(e);
        }
    }
356832
public static Protos.CommandInfo.URI uri(MesosArtifactResolver resolver, ContainerSpecification.Artifact artifact) {
		checkNotNull(resolver);
		checkNotNull(artifact);
		Option<URL> url = resolver.resolve(artifact.dest);
		if (url.isEmpty()) {
			throw new IllegalArgumentException("Unresolvable artifact: " + artifact.dest);
		}

		return Protos.CommandInfo.URI.newBuilder()
			.setValue(url.get().toExternalForm())
			.setOutputFile(artifact.dest.toString())
			.setExtract(artifact.extract)
			.setCache(artifact.cachable)
			.setExecutable(artifact.executable)
			.build();
	}
222764
private File getArtifactFile(MavenBuild build, MavenArtifact mavenArtifact) throws IOException {
        String fileName = mavenArtifact.fileName;
        if (isArchiveJenkinsVersion) {
            fileName = mavenArtifact.canonicalName;
        }
        File file = new File(new File(new File(new File(build.getArtifactsDir(), mavenArtifact.groupId),
                mavenArtifact.artifactId), mavenArtifact.version), fileName);
        if (!file.exists()) {
            throw new FileNotFoundException("Archived artifact is missing: " + file + " " + getAdditionalMessage());
        }
        return file;
    }
120741
public Artifact createArtifact(String groupId, String artifactId) {
		return this.repositorySystem.createArtifact(groupId, artifactId, "RELEASE", "jar"); //$NON-NLS-1$ //$NON-NLS-2$
	}
454814
public Set<Artifact> resolve(String groupId, String artifactId) throws MojoExecutionException {
		final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
		request.setResolveRoot(true);
		request.setResolveTransitively(true);
		request.setLocalRepository(getSession().getLocalRepository());
		request.setRemoteRepositories(getSession().getCurrentProject().getRemoteArtifactRepositories());
		request.setOffline(getSession().isOffline());
		request.setForceUpdate(getSession().getRequest().isUpdateSnapshots());
		request.setServers(getSession().getRequest().getServers());
		request.setMirrors(getSession().getRequest().getMirrors());
		request.setProxies(getSession().getRequest().getProxies());
		request.setArtifact(createArtifact(groupId, artifactId));

		final ArtifactResolutionResult result = resolve(request);

		return result.getArtifacts();
	}
1281390
protected void installLooseConfigEar(MavenProject proj, LooseConfigData config) throws Exception {
        LooseEarApplication looseEar = new LooseEarApplication(proj, config);
        looseEar.addSourceDir();
        looseEar.addApplicationXmlFile();

        Set<Artifact> artifacts = proj.getArtifacts();
        log.debug("Number of compile dependencies for " + proj.getArtifactId() + " : " + artifacts.size());

        for (Artifact artifact : artifacts) {
            if ("compile".equals(artifact.getScope()) || "runtime".equals(artifact.getScope())) {
                if (!isReactorMavenProject(artifact)) {
                    if (looseEar.isEarSkinnyWars() && "war".equals(artifact.getType())) {
                        throw new MojoExecutionException(
                                "Unable to create loose configuration for the EAR application with skinnyWars package from "
                                        + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
                                        + artifact.getVersion()
                                        + ". Please set the looseApplication configuration parameter to false and try again.");
                    }
                    looseEar.addModuleFromM2(resolveArtifact(artifact));
                } else {
                    MavenProject dependencyProject = getReactorMavenProject(artifact);
                    switch (artifact.getType()) {
                    case "jar":
                        looseEar.addJarModule(dependencyProject);
                        break;
                    case "ejb":
                        looseEar.addEjbModule(dependencyProject);
                        break;
                    case "war":
                        Element warArchive = looseEar.addWarModule(dependencyProject,
                                getWarSourceDirectory(dependencyProject));
                        if (looseEar.isEarSkinnyWars()) {
                            // add embedded lib only if they are not a compile dependency in the ear
                            // project.
                            addSkinnyWarLib(warArchive, dependencyProject, looseEar);
                        } else {
                            addEmbeddedLib(warArchive, dependencyProject, looseEar, "/WEB-INF/lib/");
                        }
                        break;
                    case "rar":
                        Element rarArchive = looseEar.addRarModule(dependencyProject);
                        addEmbeddedLib(rarArchive, dependencyProject, looseEar, "/");
                        break;
                    default:
                        // use the artifact from local .m2 repo
                        looseEar.addModuleFromM2(resolveArtifact(artifact));
                        break;
                    }
                }
            }
        }

        // add Manifest file
        File manifestFile = MavenProjectUtil.getManifestFile(proj, "maven-ear-plugin");
        looseEar.addManifestFile(manifestFile);
    }
38257
private List<String> copyDependencies(File javaDirectory) throws MojoExecutionException {
        ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();

        List<String> list = new ArrayList<String>();

        // First, copy the project's own artifact
        File artifactFile = project.getArtifact().getFile();
        list.add(layout.pathOf(project.getArtifact()));

        try {
            FileUtils.copyFile(artifactFile, new File(javaDirectory, layout.pathOf(project.getArtifact())));
        } catch (IOException ex) {
            throw new MojoExecutionException("Could not copy artifact file " + artifactFile + " to " + javaDirectory, ex);
        }

        if (excludeDependencies) {
            // skip adding dependencies from project.getArtifacts()
            return list;
        }

        for (Artifact artifact : project.getArtifacts()) {
            File file = artifact.getFile();
            File dest = new File(javaDirectory, layout.pathOf(artifact));

            getLog().debug("Adding " + file);

            try {
                FileUtils.copyFile(file, dest);
            } catch (IOException ex) {
                throw new MojoExecutionException("Error copying file " + file + " into " + javaDirectory, ex);
            }

            list.add(layout.pathOf(artifact));
        }

        return list;
    }
1198833
protected void downloadFromMavenRepo(PluginCoordinates coordinates, URI mavenRepoUrl, IAsyncResultHandler<File> handler) {
        String artifactSubPath = PluginUtils.getMavenPath(coordinates);
        try {
            File tempArtifactFile = File.createTempFile("_plugin", "dwn"); //$NON-NLS-1$ //$NON-NLS-2$
            URL artifactUrl = new URL(mavenRepoUrl.toURL(), artifactSubPath);
            downloadArtifactTo(artifactUrl, tempArtifactFile, handler);
        } catch (Exception e) {
            handler.handle(AsyncResultImpl.<File>create(e));
        }
    }
55804
public Map<Artifact, Dependency> resolve(BomConfig config) throws Exception {
        Map<Artifact, Dependency> dependencies = new LinkedHashMap<Artifact, Dependency>();
        if (config != null && config.getImports() != null) {
            for (BomImport bom : config.getImports()) {
                Map<Artifact, Dependency> deps = resolve(bom);
                for (Map.Entry<Artifact, Dependency> e : deps.entrySet()) {
                    if (!dependencies.containsKey(e.getKey())) {
                        // order is important for imported boms
                        dependencies.put(e.getKey(), e.getValue());
                    }
                }
            }
        }
        return dependencies;
    }
556203
@Override
    public void artifactResolved(RepositoryEvent event) {
        log.fine("Resolved artifact " + event.getArtifact() + " from " + event.getRepository());
    }
556716
private static Artifact validateArtifact(final Artifact artifact) {
        if (!artifact.getFile().isFile()) {
            throw new IllegalArgumentException("<"+artifact.getFile()+"> is not a file");
        }
        return artifact;
    }
150122
public static org.jfrog.hudson.ArtifactoryServer prepareArtifactoryServer(String artifactoryServerID,
                                                                              ArtifactoryServer pipelineServer) {

        if (artifactoryServerID == null && pipelineServer == null) {
            return null;
        }
        if (artifactoryServerID != null && pipelineServer != null) {
            return null;
        }
        if (pipelineServer != null) {
            CredentialsConfig credentials = pipelineServer.createCredentialsConfig();

            return new org.jfrog.hudson.ArtifactoryServer(null, pipelineServer.getUrl(), credentials,
                    credentials, pipelineServer.getConnection().getTimeout(), pipelineServer.isBypassProxy(), pipelineServer.getConnection().getRetry(), pipelineServer.getDeploymentThreads());
        }
        org.jfrog.hudson.ArtifactoryServer server = RepositoriesUtils.getArtifactoryServer(artifactoryServerID, RepositoriesUtils.getArtifactoryServers());
        if (server == null) {
            return null;
        }
        return server;
    }
779240
public static Artifact withArtifactId(String artifactId)
    {
        Artifact artifact = new Artifact();
        artifact.artifactId = new RegexParameterizedPatternParser(artifactId);
        return artifact;
    }
854699
private static File artifactToFile(final Artifact artifact) throws IllegalArgumentException {
        if (artifact == null) {
            throw new IllegalArgumentException("ArtifactResult must not be null");
        }

        // FIXME: this is not a safe assumption, file can have a different name
        if ("pom.xml".equals(artifact.getFile().getName())) {

            String artifactId = artifact.getArtifactId();
            String extension = artifact.getExtension();
            String classifier = artifact.getClassifier();

            File root = new File(artifact.getFile().getParentFile(), "target/classes");
            if (!Validate.isNullOrEmpty(classifier) && "tests".equals(classifier)) {
                // SHRINKRES-102, allow test classes to be packaged as well
                root = new File(artifact.getFile().getParentFile(), "target/test-classes");
            } else if ("war".equals(artifact.getProperty(ArtifactProperties.TYPE, null))) {
                // SHRINKRES-263, allow .war files to be packaged as well
                root = new File(artifact.getFile().getParentFile(), "target/" + artifactId + "-" + artifact.getVersion());
            }

            try {
                File archive = File.createTempFile(artifactId + "-", "." + extension);
                archive.deleteOnExit();
                PackageDirHelper.packageDirectories(archive, root);
                return archive;
            } catch (IOException e) {
                throw new IllegalArgumentException("Unable to get artifact " + artifactId + " from the classpath", e);

            }

        } else {
            return artifact.getFile();
        }
    }
526400
public final Artifact createArtifact(String groupId, String artifactId, String version) {
		return createArtifact(groupId, artifactId, version, "runtime", "jar"); //$NON-NLS-1$ //$NON-NLS-2$
	}
268752
private Response downloadArtifact(Node node) throws Exception
   {
      NodeRepresentation nodeRepresentation = nodeRepresentationService.getNodeRepresentation(node, null);
      if (node.canAddMixin("exo:mavencounter"))
      {
         node.addMixin("exo:mavencounter");
         node.getSession().save();
      }
      node.setProperty("exo:downloadcounter", node.getProperty("exo:downloadcounter").getLong() + 1l);
      node.getSession().save();
      long lastModified = nodeRepresentation.getLastModified();
      String contentType = nodeRepresentation.getMediaType();
      long contentLength = nodeRepresentation.getContentLenght();
      InputStream entity = nodeRepresentation.getInputStream();
      Response response =
         Response.ok(entity, contentType).header(HttpHeaders.CONTENT_LENGTH, Long.toString(contentLength))
            .lastModified(new Date(lastModified)).build();
      return response;
   }