Search in sources :

Example 1 with ChecksumFileHandler

use of com.thoughtworks.go.domain.ChecksumFileHandler 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)

Example 2 with ChecksumFileHandler

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

the class DownloadDirCommandExecutor 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");
    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);
    }
    DirHandler handler = new DirHandler(src, buildSession.resolveRelativeDir(command.getWorkingDirectory(), dest));
    buildSession.download(handler, url, checksumFileHandler, checksumUrl);
    return true;
}
Also used : DirHandler(com.thoughtworks.go.domain.DirHandler) URLService(com.thoughtworks.go.util.URLService) ChecksumFileHandler(com.thoughtworks.go.domain.ChecksumFileHandler) File(java.io.File)

Aggregations

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