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