[yocto] [eclipse][PATCH 2/4] plugins/cmake: Enable separate capturing of cmake stderr

Timo Mueller mail at timomueller.eu
Thu May 22 02:58:20 PDT 2014


From: Timo Mueller <timo.mueller at bmw-carit.de>

The error reported by CMake was logged to the console but not used in
any error dialog shown to the user so far.

By capturing the error in a separate stream we can use it when reproting
the error to the user.

Signed-off-by: Timo Mueller <timo.mueller at bmw-carit.de>
---
 .../cmake/managedbuilder/util/SystemProcess.java   | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java
index 764a1f6..9fe0ce1 100644
--- a/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java
+++ b/plugins/org.yocto.cmake.managedbuilder/src/org/yocto/cmake/managedbuilder/util/SystemProcess.java
@@ -24,6 +24,7 @@ public class SystemProcess {
 	private ProcessBuilder builder;
 	private Process process;
 	private StreamPipe outputRedirector;
+	private StreamPipe errorRedirector;
 
 	public SystemProcess(LinkedList<String> command) {
 		this(command, null);
@@ -47,7 +48,6 @@ public class SystemProcess {
 		if (workingDirectory != null) {
 			builder.directory(workingDirectory);
 		}
-		builder.redirectErrorStream(true);
 
 		if(additionalEnvironmentVariables != null && !additionalEnvironmentVariables.isEmpty()) {
 			builder.environment().putAll(additionalEnvironmentVariables);
@@ -56,11 +56,21 @@ public class SystemProcess {
 
 	public void start(OutputStream out) throws IOException {
 		if (builder != null) {
+			builder.redirectErrorStream(true);
 			process = builder.start();
 			outputRedirector = redirectOutput(process, out);
 		}
 	}
 
+	public void start(OutputStream out, OutputStream err) throws IOException {
+		if (builder != null) {
+			builder.redirectErrorStream(false);
+			process = builder.start();
+			outputRedirector = redirectOutput(process, out);
+			errorRedirector = redirectError(process, err, out);
+		}
+	}
+
 	public int waitForResultAndStop() throws InterruptedException {
 		if (process == null) {
 			return -1;
@@ -69,6 +79,10 @@ public class SystemProcess {
 		process.waitFor();
 		outputRedirector.interrupt();
 
+		if (!builder.redirectErrorStream()) {
+			errorRedirector.interrupt();
+		}
+
 		return process.exitValue();
 	}
 
@@ -76,6 +90,14 @@ public class SystemProcess {
 		process.destroy();
 	}
 
+	private StreamPipe redirectError(Process process, OutputStream errOut, OutputStream out) {
+		InputStream err = process.getErrorStream();
+		StreamPipe stderrPipe = new StreamPipe(err, errOut, out);
+		stderrPipe.start();
+
+		return stderrPipe;
+	}
+
 	private StreamPipe redirectOutput(Process process, OutputStream out) {
 		InputStream in = process.getInputStream();
 		StreamPipe stdoutPipe = new StreamPipe(in, out);
-- 
1.9.0




More information about the yocto mailing list