Resilience fixes

This commit is contained in:
crschnick 2023-08-03 17:33:34 +00:00
parent 56930c07a6
commit 454e8aea75

View file

@ -1,5 +1,7 @@
package io.xpipe.core.process; package io.xpipe.core.process;
import lombok.SneakyThrows;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -61,6 +63,10 @@ public class CommandBuilder {
public CommandBuilder addQuoted(String s) { public CommandBuilder addQuoted(String s) {
elements.add(sc -> { elements.add(sc -> {
if (s == null) {
return null;
}
if (sc == null) { if (sc == null) {
return "\"" + s + "\""; return "\"" + s + "\"";
} }
@ -102,6 +108,10 @@ public class CommandBuilder {
public CommandBuilder addFile(String s) { public CommandBuilder addFile(String s) {
elements.add(sc -> { elements.add(sc -> {
if (s == null) {
return null;
}
if (sc == null) { if (sc == null) {
return "\"" + s + "\""; return "\"" + s + "\"";
} }
@ -128,13 +138,17 @@ public class CommandBuilder {
return sc.command(this); return sc.command(this);
} }
@SneakyThrows
public String buildSimple() { public String buildSimple() {
return String.join(" ", elements.stream().map(element -> { List<String> list = new ArrayList<>();
try { for (Element element : elements) {
return element.evaluate(null); String evaluate = element.evaluate(null);
} catch (Exception e) { if (evaluate == null) {
throw new RuntimeException(e); continue;
} }
}).toList());
list.add(evaluate);
}
return String.join(" ", list);
} }
} }