Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove binary folder from allure execution search #342

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-bamboo</artifactId>
<version>1.18.1-SNAPSHOT</version>
<version>1.18.2-SNAPSHOT</version>
<name>Allure for Bamboo</name>
<description>Allure reports right in deployment plans in Bamboo</description>
<packaging>atlassian-plugin</packaging>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/qameta/allure/bamboo/AllureDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Optional<Path> downloadAndExtractAllureTo(final String allureHomeDir,
ZipUtil.unzip(zipFilePath, extractDir.toString());

if (homeDir.exists()) {
LOGGER.info("Directory " + homeDir + " already exists, removing it..");
LOGGER.info("Directory {} already exists, removing it..", homeDir);
deleteQuietly(homeDir);
}
moveDirectory(extractDir.resolve(extractedDirName).toFile(), homeDir);
Expand All @@ -78,9 +78,7 @@ private Optional<Path> downloadAllure(final String version) {
LOGGER.info("Downloading allure.zip from {} to {}", url, downloadToFile);
return Downloader.download(url, downloadToFile);
} catch (Exception e) {
LOGGER
.warn("Failed to download from {}. Root cause : {}.",
url, e.toString());
LOGGER.warn("Failed to download from {}. Root cause : {}.", url, e.toString());
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.qameta.allure.bamboo;

import com.google.common.annotations.VisibleForTesting;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -30,11 +29,12 @@
import static java.util.regex.Pattern.compile;

public class AllureExecutableProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(AllureExecutableProvider.class);
static final String DEFAULT_VERSION = "2.21.0";
static final String DEFAULT_PATH = "/tmp/allure/2.21.0";
static final String DEFAULT_VERSION = "2.30.0";
static final String DEFAULT_PATH = "/tmp/allure/2.30.0";
static final String BIN = "bin";
private static final Pattern EXEC_NAME_PATTERN = compile("[^\\d]*(\\d[0-9\\.]{2,}[a-zA-Z0-9\\-]*)$");
private static final String BINARY_SUBDIR = "binary";

private final BambooExecutablesManager bambooExecutablesManager;
private final AllureDownloader allureDownloader;
Expand All @@ -48,28 +48,22 @@ public AllureExecutableProvider(final BambooExecutablesManager bambooExecutables
this.cmdLine = requireNonNull(cmdLine);
}

@VisibleForTesting
public static String getAllureSubDir() {
return BINARY_SUBDIR;
}

Optional<AllureExecutable> provide(final boolean isDownloadEnabled, final String executableName) {
return bambooExecutablesManager.getExecutableByName(executableName)
.map(allureHomeDir -> {
LOGGER.debug("Found allure executable by name '{}': '{}'", executableName, allureHomeDir);
final String allureHomeSubDir = Paths.get(allureHomeDir, BINARY_SUBDIR).toString();
final Path cmdPath = Paths.get(allureHomeSubDir, "bin", getAllureExecutableName());
LOGGER.info("Found allure executable by name '{}': '{}'", executableName, allureHomeDir);
final Path cmdPath = Paths.get(allureHomeDir, BIN, getAllureExecutableName());
final AllureExecutable executable = new AllureExecutable(cmdPath, cmdLine);
LOGGER.debug("Checking the existence of the command path for executable '{}': '{}'",
LOGGER.info("Checking the existence of the command path for executable '{}': '{}'",
executableName, cmdPath);
final boolean commandExists = cmdLine.hasCommand(cmdPath.toString());
LOGGER.debug("System has command for executable '{}': {}, downloadEnabled={}",
LOGGER.info("System has command for executable '{}': {}, downloadEnabled={}",
executableName, commandExists, isDownloadEnabled);
if (commandExists) {
return executable;
} else if (isDownloadEnabled) {
final Matcher nameMatcher = EXEC_NAME_PATTERN.matcher(executableName);
return allureDownloader.downloadAndExtractAllureTo(allureHomeSubDir,
return allureDownloader.downloadAndExtractAllureTo(allureHomeDir,
nameMatcher.matches() ? nameMatcher.group(1) : DEFAULT_VERSION)
.map(path -> executable).orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@
import java.nio.file.Paths;
import java.util.Optional;

import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN;
import static io.qameta.allure.bamboo.AllureExecutableProvider.DEFAULT_VERSION;
import static io.qameta.allure.bamboo.AllureExecutableProvider.getAllureSubDir;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.junit.MockitoJUnit.rule;

public class AllureExecutableProviderTest {

private static final String ALLURE_2_0_0 = "Allure 2.0.0";
private static final String EXECUTABLE_NAME_2_0_0 = "2.0.0";
private static final String BIN = "bin";
private static final String ALLURE_2_21_0 = "Allure 2.21.0";
private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0";
private final String homeDir = "/home/allure";
private final String binaryDir = Paths.get(this.homeDir, getAllureSubDir()).toString();

@Rule
public MockitoRule mockitoRule = rule();
Expand All @@ -58,39 +56,39 @@ public class AllureExecutableProviderTest {
@Before
public void setUp() throws Exception {
config = new AllureGlobalConfig();
allureCmdPath = Paths.get(binaryDir, BIN, "allure");
allureBatCmdPath = Paths.get(binaryDir, BIN, "allure.bat");
allureCmdPath = Paths.get(homeDir, BIN, "allure");
allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat");
when(downloader.downloadAndExtractAllureTo(anyString(), anyString())).thenReturn(Optional.empty());
}

@Test
public void itShouldProvideDefaultVersion() throws Exception {
provide("Allure WITHOUT VERSION");
verify(downloader).downloadAndExtractAllureTo(binaryDir, DEFAULT_VERSION);
verify(downloader).downloadAndExtractAllureTo(homeDir, DEFAULT_VERSION);
}

@Test
public void itShouldProvideTheGivenVersionWithFullSemverWithoutName() throws Exception {
provide(EXECUTABLE_NAME_2_0_0);
verify(downloader).downloadAndExtractAllureTo(binaryDir, EXECUTABLE_NAME_2_0_0);
provide(EXECUTABLE_NAME_2_21_0);
verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0);
}

@Test
public void itShouldProvideTheGivenVersionWithFullSemverWithoutMilestone() throws Exception {
provide(ALLURE_2_0_0);
verify(downloader).downloadAndExtractAllureTo(binaryDir, EXECUTABLE_NAME_2_0_0);
provide(ALLURE_2_21_0);
verify(downloader).downloadAndExtractAllureTo(homeDir, EXECUTABLE_NAME_2_21_0);
}

@Test
public void itShouldProvideTheGivenVersionWithMajorMinorWithoutMilestone() throws Exception {
provide("Allure 2.0");
verify(downloader).downloadAndExtractAllureTo(binaryDir, "2.0");
provide("Allure 2.13.7");
verify(downloader).downloadAndExtractAllureTo(homeDir, "2.13.7");
}

@Test
public void itShouldProvideTheGivenVersionWithMilestone() throws Exception {
provide("Allure 2.0-BETA4");
verify(downloader).downloadAndExtractAllureTo(binaryDir, "2.0-BETA4");
verify(downloader).downloadAndExtractAllureTo(homeDir, "2.0-BETA4");
}

private Optional<AllureExecutable> provide(String executableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
import java.nio.file.Paths;
import java.util.Optional;

import static io.qameta.allure.bamboo.AllureExecutableProvider.getAllureSubDir;
import static io.qameta.allure.bamboo.AllureExecutableProvider.BIN;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.junit.MockitoJUnit.rule;

public class SecondAllureExecutableProviderTest {

private static final String ALLURE_2_0_0 = "Allure 2.0.0";
private static final String EXECUTABLE_NAME_2_0_0 = "2.0.0";
private static final String BIN = "bin";
private static final String ALLURE_2_21_0 = "Allure 2.21.0";
private static final String EXECUTABLE_NAME_2_21_0 = "2.21.0";
private final String homeDir = "/home/allure";
private final String binaryDir = Paths.get(this.homeDir, getAllureSubDir()).toString();

@Rule
public MockitoRule mockitoRule = rule();
Expand All @@ -57,8 +55,8 @@ public class SecondAllureExecutableProviderTest {
@Before
public void setUp() throws Exception {
config = new AllureGlobalConfig();
allureCmdPath = Paths.get(binaryDir, BIN, "allure");
allureBatCmdPath = Paths.get(binaryDir, BIN, "allure.bat");
allureCmdPath = Paths.get(homeDir, BIN, "allure");
allureBatCmdPath = Paths.get(homeDir, BIN, "allure.bat");
}

@Test
Expand All @@ -77,7 +75,7 @@ public void itShouldProvideExecutableForWindows() throws Exception {
when(cmdLine.hasCommand(allureBatCmdPath.toString())).thenReturn(true);
when(cmdLine.isWindows()).thenReturn(true);

final Optional<AllureExecutable> res = provide(ALLURE_2_0_0);
final Optional<AllureExecutable> res = provide(ALLURE_2_21_0);

assertThat(res.isPresent(), equalTo(true));
assertThat(res.get().getCmdPath(), equalTo(allureBatCmdPath));
Expand Down
Loading