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

#232: Fix empty config path #233

Merged
merged 1 commit into from
Mar 21, 2019
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.yandex.qatools.allure.jenkins;

import com.google.common.base.Optional;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -17,6 +18,7 @@
import hudson.tasks.Recorder;
import jenkins.model.Jenkins;
import jenkins.tasks.SimpleBuildStep;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import ru.yandex.qatools.allure.jenkins.callables.AddExecutorInfo;
Expand Down Expand Up @@ -185,7 +187,7 @@ public String getReport() {
}

public String getConfigPath() {
return configPath;
return StringUtils.isNotBlank(configPath) ? configPath : null;
}

@Nonnull
Expand Down Expand Up @@ -290,7 +292,7 @@ private void generateReport(@Nonnull List<FilePath> resultsPaths, @Nonnull Run<?

final ReportBuildPolicy reportBuildPolicy = getReportBuildPolicy();
if (!reportBuildPolicy.isNeedToBuildReport(run)) {
listener.getLogger().println(String.format("allure report generation reject by policy [%s]",
listener.getLogger().println(String.format("Allure report generation reject by policy [%s]",
reportBuildPolicy.getTitle()));
return;
}
Expand All @@ -301,16 +303,13 @@ private void generateReport(@Nonnull List<FilePath> resultsPaths, @Nonnull Run<?
final AllureCommandlineInstallation commandline = getCommandline(launcher, listener, buildEnvVars);

final FilePath reportPath = workspace.child(getReport());
FilePath configPath = null;

try {
configPath = workspace.child(getConfigPath());
} catch (NullPointerException e) {
configPath = null;
final ReportBuilder builder = new ReportBuilder(launcher, listener, workspace, buildEnvVars, commandline);
if (getConfigPath() != null && workspace.child(getConfigPath()).exists()) {
final FilePath configFilePath = workspace.child(getConfigPath()).absolutize();
listener.getLogger().println("Allure config file: " + configFilePath.absolutize());
builder.setConfigFilePath(configFilePath);
}

final int exitCode = new ReportBuilder(launcher, listener, workspace, buildEnvVars, commandline)
.build(resultsPaths, reportPath, configPath);
final int exitCode = builder.build(resultsPaths, reportPath);
if (exitCode != 0) {
throw new AllurePluginException("Can not generate Allure Report, exit code: " + exitCode);
}
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/ru/yandex/qatools/allure/jenkins/ReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class ReportBuilder {

private final AllureCommandlineInstallation commandline;

private FilePath configFilePath;

public ReportBuilder(@Nonnull Launcher launcher, @Nonnull TaskListener listener, @Nonnull FilePath workspace,
@Nonnull EnvVars envVars, @Nonnull AllureCommandlineInstallation commandline) {
this.workspace = workspace;
Expand All @@ -41,28 +43,28 @@ public ReportBuilder(@Nonnull Launcher launcher, @Nonnull TaskListener listener,
this.commandline = commandline;
}

public int build(@Nonnull List<FilePath> resultsPaths, @Nonnull FilePath reportPath,
FilePath configPath) //NOSONAR
public void setConfigFilePath(final FilePath configFilePath) {
this.configFilePath = configFilePath;
}

public int build(@Nonnull List<FilePath> resultsPaths, @Nonnull FilePath reportPath) //NOSONAR
throws IOException, InterruptedException {
final String version = commandline.getMajorVersion(launcher);
final ArgumentListBuilder arguments = getArguments(version, resultsPaths, reportPath, configPath);


final ArgumentListBuilder arguments = getArguments(version, resultsPaths, reportPath);

return launcher.launch().cmds(arguments)
.envs(envVars).stdout(listener).pwd(workspace).join();
}

private ArgumentListBuilder getArguments(String version, @Nonnull List<FilePath> resultsPaths,
@Nonnull FilePath reportPath, FilePath configPath)
@Nonnull FilePath reportPath)
throws IOException, InterruptedException {
return version.startsWith("2") ? getAllure2Arguments(resultsPaths, reportPath, configPath)
return version.startsWith("2") ? getAllure2Arguments(resultsPaths, reportPath)
: getAllure1Arguments(resultsPaths, reportPath);
}

private ArgumentListBuilder getAllure2Arguments(@Nonnull List<FilePath> resultsPaths,
@Nonnull FilePath reportPath,
FilePath configPath) //NOSONAR
@Nonnull FilePath reportPath) //NOSONAR
throws IOException, InterruptedException {
final ArgumentListBuilder arguments = new ArgumentListBuilder();
arguments.add(commandline.getExecutable(launcher));
Expand All @@ -73,9 +75,9 @@ private ArgumentListBuilder getAllure2Arguments(@Nonnull List<FilePath> resultsP
arguments.add(CLEAN_OPTION);
arguments.add(OUTPUT_DIR_OPTION);
arguments.add(reportPath.getRemote());
if (configPath != null) {
if (configFilePath != null) {
arguments.add(CONFIG_OPTION);
arguments.add(configPath.getRemote());
arguments.add(configFilePath.getRemote());
}
return arguments;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void shouldGenerateReport() throws Exception {
results.child("sample-testsuite.xml").copyFrom(is);
}
FilePath report = new FilePath(folder.getRoot()).child("some folder with (x22) spaces");
int exitCode = builder.build(Collections.singletonList(results), report, null);
int exitCode = builder.build(Collections.singletonList(results), report);
assertThat(exitCode).as("Should exit with code 0").isEqualTo(0);
}
}