org.jfrog.hudson.generic.DependenciesDownloaderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artifactory Show documentation
Show all versions of artifactory Show documentation
Integrates Artifactory to Hudson
The newest version!
package org.jfrog.hudson.generic;
import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import org.apache.commons.io.IOUtils;
import org.jfrog.build.api.Dependency;
import org.jfrog.build.api.dependency.DownloadableArtifact;
import org.jfrog.build.api.util.FileChecksumCalculator;
import org.jfrog.build.api.util.Log;
import org.jfrog.build.client.ArtifactoryDependenciesClient;
import org.jfrog.build.util.DependenciesDownloader;
import org.jfrog.build.util.DependenciesDownloaderHelper;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Primary implementation of dependencies downloader,
* handles Jenkins slaves and re-use a client for HTTP communication.
*
* @author Shay Yaakov
*/
public class DependenciesDownloaderImpl implements DependenciesDownloader {
private ArtifactoryDependenciesClient client;
private FilePath workspace;
private Log log;
public DependenciesDownloaderImpl(ArtifactoryDependenciesClient client, FilePath workspace, Log log) {
this.client = client;
this.workspace = workspace;
this.log = log;
}
public ArtifactoryDependenciesClient getClient() {
return client;
}
public List download(Set downloadableArtifacts) throws IOException {
DependenciesDownloaderHelper helper = new DependenciesDownloaderHelper(this, log);
return helper.downloadDependencies(downloadableArtifacts);
}
public String getTargetDir(String targetDir, String relativeDir) {
FilePath targetDirFile = new FilePath(workspace, targetDir).child(relativeDir);
return targetDirFile.getRemote();
}
public Map saveDownloadedFile(InputStream is, String filePath) throws IOException {
try {
FilePath child = workspace.child(filePath);
child.copyFrom(is);
return child.act(new DownloadFileCallable(log));
} catch (InterruptedException e) {
log.warn("Caught interrupted exception: " + e.getLocalizedMessage());
} finally {
IOUtils.closeQuietly(is);
}
return null;
}
private static class DownloadFileCallable implements FilePath.FileCallable