Skip to content

Commit

Permalink
Add Slf4j version to pom to prevent incompatibilities (refs #35) (#38)
Browse files Browse the repository at this point in the history
* Add Slf4j version to pom to prevent incompatibilities (refs #35)

* More debug logging in search for the existing command (refs #35)

* Fix download url slash for windows
  • Loading branch information
smecsia authored Dec 5, 2017
1 parent 6368bd9 commit 7bee301
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
17 changes: 15 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
<url>https://github.com/allure-framework</url>
</organization>
<properties>
<amps.version>6.2.11</amps.version>
<amps.version>6.3.7</amps.version>
<bamboo.version>5.10.3</bamboo.version>
<bamboo.data.version>5.10.3</bamboo.data.version>
<bamboo.data.version>${bamboo.version}</bamboo.data.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<slf4j.version>1.7.21</slf4j.version>
<compiler.version>1.8</compiler.version>
</properties>

Expand Down Expand Up @@ -52,6 +53,18 @@
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/qameta/allure/bamboo/AllureDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AllureDownloader {
Optional<Path> downloadAndExtractAllureTo(String allureHomeDir, String version) {
return downloadAllure(version).map(zipFilePath -> {
try {
LOGGER.info("Extracting file " + zipFilePath + " to " + allureHomeDir + "...");
LOGGER.info("Extracting file {} to {}...", zipFilePath, allureHomeDir);
final String extractedDirName = "allure-" + version;
final File homeDir = new File(allureHomeDir);
final Path extracteDir = zipFilePath.getParent();
Expand All @@ -59,7 +59,7 @@ private Optional<Path> downloadAllure(String version) {
try {
final URL url = buildAllureDownloadUrl(version);
final Path downloadToFile = createTempFile("allure", "zip");
LOGGER.info("Downloading allure.zip from " + url + " to " + downloadToFile);
LOGGER.info("Downloading allure.zip from {} to {}", url, downloadToFile);
copyURLToFile(url, downloadToFile.toFile(), CONN_TIMEOUT_MS, DOWNLOAD_TIMEOUT_MS);
return Optional.of(downloadToFile);
} catch (IOException e) {
Expand All @@ -70,7 +70,7 @@ private Optional<Path> downloadAllure(String version) {

private URL buildAllureDownloadUrl(String version) throws MalformedURLException {
return fromPath(settingsManager.getSettings().getDownloadBaseUrl())
.path(Paths.get(version, "allure-" + version + ".zip").toString())
.path(version + "/" + "allure-" + version + ".zip")
.build().toURL();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.annotations.VisibleForTesting;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -13,6 +15,7 @@
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.2.1";
static final String DEFAULT_PATH = "/tmp/allure/2.2.1";
private static final Pattern EXEC_NAME_PATTERN = compile("[^\\d]*(\\d[0-9\\.]{2,}[a-zA-Z0-9\\-]*)$");
Expand All @@ -38,14 +41,20 @@ public static String getAllureSubDir() {
Optional<AllureExecutable> provide(boolean isDownloadEnabled, 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());
if (!cmdLine.hasCommand(cmdPath.toString()) && isDownloadEnabled) {
LOGGER.debug("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={}",
executableName, commandExists, isDownloadEnabled);
if (!commandExists && isDownloadEnabled) {
final Matcher nameMatcher = EXEC_NAME_PATTERN.matcher(executableName);
allureDownloader.downloadAndExtractAllureTo(allureHomeSubDir,
nameMatcher.matches() ? nameMatcher.group(1) : DEFAULT_VERSION);
}
return (cmdLine.hasCommand(cmdPath.toString())) ? new AllureExecutable(cmdPath, cmdLine) : null;
return commandExists ? new AllureExecutable(cmdPath, cmdLine) : null;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.atlassian.bamboo.v2.build.agent.capability.CapabilitySetManager;
import com.atlassian.bamboo.v2.build.agent.capability.LocalCapabilitySet;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.List;
Expand All @@ -20,6 +22,7 @@
import static java.util.stream.Collectors.toList;

public class BambooExecutablesManager {
private static final Logger LOGGER = LoggerFactory.getLogger(BambooExecutablesManager.class);
private final CapabilitySetManager capabilitySetManager;

public BambooExecutablesManager(CapabilitySetManager capabilitySetManager) {
Expand All @@ -42,10 +45,14 @@ Optional<String> getDefaultAllureExecutable() {
}

Optional<String> getExecutableByName(String executableName) {
LOGGER.debug("Trying to find a capability by executable name '{}'", executableName);
return getCapabilityKeys().stream()
.filter(capKey -> {
final String[] strings = capKey.split("\\.", 4);
return strings.length == 4 && executableName.equals(strings[3]);
final boolean matches = strings.length == 4 && executableName.equals(strings[3]);
LOGGER.debug("Checking key '{}' to matches executable name '{}'={}...",
capKey, executableName, matches);
return matches;
})
.findFirst()
.map(this::getCapability)
Expand Down

0 comments on commit 7bee301

Please # to comment.