From ce770b032aafb0c2e2a86aab156eec182d679ad6 Mon Sep 17 00:00:00 2001 From: Joel Thibault Date: Wed, 9 Apr 2014 14:29:26 -0400 Subject: [PATCH] Move execAndCheck() to ProcessController --- .../utils/runtime/ProcessController.java | 20 +++++++++++++++++ .../commandline/LoggingIntegrationTest.java | 22 ++----------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/runtime/ProcessController.java b/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/runtime/ProcessController.java index 097362044..da7de61fe 100644 --- a/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/runtime/ProcessController.java +++ b/public/gatk-framework/src/main/java/org/broadinstitute/sting/utils/runtime/ProcessController.java @@ -29,6 +29,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.UserException; @@ -267,6 +268,25 @@ public class ProcessController { return new ProcessOutput(exitCode, stdout, stderr); } + /** + * Executes a command line program with the settings and waits for it to return, + * processing the output on a background thread. + * + * Throws an IOException if the ProcessOutput exit code is nonzero + * + * @param settings Settings to be run. + */ + public ProcessOutput execAndCheck(ProcessSettings settings) throws IOException { + ProcessOutput po = exec(settings); + if (po.getExitValue() != 0) { + String message = String.format("Process exited with %d\nCommand Line: %s", + po.getExitValue(), + Utils.join(" ", settings.getCommand())); + throw new IOException(message); + } + return po; + } + /** * @return The set of still running processes. */ diff --git a/public/gatk-framework/src/test/java/org/broadinstitute/sting/commandline/LoggingIntegrationTest.java b/public/gatk-framework/src/test/java/org/broadinstitute/sting/commandline/LoggingIntegrationTest.java index 6c8c9a473..fdf0ae0ea 100644 --- a/public/gatk-framework/src/test/java/org/broadinstitute/sting/commandline/LoggingIntegrationTest.java +++ b/public/gatk-framework/src/test/java/org/broadinstitute/sting/commandline/LoggingIntegrationTest.java @@ -40,7 +40,6 @@ import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.MD5DB; import org.broadinstitute.sting.MD5Mismatch; import org.broadinstitute.sting.gatk.CommandLineGATK; -import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.runtime.*; public class LoggingIntegrationTest { @@ -100,14 +99,14 @@ public class LoggingIntegrationTest { // output argument ProcessSettings ps = new ProcessSettings(cfg.getCmdLine(false).split("\\s+")); - execAndCheck(pc, ps); + pc.execAndCheck(ps); String output_argument_md5 = md5db.calculateFileMD5(cfg.argumentOutputFile); // pipe to stdout ps = new ProcessSettings(cfg.getCmdLine(true).split("\\s+")); ps.setStdoutSettings(new OutputStreamSettings(cfg.pipedOutputFile)); - execAndCheck(pc, ps); + pc.execAndCheck(ps); MD5DB.MD5Match result = md5db.testFileMD5("LoggingIntegrationTest", "LoggingIntegrationTest", cfg.pipedOutputFile, output_argument_md5, false); if(result.failed) { @@ -115,21 +114,4 @@ public class LoggingIntegrationTest { Assert.fail(failure.toString()); } } - - /** - * Execute a process, and throw an IOException if the exit code is nonzero - * - * @param pc - * @param ps - * @throws IOException - */ - private void execAndCheck(ProcessController pc, ProcessSettings ps) throws IOException { - ProcessOutput po = pc.exec(ps); - if (po.getExitValue() != 0) { - String message = String.format("Process exited with %d\nCommand Line: %s", - po.getExitValue(), - Utils.join(" ", ps.getCommand())); - throw new IOException(message); - } - } } \ No newline at end of file