1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 23:55:26 +02:00

fix for Bug 161773 - introducing IHostOutput

This commit is contained in:
David McKnight 2006-10-25 16:09:19 +00:00
parent c39ad5b393
commit 441fbea44f
14 changed files with 117 additions and 59 deletions

View file

@ -19,9 +19,12 @@ package org.eclipse.rse.internal.services.dstore.shell;
import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.extra.internal.extra.DomainEvent;
import org.eclipse.dstore.extra.internal.extra.IDomainListener;
import org.eclipse.rse.services.dstore.shells.DStoreHostOutput;
import org.eclipse.rse.services.shells.AbstractHostShellOutputReader;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellOutputReader;
import org.eclipse.rse.services.shells.SimpleHostOutput;
public class DStoreShellOutputReader extends AbstractHostShellOutputReader implements IHostShellOutputReader, IDomainListener
{
@ -45,7 +48,7 @@ public class DStoreShellOutputReader extends AbstractHostShellOutputReader imple
return pwd;
}
protected Object internalReadLine()
protected IHostOutput internalReadLine()
{
if (_status != null && _keepRunning)
{
@ -54,18 +57,18 @@ public class DStoreShellOutputReader extends AbstractHostShellOutputReader imple
while (newSize > _statusOffset)
{
DataElement line = _status.get(_statusOffset++);
String type = line.getType();
boolean isError = type.equals("error") || type.equals("stderr");
if (_isErrorReader && isError)
{
return line;
return new DStoreHostOutput(line);
}
else if (!_isErrorReader && !isError)
{
return line;
return new DStoreHostOutput(line);
}
}
@ -85,14 +88,14 @@ public class DStoreShellOutputReader extends AbstractHostShellOutputReader imple
if (!_isErrorReader)
{
DataElement dummyLine = _status.getDataStore().createObject(_status, "stdout", "");
return dummyLine;
return new DStoreHostOutput(dummyLine);
}
else
{
return null;
}
}
return "";
return new SimpleHostOutput("");
}
public boolean listeningTo(DomainEvent e)

View file

@ -0,0 +1,30 @@
package org.eclipse.rse.services.dstore.shells;
import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.rse.services.shells.IHostOutput;
public class DStoreHostOutput implements IHostOutput
{
private DataElement _element;
public DStoreHostOutput(DataElement element)
{
_element = element;
}
public String getString()
{
return _element.getName();
}
public DataElement getElement()
{
return _element;
}
public String toString()
{
return getString();
}
}

View file

