Skip to content

Commit bc4a268

Browse files
committed
Add support for environment variables into ProcessRunner so that MavenRunner's support for remote debug works again.
1 parent b314a01 commit bc4a268

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

lib/src/main/java/com/diffplug/spotless/ProcessRunner.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.charset.StandardCharsets;
2525
import java.util.Arrays;
2626
import java.util.List;
27+
import java.util.Map;
2728
import java.util.concurrent.ExecutionException;
2829
import java.util.concurrent.ExecutorService;
2930
import java.util.concurrent.Executors;
@@ -57,18 +58,18 @@ public Result shell(String cmd) throws IOException, InterruptedException {
5758

5859
/** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */
5960
public Result shellWinUnix(String cmdWin, String cmdUnix) throws IOException, InterruptedException {
60-
return shellWinUnix(null, cmdWin, cmdUnix);
61+
return shellWinUnix(null, null, cmdWin, cmdUnix);
6162
}
6263

6364
/** Executes the given shell command (using {@code cmd} on windows and {@code sh} on unix). */
64-
public Result shellWinUnix(File cwd, String cmdWin, String cmdUnix) throws IOException, InterruptedException {
65+
public Result shellWinUnix(File cwd, Map<String, String> environment, String cmdWin, String cmdUnix) throws IOException, InterruptedException {
6566
List<String> args;
6667
if (FileSignature.machineIsWin()) {
6768
args = Arrays.asList("cmd", "/c", cmdWin);
6869
} else {
6970
args = Arrays.asList("sh", "-c", cmdUnix);
7071
}
71-
return exec(cwd, args);
72+
return exec(cwd, environment, new byte[0], args);
7273
}
7374

7475
/** Creates a process with the given arguments. */
@@ -83,25 +84,23 @@ public Result exec(byte[] stdin, String... args) throws IOException, Interrupted
8384

8485
/** Creates a process with the given arguments. */
8586
public Result exec(List<String> args) throws IOException, InterruptedException {
86-
return exec((File) null, args);
87-
}
88-
89-
/** Creates a process with the given arguments. */
90-
public Result exec(File cwd, List<String> args) throws IOException, InterruptedException {
91-
return exec(cwd, new byte[0], args);
87+
return exec(null, args);
9288
}
9389

9490
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
9591
public Result exec(byte[] stdin, List<String> args) throws IOException, InterruptedException {
96-
return exec(null, stdin, args);
92+
return exec(null, null, stdin, args);
9793
}
9894

9995
/** Creates a process with the given arguments, the given byte array is written to stdin immediately. */
100-
public Result exec(File cwd, byte[] stdin, List<String> args) throws IOException, InterruptedException {
96+
public Result exec(File cwd, Map<String, String> environment, byte[] stdin, List<String> args) throws IOException, InterruptedException {
10197
ProcessBuilder builder = new ProcessBuilder(args);
10298
if (cwd != null) {
10399
builder.directory(cwd);
104100
}
101+
if (environment != null) {
102+
builder.environment().putAll(environment);
103+
}
105104
Process process = builder.start();
106105
Future<byte[]> outputFut = threadStdOut.submit(() -> drainToBytes(process.getInputStream(), bufStdOut));
107106
Future<byte[]> errorFut = threadStdErr.submit(() -> drainToBytes(process.getErrorStream(), bufStdErr));

plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private ProcessRunner.Result run() throws IOException, InterruptedException {
6969
Objects.requireNonNull(args, "Need to call withArguments() first");
7070
// run maven with the given args in the given directory
7171
String argsString = "-e " + String.join(" ", Arrays.asList(args));
72-
return runner.shellWinUnix(projectDir, "mvnw " + argsString, "./mvnw " + argsString);
72+
return runner.shellWinUnix(projectDir, environment, "mvnw " + argsString, "./mvnw " + argsString);
7373
}
7474

7575
/** Runs the command and asserts that exit code is 0. */

0 commit comments

Comments
 (0)