mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Cleanup of PTY class
Change-Id: If04a3ccbc178040d4929767ef1f4c0f1672dfae9 Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
This commit is contained in:
parent
38e970a45d
commit
8e42cc8b7b
7 changed files with 20 additions and 43 deletions
|
@ -39,7 +39,7 @@ public class PTY {
|
||||||
TERMINAL
|
TERMINAL
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean console;
|
final Mode mode;
|
||||||
final String slave;
|
final String slave;
|
||||||
final PTYInputStream in;
|
final PTYInputStream in;
|
||||||
final PTYOutputStream out;
|
final PTYOutputStream out;
|
||||||
|
@ -72,6 +72,7 @@ public class PTY {
|
||||||
/**
|
/**
|
||||||
* @return whether PTY support for console mode is available on this platform
|
* @return whether PTY support for console mode is available on this platform
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isSupported() {
|
public static boolean isSupported() {
|
||||||
return isSupported(Mode.CONSOLE);
|
return isSupported(Mode.CONSOLE);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ public class PTY {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create PTY for use with Eclipse console.
|
* Create PTY for use with Eclipse console.
|
||||||
* Identical to {@link PTY#PTY(boolean) PTY(Mode.CONSOLE)}.
|
* Identical to {@link PTY#PTY(Mode.CONSOLE)}.
|
||||||
*/
|
*/
|
||||||
public PTY() throws IOException {
|
public PTY() throws IOException {
|
||||||
this(Mode.CONSOLE);
|
this(Mode.CONSOLE);
|
||||||
|
@ -114,39 +115,11 @@ public class PTY {
|
||||||
* @since 5.6
|
* @since 5.6
|
||||||
*/
|
*/
|
||||||
public PTY(Mode mode) throws IOException {
|
public PTY(Mode mode) throws IOException {
|
||||||
this(mode == Mode.CONSOLE);
|
this.mode = mode;
|
||||||
}
|
if (isConsole() && !isConsoleModeSupported) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Create pseudo terminal.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* The provided flag indicates whether the pseudo terminal is used with the interactive
|
|
||||||
* Eclipse console:
|
|
||||||
* <ul>
|
|
||||||
* <li>If <code>true</code> the terminal is configured with no echo and stderr is
|
|
||||||
* redirected to a pipe instead of the PTY. This mode is not supported on windows</li>
|
|
||||||
* <li>If <code>false</code> the terminal is configured with echo and stderr is
|
|
||||||
* connected to the PTY. This mode is best suited for use with a proper terminal emulation.
|
|
||||||
* Note that this mode might not be supported on all platforms.
|
|
||||||
* Known platforms which support this mode are:
|
|
||||||
* <code>linux-x86</code>, <code>linux-x86_64</code>, <code>solaris-sparc</code>, <code>macosx</code>.
|
|
||||||
* </li>
|
|
||||||
* </ul>
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param console whether terminal is used with Eclipse console
|
|
||||||
* @throws IOException if the PTY could not be created
|
|
||||||
* @deprecated Use {@link #PTY(Mode)} instead
|
|
||||||
* @since 5.2
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PTY(boolean console) throws IOException {
|
|
||||||
this.console = console;
|
|
||||||
if (console && !isConsoleModeSupported) {
|
|
||||||
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
||||||
}
|
}
|
||||||
slave = hasPTY ? openMaster(console) : null;
|
slave = hasPTY ? openMaster(isConsole()) : null;
|
||||||
|
|
||||||
if (slave == null) {
|
if (slave == null) {
|
||||||
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
throw new IOException(Messages.Util_exception_cannotCreatePty);
|
||||||
|
@ -165,8 +138,9 @@ public class PTY {
|
||||||
public void validateSlaveName() throws IOException {
|
public void validateSlaveName() throws IOException {
|
||||||
// on windows the slave name is just an internal identifier
|
// on windows the slave name is just an internal identifier
|
||||||
// and does not represent a real device
|
// and does not represent a real device
|
||||||
if (isWinPTY)
|
if (isWinPTY) {
|
||||||
throw new IOException("Slave name is not valid"); //$NON-NLS-1$
|
throw new IOException("Slave name is not valid"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSlaveName() {
|
public String getSlaveName() {
|
||||||
|
@ -183,7 +157,7 @@ public class PTY {
|
||||||
* @since 5.2
|
* @since 5.2
|
||||||
*/
|
*/
|
||||||
public final boolean isConsole() {
|
public final boolean isConsole() {
|
||||||
return console;
|
return mode == Mode.CONSOLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PTYOutputStream getOutputStream() {
|
public PTYOutputStream getOutputStream() {
|
||||||
|
@ -227,9 +201,9 @@ public class PTY {
|
||||||
public int exec_pty(Spawner spawner, String[] cmdarray, String[] envp, String dir, IChannel[] chan)
|
public int exec_pty(Spawner spawner, String[] cmdarray, String[] envp, String dir, IChannel[] chan)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (isWinPTY) {
|
if (isWinPTY) {
|
||||||
return exec2(cmdarray, envp, dir, chan, slave, master, console);
|
return exec2(cmdarray, envp, dir, chan, slave, master, isConsole());
|
||||||
} else {
|
} else {
|
||||||
return spawner.exec2(cmdarray, envp, dir, chan, slave, master, console);
|
return spawner.exec2(cmdarray, envp, dir, chan, slave, master, isConsole());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,10 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.eclipse.cdt.utils.pty.PTY.MasterFD;
|
import org.eclipse.cdt.utils.pty.PTY.MasterFD;
|
||||||
|
|
||||||
class PTYInputStream extends InputStream {
|
/**
|
||||||
|
* @since 6.0
|
||||||
|
*/
|
||||||
|
public class PTYInputStream extends InputStream {
|
||||||
|
|
||||||
MasterFD master;
|
MasterFD master;
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class Utilities {
|
||||||
if (workDir == null) {
|
if (workDir == null) {
|
||||||
return ProcessFactory.getFactory().exec(commandArray, envp);
|
return ProcessFactory.getFactory().exec(commandArray, envp);
|
||||||
}
|
}
|
||||||
if (PTY.isSupported() && usePty) {
|
if (PTY.isSupported(PTY.Mode.CONSOLE) && usePty) {
|
||||||
return ProcessFactory.getFactory().exec(commandArray, envp, workDir, new PTY());
|
return ProcessFactory.getFactory().exec(commandArray, envp, workDir, new PTY());
|
||||||
} else {
|
} else {
|
||||||
return ProcessFactory.getFactory().exec(commandArray, envp, workDir);
|
return ProcessFactory.getFactory().exec(commandArray, envp, workDir);
|
||||||
|
|
|
@ -280,7 +280,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate2 {
|
||||||
*/
|
*/
|
||||||
protected Process exec(String[] cmdLine, String[] environ, File workingDirectory) throws CoreException {
|
protected Process exec(String[] cmdLine, String[] environ, File workingDirectory) throws CoreException {
|
||||||
try {
|
try {
|
||||||
if (PTY.isSupported()) {
|
if (PTY.isSupported(PTY.Mode.CONSOLE)) {
|
||||||
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory, new PTY());
|
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory, new PTY());
|
||||||
} else {
|
} else {
|
||||||
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
|
return ProcessFactory.getFactory().exec(cmdLine, environ, workingDirectory);
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class CMainTab extends CAbstractMainTab {
|
||||||
updateLaunchConfigurationDialog();
|
updateLaunchConfigurationDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fTerminalButton.setEnabled(PTY.isSupported());
|
fTerminalButton.setEnabled(PTY.isSupported(PTY.Mode.CONSOLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class ProcessSettings {
|
||||||
private PTY pty;
|
private PTY pty;
|
||||||
// Flag to control the local echo (defaults to true if
|
// Flag to control the local echo (defaults to true if
|
||||||
// the PTY is not supported on the current host platform)
|
// the PTY is not supported on the current host platform)
|
||||||
private boolean localEcho = !PTY.isSupported();
|
private boolean localEcho = !PTY.isSupported(PTY.Mode.CONSOLE);
|
||||||
// The line separator setting
|
// The line separator setting
|
||||||
private String lineSeparator = null;
|
private String lineSeparator = null;
|
||||||
// The list of stdout output listeners
|
// The list of stdout output listeners
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class ProcessSettingsPage extends AbstractSettingsPage {
|
||||||
localEchoSelectorControl = new Button(composite, SWT.CHECK);
|
localEchoSelectorControl = new Button(composite, SWT.CHECK);
|
||||||
localEchoSelectorControl.setText(Messages.ProcessSettingsPage_localEchoSelectorControl_label);
|
localEchoSelectorControl.setText(Messages.ProcessSettingsPage_localEchoSelectorControl_label);
|
||||||
localEchoSelectorControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
localEchoSelectorControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
localEchoSelectorControl.setSelection(!PTY.isSupported());
|
localEchoSelectorControl.setSelection(!PTY.isSupported(PTY.Mode.CONSOLE));
|
||||||
|
|
||||||
// Initialize the control content
|
// Initialize the control content
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
Loading…
Add table
Reference in a new issue