@ -21,8 +21,10 @@ import java.io.IOException;
import org.eclipse.rse.services.local.Activator;
import org.eclipse.rse.services.shells.AbstractHostShellOutputReader;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellOutputReader;
import org.eclipse.rse.services.shells.SimpleHostOutput;
/**
* Listener to shell output. As io streams through, refresh events are sent out
@ -133,7 +135,7 @@ public class LocalShellOutputReader extends AbstractHostShellOutputReader implem
return theLine.toString();
}
*/
protected Object internalReadLine() {
protected IHostOutput internalReadLine() {
if (_reader == null) {
//Our workaround sets the stderr reader to null, so we never give any stderr output.
//TODO Check if ssh supports some method of having separate stdout and stderr streams
@ -232,7 +234,7 @@ public class LocalShellOutputReader extends AbstractHostShellOutputReader implem
String debugLine = theDebugLine.toString();
debugLine.compareTo(""); //$NON-NLS-1$
}
return theLine.toString();
return new SimpleHostOutput(theLine.toString());
}

View file

@ -21,8 +21,10 @@ import java.io.BufferedReader;
import java.io.IOException;
import org.eclipse.rse.services.shells.AbstractHostShellOutputReader;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellOutputReader;
import org.eclipse.rse.services.shells.SimpleHostOutput;
import org.eclipse.rse.services.ssh.Activator;
/**
@ -49,7 +51,7 @@ public class SshShellOutputReader extends AbstractHostShellOutputReader
getHostShell().isActive();
}
protected Object internalReadLine() {
protected IHostOutput internalReadLine() {
if (fReader == null) {
//Our workaround sets the stderr reader to null, so we never give any stderr output.
//TODO Check if ssh supports some method of having separate stdout and stderr streams
@ -150,7 +152,7 @@ public class SshShellOutputReader extends AbstractHostShellOutputReader
String debugLine = theDebugLine.toString();
debugLine.compareTo(""); //$NON-NLS-1$
}
return theLine.toString();
return new SimpleHostOutput(theLine.toString());
}
}

View file

@ -67,19 +67,11 @@ public abstract class AbstractHostShellOutputReader extends Thread implements I
public void handle()
{
Object line = internalReadLine();
IHostOutput line = internalReadLine();
if (line != null)
{
if (line instanceof String)
{
//if (lineStr.length() > 0)
addLine(line);
}
else
{
addLine(line);
}
addLine(line);
}
else
@ -89,7 +81,7 @@ public abstract class AbstractHostShellOutputReader extends Thread implements I
}
protected void addLine(Object line)
protected void addLine(IHostOutput line)
{
_linesOfOutput.add(line);
int sizenow = _linesOfOutput.size();
@ -108,19 +100,19 @@ public abstract class AbstractHostShellOutputReader extends Thread implements I
}
}
public Object readLine()
public IHostOutput readLine()
{
if (!isAlive())
{
internalReadLine();
start();
}
return _linesOfOutput.get(_consumerOffset++);
return (IHostOutput)_linesOfOutput.get(_consumerOffset++);
}
public Object readLine(int lineNumber)
public IHostOutput readLine(int lineNumber)
{
return _linesOfOutput.get(lineNumber);
return (IHostOutput)_linesOfOutput.get(lineNumber);
}
@ -191,6 +183,6 @@ public abstract class AbstractHostShellOutputReader extends Thread implements I
}
}
protected abstract Object internalReadLine();
protected abstract IHostOutput internalReadLine();
}

View file

@ -41,9 +41,9 @@ public class HostShellChangeEvent implements IHostShellChangeEvent
return _reader;
}
public Object[] getLines()
public IHostOutput[] getLines()
{
Object[] lines = new Object[_range];
IHostOutput[] lines = new IHostOutput[_range];
int r = 0;
int size = _offset + _range ;
for (int i= _offset; i < size; i++)
@ -54,7 +54,7 @@ public class HostShellChangeEvent implements IHostShellChangeEvent
return lines;
}
public Object[] getLineObjects()
public IHostOutput[] getLineObjects()
{
return getLines();
}

View file

@ -0,0 +1,6 @@
package org.eclipse.rse.services.shells;
public interface IHostOutput
{
public String getString();
}

View file

@ -20,6 +20,6 @@ public interface IHostShellChangeEvent
{
public IHostShell getHostShell();
public IHostShellOutputReader getReader();
public Object[] getLines();
public IHostOutput[] getLines();
public boolean isError();
}

View file

@ -18,8 +18,8 @@ package org.eclipse.rse.services.shells;
public interface IHostShellOutputReader extends IHostShellOutputNotifier
{
public Object readLine();
public Object readLine(int index);
public IHostOutput readLine();
public IHostOutput readLine(int index);
public void addOutputListener(IHostShellOutputListener listener);
public boolean isErrorReader();
public void finish();

View file

@ -0,0 +1,20 @@
package org.eclipse.rse.services.shells;
public class SimpleHostOutput implements IHostOutput
{
private String _line;
public SimpleHostOutput(String line)
{
_line = line;
}
public String getString()
{
return _line;
}
public String toString()
{
return _line;
}
}

View file

@ -20,8 +20,10 @@ import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefresh
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteCommandShell;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.services.shells.SimpleHostOutput;
import org.eclipse.rse.subsystems.shells.core.ShellStrings;
import org.eclipse.rse.subsystems.shells.core.subsystems.ICandidateCommand;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
@ -59,33 +61,30 @@ public class ServiceCommandShell extends RemoteCommandShell implements IServiceC
public void shellOutputChanged(IHostShellChangeEvent event)
{
Object[] lines = event.getLines();
IHostOutput[] lines = event.getLines();
IRemoteOutput[] outputs = new IRemoteOutput[lines.length];
for (int i = 0; i < lines.length; i++)
{
RemoteOutput output = null;
Object lineObj = lines[i];
if (lineObj instanceof String)
IHostOutput lineObj = lines[i];
if (lineObj instanceof SimpleHostOutput)
{
String line = (String)lineObj;
if (line != null)
SimpleHostOutput line = (SimpleHostOutput)lineObj;
String type = event.isError() ? "stderr" : "stdout";
if (event.isError())
{
String type = event.isError() ? "stderr" : "stdout";
if (event.isError())
{
output = new RemoteError(this, type);
}
else
{
output = new RemoteOutput(this, type);
}
output.setText(line);
addOutput(output);
outputs[i] = output;
output = new RemoteError(this, type);
}
else
{
output = new RemoteOutput(this, type);
}
String str = line.getString();
output.setText(str);
addOutput(output);
outputs[i] = output;
}
}
if (_lastRefreshJob == null || _lastRefreshJob.isComplete())

View file

@ -21,7 +21,9 @@ import org.eclipse.rse.internal.services.dstore.shell.DStoreShellOutputReader;
import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput;
import org.eclipse.rse.services.dstore.shells.DStoreHostOutput;
import org.eclipse.rse.services.dstore.shells.DStoreHostShell;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
@ -57,15 +59,15 @@ public class DStoreServiceCommandShell extends ServiceCommandShell
public void shellOutputChanged(IHostShellChangeEvent event)
{
Object[] lines = event.getLines();
IHostOutput[] lines = event.getLines();
IRemoteOutput[] outputs = new IRemoteOutput[lines.length];
for (int i = 0; i < lines.length; i++)
{
RemoteOutput output = null;
Object lineObj = lines[i];
if (lineObj instanceof DataElement)
if (lineObj instanceof DStoreHostOutput)
{
DataElement line = (DataElement)lineObj;
DataElement line = ((DStoreHostOutput)lineObj).getElement();
String type = line.getType();
String src = line.getSource();
if (event.isError())

View file

@ -23,6 +23,7 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.services.shells.ParsedOutput;
@ -74,11 +75,11 @@ public class LocalServiceCommandShell extends ServiceCommandShell
public void shellOutputChanged(IHostShellChangeEvent event)
{
Object[] lines = event.getLines();
IHostOutput[] lines = event.getLines();
IRemoteOutput[] outputs = new IRemoteOutput[lines.length];
for (int i = 0; i < lines.length; i++)
{
String line = (String)lines[i];
String line = lines[i].getString();
ParsedOutput parsedMsg = null;
try

View file

@ -25,6 +25,7 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.internal.subsystems.shells.servicesubsystem.OutputRefreshJob;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteError;
import org.eclipse.rse.internal.subsystems.shells.subsystems.RemoteOutput;
import org.eclipse.rse.services.shells.IHostOutput;
import org.eclipse.rse.services.shells.IHostShell;
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
import org.eclipse.rse.services.shells.ParsedOutput;
@ -77,12 +78,12 @@ public class SshServiceCommandShell extends ServiceCommandShell implements ISyst
public void shellOutputChanged(IHostShellChangeEvent event)
{
Object[] lines = event.getLines();
IHostOutput[] lines = event.getLines();
boolean gotCommand = false;
ArrayList outputs = new ArrayList(lines.length);
for (int i = 0; i < lines.length; i++)
{
String line = (String)lines[i];
String line = lines[i].getString();
if (line.endsWith(getPromptCommand())) {
continue; //ignore our synthetic prompt command
}