From 10381a74e4ee96ac85efe9790fe4d79e162db9c7 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 8 Sep 2016 21:06:44 -0400 Subject: [PATCH] Bug 303808: Remove dependency on o.e.tm.view.* The streams connector provided by TM was located in the o.e.tm.view.* plugins which bring in the terminals view. This patch implements our own streams connector so that we don't have this extra dependency. Change-Id: If2a8bdfbdd87eb9ec5c42180a372634e322ba1c1 --- .../debug.product | 2 - .../META-INF/MANIFEST.MF | 4 +- .../ui/console/GdbFullCliConsolePage.java | 30 +--- .../ui/console/GdbTerminalConnector.java | 158 ++++++++++++++++++ releng/org.eclipse.cdt.target/cdt.target | 3 +- 5 files changed, 161 insertions(+), 36 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java diff --git a/debug/org.eclipse.cdt.debug.application.product/debug.product b/debug/org.eclipse.cdt.debug.application.product/debug.product index f243204b410..f5c8076a2d4 100644 --- a/debug/org.eclipse.cdt.debug.application.product/debug.product +++ b/debug/org.eclipse.cdt.debug.application.product/debug.product @@ -350,8 +350,6 @@ Java and all Java-based trademarks are trademarks of Oracle Corporation in the U - - diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/META-INF/MANIFEST.MF b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/META-INF/MANIFEST.MF index 35449285435..b63c5ebfc1f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/META-INF/MANIFEST.MF +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/META-INF/MANIFEST.MF @@ -26,9 +26,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.launch;bundle-version="6.1.0", org.eclipse.debug.core, org.eclipse.core.resources, - org.eclipse.tm.terminal.control;bundle-version="4.0.0", - org.eclipse.tm.terminal.view.core;bundle-version="4.0.0", - org.eclipse.tm.terminal.view.ui;bundle-version="4.1.0" + org.eclipse.tm.terminal.control;bundle-version="4.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.eclipse.cdt.dsf.gdb.internal.ui;x-friends:="org.eclipse.cdt.docker.launcher", diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java index 5d8261e9cc7..5d3425e1317 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java @@ -9,8 +9,6 @@ package org.eclipse.cdt.dsf.gdb.internal.ui.console; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.RejectedExecutionException; import org.eclipse.cdt.debug.internal.ui.views.debuggerconsole.DebuggerConsoleView; @@ -45,10 +43,6 @@ import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; -import org.eclipse.tm.terminal.view.core.interfaces.ITerminalServiceOutputStreamMonitorListener; -import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants; -import org.eclipse.tm.terminal.view.ui.interfaces.ILauncherDelegate; -import org.eclipse.tm.terminal.view.ui.launcher.LauncherDelegateManager; import org.eclipse.ui.part.Page; public class GdbFullCliConsolePage extends Page implements IDebugContextListener { @@ -210,13 +204,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener } protected void attachTerminal(Process process) { - ILauncherDelegate delegate = - LauncherDelegateManager.getInstance().getLauncherDelegate("org.eclipse.tm.terminal.connector.streams.launcher.streams", false); //$NON-NLS-1$ - if (delegate != null) { - Map properties = createNewSettings(process); - - ITerminalConnector connector = delegate.createTerminalConnector(properties); - fTerminalControl.setConnector(connector); + fTerminalControl.setConnector(new GdbTerminalConnector(process)); if (fTerminalControl instanceof ITerminalControl) { ((ITerminalControl)fTerminalControl).setConnectOnEnterIfClosed(false); ((ITerminalControl)fTerminalControl).setVT100LineWrapping(true); @@ -233,22 +221,6 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener } } }); - } - } - - protected Map createNewSettings(Process process) { - - // Create the terminal connector - Map properties = new HashMap(); - properties.put(ITerminalsConnectorConstants.PROP_LOCAL_ECHO, Boolean.FALSE); - properties.put(ITerminalsConnectorConstants.PROP_STREAMS_STDIN, process.getOutputStream()); - properties.put(ITerminalsConnectorConstants.PROP_STREAMS_STDOUT, process.getInputStream()); - properties.put(ITerminalsConnectorConstants.PROP_STREAMS_STDERR, process.getErrorStream()); - properties.put(ITerminalsConnectorConstants.PROP_STDOUT_LISTENERS, - new ITerminalServiceOutputStreamMonitorListener[0]); - properties.put(ITerminalsConnectorConstants.PROP_STDERR_LISTENERS, - new ITerminalServiceOutputStreamMonitorListener[0]); - return properties; } /** diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java new file mode 100644 index 00000000000..88e21d58816 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbTerminalConnector.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.internal.ui.console; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; +import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; +import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; + +/** + * Class that connects the GDB process I/O with the terminal. + */ +public class GdbTerminalConnector extends PlatformObject implements ITerminalConnector { + + private ITerminalControl fControl; + private final Process fProcess; + + public GdbTerminalConnector(Process process) { + if (process == null) { + throw new IllegalArgumentException("Invalid Process"); //$NON-NLS-1$ + } + + fProcess = process; + } + + @Override + public void disconnect() { + // Set the terminal control state to CLOSED. + if (fControl != null) { + fControl.setState(TerminalState.CLOSED); + } + } + + @Override + public OutputStream getTerminalToRemoteStream() { + // When the user writes to the terminal, it should be sent + // directly to GDB + return fProcess.getOutputStream(); + } + + @Override + public void connect(ITerminalControl control) { + if (control == null) { + throw new IllegalArgumentException("Invalid ITerminalControl"); //$NON-NLS-1$ + } + + fControl = control; + + // connect the streams + new OutputReadJob(fProcess.getInputStream()).schedule(); + new OutputReadJob(fProcess.getErrorStream()).schedule(); + + // Set the terminal control state to CONNECTED + fControl.setState(TerminalState.CONNECTED); + } + + + @Override + public void setTerminalSize(int newWidth, int newHeight) { + } + + @Override + public String getId() { + // No need for an id, as we're are just used locally + return null; + } + + @Override + public String getName() { + // No name + return null; + } + + @Override + public boolean isHidden() { + // in case we do leak into the TM world, we shouldn't be visible + return true; + } + + @Override + public boolean isInitialized() { + return true; + } + + @Override + public String getInitializationErrorMessage() { + return null; + } + + @Override + public boolean isLocalEcho() { + return false; + } + + @Override + public void setDefaultSettings() { + // we don't do settings + } + + @Override + public String getSettingsSummary() { + // we don't do settings + return null; + } + + @Override + public void load(ISettingsStore arg0) { + // we don't do settings + } + + @Override + public void save(ISettingsStore arg0) { + // we don't do settings + } + + private class OutputReadJob extends Job { + { + setSystem(true); + } + + private InputStream fInputStream; + + OutputReadJob(InputStream inputStream) { + super("GDB CLI output Job"); //$NON-NLS-1$ + fInputStream = inputStream; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + byte[] b = new byte[1024]; + int read = 0; + do { + read = fInputStream.read(b); + if (read > 0) { + fControl.getRemoteToTerminalOutputStream().write(b, 0, read); + } + } while (read >= 0); + } catch (IOException e) { + } + return Status.OK_STATUS; + } + } +} diff --git a/releng/org.eclipse.cdt.target/cdt.target b/releng/org.eclipse.cdt.target/cdt.target index b7e1a52c59a..9cd0cd04fc1 100644 --- a/releng/org.eclipse.cdt.target/cdt.target +++ b/releng/org.eclipse.cdt.target/cdt.target @@ -1,5 +1,5 @@ - + @@ -60,7 +60,6 @@ -