Compare commits

...

1 Commits

3 changed files with 18 additions and 11 deletions

View File

@@ -147,18 +147,14 @@ public final class ScriptService {
public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, String command) { public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, String command) {
return scriptCommands(interpreter, beforeCommands, List.of(command), TargetOS.LINUX); return scriptCommands(interpreter, beforeCommands, List.of(command), TargetOS.LINUX.lineSeparator);
} }
public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, List<String> commands) { public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, List<String> commands) {
return scriptCommands(interpreter, beforeCommands, commands, TargetOS.LINUX); return scriptCommands(interpreter, beforeCommands, commands, TargetOS.LINUX.lineSeparator);
} }
public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, String command, TargetOS targetOS) { public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, List<String> commands, String commandSeparator) {
return scriptCommands(interpreter, beforeCommands, List.of(command), targetOS);
}
public static List<String> scriptCommands(List<String> interpreter, List<String> beforeCommands, List<String> commands, TargetOS targetOS) {
ArrayList<String> commandsArgs = new ArrayList<>(interpreter); ArrayList<String> commandsArgs = new ArrayList<>(interpreter);
commandsArgs.add( commandsArgs.add(
Stream Stream
@@ -166,7 +162,7 @@ public final class ScriptService {
ListUtils.emptyOnNull(beforeCommands).stream(), ListUtils.emptyOnNull(beforeCommands).stream(),
commands.stream() commands.stream()
) )
.collect(Collectors.joining(targetOS.lineSeparator)) .collect(Collectors.joining(commandSeparator))
); );
return commandsArgs; return commandsArgs;

View File

@@ -115,6 +115,12 @@ public abstract class AbstractExecScript extends Task implements NamespaceFilesI
@Deprecated @Deprecated
protected DockerOptions docker; protected DockerOptions docker;
@Schema(
title = "The separator to use between commands.",
description = "Defaults to OS line separator"
)
protected Property<String> commandsSeparator;
@Schema( @Schema(
title = "The task runner container image, only used if the task runner is container-based." title = "The task runner container image, only used if the task runner is container-based."
) )
@@ -165,6 +171,7 @@ public abstract class AbstractExecScript extends Task implements NamespaceFilesI
.withEnableOutputDirectory(runContext.render(this.getOutputDirectory()).as(Boolean.class).orElse(null)) .withEnableOutputDirectory(runContext.render(this.getOutputDirectory()).as(Boolean.class).orElse(null))
.withTimeout(runContext.render(this.getTimeout()).as(Duration.class).orElse(null)) .withTimeout(runContext.render(this.getTimeout()).as(Duration.class).orElse(null))
.withTargetOS(runContext.render(this.getTargetOS()).as(TargetOS.class).orElseThrow()) .withTargetOS(runContext.render(this.getTargetOS()).as(TargetOS.class).orElseThrow())
.withCommandsSeparator(runContext.render(this.getCommandsSeparator()).as(String.class).orElseThrow())
.withFailFast(runContext.render(this.getFailFast()).as(Boolean.class).orElse(false)); .withFailFast(runContext.render(this.getFailFast()).as(Boolean.class).orElse(false));
} }

View File

@@ -94,6 +94,9 @@ public class CommandsWrapper implements TaskCommands {
@With @With
private TargetOS targetOS; private TargetOS targetOS;
@With
private String commandsSeparator;
public CommandsWrapper(RunContext runContext) { public CommandsWrapper(RunContext runContext) {
this.runContext = runContext; this.runContext = runContext;
this.workingDirectory = runContext.workingDir().path(); this.workingDirectory = runContext.workingDir().path();
@@ -125,7 +128,8 @@ public class CommandsWrapper implements TaskCommands {
outputFiles, outputFiles,
enableOutputDirectory, enableOutputDirectory,
timeout, timeout,
targetOS targetOS,
commandsSeparator
); );
} }
@@ -172,7 +176,7 @@ public class CommandsWrapper implements TaskCommands {
renderedInterpreter, renderedInterpreter,
this.isBeforeCommandsWithOptions() ? getBeforeCommandsWithOptions(renderedBeforeCommands) : renderedBeforeCommands, this.isBeforeCommandsWithOptions() ? getBeforeCommandsWithOptions(renderedBeforeCommands) : renderedBeforeCommands,
renderedCommands, renderedCommands,
Optional.ofNullable(targetOS).orElse(TargetOS.AUTO) Optional.ofNullable(commandsSeparator).orElse(Optional.ofNullable(targetOS).orElse(TargetOS.AUTO).lineSeparator)
); );
this.commands = Property.ofValue(finalCommands); this.commands = Property.ofValue(finalCommands);
@@ -310,4 +314,4 @@ public class CommandsWrapper implements TaskCommands {
// errexit option may be unsupported by non-shell interpreter. // errexit option may be unsupported by non-shell interpreter.
return List.of("set -e"); return List.of("set -e");
} }
} }