Skip to content

Commit

Permalink
Fix download url discrepancy.
Browse files Browse the repository at this point in the history
After 2.7.0 it looks like the following has changed

1. The standalone binary name has changed from 
“allure” to “allure-commandline”

This changes captures the change in the standalone
binary name and also accommodates the url suffix
pattern for the newer version downloads.
  • Loading branch information
krmahadevan committed Jul 27, 2019
1 parent 5ec9539 commit 15e4282
Showing 1 changed file with 30 additions and 17 deletions.
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.getCause());
}
}
} 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};
}
}

0 comments on commit 15e4282

Please # to comment.