##// END OF EJS Templates
WIP improved exec builder
cin -
r10:14be6b35c80a default
parent child
Show More
@@ -8,6 +8,7 import java.util.Objects;
8 8 import java.util.Optional;
9 9 import java.util.concurrent.CompletableFuture;
10 10 import java.util.stream.Stream;
11 import java.util.Collection;
11 12
12 13 import org.eclipse.jdt.annotation.NonNullByDefault;
13 14
@@ -31,22 +32,31 public abstract class ExecBuilder {
31 32 private RedirectTo errorRedirect;
32 33
33 34 /** Sets command line, clears previous one if any */
34 public void command(String cmd, String... args) {
35 public ExecBuilder command(String cmd, String... args) {
35 36 commandLine.clear();
36 37 commandLine.add(cmd);
37 38 Stream.of(args).forEach(commandLine::add);
39 return this;
40 }
41
42 public ExecBuilder command(Collection<String> cmd) {
43 this.commandLine.clear();
44 this.commandLine.addAll(cmd);
45 return this;
38 46 }
39 47
40 48 /** Adds an argument to the command line */
41 public void argument(String arg) {
49 public ExecBuilder argument(String arg) {
42 50 Objects.requireNonNull(arg, "arg parameter can't be null");
43 51 commandLine.add(arg);
52 return this;
44 53 }
45 54
46 55 /** Sets the working directory */
47 public void directory(File directory) {
56 public ExecBuilder directory(File directory) {
48 57 Objects.requireNonNull(directory, "directory parameter can't be null");
49 58 this.directory = directory;
59 return this;
50 60 }
51 61
52 62 /**
@@ -55,14 +65,24 public abstract class ExecBuilder {
55 65 * @param envVar The name of the environment variable
56 66 * @param value The value to set,
57 67 */
58 public void setEnvironment(String envVar, String value) {
68 public ExecBuilder setEnvironment(String envVar, String value) {
59 69 Objects.requireNonNull(value, "Value can't be null");
60 70 Objects.requireNonNull(envVar, "envVar parameter can't be null");
61 71 environment.put(envVar, value);
72 return this;
62 73 }
63 74
64 public void unsetEnvironment(String envVar) {
75 public ExecBuilder setEnvironment(Map<String, String> env) {
76 Objects.requireNonNull(env, "env parameter can't be null");
77
78 environment.clear();
79 environment.putAll(env);
80 return this;
81 }
82
83 public ExecBuilder unsetEnvironment(String envVar) {
65 84 environment.remove(envVar);
85 return this;
66 86 }
67 87
68 88 /**
@@ -72,27 +92,30 public abstract class ExecBuilder {
72 92 * <p>
73 93 * If redirection
74 94 */
75 public void stdin(RedirectFrom from) {
95 public ExecBuilder stdin(RedirectFrom from) {
76 96 Objects.requireNonNull(from, "from parameter can't be null");
77 97 inputRedirect = from;
98 return this;
78 99 }
79 100
80 101 /**
81 102 * Sets redirection for the stdout, {@link RedirectTo} will be applied
82 103 * every time the process is started.
83 104 */
84 public void stdout(RedirectTo out) {
105 public ExecBuilder stdout(RedirectTo out) {
85 106 Objects.requireNonNull(out, "out parameter can't be null");
86 107 outputRedirect = out;
108 return this;
87 109 }
88 110
89 111 /**
90 112 * Sets redirection for the stderr, {@link RedirectTo} will be applied
91 113 * every time the process is started.
92 114 */
93 public void stderr(RedirectTo err) {
115 public ExecBuilder stderr(RedirectTo err) {
94 116 Objects.requireNonNull(err, "err parameter can't be null");
95 117 errorRedirect = err;
118 return this;
96 119 }
97 120
98 121 /** Implement this function to */
General Comments 0
You need to be logged in to leave comments. Login now