diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataElement.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataElement.java index e383df38689..defa3f9c0b5 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataElement.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataElement.java @@ -460,6 +460,8 @@ public final class DataElement implements IDataElement */ public String getAttribute(int attributeIndex) { + if (_attributes == null) + return ""; return _attributes[attributeIndex]; } diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java index c2e3b02b997..f6c143f40d5 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java @@ -1226,7 +1226,10 @@ public final class DataStore parent.addNestedData(newObject, false); } - _hashMap.put(id, newObject); + synchronized (_hashMap) + { + _hashMap.put(id, newObject); + } if (_autoRefresh) refresh(parent); @@ -1326,7 +1329,10 @@ public final class DataStore _relDescriptorMap.put(attributes[DE.A_NAME], newObject); } - _hashMap.put(attributes[DE.A_ID], newObject); + synchronized (_hashMap) + { + _hashMap.put(attributes[DE.A_ID], newObject); + } return newObject; } @@ -2467,6 +2473,10 @@ public final class DataStore flush(_hostRoot); flush(_minerRoot); flush(_tempRoot); + flush(_descriptorRoot); + flush(_dummy); + flush(_root); + } /** @@ -3768,8 +3778,15 @@ public final class DataStore } String id = toDelete.getAttribute(DE.A_ID); - _hashMap.remove(id); + synchronized (_hashMap) + { + _hashMap.remove(id); + } + if (!isConnected()) + { + from.removeNestedData(toDelete); + } } } @@ -3945,7 +3962,9 @@ public final class DataStore { // dy: the call to flush deletes all the elements in the tree // which causes havoc for iSeries caching when switching between offline / online - //flush(); + if (isVirtual()) + flush(); + if (_tracingOn) { diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/CommandMinerThread.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/CommandMinerThread.java index 2260685cc8e..70e99d1d6d1 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/CommandMinerThread.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/CommandMinerThread.java @@ -99,8 +99,10 @@ public class CommandMinerThread extends MinerThread _patterns = thePatterns; _patterns.refresh(_invocation); + + boolean isZ = theOS.toLowerCase().startsWith("z");//$NON-NLS-1$ - if (theOS.toLowerCase().startsWith("z")) //$NON-NLS-1$ + if (isZ) { System.setProperty("dstore.stdin.encoding","Cp037"); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -113,11 +115,12 @@ public class CommandMinerThread extends MinerThread try { + String userHome = System.getProperty("user.home");//$NON-NLS-1$ _cwdStr = theElement.getSource(); if (_cwdStr == null || _cwdStr.length() == 0) { - _cwdStr = System.getProperty("user.home"); //$NON-NLS-1$ + _cwdStr = userHome; } File theDirectory = new File(_cwdStr); @@ -129,10 +132,13 @@ public class CommandMinerThread extends MinerThread } catch (Exception e) { - _cwdStr = System.getProperty("user.home"); //$NON-NLS-1$ + _cwdStr = userHome; } _status.setAttribute(DE.A_SOURCE, _cwdStr); + + boolean didLogin = false; + String theShell = null; if (!_isWindows) { @@ -151,15 +157,30 @@ public class CommandMinerThread extends MinerThread String property = "SHELL="; //$NON-NLS-1$ String[] env = getEnvironment(_subject); + boolean isBash = false; + boolean isBashonZ = false; + boolean isSHonZ = false; + for (int i = 0; i < env.length; i++) { String var = env[i]; if (var.startsWith(property)) { theShell = var.substring(property.length(), var.length()); - if (theShell.endsWith("bash")) //$NON-NLS-1$ + if (theShell.endsWith("bash"))//$NON-NLS-1$ { - theShell = "sh"; //$NON-NLS-1$ + if (isZ) + { + isBashonZ = true; + } + else + { + isBash = true; + } + } + else if (theShell.endsWith("sh") && isZ)//$NON-NLS-1$ + { + isSHonZ = true; } } } @@ -171,13 +192,33 @@ public class CommandMinerThread extends MinerThread { _invocation = "sh"; //$NON-NLS-1$ _isShell = true; + if (isZ) + isSHonZ = true; } if (_isTTY) { - String args[] = new String[2]; - args[0] = PSEUDO_TERMINAL; - args[1] = _invocation; - _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + if (isSHonZ) + { + String args[] = new String[3]; + args[0] = PSEUDO_TERMINAL; + args[1] = _invocation; + args[2] = "-L"; //$NON-NLS-1$ + + try { + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + catch (Exception e) { + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } + didLogin = true; + } + else + { + String args[] = new String[2]; + args[0] = PSEUDO_TERMINAL; + args[1] = _invocation; + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } } else { @@ -192,10 +233,40 @@ public class CommandMinerThread extends MinerThread _isShell = true; - if (_isTTY) { String args[] = null; + if (isBashonZ) + { + args = new String[5]; + args[0] = PSEUDO_TERMINAL; + args[1] = "-w"; //$NON-NLS-1$ + args[2] = "256"; //$NON-NLS-1$ + args[3] = _invocation; + args[4] = "--login"; //$NON-NLS-1$ + didLogin = true; + } + else if (isBash) + { + args = new String[5]; + args[0] = PSEUDO_TERMINAL; + args[1] = "-w"; //$NON-NLS-1$ + args[2] = "256"; //$NON-NLS-1$ + args[3] = _invocation; + args[4] = "-l"; //$NON-NLS-1$ + didLogin = true; + } + else if (isSHonZ) + { + args = new String[5]; + args[0] = PSEUDO_TERMINAL; + args[1] = "-w"; //$NON-NLS-1$ + args[2] = "256"; //$NON-NLS-1$ + args[3] = _invocation; + args[4] = "-L"; //$NON-NLS-1$ + didLogin = true; + } + else { args = new String[4]; args[0] = PSEUDO_TERMINAL; @@ -204,12 +275,35 @@ public class CommandMinerThread extends MinerThread args[3] = _invocation; } - - _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + try { + _theProcess = Runtime.getRuntime().exec(args, env, theDirectory); + } + catch (Exception e) { + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } + } else { - _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + if (isBashonZ) + { + _theProcess = Runtime.getRuntime().exec(_invocation + " --login", env, theDirectory); //$NON-NLS-1$ + didLogin = true; + } + else if (isBash) + { + _theProcess = Runtime.getRuntime().exec(_invocation + " -l", env, theDirectory); //$NON-NLS-1$ + didLogin = true; + } + else if (isSHonZ) + { + _theProcess = Runtime.getRuntime().exec(_invocation + " -L", env, theDirectory); //$NON-NLS-1$ + didLogin = true; + } + else + { + _theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); + } } } else @@ -317,6 +411,51 @@ public class CommandMinerThread extends MinerThread _stdOutput = new BufferedWriter(new OutputStreamWriter(output)); } + createObject("command", _invocation); //$NON-NLS-1$ + createObject("stdout", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + status.setAttribute(DE.A_NAME, "progress"); //$NON-NLS-1$ + _dataStore.update(status); + _dataStore.disconnectObjects(status); + + _stdOutputHandler = new OutputHandler(_stdInput, null, _isWindows || _isTTY, false, _isShell, this); + _stdOutputHandler.setWaitTime(100); + _stdOutputHandler.start(); + + _stdErrorHandler = new OutputHandler(_stdError, null, _isWindows || _isTTY, true, _isShell, this); + _stdErrorHandler.setWaitTime(100); + _stdErrorHandler.start(); + + if (didLogin && !userHome.equals(_cwdStr)) + { + // need to CD to the correct directory + final String cdCmd = "cd " + _cwdStr; //$NON-NLS-1$ + Thread cdThread = new Thread( + new Runnable() + { + public void run() + { + // wait a second so the profile can complete startup + try + { + sleep(1000); + } + catch (Exception e) + { + + } + sendInput(cdCmd); + } + }); + cdThread.start(); + + } + else if (_isShell && !_isWindows && !_isTTY) + { + createPrompt(_cwdStr +">", _cwdStr); //$NON-NLS-1$ + refreshStatus(); + } + } catch (IOException e) { @@ -327,29 +466,6 @@ public class CommandMinerThread extends MinerThread return; } - createObject("command", _invocation); //$NON-NLS-1$ - createObject("stdout", ""); //$NON-NLS-1$ //$NON-NLS-2$ - - - - if (_isShell && !_isWindows && !_isTTY) - { - createPrompt(_cwdStr +">", _cwdStr); //$NON-NLS-1$ - //createObject("prompt", _cwdStr + ">"); - } - - status.setAttribute(DE.A_NAME, "progress"); //$NON-NLS-1$ - _dataStore.update(status); - _dataStore.disconnectObjects(status); - _stdOutputHandler = new OutputHandler(_stdInput, null, _isWindows || _isTTY, false, _isShell, this); - _stdOutputHandler.setWaitTime(10); - _stdOutputHandler.start(); - _stdErrorHandler = new OutputHandler(_stdError, null, _isWindows || _isTTY, true, _isShell, this); - _stdErrorHandler.setWaitTime(10); - _stdErrorHandler.start(); - - getCurrentProccesses(); - queryCWD(); } @@ -417,20 +533,7 @@ public class CommandMinerThread extends MinerThread } - private void getCurrentProccesses() - { - if (!_isWindows) - { - /* - if (_processTracker == null) - { - _processTracker = new ProcessTracker(); - _processTracker.start(); - } - _processTracker.doUpdate(); - */ - } - } + public void sendBreak() { @@ -535,8 +638,6 @@ public class CommandMinerThread extends MinerThread } } } - - _stdOutputHandler.newCommand(); } catch (IOException e) { @@ -862,7 +963,7 @@ public class CommandMinerThread extends MinerThread else { exitcode = _theProcess.exitValue(); - createObject("prompt", "> Shell Completed (exit code = " + exitcode + ")"); + createObject("prompt", "> Shell Completed (exit code = " + exitcode + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } catch (IllegalThreadStateException e) @@ -879,7 +980,7 @@ public class CommandMinerThread extends MinerThread _stdInput.close(); _stdError.close(); - _status.setAttribute(DE.A_NAME, "done"); + _status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ _dataStore.refresh(_status); // disconnecting all @@ -888,7 +989,7 @@ public class CommandMinerThread extends MinerThread // clean up the associated environment - List projectEnvReference = _subject.getAssociated("inhabits"); + List projectEnvReference = _subject.getAssociated("inhabits"); //$NON-NLS-1$ if (projectEnvReference != null) { @@ -905,88 +1006,131 @@ public class CommandMinerThread extends MinerThread } } + public void interpretLine(String line, boolean stdError) { - // for prompting - if (line.startsWith("1) { - // special processing - String statement = line.substring(1); - String pair[] = statement.split("="); //$NON-NLS-1$ -// String key = pair[0]; - String value = pair[1]; - _status.setAttribute(DE.A_SOURCE, value); - - return; - } - if (line.indexOf("echo '<'PWD=$PWD") > 0) //$NON-NLS-1$ - { - // ignore this line - return; - } - - ParsedOutput parsedMsg = null; - - try - { - parsedMsg = _patterns.matchLine(removeWhitespace(line)); - } - catch (Throwable e) - { - e.printStackTrace(); - } - - if (parsedMsg == null) - { - - if (stdError) + int beg=0; + int end=maxLine; + for(int i=0;iline.length()) + { + lines[i]=line.substring(beg); + } + else + { + lines[i]=line.substring(beg,end); + } + beg=end; + end=end+maxLine; + //} + //catch(Exception e) + //{ + // createObject(_descriptors._stdout, "<> line:= " + num + " beg : " + beg + " end = " + end); + // return; + //} + } + } + else + { + lines[0]=line; + } + + for(int i=0;i 0) //$NON-NLS-1$ + { + // ignore this line } else { - createObject(_descriptors._stdout, line); - } - } - else - { - try - { - String fileName = parsedMsg.file; -// DataElement object = null; - if (parsedMsg.type.equals("prompt")) //$NON-NLS-1$ + ParsedOutput parsedMsg = null; + + try { - File promptFile = new File(fileName); - if (promptFile.exists()) + parsedMsg = _patterns.matchLine(removeWhitespace(line)); + } + catch (Throwable e) + { + e.printStackTrace(); + } + if (parsedMsg == null) + { + if (stdError) { - createPrompt(line, fileName); + createObject(_descriptors._stderr, line); } else { createObject(_descriptors._stdout, line); } } - else if (parsedMsg.type.equals("file")) //$NON-NLS-1$ - { -// object = createObject(parsedMsg.type, line, fileName, null); - createObject(parsedMsg.type, line, fileName, null); - } else - { -// object = createObject(parsedMsg.type, line, fileName, new Integer(parsedMsg.line)); - createObject(parsedMsg.type, line, fileName, new Integer(parsedMsg.line)); + { + try + { + String fileName = parsedMsg.file; + DataElement object = null; + if (parsedMsg.type.equals("prompt")) + { + if (fileName.contains("~")) + { + String userHome = System.getProperty("user.home"); + fileName = fileName.replace("~", userHome); + } + + File promptFile = new File(fileName); + if (promptFile.exists()) + { + createPrompt(line, fileName); + } + else + { + createObject(_descriptors._stdout, line); + } + } + else if (parsedMsg.type.equals("file")) + { + object = createObject(parsedMsg.type, line, fileName, null); + } + else + { + object = createObject(parsedMsg.type, line, fileName, new Integer(parsedMsg.line)); + } + } + catch (NumberFormatException e) + { + e.printStackTrace(); + } } - - } - catch (NumberFormatException e) - { - e.printStackTrace(); } } + // moving this to do refresh after serious of lines interpretted + //refreshStatus(); } - + public void refreshStatus() { _dataStore.refresh(_status); diff --git a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/OutputHandler.java b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/OutputHandler.java index bd4b9c5eab7..1f6794c6b43 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/OutputHandler.java +++ b/rse/plugins/org.eclipse.rse.services.dstore/miners/org/eclipse/rse/internal/dstore/universal/miners/command/OutputHandler.java @@ -29,372 +29,262 @@ import org.eclipse.dstore.core.model.Handler; * The OutputHandler class is used to listen to a particular output or error stream, * interpret that information and create DataElements for it for use on the client. */ -public class OutputHandler extends Handler -{ +/** + * The OutputHandler class is used to listen to a particular output or error + * stream, interpret that information and create DataElements for it for use on + * the client. + */ +public class OutputHandler extends Handler { + private DataInputStream _reader; private boolean _isStdError; + private boolean _isTerminal; private CommandMinerThread _commandThread; + private boolean _isShell; -// private static int MAX_OFFSET = 10000; + + + private static int MAX_OFFSET = 10000; + private boolean _endOfStream = false; - - + private List _encodings; - - public OutputHandler(DataInputStream reader, String qualifier, boolean isTerminal, boolean isStdError, boolean isShell, CommandMinerThread commandThread) - { + public OutputHandler(DataInputStream reader, String qualifier, + boolean isTerminal, boolean isStdError, boolean isShell, + CommandMinerThread commandThread) { _reader = reader; _isStdError = isStdError; _isTerminal = isTerminal; _commandThread = commandThread; _isShell = isShell; + _encodings = new ArrayList(); String system = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ - - if (system.startsWith("z")) //$NON-NLS-1$ - { + + if (system.startsWith("z")) { //$NON-NLS-1$ _encodings.add("IBM-1047"); //$NON-NLS-1$ /* - _encodings.add("Cp1047"); - _encodings.add("Cp037"); - _encodings.add("UTF8"); - */ + * _encodings.add("Cp1047"); _encodings.add("Cp037"); + * _encodings.add("UTF8"); + */ + } else { + String specialEncoding = System + .getProperty("dstore.stdin.encoding"); //$NON-NLS-1$ + if (specialEncoding != null) { + _encodings.add(specialEncoding); + } + _encodings.add(System.getProperty("file.encoding")); //$NON-NLS-1$ } - else - { - String specialEncoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$ - if (specialEncoding != null) - { - _encodings.add(specialEncoding); - } - _encodings.add(System.getProperty("file.encoding")); //$NON-NLS-1$ - } - + } - public void newCommand() - { - } - public void handle() - { - String[] lines = readLines(); - if (lines != null) - { - - /* - if (lines.length == 0) - { - _reader. - } - - // don't do anything unless we require output - if (_newCommand && !_isTerminal) - { - doPrompt(); - } - } - else - */ - for (int i = 0; i < lines.length; i++) - { - String line = lines[i]; + + public void handle() { + String[] lines = readLines(); + if (lines != null) { + + /* + * if (lines.length == 0) { _reader. } + * // don't do anything unless we require output if (_newCommand && + * !_isTerminal) { doPrompt(); } } else + */ + for (int i = 0; i < lines.length; i++) { + String line = lines[i]; _commandThread.interpretLine(line, _isStdError); } + if (!_isTerminal) - doPrompt(); - + doPrompt(); + _commandThread.refreshStatus(); - } - else - { + } else { finish(); } } - private void doPrompt() - { - try - { - if ((_reader.available() == 0) && !_isStdError && _isShell) - { - if (!_isTerminal) - { - try - { + private void doPrompt() { + try { + if ((_reader.available() == 0) && !_isStdError && _isShell) { + if (!_isTerminal) { + try { Thread.sleep(500); - if (_reader.available() == 0) - { - // create fake prompt - _commandThread.createPrompt(_commandThread.getCWD() + '>', _commandThread.getCWD()); + if (_reader.available() == 0) { + // create fake prompt + _commandThread.createPrompt( + _commandThread.getCWD() + '>', + _commandThread.getCWD()); } - } - catch (Exception e) - { + } catch (Exception e) { } } } - } - catch (IOException e) - { + } catch (IOException e) { e.printStackTrace(); } } - - public synchronized void waitForInput() - { + + + private int checkAvailable() { try { - Thread.sleep(100); + int available = _reader.available(); + + // if there's none, wait a bit and return true to continue + if (available <= 0) { + sleep(100); + available = _reader.available(); + } + return available; } catch (Exception e) - { - + { } + return 0; } - - - private String[] readLines() - { - if (_endOfStream) - { + + private String[] readLines() { + if (_endOfStream) { return null; } - String[] output = null; - - try - { - - // find out how many bytes are available to be read - int available = _reader.available(); - int lookahead = 0; - - // if there's none, wait a bit and return true to continue - if (available <= 0) - { - sleep(100); - available = _reader.available(); + String[] output = null; - if (available == 0) - { + try { + + // find out how many bytes are available to be read + int available = checkAvailable(); + + int lookahead = 0; + + // redetermine available if none available now + if (available == 0) { lookahead = _reader.read(); - if (lookahead == -1) - { + if (lookahead == -1) { return null; - } - else - { + } else { available = _reader.available() + 1; } } - } - - byte[] readBytes = new byte[available]; - // read the available bytes - int numRead = 0; - if (lookahead > 0) - { - readBytes[0] = (byte)lookahead; - numRead = _reader.read(readBytes, 1, available - 1) + 1; - } - else - { - numRead = _reader.read(readBytes, 0, available); - } - - // if we've reached end of stream, quit - if (numRead == -1) - { - return null; - } - + byte[] readBytes = new byte[available]; - if (readBytes[numRead - 1]== -1) - { - _endOfStream = true; - } - - // use various encodings as a precaution - // note that the first encoding will be the encoding that we were given - int encodingIndex = 0; - - while (encodingIndex < _encodings.size()) - { - String encoding = (String)(_encodings.get(encodingIndex)); - - // get the output using the encoding - try - { - String fullOutput = new String(readBytes, 0, numRead, encoding); - - // if output is not null, we assume the encoding was correct and process the output - - // tokenize the output so that we can get each line of output - // the delimiters are therefore set to "\n\r" - StringTokenizer tokenizer = new StringTokenizer(fullOutput, "\n\r"); //$NON-NLS-1$ - int numTokens = tokenizer.countTokens(); - output = new String[numTokens]; - int index = 0; - while (tokenizer.hasMoreTokens()) - { - output[index] = tokenizer.nextToken(); - index++; - } - - - return output; - } - catch (Exception e) - { - } - } - } - catch (Exception e) - { - - } - return output; - } -/* - private String readLine() - { - - - int ch; - boolean done = false; - int byteArrayOffset = 0; - while (!done && !isFinished() && (byteArrayOffset < MAX_OFFSET)) - { - try - { - //synchronized (_reader) - { - - if (byteArrayOffset > 0 && (_reader.available() == 0)) - { - try - { - Thread.sleep(_waitIncrement); - } - catch (InterruptedException e) - { - } - if (_reader.available() == 0) - { - _isWaiting = true; - done = true; - //System.out.println("return nothiong"); - //return ""; - } - - } - - ch = _reader.read(); - - _isWaiting = false; - switch (ch) - { - case -1 : - case 65535 : - if (byteArrayOffset == 0) //End of Reader - { - return null; - } - done = true; - break; - - case 10 : // new line - case 13 : // carriage return - done = true; //Newline - break; - - case 27: - break; - - case 9 : - - - // DKM - test - can we preserve tabs? - _byteArray[byteArrayOffset++] = (byte)ch; - - //theLine.append(" "); //Tab - break; - - default : - char tch = (char) ch; - if (!Character.isISOControl(tch)) - { - //System.out.println("char="+tch); - _byteArray[byteArrayOffset++] = (byte)ch; - } - else - { - //System.out.println("ignoring:"+ch); - // ignore next char too - if (_reader.available() > 0) - _reader.read(); - } - break; - } - - - //Check to see if the BufferedReader is still ready which means there are more characters - //in the Buffer...If not, then we assume it is waiting for input. - if (_reader.available() == 0) - { - //wait to make sure - try - { - Thread.sleep(_waitIncrement); - } - catch (InterruptedException e) - { - } - if (_reader.available() == 0) - { - _isWaiting = true; - done = true; - } - } - } + // read the available bytes + int numRead = 0; + if (lookahead > 0) { + readBytes[0] = (byte) lookahead; + numRead = _reader.read(readBytes, 1, available - 1) + 1; + } else { + numRead = _reader.read(readBytes, 0, available); } - catch (IOException e) - { + + // if we've reached end of stream, quit + if (numRead == -1) { return null; } - } - - String lineObject = null; - if (byteArrayOffset > 0) - { - - int encodingIndex = 0; - //printEncodedLines(_byteArray, 0, byteArrayOffset); - + + if (readBytes[numRead - 1] == -1) { + _endOfStream = true; + } + + // use various encodings as a precaution + // note that the first encoding will be the encoding that we were + // given + int encodingIndex = 0; + + while (encodingIndex < _encodings.size()) { + String encoding = (String) (_encodings.get(encodingIndex)); + + // get the output using the encoding + try { + String fullOutput = new String(readBytes, 0, numRead, + encoding); + + // if output is not null, we assume the encoding was correct + // and process the output + if (fullOutput != null /* && fullOutput.length() == numRead */) { + // tokenize the output so that we can get each line of + // output + // the delimiters are therefore set to "\n\r" + StringTokenizer tokenizer = new StringTokenizer( + fullOutput, "\n\r"); //$NON-NLS-1$ + int numTokens = tokenizer.countTokens(); + output = new String[numTokens]; + int index = 0; + while (tokenizer.hasMoreTokens()) { + output[index] = tokenizer.nextToken(); + index++; + } + + String lastLine = output[index - 1]; + if (!_endOfStream && (!fullOutput.endsWith("\n") && !fullOutput.endsWith("\r"))) //$NON-NLS-1$ //$NON-NLS-2$ + { + // our last line may be cut off + byte[] lastBytes = new byte[MAX_OFFSET]; + + int lastIndex = 0; + + available = _reader.available(); + if (available > 0) + { + while (!_endOfStream && lastIndex < MAX_OFFSET) + { + available = _reader.available(); + if (available == 0) + { + String suffix = new String(lastBytes, 0, lastIndex, encoding); + output[index - 1] = lastLine + suffix.substring(0, suffix.length() - 2); + return output; + } + int c = _reader.read(); + if (c == -1) + { + _endOfStream = true; + String suffix = new String(lastBytes, 0, lastIndex, encoding); + output[index - 1] = lastLine + suffix.substring(0, suffix.length() - 2); + return output; + } + else + { + lastBytes[lastIndex] = (byte)c; + + // check for end of line + String suffix = new String(lastBytes, 0, lastIndex + 1, encoding); + if (suffix.contains("\r") || suffix.contains("\n")) //$NON-NLS-1$ //$NON-NLS-2$ + { + // we've hit the end of line; + output[index - 1] = lastLine + suffix.substring(0, suffix.length() - 1); + return output; + } + + lastIndex++; + } - while (lineObject == null && encodingIndex < _encodings.size()) - { - lineObject = getEncodedLine(_byteArray, 0, byteArrayOffset, (String) _encodings.get(encodingIndex)); - encodingIndex++; + } + } + + } + + return output; + } + } catch (Exception e) { } - - if (lineObject == null) - { - lineObject = new String(_byteArray, 0, byteArrayOffset); - } - } - else - { - lineObject =""; - } + } + } catch (Exception e) { - - return lineObject; + } + return output; } - */ -} + + + public synchronized void waitForInput() { + try { + Thread.sleep(100); + } catch (Exception e) { + + } + } +} \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/data/patterns.dat b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/data/patterns.dat index 905c9cfc176..114dcd363c7 100644 --- a/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/data/patterns.dat +++ b/rse/plugins/org.eclipse.rse.services.dstore/serverruntime/data/patterns.dat @@ -143,7 +143,11 @@ command: ls\s.* file file pattern=([\p{L}_\d!@$\-\+,.()\s]+) command: .* + prompt file pattern=[\w,\d,\-,\+]+@[\w,\d,\-,\+]+:([\w,.,/,,(,),\\,\-,\+,\d,:,\s,\~]*)>.* prompt file pattern=([\p{L}_\d!@$\-\+,./()\\,:,\s]*)>.* + prompt file pattern=[\w,\d,\-,\+]+:([\w,.,/,(,),\\,\-,\+,\d,:,\s,~]*)>.* + prompt file pattern=([\w,.,/,(,),\\,\-,\+,\d,:,\s,~]*)>.* + command: find .* file file pattern=([\p{L}_\d!@$\-\+,./()\\]+) diff --git a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/internal/subsystems/shells/dstore/DStoreServiceCommandShell.java b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/internal/subsystems/shells/dstore/DStoreServiceCommandShell.java index ab438fb36e4..acd474c6992 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/internal/subsystems/shells/dstore/DStoreServiceCommandShell.java +++ b/rse/plugins/org.eclipse.rse.subsystems.shells.dstore/src/org/eclipse/rse/internal/subsystems/shells/dstore/DStoreServiceCommandShell.java @@ -237,20 +237,28 @@ public class DStoreServiceCommandShell extends ServiceCommandShell DataStore ds = status.getDataStore(); int ssize = status.getNestedSize(); - if (status.get(ssize - 1).isSpirit() || !ds.isDoSpirit()) + if (ssize > 0) { - // objects can be deleted directly at this point since there will be no more updates from the server - ds.deleteObjects(status); - ds.refresh(status); - } - else - { - // cleanup later - // objects need to be deleted later since the server will still be sending spirited update - // if we don't defer this, then the deleted elements would get recreated when the spirits are updated - CleanUpSpirited cleanUp = new CleanUpSpirited(status, getId()); - cleanUp.start(); + if (!ds.isConnected()) + { + status.removeNestedData(); + } + else if (status.get(ssize - 1).isSpirit() || !ds.isDoSpirit()) + { + // objects can be deleted directly at this point since there will be no more updates from the server + ds.deleteObjects(status); + ds.refresh(status); + } + else + { + // cleanup later + // objects need to be deleted later since the server will still be sending spirited update + // if we don't defer this, then the deleted elements would get recreated when the spirits are updated + CleanUpSpirited cleanUp = new CleanUpSpirited(status, getId()); + cleanUp.start(); + } } +