From 15e428248d7d484f74a961a25c13cbdddff8a24a Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Sat, 27 Jul 2019 13:14:46 +0530 Subject: [PATCH] Fix download url discrepancy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../allure/bamboo/AllureDownloader.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/qameta/allure/bamboo/AllureDownloader.java b/src/main/java/io/qameta/allure/bamboo/AllureDownloader.java index fc6e1f2..3b44a84 100644 --- a/src/main/java/io/qameta/allure/bamboo/AllureDownloader.java +++ b/src/main/java/io/qameta/allure/bamboo/AllureDownloader.java @@ -60,19 +60,27 @@ Optional downloadAndExtractAllureTo(String allureHomeDir, String version) private Optional 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); @@ -80,9 +88,14 @@ private Optional downloadAllure(String version) { 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}; } }