Skip to contentSkip to conversation

Adapt API to RSE API local patch change

PATCH New Ioana Grigoropol 1 participant 1 message Feb 1, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Adapt API to RSE API local patch change

- make a single point change to output processing after running a command
- read output from remote commands using IHostShell interface

---
 .../org/yocto/bc/remote/utils/CommandRunnable.java |   58 +------------------
 .../org/yocto/bc/remote/utils/RemoteHelper.java    |   61 ++++++++++++++++++++
 .../org/yocto/bc/remote/utils/RemoteMachine.java   |   59 +------------------
 .../bc/remote/utils/YoctoRunnableWithProgress.java |   61 +-------------------
 4 files changed, 68 insertions(+), 171 deletions(-)
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/CommandRunnable.java +3 -55
index 98c3758..7406f50 100644
@@ -1,11 +1,13 @@
 package org.yocto.bc.remote.utils;
 
 import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.util.concurrent.locks.Lock;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.services.shells.HostShellProcessAdapter;
 import org.eclipse.rse.services.shells.IHostShell;
 
 public class CommandRunnable implements Runnable{
@@ -26,7 +28,7 @@ public class CommandRunnable implements Runnable{
 	public void run() {
 		try {
 			hostShell = RemoteHelper.runCommandRemote(connection, cmd, monitor);
-			cmd.setProcessBuffer(processOutput());
+			cmd.setProcessBuffer(RemoteHelper.processOutput(monitor, hostShell, cmdHandler, new char[]{'\n'}));
 		} catch (CoreException e) {
 			e.printStackTrace();
 		} catch (Exception e) {
@@ -34,58 +36,4 @@ public class CommandRunnable implements Runnable{
 		}
 	}
 
-	private ProcessStreamBuffer processOutput() throws Exception {
-		if (hostShell == null)
-			throw new Exception("An error has occured while trying to run remote command!");
-
-		Lock lock = hostShell.getStandardOutputReader().getReaderLock();
-		lock.lock();
-		ProcessStreamBuffer processBuffer = new ProcessStreamBuffer();
-		BufferedReader inbr = hostShell.getStandardOutputReader().getReader();
-		BufferedReader errbr = hostShell.getStandardErrorReader().getReader();
-		boolean cancel = false;
-		while (!cancel) {
-			if(monitor.isCanceled()) {
-				cancel = true;
-				lock.unlock();
-				throw new InterruptedException("User Cancelled");
-			}
-			StringBuffer buffer = new StringBuffer();
-			int c;
-			if (errbr != null)
-			while ((c = errbr.read()) != -1) {
-				char ch = (char) c;
-				buffer.append(ch);
-				if (ch == '\n'){
-					String str = buffer.toString();
-					processBuffer.addErrorLine(str);
-					System.out.println(str);
-					if (str.trim().equals(RemoteHelper.TERMINATOR)) {
-						break;
-					}
-					cmdHandler.response(str, true);
-					buffer.delete(0, buffer.length());
-				}
-			}
-			if (inbr != null)
-			while ((c = inbr.read()) != -1) {
-				char ch = (char) c;
-				buffer.append(ch);
-				if (ch == '\n'){
-					String str = buffer.toString();
-					processBuffer.addOutputLine(str);
-					System.out.println(str);
-					if (str.trim().equals(RemoteHelper.TERMINATOR)) {
-						break;
-					}
-					cmdHandler.response(str, false);
-					buffer.delete(0, buffer.length());
-				}
-			}
-			cancel = true;
-		}
-		lock.unlock();
-		return processBuffer;
-	}
-
 }
plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteHelper.java +61 -0

85 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/RemoteMachine.java +3 -56

93 lines not on this page · raw message

plugins/org.yocto.bc.ui/src/org/yocto/bc/remote/utils/YoctoRunnableWithProgress.java +1 -60

80 lines not on this page · raw message

Signature · 1 line
1.7.9.5