Skip to content

Commit 2a47b28

Browse files
committed
Replace deprecated call to exec
1 parent ef80869 commit 2a47b28

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/test/java/io/jenkins/plugins/util/IntegrationTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,18 @@ protected void makeFileUnreadable(final String absolutePath) {
746746

747747
private void setAccessModeOnWindows(final String path, final String command, final String accessMode) {
748748
try {
749-
var process = Runtime.getRuntime()
750-
.exec("icacls \"" + path + "\" " + command + " *S-1-1-0:" + accessMode);
751-
process.waitFor();
749+
var process = new ProcessBuilder("icacls",
750+
path, command, "*S-1-1-0:" + accessMode)
751+
.redirectErrorStream(true)
752+
.start();
753+
var exitCode = process.waitFor();
754+
if (exitCode != 0) {
755+
String output;
756+
try (var in = process.getInputStream()) {
757+
output = new String(in.readAllBytes(), StandardCharsets.UTF_8);
758+
}
759+
throw new AssertionError("icacls failed with exit code " + exitCode + ": " + output);
760+
}
752761
}
753762
catch (IOException | InterruptedException e) {
754763
throw new AssertionError(e);

0 commit comments

Comments
 (0)