[java-idp-integration-tests] 02/02: Use ProcessBuilder instead of Runtime for CLI processes
Tom Zeller
tzeller at dragonacea.biz
Mon Feb 19 01:30:05 UTC 2024
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=7181cd800df22a58bbc684ce4816fce8d798d924
commit 7181cd800df22a58bbc684ce4816fce8d798d924
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Sun Feb 18 19:29:42 2024 -0600
Use ProcessBuilder instead of Runtime for CLI processes
Mostly for logging
---
.../idp/integration/tests/BaseIntegrationTest.java | 43 ++++++++++---------
.../integration/tests/plugins/BasePluginTest.java | 48 +++++++++++-----------
2 files changed, 49 insertions(+), 42 deletions(-)
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index 12d6338..73475eb 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -2419,15 +2419,17 @@ public abstract class BaseIntegrationTest {
*/
public void buildWAR() throws IOException {
- final String[] commands = new String[] {
- buildCLI,
+ final String[] commands = new String[] { //
+ buildCLI, //
"-Didp.target.dir=" + idpHome };
- final String logPrefix = "Build WAR :";
+ final Process process = new ProcessBuilder() //
+ .command(commands)
+ .directory(idpHome)
+ .redirectErrorStream(true)
+ .start();
- final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
-
- logProcess(process, logPrefix);
+ logProcess(process, "Build WAR :");
}
/**
@@ -2482,12 +2484,14 @@ public abstract class BaseIntegrationTest {
*/
public void enableModule(@Nonnull final String module) throws IOException {
- final String[] commands = new String[] {
- moduleCLI,
- "-e",
- module };
+ final String[] commands = new String[] { //
+ moduleCLI, //
+ "-e", module };
- final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+ final Process process = new ProcessBuilder() //
+ .command(commands)
+ .directory(idpHome)
+ .start();
logProcess(process, "module :");
}
@@ -2767,17 +2771,18 @@ public abstract class BaseIntegrationTest {
*/
public void reloadService(@Nonnull final String id) throws IOException {
- final String[] commands = new String[] {
- reloadServiceCLI,
- "-id",
- id,
- "--url",
- getBaseURL(false) + "/idp",
- };
+ final String[] commands = new String[] { //
+ reloadServiceCLI, //
+ "-id", id, //
+ "--url", getBaseURL(false) + "/idp" };
log.debug("Reloading service '{}' using command '{}'", id, commands);
- final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+ final Process process = new ProcessBuilder() //
+ .command(commands)
+ .directory(idpHome)
+ .redirectErrorStream(true)
+ .start();
logProcess(process, "reload-service :");
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
index fa01763..0fec929 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
@@ -172,7 +172,7 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
while ((line = reader.readLine()) != null) {
// line should be something like :
// Plugin net.shibboleth.idp.plugin.oidc.op: version 3.3.0 available for install
- log.trace("Available plugins {}", line);
+ log.trace("Available plugins : {}", line);
final String[] strings = line.split("\\s+");
// TODO line.matches(available for install)
@@ -198,24 +198,25 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
final Path pathToTruststore = pathToTruststores.resolve(plugin).resolve("truststore.asc").toAbsolutePath();
- Assert.assertTrue(pathToTruststore.toFile().exists(), "Path to truststore should exist " + pathToTruststore);
+ assert pathToTruststore.toFile().exists() : "Path to truststore " + pathToTruststore + "should exist";
final String truststore = pathToTruststore.toString();
- final String[] commands = new String[] {
- pluginCLI,
- "--noRebuild",
- "--noPrompt",
- "-I",
- plugin,
- "--truststore",
- truststore };
+ final String[] commands = new String[] { //
+ pluginCLI, //
+ "--noRebuild", //
+ "--noPrompt", //
+ "-I", plugin, //
+ "--truststore", truststore };
- final String logPrefix = "Installing " + plugin + " :";
+ log.debug("Install plugin '{}'", plugin);
- final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+ final Process process = new ProcessBuilder() //
+ .command(commands)
+ .directory(idpHome)
+ .start();
- logProcess(process, logPrefix);
+ logProcess(process, "Install plugin :");
}
/**
@@ -250,7 +251,7 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
while ((line = reader.readLine()) != null) {
// line should be something like :
// Plugin: net.shibboleth.idp.plugin.rhino Current Version: 1.0.0
- log.trace("Installed plugins {}", line);
+ log.trace("Installed plugins : {}", line);
final String[] strings = line.split("\\s+");
if (strings.length == 5) {
installedPlugins.add(strings[1]);
@@ -271,17 +272,18 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
*/
public void removePlugin(@Nonnull final String plugin) throws IOException {
- final String[] commands = new String[] {
- pluginCLI,
- "--noRebuild",
- "--noPrompt",
- "-r",
- plugin };
+ final String[] commands = new String[] { pluginCLI, //
+ "--noRebuild", //
+ "--noPrompt", //
+ "-r", plugin };
- final String logPrefix = "Removing " + plugin + " :";
+ log.debug("Remove plugin '{}'", plugin);
- final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+ final Process process = new ProcessBuilder() //
+ .command(commands)
+ .directory(idpHome)
+ .start();
- logProcess(process, logPrefix);
+ logProcess(process, "Remove plugin :");
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list