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

View File

@@ -115,6 +115,12 @@ public abstract class AbstractExecScript extends Task implements NamespaceFilesI
@Deprecated
protected DockerOptions docker;
@Schema(
title = "The separator to use between commands.",
description = "Defaults to OS line separator"
)
protected Property<String> commandsSeparator;
@Schema(
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))
.withTimeout(runContext.render(this.getTimeout()).as(Duration.class).orElse(null))
.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));
}

View File

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