+ * Creates a {@link PumpStreamHandler} which redirects streams to the custom
+ * logging mechanism.
+ */
+ protected ExecuteStreamHandler createExecuteStreamHandler(
+ final Writer stdOutWriter, final OutputStream stdOutputStream,
+ final Writer stdErrWriter, final InputStream stdInStream) {
+
+ // Log writers
+
+ PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
+ stdOutputStream != null ? stdOutputStream
+ : new LogOutputStream() {
+ protected void processLine(String line, int level) {
+ if (line != null && !line.trim().equals(""))
+ logStdOut(line);
+ if (stdOutWriter != null)
+ appendLineToFile(stdOutWriter, line);
+ }
+ }, new LogOutputStream() {
+ protected void processLine(String line, int level) {
+ if (line != null && !line.trim().equals(""))
+ logStdErr(line);
+ if (stdErrWriter != null)
+ appendLineToFile(stdErrWriter, line);
+ }
+ }, stdInStream) {
+
+ @Override
+ public void stop() {
+ // prevents the method to block when joining stdin
+ if (stdInSink != null)
+ IOUtils.closeQuietly(stdInSink);
+
+ super.stop();
+ }
+ };
+ return pumpStreamHandler;
+ }
+
+ /** Creates the default {@link ExecuteResultHandler}. */
+ protected ExecuteResultHandler createExecuteResultHandler(
+ final CommandLine commandLine) {
+ return new ExecuteResultHandler() {
+
+ public void onProcessComplete(int exitValue) {
+ String msg = "System call '" + commandLine
+ + "' properly completed.";
+ if (log.isTraceEnabled())
+ log.trace(msg);
+ if (testResult != null) {
+ forwardPath(testResult);
+ testResult.addResultPart(new SimpleResultPart(
+ TestStatus.PASSED, msg));
+ }
+ }
+
+ public void onProcessFailed(ExecuteException e) {
+ String msg = "System call '" + commandLine + "' failed.";
+ if (testResult != null) {
+ forwardPath(testResult);
+ testResult.addResultPart(new SimpleResultPart(
+ TestStatus.ERROR, msg, e));
+ } else {
+ if (exceptionOnFailed)
+ throw new SlcException(msg, e);
+ else
+ log.error(msg, e);
+ }
+ }
+ };
+ }
+
+ protected void forwardPath(TestResult testResult) {
+ // TODO: allocate a TreeSPath
+ }
+
+ /**
+ * Shortcut method getting the execDir to use