Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix download url discrepancy. #61

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions src/main/java/io/qameta/allure/bamboo/AllureDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,42 @@ Optional<Path> downloadAndExtractAllureTo(String allureHomeDir, String version)

private Optional<Path> downloadAllure(String version) {
try {
final URL url = buildAllureDownloadUrl(version);
final Path downloadToFile = createTempFile("allure", ".zip");
LOGGER.info("Downloading allure.zip from {} to {}", url, downloadToFile);
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(CONN_TIMEOUT_MS);
connection.setReadTimeout(DOWNLOAD_TIMEOUT_MS);
connection.setRequestProperty("Connection", "close");
connection.setRequestProperty("Pragma", "no-cache");
((HttpURLConnection)connection).setInstanceFollowRedirects(true);
connection.connect();
try (InputStream input = connection.getInputStream()) {
copyInputStreamToFile(input, downloadToFile.toFile());
return Optional.of(downloadToFile);
URL[] urls = buildAllureDownloadUrls(version);
for (URL url : urls) {
try {
final Path downloadToFile = createTempFile("allure", ".zip");
LOGGER.info("Downloading allure.zip from {} to {}", url, downloadToFile);
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(CONN_TIMEOUT_MS);
connection.setReadTimeout(DOWNLOAD_TIMEOUT_MS);
connection.setRequestProperty("Connection", "close");
connection.setRequestProperty("Pragma", "no-cache");
((HttpURLConnection) connection).setInstanceFollowRedirects(true);
connection.connect();
try (InputStream input = connection.getInputStream()) {
copyInputStreamToFile(input, downloadToFile.toFile());
return Optional.of(downloadToFile);
}
} catch (Exception e) {
LOGGER
.warn("Failed to download from {}. Root cause : {}. Trying with next url.",
url, e.getMessage());
}
}
} catch (Exception e) {
LOGGER.error("Failed to download Allure of version {}", version, e);
}
return Optional.empty();
}

private URL buildAllureDownloadUrl(String version) throws MalformedURLException {
return fromPath(settingsManager.getSettings().getDownloadBaseUrl())
.path(version + "/" + "allure-" + version + ".zip")
.build().toURL();
private URL[] buildAllureDownloadUrls(String version) throws MalformedURLException {
URL oldUrl = fromPath(settingsManager.getSettings().getDownloadBaseUrl())
.path(version + "/" + "allure-" + version + ".zip")
.build().toURL();
String binaryName = "allure-commandline";
URL newUrl = fromPath(settingsManager.getSettings().getDownloadBaseUrl())
.path(binaryName + "/" + version + "/" + binaryName + "-" + version + ".zip")
.build().toURL();
return new URL[]{oldUrl, newUrl};
}
}