Skip to content
Permalink
Browse files
Simple build log zip downloader implemented
  • Loading branch information
dspavlov committed Jul 21, 2017
1 parent a06a177 commit 9363a2dbe8952b6c07e9d33a49bf93b9412ba9a2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
@@ -10,6 +10,9 @@
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# IDEA project
.idea/

# Package Files #
*.jar
*.war
@@ -1,5 +1,8 @@
import com.google.common.util.concurrent.MoreExecutors;
import java.io.File;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import org.apache.ignite.ci.DownloadBuildLog;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.HttpUtil;
@@ -11,18 +14,23 @@
*/
public class DownloadBuildLogTest {
public static void main(String[] args) throws Exception {
File workDir = HelperConfig.resolveWorkDir();
Properties properties = HelperConfig.loadAuthProperties(workDir);
final File workDir = HelperConfig.resolveWorkDir();
final Properties properties = HelperConfig.loadAuthProperties(workDir);

String basicAuthToken = HelperConfig.prepareBasicHttpAuthToken(properties);
final String host = properties.getProperty("host", "http://ci.ignite.apache.org/");
final String basicAuthToken = HelperConfig.prepareBasicHttpAuthToken(properties);

File logsDir = ensureDirExist(new File(workDir, "logs"));
final File logsDir = ensureDirExist(new File(workDir, "logs"));

int buildId = 736822;
DownloadBuildLog buildLog = new DownloadBuildLog(buildId, basicAuthToken, logsDir);
File run = buildLog.run();
System.out.println("Cached locally: [" + run.getCanonicalPath()
+ "], " + run.toURI());
final int buildId = 736822;
final DownloadBuildLog buildLog = new DownloadBuildLog(buildId,
host, basicAuthToken, logsDir, true);

final Executor executor = MoreExecutors.directExecutor();
final CompletableFuture<File> future = CompletableFuture.supplyAsync(buildLog, executor);
final File log = future.get();
System.out.println("Cached locally: [" + log.getCanonicalPath()
+ "], " + log.toURI());

}

@@ -2,32 +2,53 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Supplier;

import static org.apache.ignite.ci.HelperConfig.ensureDirExist;

/**
* Created by Дмитрий on 21.07.2017
*/
public class DownloadBuildLog {
public class DownloadBuildLog implements Supplier<File> {
private int buildId;
private final String token;
private final File dir;
private String host;
private boolean archive;

public DownloadBuildLog(int buildId, String host, String basicAuthToken, File logsDir) {
this(buildId, host, basicAuthToken, logsDir, false);
}

public DownloadBuildLog(int buildId, String basicAuthToken, File logsDir) {
public DownloadBuildLog(int buildId, String host, String basicAuthToken,
File logsDir, boolean archive) {
this.buildId = buildId;
token = basicAuthToken;
dir = logsDir;
this.token = basicAuthToken;
this.dir = logsDir;
this.host = host;
this.archive = archive;
}

public File run() throws IOException {
public File get() {
String buildIdStr = Integer.toString(buildId);
String url = "http://ci.ignite.apache.org/downloadBuildLog.html?buildId=" + buildIdStr;
File file = new File(dir, "buildId" + buildIdStr + ".log");
if(file.exists() && file.canRead() && file.length()>0) {
String url = host + "downloadBuildLog.html" +
"?buildId=" + buildIdStr
+ (archive ? "&archived=true" : "");
final File buildDirectory = ensureDirExist(new File(dir, "buildId" + buildIdStr));
final File file = new File(buildDirectory,
"build.log" + (archive ? ".zip" : ""));
if (file.exists() && file.canRead() && file.length() > 0) {
System.err.println("Nothing to do, file is cached " + file);
return file;
}
HttpUtil.sendGetCopyToFile(token, url, file);
try {
HttpUtil.sendGetCopyToFile(token, url, file);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
return file;


}

}

0 comments on commit 9363a2d

Please sign in to comment.