Search in sources :

Example 1 with FileHandler

use of com.thoughtworks.go.domain.FileHandler in project gocd by gocd.

the class DownloadFileCommandExecutor method execute.

@Override
public boolean execute(BuildCommand command, BuildSession buildSession) {
    URLService urlService = new URLService();
    String url = urlService.prefixPartialUrl(command.getStringArg("url"));
    String dest = command.getStringArg("dest");
    String src = command.getStringArg("src");
    File artifact = buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest);
    FileHandler handler = new FileHandler(artifact, src);
    String checksumUrl = null;
    ChecksumFileHandler checksumFileHandler = null;
    if (command.hasArg("checksumUrl")) {
        checksumUrl = new URLService().prefixPartialUrl(command.getStringArg("checksumUrl"));
        File checksumFile;
        if (command.hasArg("checksumFile")) {
            checksumFile = buildSession.resolveRelativeDir(command.getWorkingDirectory(), command.getStringArg("checksumFile"));
        } else {
            checksumFile = TempFiles.createUniqueFile("checksum");
        }
        checksumFileHandler = new ChecksumFileHandler(checksumFile);
    }
    boolean fileExist = artifact.exists();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Requesting the file [" + artifact.getAbsolutePath() + "], exist? [" + fileExist + "]");
    }
    if (fileExist && artifact.isFile()) {
        try {
            url += "?sha1=" + java.net.URLEncoder.encode(StringUtil.sha1Digest(artifact), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            LOG.error("Download error", e);
            return false;
        }
    }
    buildSession.download(handler, url, checksumFileHandler, checksumUrl);
    return true;
}
Also used : URLService(com.thoughtworks.go.util.URLService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) File(java.io.File) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) FileHandler(com.thoughtworks.go.domain.FileHandler)

Aggregations

ChecksumFileHandler (com.thoughtworks.go.domain.ChecksumFileHandler)1 FileHandler (com.thoughtworks.go.domain.FileHandler)1 URLService (com.thoughtworks.go.util.URLService)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1