mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 13:05:22 +02:00
[258720] Fixed incorrect condition and created junit test to cover this bug.
This commit is contained in:
parent
12dc5146ea
commit
afd9bf1a3f
4 changed files with 69 additions and 25 deletions
|
@ -17,6 +17,7 @@
|
||||||
* David McKnight (IBM) - [196301] Check that the remote encoding isn't null before using it
|
* David McKnight (IBM) - [196301] Check that the remote encoding isn't null before using it
|
||||||
* Martin Oberhuber (Wind River) - [204744] Honor encoding in SSH command input field
|
* Martin Oberhuber (Wind River) - [204744] Honor encoding in SSH command input field
|
||||||
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
||||||
|
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.services.ssh.shell;
|
package org.eclipse.rse.internal.services.ssh.shell;
|
||||||
|
@ -115,7 +116,8 @@ public class SshHostShell extends AbstractHostShell implements IHostShell {
|
||||||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||||
) {
|
) {
|
||||||
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
}
|
||||||
|
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||||
writeToShell(getPromptCommand());
|
writeToShell(getPromptCommand());
|
||||||
} else if(commandToRun!=null && commandToRun.length()>0) {
|
} else if(commandToRun!=null && commandToRun.length()>0) {
|
||||||
writeToShell(commandToRun);
|
writeToShell(commandToRun);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 IBM Corporation and others.
|
* Copyright (c) 2006, 2008 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -13,10 +13,11 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Oberhuber (Wind River) - Adapted from LocalHostShell.
|
* Martin Oberhuber (Wind River) - Adapted from LocalHostShell.
|
||||||
* Sheldon D'souza (Celunite) - Adapted from SshHostShell
|
* Sheldon D'souza (Celunite) - Adapted from SshHostShell
|
||||||
* Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
|
* Sheldon D'souza (Celunite) - [187301] support multiple telnet shells
|
||||||
* David McKnight (IBM) - [191599] Use the remote encoding specified in the host property page
|
* David McKnight (IBM) - [191599] Use the remote encoding specified in the host property page
|
||||||
* Martin Oberhuber (Wind River) - [194466] Fix shell terminated state when stream is closed
|
* Martin Oberhuber (Wind River) - [194466] Fix shell terminated state when stream is closed
|
||||||
|
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.rse.internal.services.telnet.shell;
|
package org.eclipse.rse.internal.services.telnet.shell;
|
||||||
|
|
||||||
|
@ -75,7 +76,8 @@ public class TelnetHostShell extends AbstractHostShell implements IHostShell {
|
||||||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||||
) {
|
) {
|
||||||
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
writeToShell("cd "+PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
}
|
||||||
|
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||||
writeToShell(getPromptCommand());
|
writeToShell(getPromptCommand());
|
||||||
} else if(commandToRun!=null && commandToRun.length()>0) {
|
} else if(commandToRun!=null && commandToRun.length()>0) {
|
||||||
writeToShell(commandToRun);
|
writeToShell(commandToRun);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
* Martin Oberhuber (Wind River) - [226262] Make IService IAdaptable
|
||||||
* Anna Dushistova (MontaVista) - adapted from SshHostShell
|
* Anna Dushistova (MontaVista) - adapted from SshHostShell
|
||||||
* Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
|
* Anna Dushistova (MontaVista) - [240523] [rseterminals] Provide a generic adapter factory that adapts any ITerminalService to an IShellService
|
||||||
|
* Anna Dushistova (MontaVista) - [258720] SshHostShell fails to run command if initialWorkingDirectory supplied
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.services.shells;
|
package org.eclipse.rse.internal.services.shells;
|
||||||
|
@ -88,7 +89,8 @@ public class TerminalServiceHostShell extends AbstractHostShell {
|
||||||
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
&& !initialWorkingDirectory.equals("Command Shell") //$NON-NLS-1$ //FIXME workaround for bug 153047
|
||||||
) {
|
) {
|
||||||
writeToShell("cd " + PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
writeToShell("cd " + PathUtility.enQuoteUnix(initialWorkingDirectory)); //$NON-NLS-1$
|
||||||
} else if (SHELL_INVOCATION.equals(commandToRun)) {
|
}
|
||||||
|
if (SHELL_INVOCATION.equals(commandToRun)) {
|
||||||
writeToShell(getPromptCommand());
|
writeToShell(getPromptCommand());
|
||||||
} else if (commandToRun != null && commandToRun.length() > 0) {
|
} else if (commandToRun != null && commandToRun.length() > 0) {
|
||||||
writeToShell(commandToRun);
|
writeToShell(commandToRun);
|
||||||
|
|
|
@ -131,57 +131,92 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLaunchShell() throws Exception {
|
public void testLaunchShell() throws Exception {
|
||||||
IHostShell hostShell = shellService.launchShell("", new String[] {},
|
Object[] allOutput = launchShell("", "echo test", new String[] {});
|
||||||
|
boolean matchFound = false;
|
||||||
|
for (int i = 0; i < allOutput.length; i++) {
|
||||||
|
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||||
|
.equals("test");
|
||||||
|
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||||
|
if (matchFound)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assertTrue(matchFound);
|
||||||
|
// now set working directory -- Linux only
|
||||||
|
allOutput = launchShell("/", "echo test", new String[] {});
|
||||||
|
matchFound = false;
|
||||||
|
for (int i = 0; i < allOutput.length; i++) {
|
||||||
|
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||||
|
.equals("test");
|
||||||
|
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||||
|
if (matchFound)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] launchShell(String workingDirectory, String cmd,
|
||||||
|
String[] env) throws SystemMessageException, InterruptedException {
|
||||||
|
IHostShell hostShell = shellService.launchShell(workingDirectory, env,
|
||||||
mon);
|
mon);
|
||||||
assertNotNull(hostShell);
|
assertNotNull(hostShell);
|
||||||
assertNotNull(hostShell.getStandardOutputReader());
|
assertNotNull(hostShell.getStandardOutputReader());
|
||||||
ShellOutputListener outputListener = new ShellOutputListener();
|
ShellOutputListener outputListener = new ShellOutputListener();
|
||||||
hostShell.addOutputListener(outputListener);
|
hostShell.addOutputListener(outputListener);
|
||||||
// run command
|
// run command
|
||||||
hostShell.writeToShell("echo test");
|
hostShell.writeToShell(cmd);
|
||||||
hostShell.writeToShell("exit");
|
hostShell.writeToShell("exit");
|
||||||
while (hostShell.isActive()) {
|
while (hostShell.isActive()) {
|
||||||
Thread.sleep(200);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
Object[] allOutput = outputListener.getAllOutput();
|
Object[] allOutput = outputListener.getAllOutput();
|
||||||
|
return allOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRunCommand() throws Exception {
|
||||||
|
Object[] allOutput = runCommand("", "echo test", new String[] {});
|
||||||
boolean matchFound = false;
|
boolean matchFound = false;
|
||||||
for (int i = 0; i < allOutput.length; i++) {
|
for (int i = 0; i < allOutput.length; i++) {
|
||||||
|
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||||
.equals("test");
|
.equals("test");
|
||||||
if (matchFound)
|
if (matchFound)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assertTrue(matchFound);
|
assertTrue("Failed without changing initial working directory",matchFound);
|
||||||
|
//set initial working directory -- Linux only
|
||||||
|
allOutput = runCommand("/", "echo test", new String[] {});
|
||||||
|
matchFound = false;
|
||||||
|
for (int i = 0; i < allOutput.length; i++) {
|
||||||
|
System.out.println(((IHostOutput) allOutput[i]).getString());
|
||||||
|
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||||
|
.equals("test");
|
||||||
|
if (matchFound)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
assertTrue("Failed with changing initial working directory",matchFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRunCommand() throws Exception {
|
public Object[] runCommand(String workingDirectory, String cmd, String[] env)
|
||||||
|
throws SystemMessageException, InterruptedException {
|
||||||
IHostShell hostShell = null;
|
IHostShell hostShell = null;
|
||||||
hostShell = shellService.runCommand("", "echo test", new String[] {},
|
hostShell = shellService.runCommand(workingDirectory, cmd, env, mon);
|
||||||
mon);
|
|
||||||
ShellOutputListener outputListener = new ShellOutputListener();
|
ShellOutputListener outputListener = new ShellOutputListener();
|
||||||
hostShell.addOutputListener(outputListener);
|
hostShell.addOutputListener(outputListener);
|
||||||
hostShell.writeToShell("exit");
|
hostShell.writeToShell("exit");
|
||||||
assertNotNull(hostShell);
|
assertNotNull(hostShell);
|
||||||
assertNotNull(hostShell.getStandardOutputReader());
|
assertNotNull(hostShell.getStandardOutputReader());
|
||||||
while (hostShell.isActive()) {
|
while (hostShell.isActive()) {
|
||||||
Thread.sleep(200);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
Object[] allOutput = outputListener.getAllOutput();
|
Object[] allOutput = outputListener.getAllOutput();
|
||||||
boolean matchFound = false;
|
return allOutput;
|
||||||
for (int i = 0; i < allOutput.length; i++) {
|
|
||||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
|
||||||
.equals("test");
|
|
||||||
if (matchFound)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assertTrue(matchFound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRunCommandViaHostShellProcessAdapter() throws Exception {
|
public void testRunCommandViaHostShellProcessAdapter() throws Exception {
|
||||||
IHostShell hostShell = null;
|
IHostShell hostShell = null;
|
||||||
|
String commandSeparator = (shellSubSystem!=null)?shellSubSystem.getParentRemoteCmdSubSystemConfiguration()
|
||||||
|
.getCommandSeparator():"\r\n";
|
||||||
hostShell = shellService.runCommand("", "echo test"
|
hostShell = shellService.runCommand("", "echo test"
|
||||||
+ shellSubSystem.getParentRemoteCmdSubSystemConfiguration()
|
+ commandSeparator + " exit", new String[] {}, mon);
|
||||||
.getCommandSeparator() + " exit", new String[] {}, mon);
|
|
||||||
HostShellProcessAdapter p = null;
|
HostShellProcessAdapter p = null;
|
||||||
try {
|
try {
|
||||||
p = new HostShellProcessAdapter(hostShell);
|
p = new HostShellProcessAdapter(hostShell);
|
||||||
|
@ -196,7 +231,10 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
||||||
boolean matchFound = false;
|
boolean matchFound = false;
|
||||||
try {
|
try {
|
||||||
while ((nextLine = bufferReader.readLine()) != null) {
|
while ((nextLine = bufferReader.readLine()) != null) {
|
||||||
|
System.out.println(nextLine);
|
||||||
matchFound = nextLine.equals("test");
|
matchFound = nextLine.equals("test");
|
||||||
|
if(matchFound)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
bufferReader.close();
|
bufferReader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue