From 15c8bad95d394bef30dda8662e490e78b1afee33 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 13 Nov 2017 15:25:52 -0500 Subject: Serial Flash Target and Launch. Clean up Generic Launch. Adds target, launch classes, and launch bar support for targets intended to upload their code to flash using a Serial Port. The port is co-ordinated with the Serial Terminal so that the terminal is paused during the upload. Also cleaned up the Generic Launch so it's not using the External Tools launch which has a number of UX issues. This simplifies the settings and gives us more control. And it's made reusable for the Serial Flash launch. Change-Id: I31e9970243fbf1cf22d027bbdb892fde104dbefe --- .../org.eclipse.cdt.launch.serial-feature/.project | 17 + .../build.properties | 1 + .../feature.xml | 32 + .../org.eclipse.cdt.launch.serial.core/.classpath | 7 + cross/org.eclipse.cdt.launch.serial.core/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 16 + .../build.properties | 5 + .../org.eclipse.cdt.launch.serial.core/plugin.xml | 29 + .../serial/SerialFlashLaunchTargetProvider.java | 36 ++ .../cdt/launch/serial/internal/Activator.java | 30 + .../cdt/launch/serial/internal/Messages.java | 23 + .../launch/serial/internal/SerialFlashLaunch.java | 67 ++ .../internal/SerialFlashLaunchConfigDelegate.java | 37 ++ .../internal/SerialFlashLaunchConfigProvider.java | 32 + .../cdt/launch/serial/internal/messages.properties | 9 + cross/org.eclipse.cdt.launch.serial.ui/.classpath | 7 + cross/org.eclipse.cdt.launch.serial.ui/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 16 + .../build.properties | 6 + .../icons/cdt_logo_16.png | Bin 0 -> 896 bytes cross/org.eclipse.cdt.launch.serial.ui/plugin.xml | 26 + .../cdt/launch/serial/ui/internal/Activator.java | 52 ++ .../cdt/launch/serial/ui/internal/Messages.java | 29 + .../ui/internal/NewSerialFlashTargetWizard.java | 53 ++ .../internal/NewSerialFlashTargetWizardPage.java | 130 ++++ .../internal/SerialFlashLaunchConfigTabGroup.java | 24 + .../SerialFlashLaunchTargetLabelProvider.java | 35 + .../launch/serial/ui/internal/messages.properties | 15 + debug/org.eclipse.cdt.debug.core/plugin.xml | 9 +- .../core/ICDTLaunchConfigurationConstants.java | 10 + .../CoreBuildGenericLaunchConfigDelegate.java | 88 +++ .../CoreBuildGenericLaunchConfigProvider.java | 165 +++++ .../eclipse/cdt/debug/core/launch/NullProcess.java | 107 +++ .../eclipse/cdt/debug/internal/core/Messages.java | 25 + .../CoreBuildGenericLaunchConfigProvider.java | 150 ----- .../cdt/debug/internal/core/messages.properties | 11 + .../cdt/dsf/gdb/service/GDBProcesses_7_12.java | 3 + .../service/command/commands/MITargetAttach.java | 5 +- launch/org.eclipse.cdt.launch/plugin.xml | 7 +- .../corebuild/GenericLaunchConfigTabGroup.java | 28 + .../eclipse/cdt/launch/internal/ui/Messages.java | 36 ++ .../cdt/launch/internal/ui/messages.properties | 22 + .../cdt/launch/ui/corebuild/GenericMainTab.java | 715 +++++++++++++++++++++ .../src/org/eclipse/cdt/serial/SerialPort.java | 24 +- pom.xml | 5 +- 47 files changed, 2052 insertions(+), 162 deletions(-) create mode 100644 cross/org.eclipse.cdt.launch.serial-feature/.project create mode 100644 cross/org.eclipse.cdt.launch.serial-feature/build.properties create mode 100644 cross/org.eclipse.cdt.launch.serial-feature/feature.xml create mode 100644 cross/org.eclipse.cdt.launch.serial.core/.classpath create mode 100644 cross/org.eclipse.cdt.launch.serial.core/.project create mode 100644 cross/org.eclipse.cdt.launch.serial.core/.settings/org.eclipse.jdt.core.prefs create mode 100644 cross/org.eclipse.cdt.launch.serial.core/META-INF/MANIFEST.MF create mode 100644 cross/org.eclipse.cdt.launch.serial.core/build.properties create mode 100644 cross/org.eclipse.cdt.launch.serial.core/plugin.xml create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/SerialFlashLaunchTargetProvider.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Activator.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Messages.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunch.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigDelegate.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigProvider.java create mode 100644 cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/messages.properties create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/.classpath create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/.project create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/META-INF/MANIFEST.MF create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/build.properties create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/icons/cdt_logo_16.png create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/plugin.xml create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Activator.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Messages.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizard.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchConfigTabGroup.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchTargetLabelProvider.java create mode 100644 cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/messages.properties create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigDelegate.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigProvider.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/NullProcess.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Messages.java delete mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildGenericLaunchConfigProvider.java create mode 100644 debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/messages.properties create mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/GenericLaunchConfigTabGroup.java create mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/Messages.java create mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/messages.properties create mode 100644 launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/GenericMainTab.java diff --git a/cross/org.eclipse.cdt.launch.serial-feature/.project b/cross/org.eclipse.cdt.launch.serial-feature/.project new file mode 100644 index 00000000000..acb0250e3e2 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial-feature/.project @@ -0,0 +1,17 @@ + + + org.eclipse.cdt.launch.serial-feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/cross/org.eclipse.cdt.launch.serial-feature/build.properties b/cross/org.eclipse.cdt.launch.serial-feature/build.properties new file mode 100644 index 00000000000..82ab19c62d1 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial-feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/cross/org.eclipse.cdt.launch.serial-feature/feature.xml b/cross/org.eclipse.cdt.launch.serial-feature/feature.xml new file mode 100644 index 00000000000..e5839b48b36 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial-feature/feature.xml @@ -0,0 +1,32 @@ + + + + + [Enter Feature Description here.] + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + diff --git a/cross/org.eclipse.cdt.launch.serial.core/.classpath b/cross/org.eclipse.cdt.launch.serial.core/.classpath new file mode 100644 index 00000000000..b862a296d38 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cross/org.eclipse.cdt.launch.serial.core/.project b/cross/org.eclipse.cdt.launch.serial.core/.project new file mode 100644 index 00000000000..0bad6ef6c55 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.launch.serial.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/cross/org.eclipse.cdt.launch.serial.core/.settings/org.eclipse.jdt.core.prefs b/cross/org.eclipse.cdt.launch.serial.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..295926d9641 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/cross/org.eclipse.cdt.launch.serial.core/META-INF/MANIFEST.MF b/cross/org.eclipse.cdt.launch.serial.core/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..fb7f81b1416 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Launch over Serial Core Plugin +Bundle-SymbolicName: org.eclipse.cdt.launch.serial.core;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Eclipse CDT +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.13.0", + org.eclipse.debug.core;bundle-version="3.11.0", + org.eclipse.launchbar.core;bundle-version="2.2.0", + org.eclipse.cdt.core;bundle-version="6.4.0", + org.eclipse.cdt.debug.core;bundle-version="8.3.0", + org.eclipse.cdt.native.serial;bundle-version="1.1.0" +Export-Package: org.eclipse.cdt.launch.serial +Bundle-Activator: org.eclipse.cdt.launch.serial.internal.Activator +Bundle-ActivationPolicy: lazy diff --git a/cross/org.eclipse.cdt.launch.serial.core/build.properties b/cross/org.eclipse.cdt.launch.serial.core/build.properties new file mode 100644 index 00000000000..6f20375d6c7 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/cross/org.eclipse.cdt.launch.serial.core/plugin.xml b/cross/org.eclipse.cdt.launch.serial.core/plugin.xml new file mode 100644 index 00000000000..537bc36e76b --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/plugin.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/SerialFlashLaunchTargetProvider.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/SerialFlashLaunchTargetProvider.java new file mode 100644 index 00000000000..ec3e47f63c6 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/SerialFlashLaunchTargetProvider.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial; + +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetProvider; +import org.eclipse.launchbar.core.target.TargetStatus; + +/** + * Launch Target used to flash images to a device over a serial port, usually + * USB serial. + */ +public class SerialFlashLaunchTargetProvider implements ILaunchTargetProvider { + + public static final String TYPE_ID = "org.eclipse.cdt.launch.serial.core.serialFlashTarget"; //$NON-NLS-1$ + + public static final String ATTR_SERIAL_PORT = "org.eclipse.cdt.launch.serial.core.serialPort"; //$NON-NLS-1$ + + @Override + public void init(ILaunchTargetManager targetManager) { + // Nothing to do at init time + } + + @Override + public TargetStatus getStatus(ILaunchTarget target) { + // Always OK + return TargetStatus.OK_STATUS; + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Activator.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Activator.java new file mode 100644 index 00000000000..ca9822e4d29 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Activator.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.internal; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; + +public class Activator extends Plugin { + + public static final String PLUGIN_ID = "org.eclipse.cdt.launch.serial.core"; //$NON-NLS-1$ + + private static Activator plugin; + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + public static void log(IStatus status) { + plugin.getLog().log(status); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Messages.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Messages.java new file mode 100644 index 00000000000..3b18b53d8d4 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/Messages.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.internal; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.launch.serial.internal.messages"; //$NON-NLS-1$ + public static String SerialFlashLaunch_Pause; + public static String SerialFlashLaunch_Resume; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunch.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunch.java new file mode 100644 index 00000000000..e810d708f32 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunch.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.internal; + +import java.io.IOException; + +import org.eclipse.cdt.launch.serial.SerialFlashLaunchTargetProvider; +import org.eclipse.cdt.serial.SerialPort; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.launch.TargetedLaunch; + +public class SerialFlashLaunch extends TargetedLaunch { + + private SerialPort serialPort; + private boolean wasOpen; + + public SerialFlashLaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator, + ILaunchTarget target) { + super(launchConfiguration, mode, target, locator); + String serialPortName = target.getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, ""); //$NON-NLS-1$ + if (!serialPortName.isEmpty()) { + serialPort = SerialPort.get(serialPortName); + } + + DebugPlugin.getDefault().addDebugEventListener(this); + } + + public void start() { + if (serialPort != null) { + wasOpen = serialPort.isOpen(); + if (wasOpen) { + try { + serialPort.pause(); + } catch (IOException e) { + Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SerialFlashLaunch_Pause, e)); + } + } + } else { + wasOpen = false; + } + } + + @Override + public void handleDebugEvents(DebugEvent[] events) { + super.handleDebugEvents(events); + if (isTerminated() && wasOpen) { + try { + serialPort.resume(); + } catch (IOException e) { + Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SerialFlashLaunch_Resume, e)); + } + wasOpen = false; + } + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigDelegate.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigDelegate.java new file mode 100644 index 00000000000..3473c4296f3 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigDelegate.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.internal; + +import org.eclipse.cdt.debug.core.launch.CoreBuildGenericLaunchConfigDelegate; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.launch.ITargetedLaunch; + +public class SerialFlashLaunchConfigDelegate extends CoreBuildGenericLaunchConfigDelegate { + + public static final String TYPE_ID = "org.eclipse.cdt.launch.serial.launchConfigurationType"; //$NON-NLS-1$ + + @Override + public ITargetedLaunch getLaunch(ILaunchConfiguration configuration, String mode, ILaunchTarget target) + throws CoreException { + return new SerialFlashLaunch(configuration, mode, null, target); + } + + @Override + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) + throws CoreException { + // Start the launch (pause the serial port) + ((SerialFlashLaunch) launch).start(); + + super.launch(configuration, mode, launch, monitor); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigProvider.java b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigProvider.java new file mode 100644 index 00000000000..d1cfb4dff92 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/SerialFlashLaunchConfigProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.internal; + +import org.eclipse.cdt.debug.core.launch.CoreBuildGenericLaunchConfigProvider; +import org.eclipse.cdt.launch.serial.SerialFlashLaunchTargetProvider; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.target.ILaunchTarget; + +public class SerialFlashLaunchConfigProvider extends CoreBuildGenericLaunchConfigProvider { + + @Override + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + return target.getTypeId().equals(SerialFlashLaunchTargetProvider.TYPE_ID); + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { + return DebugPlugin.getDefault().getLaunchManager() + .getLaunchConfigurationType(SerialFlashLaunchConfigDelegate.TYPE_ID); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/messages.properties b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/messages.properties new file mode 100644 index 00000000000..02efebb9d0b --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.core/src/org/eclipse/cdt/launch/serial/internal/messages.properties @@ -0,0 +1,9 @@ +################################################################################ +# Copyright (c) 2017 QNX Software Systems 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 +################################################################################ +SerialFlashLaunch_Pause=Pausing serial port +SerialFlashLaunch_Resume=Resuming serial port diff --git a/cross/org.eclipse.cdt.launch.serial.ui/.classpath b/cross/org.eclipse.cdt.launch.serial.ui/.classpath new file mode 100644 index 00000000000..b862a296d38 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cross/org.eclipse.cdt.launch.serial.ui/.project b/cross/org.eclipse.cdt.launch.serial.ui/.project new file mode 100644 index 00000000000..0977dd1f5ea --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/.project @@ -0,0 +1,28 @@ + + + org.eclipse.cdt.launch.serial.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/cross/org.eclipse.cdt.launch.serial.ui/.settings/org.eclipse.jdt.core.prefs b/cross/org.eclipse.cdt.launch.serial.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..295926d9641 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/cross/org.eclipse.cdt.launch.serial.ui/META-INF/MANIFEST.MF b/cross/org.eclipse.cdt.launch.serial.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..1530f18559d --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Ui +Bundle-SymbolicName: org.eclipse.cdt.launch.serial.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.13.0", + org.eclipse.ui;bundle-version="3.109.0", + org.eclipse.debug.ui;bundle-version="3.12.50", + org.eclipse.launchbar.core;bundle-version="2.2.0", + org.eclipse.launchbar.ui;bundle-version="2.2.0", + org.eclipse.cdt.launch.serial.core;bundle-version="1.0.0", + org.eclipse.cdt.native.serial;bundle-version="1.1.0", + org.eclipse.cdt.launch;bundle-version="9.2.0" +Bundle-Activator: org.eclipse.cdt.launch.serial.ui.internal.Activator +Bundle-ActivationPolicy: lazy diff --git a/cross/org.eclipse.cdt.launch.serial.ui/build.properties b/cross/org.eclipse.cdt.launch.serial.ui/build.properties new file mode 100644 index 00000000000..285b8bf47b6 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/ diff --git a/cross/org.eclipse.cdt.launch.serial.ui/icons/cdt_logo_16.png b/cross/org.eclipse.cdt.launch.serial.ui/icons/cdt_logo_16.png new file mode 100644 index 00000000000..fb343a10650 Binary files /dev/null and b/cross/org.eclipse.cdt.launch.serial.ui/icons/cdt_logo_16.png differ diff --git a/cross/org.eclipse.cdt.launch.serial.ui/plugin.xml b/cross/org.eclipse.cdt.launch.serial.ui/plugin.xml new file mode 100644 index 00000000000..9067c806bdb --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/plugin.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Activator.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Activator.java new file mode 100644 index 00000000000..42ec9d2a6a7 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Activator.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class Activator extends AbstractUIPlugin { + + public static final String PLUGIN_ID = "org.eclipse.cdt.launch.serial.ui"; //$NON-NLS-1$ + + public static final String IMG_CDT_LOGO = "org.eclipse.cdt.launch.serial.ui.cdt_logo_16"; //$NON-NLS-1$ + + private static AbstractUIPlugin plugin; + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + @Override + protected void initializeImageRegistry(ImageRegistry reg) { + super.initializeImageRegistry(reg); + + reg.put(IMG_CDT_LOGO, imageDescriptorFromPlugin(PLUGIN_ID, "icons/cdt_logo_16.png")); //$NON-NLS-1$ + } + + public static Image getImage(String key) { + return plugin.getImageRegistry().get(key); + } + + public static void log(IStatus status) { + plugin.getLog().log(status); + } + + public static T getService(Class service) { + BundleContext context = plugin.getBundle().getBundleContext(); + ServiceReference ref = context.getServiceReference(service); + return ref != null ? context.getService(ref) : null; + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Messages.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Messages.java new file mode 100644 index 00000000000..716945251ef --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/Messages.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.launch.serial.ui.internal.messages"; //$NON-NLS-1$ + public static String NewSerialFlashTargetWizard_Title; + public static String NewSerialFlashTargetWizardPage_CPUArchitecture; + public static String NewSerialFlashTargetWizardPage_Description; + public static String NewSerialFlashTargetWizardPage_Fetching; + public static String NewSerialFlashTargetWizardPage_Name; + public static String NewSerialFlashTargetWizardPage_OperatingSystem; + public static String NewSerialFlashTargetWizardPage_SerialPort; + public static String NewSerialFlashTargetWizardPage_Title; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizard.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizard.java new file mode 100644 index 00000000000..b1f28537234 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizard.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import org.eclipse.cdt.launch.serial.SerialFlashLaunchTargetProvider; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; +import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy; +import org.eclipse.launchbar.ui.target.LaunchTargetWizard; + +public class NewSerialFlashTargetWizard extends LaunchTargetWizard { + + private NewSerialFlashTargetWizardPage page; + + public NewSerialFlashTargetWizard() { + setWindowTitle(Messages.NewSerialFlashTargetWizard_Title); + } + + @Override + public void addPages() { + super.addPages(); + + page = new NewSerialFlashTargetWizardPage(getLaunchTarget()); + addPage(page); + } + + @Override + public boolean performFinish() { + ILaunchTargetManager manager = Activator.getService(ILaunchTargetManager.class); + String typeId = SerialFlashLaunchTargetProvider.TYPE_ID; + String id = page.getTargetName(); + + ILaunchTarget target = getLaunchTarget(); + if (target == null) { + target = manager.addLaunchTarget(typeId, id); + } + + ILaunchTargetWorkingCopy wc = target.getWorkingCopy(); + wc.setId(id); + wc.setAttribute(ILaunchTarget.ATTR_OS, page.getOS()); + wc.setAttribute(ILaunchTarget.ATTR_ARCH, page.getArch()); + wc.setAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, page.getSerialPortName()); + wc.save(); + + return true; + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java new file mode 100644 index 00000000000..58ab4e7660a --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import java.io.IOException; + +import org.eclipse.cdt.launch.serial.SerialFlashLaunchTargetProvider; +import org.eclipse.cdt.serial.SerialPort; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class NewSerialFlashTargetWizardPage extends WizardPage { + + private ILaunchTarget launchTarget; + + private Text nameText; + private Text osText; + private Text archText; + private Combo serialPortCombo; + + public NewSerialFlashTargetWizardPage(ILaunchTarget launchTarget) { + super(NewSerialFlashTargetWizardPage.class.getName()); + this.launchTarget = launchTarget; + setTitle(Messages.NewSerialFlashTargetWizardPage_Title); + setDescription(Messages.NewSerialFlashTargetWizardPage_Description); + } + + @Override + public void createControl(Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new GridLayout(2, false)); + setControl(comp); + + Label label = new Label(comp, SWT.NONE); + label.setText(Messages.NewSerialFlashTargetWizardPage_Name); + + nameText = new Text(comp, SWT.BORDER); + nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + if (launchTarget != null) { + nameText.setText(launchTarget.getId()); + } + + label = new Label(comp, SWT.NONE); + label.setText(Messages.NewSerialFlashTargetWizardPage_OperatingSystem); + + osText = new Text(comp, SWT.BORDER); + osText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + if (launchTarget != null) { + String os = launchTarget.getAttribute(ILaunchTarget.ATTR_OS, null); + if (os != null) { + osText.setText(os); + } + } + + label = new Label(comp, SWT.NONE); + label.setText(Messages.NewSerialFlashTargetWizardPage_CPUArchitecture); + + archText = new Text(comp, SWT.BORDER); + archText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + if (launchTarget != null) { + String arch = launchTarget.getAttribute(ILaunchTarget.ATTR_ARCH, null); + if (arch != null) { + archText.setText(arch); + } + } + + label = new Label(comp, SWT.NONE); + label.setText(Messages.NewSerialFlashTargetWizardPage_SerialPort); + + serialPortCombo = new Combo(comp, SWT.NONE); + try { + String[] ports = SerialPort.list(); + for (String port : ports) { + serialPortCombo.add(port); + } + if (serialPortCombo.getItemCount() > 0) { + if (launchTarget != null) { + String targetPort = launchTarget.getAttribute(SerialFlashLaunchTargetProvider.ATTR_SERIAL_PORT, + null); + if (targetPort != null) { + int i = 0; + for (String port : ports) { + if (port.equals(targetPort)) { + serialPortCombo.select(i); + break; + } + } + } + } + + if (serialPortCombo.getSelectionIndex() < 0) { + serialPortCombo.select(0); + } + } + } catch (IOException e) { + Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.NewSerialFlashTargetWizardPage_Fetching, e)); + } + } + + public String getTargetName() { + return nameText.getText(); + } + + public String getOS() { + return osText.getText(); + } + + public String getArch() { + return archText.getText(); + } + + public String getSerialPortName() { + return serialPortCombo.getText(); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchConfigTabGroup.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchConfigTabGroup.java new file mode 100644 index 00000000000..96f26d4eac2 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchConfigTabGroup.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import org.eclipse.cdt.launch.ui.corebuild.GenericMainTab; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.EnvironmentTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; + +public class SerialFlashLaunchConfigTabGroup extends AbstractLaunchConfigurationTabGroup { + + @Override + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + setTabs(new ILaunchConfigurationTab[] { new GenericMainTab(), new EnvironmentTab(), new CommonTab() }); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchTargetLabelProvider.java b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchTargetLabelProvider.java new file mode 100644 index 00000000000..d0060c7e224 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/SerialFlashLaunchTargetLabelProvider.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.serial.ui.internal; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.swt.graphics.Image; + +public class SerialFlashLaunchTargetLabelProvider extends LabelProvider { + + @Override + public String getText(Object element) { + if (element instanceof ILaunchTarget) { + return ((ILaunchTarget) element).getId(); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if (element instanceof ILaunchTarget) { + Image image = Activator.getImage(Activator.IMG_CDT_LOGO); + if (image != null) { + return image; + } + } + return super.getImage(element); + } + +} diff --git a/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/messages.properties b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/messages.properties new file mode 100644 index 00000000000..a250eee1ba5 --- /dev/null +++ b/cross/org.eclipse.cdt.launch.serial.ui/src/org/eclipse/cdt/launch/serial/ui/internal/messages.properties @@ -0,0 +1,15 @@ +################################################################################ +# Copyright (c) 2017 QNX Software Systems 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 +################################################################################ +NewSerialFlashTargetWizard_Title=New Serial Flash Target +NewSerialFlashTargetWizardPage_CPUArchitecture=CPU Architecture: +NewSerialFlashTargetWizardPage_Description=Enter name and properties for the target. +NewSerialFlashTargetWizardPage_Fetching=Fetching serial ports +NewSerialFlashTargetWizardPage_Name=Name: +NewSerialFlashTargetWizardPage_OperatingSystem=Operating System: +NewSerialFlashTargetWizardPage_SerialPort=Serial Port: +NewSerialFlashTargetWizardPage_Title=Serial Flash Target diff --git a/debug/org.eclipse.cdt.debug.core/plugin.xml b/debug/org.eclipse.cdt.debug.core/plugin.xml index 39e6204629e..07ecb11d23a 100644 --- a/debug/org.eclipse.cdt.debug.core/plugin.xml +++ b/debug/org.eclipse.cdt.debug.core/plugin.xml @@ -470,6 +470,13 @@ name="%localApplicationLaunch.name" public="false"> + + @@ -491,7 +498,7 @@ priority="10"> diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java index a0180579598..8e041e0a897 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java @@ -285,6 +285,16 @@ public interface ICDTLaunchConfigurationConstants { */ public static final String ATTR_DEBUGGER_POST_MORTEM_TYPE = "org.eclipse.cdt.dsf.gdb" + ".POST_MORTEM_TYPE"; //$NON-NLS-1$ //$NON-NLS-2$ + /** + * @since 8.3 + */ + public final static String ATTR_LOCATION = CDT_LAUNCH_ID + ".ATTR_LOCATION"; //$NON-NLS-1$ + + /** + * @since 8.3 + */ + public final static String ATTR_TOOL_ARGUMENTS = CDT_LAUNCH_ID + ".ATTR_TOOL_ARGUMENTS"; //$NON-NLS-1$ + /** * Launch configuration attribute value. The key is * ATTR_DEBUGGER_STOP_AT_MAIN. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigDelegate.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigDelegate.java new file mode 100644 index 00000000000..217c6dced4f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigDelegate.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.debug.core.launch; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.internal.core.Messages; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.variables.IStringVariableManager; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; + +/** + * Delegate for Generic Launches over the Generic Launch Target. Can be + * overriden to support launch customization for similar targets. + * + * @since 8.3 + */ +public class CoreBuildGenericLaunchConfigDelegate extends CoreBuildLaunchConfigDelegate { + + public static final String TYPE_ID = "org.eclipse.cdt.debug.core.genericLaunchConfigType"; //$NON-NLS-1$ + + @Override + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) + throws CoreException { + IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); + + String location = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_LOCATION, ""); //$NON-NLS-1$ + if (location.isEmpty()) { + launch.addProcess(new NullProcess(launch, Messages.CoreBuildGenericLaunchConfigDelegate_NoAction)); + return; + } else { + String substLocation = varManager.performStringSubstitution(location); + if (substLocation.isEmpty()) { + throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, + String.format(Messages.CoreBuildGenericLaunchConfigDelegate_SubstitutionFailed, location))); + } + location = substLocation; + } + + if (!new File(location).canExecute()) { + throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, + String.format(Messages.CoreBuildGenericLaunchConfigDelegate_CommandNotValid, location))); + } + + List commands = new ArrayList<>(); + commands.add(location); + + String arguments = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$ + if (!arguments.isEmpty()) { + commands.addAll(Arrays.asList(varManager.performStringSubstitution(arguments).split(" "))); //$NON-NLS-1$ + } + + String workingDirectory = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, + ""); //$NON-NLS-1$ + File workingDir; + if (workingDirectory.isEmpty()) { + workingDir = new File(getProject(configuration).getLocationURI()); + } else { + workingDir = new File(varManager.performStringSubstitution(workingDirectory)); + if (!workingDir.isDirectory()) { + throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.PLUGIN_ID, + String.format(Messages.CoreBuildGenericLaunchConfigDelegate_WorkingDirNotExists, location))); + } + } + + String[] envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration); + + Process p = DebugPlugin.exec(commands.toArray(new String[0]), workingDir, envp); + DebugPlugin.newProcess(launch, p, String.join(" ", commands)); //$NON-NLS-1$ + } + +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigProvider.java new file mode 100644 index 00000000000..7cc54a1260b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/CoreBuildGenericLaunchConfigProvider.java @@ -0,0 +1,165 @@ +package org.eclipse.cdt.debug.core.launch; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.launchbar.core.AbstractLaunchConfigProvider; +import org.eclipse.launchbar.core.ILaunchDescriptor; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.launchbar.core.target.ILaunchTargetManager; + +/** + * Core launch configuration provider used by generic target types. + * + * @since 8.3 + */ +public class CoreBuildGenericLaunchConfigProvider extends AbstractLaunchConfigProvider { + + private static final String ATTR_OS = CDebugCorePlugin.PLUGIN_ID + ".target_os"; //$NON-NLS-1$ + private static final String ATTR_ARCH = CDebugCorePlugin.PLUGIN_ID + ".target_arch"; //$NON-NLS-1$ + private static final String EMPTY = ""; //$NON-NLS-1$ + + private Map> configs = new HashMap<>(); + + @Override + public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { + return target.getTypeId().equals(GenericTargetTypeProvider.TYPE_ID); + } + + @Override + public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { + return DebugPlugin.getDefault().getLaunchManager() + .getLaunchConfigurationType(CoreBuildGenericLaunchConfigDelegate.TYPE_ID); + } + + @Override + public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) + throws CoreException { + ILaunchConfiguration config = null; + IProject project = descriptor.getAdapter(IProject.class); + if (project != null) { + Map projectConfigs = configs.get(project); + if (projectConfigs == null) { + projectConfigs = new HashMap<>(); + configs.put(project, projectConfigs); + } + + String os = target.getAttribute(ILaunchTarget.ATTR_OS, EMPTY); + String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, EMPTY); + String targetConfig = os + '.' + arch; + config = projectConfigs.get(targetConfig); + if (config == null) { + config = createLaunchConfiguration(descriptor, target); + } + } + return config; + } + + @Override + protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, + ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { + super.populateLaunchConfiguration(descriptor, target, workingCopy); + + // Set the project + IProject project = descriptor.getAdapter(IProject.class); + workingCopy.setMappedResources(new IResource[] { project }); + + // set the OS and ARCH + String os = target.getAttribute(ILaunchTarget.ATTR_OS, EMPTY); + workingCopy.setAttribute(ATTR_OS, os); + + String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, EMPTY); + workingCopy.setAttribute(ATTR_ARCH, arch); + } + + @Override + public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { + // TODO make sure it's the correct type + if (ownsLaunchConfiguration(configuration)) { + IProject project = configuration.getMappedResources()[0].getProject(); + Map projectConfigs = configs.get(project); + if (projectConfigs == null) { + projectConfigs = new HashMap<>(); + configs.put(project, projectConfigs); + } + + String os = configuration.getAttribute(ATTR_OS, EMPTY); + String arch = configuration.getAttribute(ATTR_ARCH, EMPTY); + String targetConfig = os + '.' + arch; + projectConfigs.put(targetConfig, configuration); + return true; + } + return false; + } + + @Override + public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { + for (Entry> projectEntry : configs.entrySet()) { + Map projectConfigs = projectEntry.getValue(); + for (Entry entry : projectConfigs.entrySet()) { + if (configuration.equals(entry.getValue())) { + projectConfigs.remove(entry.getKey()); + if (projectConfigs.isEmpty()) { + configs.remove(projectEntry.getKey()); + } + return true; + } + } + } + return false; + } + + @Override + public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException { + // nothing to do + return false; + } + + @Override + public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException { + IProject project = descriptor.getAdapter(IProject.class); + if (project != null) { + Map projectConfigs = configs.get(project); + if (projectConfigs != null) { + for (ILaunchConfiguration config : projectConfigs.values()) { + config.delete(); + } + } + } + } + + @Override + public void launchTargetRemoved(ILaunchTarget target) throws CoreException { + // Any other targets have the same OS and ARCH? + String os = target.getAttribute(ILaunchTarget.ATTR_OS, EMPTY); + String arch = target.getAttribute(ILaunchTarget.ATTR_ARCH, EMPTY); + + ILaunchTargetManager targetManager = CDebugCorePlugin.getService(ILaunchTargetManager.class); + for (ILaunchTarget t : targetManager.getLaunchTargets()) { + if (!target.equals(t) && os.equals(t.getAttribute(ILaunchTarget.ATTR_OS, EMPTY)) + && arch.equals(t.getAttribute(ILaunchTarget.ATTR_ARCH, EMPTY))) { + // Yup, nothing to do then + return; + } + } + + for (Entry> projectEntry : configs.entrySet()) { + Map projectConfigs = projectEntry.getValue(); + ILaunchConfiguration config = projectConfigs.get(os); + if (config != null) { + config.delete(); + } + } + } + +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/NullProcess.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/NullProcess.java new file mode 100644 index 00000000000..ca62c059340 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/launch/NullProcess.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.debug.core.launch; + +import java.io.IOException; + +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.IStreamListener; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.core.model.IStreamMonitor; +import org.eclipse.debug.core.model.IStreamsProxy; + +/** + * A simple process that only spits out a message then terminates. + * + * @since 8.3 + */ +public class NullProcess extends PlatformObject implements IProcess { + + private final String message; + private final ILaunch launch; + + public NullProcess(ILaunch launch, String message) { + this.launch = launch; + this.message = message; + } + + @Override + public boolean canTerminate() { + return true; + } + + @Override + public boolean isTerminated() { + return true; + } + + @Override + public void terminate() throws DebugException { + } + + @Override + public String getLabel() { + return launch.getLaunchConfiguration().getName(); + } + + @Override + public ILaunch getLaunch() { + return launch; + } + + @Override + public IStreamsProxy getStreamsProxy() { + return new IStreamsProxy() { + @Override + public void write(String input) throws IOException { + // TODO Auto-generated method stub + + } + + @Override + public IStreamMonitor getOutputStreamMonitor() { + return new IStreamMonitor() { + @Override + public void removeListener(IStreamListener listener) { + } + + @Override + public String getContents() { + return message; + } + + @Override + public void addListener(IStreamListener listener) { + } + }; + } + + @Override + public IStreamMonitor getErrorStreamMonitor() { + return null; + } + }; + } + + @Override + public void setAttribute(String key, String value) { + } + + @Override + public String getAttribute(String key) { + return null; + } + + @Override + public int getExitValue() throws DebugException { + return 0; + } + +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Messages.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Messages.java new file mode 100644 index 00000000000..7de4c1786fe --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/Messages.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.debug.internal.core; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.internal.core.messages"; //$NON-NLS-1$ + public static String CoreBuildGenericLaunchConfigDelegate_CommandNotValid; + public static String CoreBuildGenericLaunchConfigDelegate_NoAction; + public static String CoreBuildGenericLaunchConfigDelegate_SubstitutionFailed; + public static String CoreBuildGenericLaunchConfigDelegate_WorkingDirNotExists; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildGenericLaunchConfigProvider.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildGenericLaunchConfigProvider.java deleted file mode 100644 index 915bbb529f1..00000000000 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/launch/CoreBuildGenericLaunchConfigProvider.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.eclipse.cdt.debug.internal.core.launch; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.eclipse.cdt.debug.core.CDebugCorePlugin; -import org.eclipse.cdt.debug.core.launch.GenericTargetTypeProvider; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.launchbar.core.AbstractLaunchConfigProvider; -import org.eclipse.launchbar.core.ILaunchDescriptor; -import org.eclipse.launchbar.core.target.ILaunchTarget; -import org.eclipse.launchbar.core.target.ILaunchTargetManager; - -public class CoreBuildGenericLaunchConfigProvider extends AbstractLaunchConfigProvider { - - private static final String TYPE_ID = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"; //$NON-NLS-1$ - private static final String ATTR_OS = CDebugCorePlugin.PLUGIN_ID + ".target_os"; //$NON-NLS-1$ - private static final String NO_OS = ""; //$NON-NLS-1$ - - private Map> configs = new HashMap<>(); - - @Override - public boolean supports(ILaunchDescriptor descriptor, ILaunchTarget target) throws CoreException { - return target.getTypeId().equals(GenericTargetTypeProvider.TYPE_ID); - } - - @Override - public ILaunchConfigurationType getLaunchConfigurationType(ILaunchDescriptor descriptor, ILaunchTarget target) - throws CoreException { - return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(TYPE_ID); - } - - @Override - public ILaunchConfiguration getLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target) - throws CoreException { - ILaunchConfiguration config = null; - IProject project = descriptor.getAdapter(IProject.class); - if (project != null) { - Map projectConfigs = configs.get(project); - if (projectConfigs == null) { - projectConfigs = new HashMap<>(); - configs.put(project, projectConfigs); - } - - String os = target.getAttribute(ILaunchTarget.ATTR_OS, NO_OS); - config = projectConfigs.get(os); - if (config == null) { - config = createLaunchConfiguration(descriptor, target); - } - } - return config; - } - - @Override - protected void populateLaunchConfiguration(ILaunchDescriptor descriptor, ILaunchTarget target, - ILaunchConfigurationWorkingCopy workingCopy) throws CoreException { - super.populateLaunchConfiguration(descriptor, target, workingCopy); - - // Set the project - IProject project = descriptor.getAdapter(IProject.class); - workingCopy.setMappedResources(new IResource[] { project }); - - // set the OS - String os = target.getAttribute(ILaunchTarget.ATTR_OS, NO_OS); - workingCopy.setAttribute(ATTR_OS, os); - } - - @Override - public boolean launchConfigurationAdded(ILaunchConfiguration configuration) throws CoreException { - if (ownsLaunchConfiguration(configuration)) { - IProject project = configuration.getMappedResources()[0].getProject(); - Map projectConfigs = configs.get(project); - if (projectConfigs == null) { - projectConfigs = new HashMap<>(); - configs.put(project, projectConfigs); - } - - String os = configuration.getAttribute(ATTR_OS, NO_OS); - projectConfigs.put(os, configuration); - return true; - } - return false; - } - - @Override - public boolean launchConfigurationRemoved(ILaunchConfiguration configuration) throws CoreException { - for (Entry> projectEntry : configs.entrySet()) { - Map projectConfigs = projectEntry.getValue(); - for (Entry entry : projectConfigs.entrySet()) { - if (configuration.equals(entry.getValue())) { - projectConfigs.remove(entry.getKey()); - if (projectConfigs.isEmpty()) { - configs.remove(projectEntry.getKey()); - } - return true; - } - } - } - return false; - } - - @Override - public boolean launchConfigurationChanged(ILaunchConfiguration configuration) throws CoreException { - // nothing to do - return false; - } - - @Override - public void launchDescriptorRemoved(ILaunchDescriptor descriptor) throws CoreException { - IProject project = descriptor.getAdapter(IProject.class); - if (project != null) { - Map projectConfigs = configs.get(project); - if (projectConfigs != null) { - for (ILaunchConfiguration config : projectConfigs.values()) { - config.delete(); - } - } - } - } - - @Override - public void launchTargetRemoved(ILaunchTarget target) throws CoreException { - // Any other targets have the same OS? - String os = target.getAttribute(ILaunchTarget.ATTR_OS, NO_OS); - - ILaunchTargetManager targetManager = CDebugCorePlugin.getService(ILaunchTargetManager.class); - for (ILaunchTarget t : targetManager.getLaunchTargets()) { - if (!target.equals(t) && os.equals(t.getAttribute(ILaunchTarget.ATTR_OS, NO_OS))) { - // Yup, nothing to do then - return; - } - } - - for (Entry> projectEntry : configs.entrySet()) { - Map projectConfigs = projectEntry.getValue(); - ILaunchConfiguration config = projectConfigs.get(os); - if (config != null) { - config.delete(); - } - } - } - -} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/messages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/messages.properties new file mode 100644 index 00000000000..c00aff78954 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/messages.properties @@ -0,0 +1,11 @@ +############################################################################### +# Copyright (c) 2003, 2010 QNX Software Systems 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 +############################################################################### +CoreBuildGenericLaunchConfigDelegate_CommandNotValid=Not a valid command "%s" +CoreBuildGenericLaunchConfigDelegate_NoAction=No action specified. Skipping. +CoreBuildGenericLaunchConfigDelegate_SubstitutionFailed=Variable substitution failed "%s" +CoreBuildGenericLaunchConfigDelegate_WorkingDirNotExists=Working directory %s does not exist diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_12.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_12.java index 7cc945a9f9b..6e58297affc 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_12.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBProcesses_7_12.java @@ -121,6 +121,9 @@ public class GDBProcesses_7_12 extends GDBProcesses_7_11 { } } + /** + * @since 5.4 + */ @Override protected boolean targetAttachRequiresTrailingNewline() { return true; diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetAttach.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetAttach.java index 9da901e7ed8..834adbf5091 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetAttach.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/commands/MITargetAttach.java @@ -66,8 +66,11 @@ public class MITargetAttach extends MICommand { } /** - * Add an extra newline to force GDB 7.11 to flush error response to the MI channel. + * Add an extra newline to force GDB 7.11 to flush error response to the MI + * channel. + * * @see GDBProcesses_7_2#targetAttachRequiresTrailingNewline + * @since 5.4 */ @Override public String constructCommand(String groupId, String threadId, int frameId) { diff --git a/launch/org.eclipse.cdt.launch/plugin.xml b/launch/org.eclipse.cdt.launch/plugin.xml index efb162da337..c85ea032a69 100644 --- a/launch/org.eclipse.cdt.launch/plugin.xml +++ b/launch/org.eclipse.cdt.launch/plugin.xml @@ -154,11 +154,16 @@ id="org.eclipse.cdt.launch.launchConfigurationTabGroup.local" type="org.eclipse.cdt.debug.core.localCoreBuildLaunchConfigType"> + + diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/GenericLaunchConfigTabGroup.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/GenericLaunchConfigTabGroup.java new file mode 100644 index 00000000000..7f6ce2376c4 --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/corebuild/GenericLaunchConfigTabGroup.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.internal.corebuild; + +import org.eclipse.cdt.launch.ui.corebuild.GenericMainTab; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; +import org.eclipse.debug.ui.CommonTab; +import org.eclipse.debug.ui.EnvironmentTab; +import org.eclipse.debug.ui.ILaunchConfigurationDialog; +import org.eclipse.debug.ui.ILaunchConfigurationTab; + +public class GenericLaunchConfigTabGroup extends AbstractLaunchConfigurationTabGroup { + + @Override + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + setTabs(new ILaunchConfigurationTab[] { + new GenericMainTab(), + new EnvironmentTab(), + new CommonTab() + }); + } + +} diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/Messages.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/Messages.java new file mode 100644 index 00000000000..d24424c3b25 --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/Messages.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2017 QNX Software Systems 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.launch.internal.ui; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.cdt.launch.internal.ui.messages"; //$NON-NLS-1$ + public static String GenericMainTab_Arguments; + public static String GenericMainTab_BrowseFileSystem; + public static String GenericMainTab_BrowseWorkspace; + public static String GenericMainTab_Location; + public static String GenericMainTab_LocationNotAFile; + public static String GenericMainTab_LocationNotExists; + public static String GenericMainTab_Main; + public static String GenericMainTab_Quotes; + public static String GenericMainTab_SelectResource; + public static String GenericMainTab_SelectWorkingDir; + public static String GenericMainTab_SpecifyLocation; + public static String GenericMainTab_Variables; + public static String GenericMainTab_WorkingDirectory; + public static String GenericMainTab_WorkingDirNotADir; + public static String GenericMainTab_WorkingDirNotExists; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/messages.properties b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/messages.properties new file mode 100644 index 00000000000..31e814f228e --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/messages.properties @@ -0,0 +1,22 @@ +############################################################################### +# Copyright (c) 2002, 2015 QNX Software Systems 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 +############################################################################### +GenericMainTab_Arguments=Arguments: +GenericMainTab_BrowseFileSystem=Browse File System... +GenericMainTab_BrowseWorkspace=Browse Workspace... +GenericMainTab_Location=Location +GenericMainTab_LocationNotAFile=External tool location specified is not a file +GenericMainTab_LocationNotExists=External tool location does not exist +GenericMainTab_Main=Main +GenericMainTab_Quotes=Note: Enclose an argument containing spaces using double-quotes (\\"). +GenericMainTab_SelectResource=Select a resource: +GenericMainTab_SelectWorkingDir=Select a working directory: +GenericMainTab_SpecifyLocation=Please specify the location of the external tool you would like to configure. +GenericMainTab_Variables=Variables... +GenericMainTab_WorkingDirectory=Working Directory: +GenericMainTab_WorkingDirNotADir=The specified location is not a directory +GenericMainTab_WorkingDirNotExists=External tool working directory does not exist or is invalid diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/GenericMainTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/GenericMainTab.java new file mode 100644 index 00000000000..45f93ca97bd --- /dev/null +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/corebuild/GenericMainTab.java @@ -0,0 +1,715 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation 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 + * + * copied from: + * org.eclipse.ui.externaltools.internal.launchConfigurations.GenericMainTab + *******************************************************************************/ +package org.eclipse.cdt.launch.ui.corebuild; + +import java.io.File; + +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.launch.internal.ui.LaunchImages; +import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; +import org.eclipse.cdt.launch.internal.ui.Messages; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.variables.IStringVariableManager; +import org.eclipse.core.variables.VariablesPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.debug.ui.StringVariableSelectionDialog; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ContainerSelectionDialog; +import org.eclipse.ui.dialogs.ResourceSelectionDialog; + +/** + * @since 9.2 + */ +public class GenericMainTab extends AbstractLaunchConfigurationTab { + + public final static String FIRST_EDIT = "editedByExternalToolsMainTab"; //$NON-NLS-1$ + + protected Text locationField; + protected Text workDirectoryField; + protected Button fileLocationButton; + protected Button workspaceLocationButton; + protected Button variablesLocationButton; + protected Button fileWorkingDirectoryButton; + protected Button workspaceWorkingDirectoryButton; + protected Button variablesWorkingDirectoryButton; + + protected Text argumentField; + protected Button argumentVariablesButton; + + protected SelectionAdapter selectionAdapter; + + protected boolean fInitializing = false; + private boolean userEdited = false; + + protected WidgetListener fListener = new WidgetListener(); + + /** + * A listener to update for text modification and widget selection. + */ + protected class WidgetListener extends SelectionAdapter implements ModifyListener { + @Override + public void modifyText(ModifyEvent e) { + if (!fInitializing) { + setDirty(true); + userEdited = true; + updateLaunchConfigurationDialog(); + } + } + + @Override + public void widgetSelected(SelectionEvent e) { + setDirty(true); + Object source = e.getSource(); + if (source == workspaceLocationButton) { + handleWorkspaceLocationButtonSelected(); + } else if (source == fileLocationButton) { + handleFileLocationButtonSelected(); + } else if (source == workspaceWorkingDirectoryButton) { + handleWorkspaceWorkingDirectoryButtonSelected(); + } else if (source == fileWorkingDirectoryButton) { + handleFileWorkingDirectoryButtonSelected(); + } else if (source == argumentVariablesButton) { + handleVariablesButtonSelected(argumentField); + } else if (source == variablesLocationButton) { + handleVariablesButtonSelected(locationField); + } else if (source == variablesWorkingDirectoryButton) { + handleVariablesButtonSelected(workDirectoryField); + } + } + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt. + * widgets.Composite) + */ + @Override + public void createControl(Composite parent) { + Composite mainComposite = new Composite(parent, SWT.NONE); + setControl(mainComposite); + mainComposite.setFont(parent.getFont()); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + mainComposite.setLayout(layout); + mainComposite.setLayoutData(gridData); + + createLocationComponent(mainComposite); + createWorkDirectoryComponent(mainComposite); + createArgumentComponent(mainComposite); + createVerticalSpacer(mainComposite, 1); + + Dialog.applyDialogFont(parent); + } + + /** + * Creates the controls needed to edit the location attribute of an external + * tool + * + * @param parent + * the composite to create the controls in + */ + protected void createLocationComponent(Composite parent) { + Group group = new Group(parent, SWT.NONE); + String locationLabel = getLocationLabel(); + group.setText(locationLabel); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + group.setLayout(layout); + group.setLayoutData(gridData); + + locationField = new Text(group, SWT.BORDER); + gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; + locationField.setLayoutData(gridData); + locationField.addModifyListener(fListener); + addControlAccessibleListener(locationField, group.getText()); + + Composite buttonComposite = new Composite(group, SWT.NONE); + layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 3; + gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(gridData); + buttonComposite.setFont(parent.getFont()); + + workspaceLocationButton = createPushButton(buttonComposite, Messages.GenericMainTab_BrowseWorkspace, null); + workspaceLocationButton.addSelectionListener(fListener); + addControlAccessibleListener(workspaceLocationButton, + group.getText() + " " + workspaceLocationButton.getText()); //$NON-NLS-1$ + + fileLocationButton = createPushButton(buttonComposite, Messages.GenericMainTab_BrowseFileSystem, null); + fileLocationButton.addSelectionListener(fListener); + addControlAccessibleListener(fileLocationButton, group.getText() + " " + fileLocationButton.getText()); //$NON-NLS-1$ + + variablesLocationButton = createPushButton(buttonComposite, Messages.GenericMainTab_Variables, null); + variablesLocationButton.addSelectionListener(fListener); + addControlAccessibleListener(variablesLocationButton, + group.getText() + " " + variablesLocationButton.getText()); //$NON-NLS-1$ + } + + /** + * Returns the label used for the location widgets. Subclasses may wish to + * override. + */ + protected String getLocationLabel() { + return Messages.GenericMainTab_Location; + } + + /** + * Creates the controls needed to edit the working directory attribute of an + * external tool + * + * @param parent + * the composite to create the controls in + */ + protected void createWorkDirectoryComponent(Composite parent) { + Group group = new Group(parent, SWT.NONE); + String groupName = getWorkingDirectoryLabel(); + group.setText(groupName); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + group.setLayout(layout); + group.setLayoutData(gridData); + + workDirectoryField = new Text(group, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; + workDirectoryField.setLayoutData(data); + workDirectoryField.addModifyListener(fListener); + addControlAccessibleListener(workDirectoryField, group.getText()); + + Composite buttonComposite = new Composite(group, SWT.NONE); + layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + layout.numColumns = 3; + gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(gridData); + buttonComposite.setFont(parent.getFont()); + + workspaceWorkingDirectoryButton = createPushButton(buttonComposite, Messages.GenericMainTab_BrowseWorkspace, null); + workspaceWorkingDirectoryButton.addSelectionListener(fListener); + addControlAccessibleListener(workspaceWorkingDirectoryButton, + group.getText() + " " + workspaceWorkingDirectoryButton.getText()); //$NON-NLS-1$ + + fileWorkingDirectoryButton = createPushButton(buttonComposite, Messages.GenericMainTab_BrowseFileSystem, null); + fileWorkingDirectoryButton.addSelectionListener(fListener); + addControlAccessibleListener(fileWorkingDirectoryButton, group.getText() + " " + fileLocationButton.getText()); //$NON-NLS-1$ + + variablesWorkingDirectoryButton = createPushButton(buttonComposite, Messages.GenericMainTab_Variables, null); + variablesWorkingDirectoryButton.addSelectionListener(fListener); + addControlAccessibleListener(variablesWorkingDirectoryButton, + group.getText() + " " + variablesWorkingDirectoryButton.getText()); //$NON-NLS-1$ + } + + /** + * Return the String to use as the label for the working directory field. + * Subclasses may wish to override. + */ + protected String getWorkingDirectoryLabel() { + return Messages.GenericMainTab_WorkingDirectory; + } + + /** + * Creates the controls needed to edit the argument and prompt for argument + * attributes of an external tool + * + * @param parent + * the composite to create the controls in + */ + protected void createArgumentComponent(Composite parent) { + Group group = new Group(parent, SWT.NONE); + String groupName = Messages.GenericMainTab_Arguments; + group.setText(groupName); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + GridData gridData = new GridData(GridData.FILL_BOTH); + group.setLayout(layout); + group.setLayoutData(gridData); + group.setFont(parent.getFont()); + + argumentField = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); + argumentField.addTraverseListener(new TraverseListener() { + @Override + public void keyTraversed(TraverseEvent event) { + if (event.detail == SWT.TRAVERSE_RETURN && (event.stateMask & SWT.MODIFIER_MASK) != 0) { + event.doit = true; + } + } + }); + + gridData = new GridData(GridData.FILL_BOTH); + gridData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; + gridData.heightHint = 30; + argumentField.setLayoutData(gridData); + argumentField.addModifyListener(fListener); + addControlAccessibleListener(argumentField, group.getText()); + + Composite composite = new Composite(group, SWT.NONE); + layout = new GridLayout(); + layout.numColumns = 1; + layout.marginHeight = 0; + layout.marginWidth = 0; + gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); + composite.setLayout(layout); + composite.setLayoutData(gridData); + composite.setFont(parent.getFont()); + + argumentVariablesButton = createPushButton(composite, Messages.GenericMainTab_Variables, null); + argumentVariablesButton.addSelectionListener(fListener); + addControlAccessibleListener(argumentVariablesButton, argumentVariablesButton.getText()); // need to strip the + // mnemonic from + // buttons + + Label instruction = new Label(group, SWT.NONE); + instruction.setText(Messages.GenericMainTab_Quotes); + gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gridData.horizontalSpan = 2; + instruction.setLayoutData(gridData); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug. + * core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + configuration.setAttribute(FIRST_EDIT, true); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug + * .core.ILaunchConfiguration) + */ + @Override + public void initializeFrom(ILaunchConfiguration configuration) { + fInitializing = true; + updateLocation(configuration); + updateWorkingDirectory(configuration); + updateArgument(configuration); + fInitializing = false; + setDirty(false); + } + + /** + * Updates the working directory widgets to match the state of the given launch + * configuration. + */ + protected void updateWorkingDirectory(ILaunchConfiguration configuration) { + String workingDir = ""; //$NON-NLS-1$ + try { + workingDir = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$ + } catch (CoreException ce) { + LaunchUIPlugin.log(ce.getStatus()); + } + workDirectoryField.setText(workingDir); + } + + /** + * Updates the location widgets to match the state of the given launch + * configuration. + */ + protected void updateLocation(ILaunchConfiguration configuration) { + String location = ""; //$NON-NLS-1$ + try { + location = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_LOCATION, ""); //$NON-NLS-1$ + } catch (CoreException ce) { + LaunchUIPlugin.log(ce.getStatus()); + } + locationField.setText(location); + } + + /** + * Updates the argument widgets to match the state of the given launch + * configuration. + */ + protected void updateArgument(ILaunchConfiguration configuration) { + String arguments = ""; //$NON-NLS-1$ + try { + arguments = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$ + } catch (CoreException ce) { + LaunchUIPlugin.log(ce.getStatus()); + } + argumentField.setText(arguments); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug. + * core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + String location = locationField.getText().trim(); + if (location.length() == 0) { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_LOCATION, (String) null); + } else { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_LOCATION, location); + } + + String workingDirectory = workDirectoryField.getText().trim(); + if (workingDirectory.length() == 0) { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null); + } else { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workingDirectory); + } + + String arguments = argumentField.getText().trim(); + if (arguments.length() == 0) { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_TOOL_ARGUMENTS, (String) null); + } else { + configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_TOOL_ARGUMENTS, arguments); + } + + if (userEdited) { + configuration.setAttribute(FIRST_EDIT, (String) null); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName() + */ + @Override + public String getName() { + return Messages.GenericMainTab_Main; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core. + * ILaunchConfiguration) + */ + @Override + public boolean isValid(ILaunchConfiguration launchConfig) { + setErrorMessage(null); + setMessage(null); + boolean newConfig = false; + try { + newConfig = launchConfig.getAttribute(FIRST_EDIT, false); + } catch (CoreException e) { + // assume false is correct + } + return validateLocation(newConfig) && validateWorkDirectory(); + } + + /** + * Validates the content of the location field. + */ + protected boolean validateLocation(boolean newConfig) { + String location = locationField.getText().trim(); + if (location.length() < 1) { + setErrorMessage(null); + setMessage(Messages.GenericMainTab_SpecifyLocation); + return true; + } + + String expandedLocation = null; + try { + expandedLocation = resolveValue(location); + if (expandedLocation == null) { // a variable that needs to be resolved at runtime + return true; + } + } catch (CoreException e) { + setErrorMessage(e.getStatus().getMessage()); + return false; + } + + File file = new File(expandedLocation); + if (!file.exists()) { // The file does not exist. + if (!newConfig) { + setErrorMessage(Messages.GenericMainTab_LocationNotExists); + } + return false; + } + if (!file.isFile()) { + if (!newConfig) { + setErrorMessage(Messages.GenericMainTab_LocationNotAFile); + } + return false; + } + return true; + } + + /** + * Validates the variables of the given string to determine if all variables are + * valid + * + * @param expression + * expression with variables + * @exception CoreException + * if a variable is specified that does not exist + */ + private void validateVaribles(String expression) throws CoreException { + IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); + manager.validateStringVariables(expression); + } + + private String resolveValue(String expression) throws CoreException { + String expanded = null; + try { + expanded = getValue(expression); + } catch (CoreException e) { // possibly just a variable that needs to be resolved at runtime + validateVaribles(expression); + return null; + } + return expanded; + } + + /** + * Validates the value of the given string to determine if any/all variables are + * valid + * + * @param expression + * expression with variables + * @return whether the expression contained any variable values + * @exception CoreException + * if variable resolution fails + */ + private String getValue(String expression) throws CoreException { + IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); + return manager.performStringSubstitution(expression); + } + + /** + * Validates the content of the working directory field. + */ + protected boolean validateWorkDirectory() { + String dir = workDirectoryField.getText().trim(); + if (dir.length() <= 0) { + return true; + } + + String expandedDir = null; + try { + expandedDir = resolveValue(dir); + if (expandedDir == null) { // a variable that needs to be resolved at runtime + return true; + } + } catch (CoreException e) { + setErrorMessage(e.getStatus().getMessage()); + return false; + } + + File file = new File(expandedDir); + if (!file.exists()) { // The directory does not exist. + setErrorMessage(Messages.GenericMainTab_WorkingDirNotExists); + return false; + } + if (!file.isDirectory()) { + setErrorMessage(Messages.GenericMainTab_WorkingDirNotADir); + return false; + } + return true; + } + + /** + * Prompts the user to choose a location from the filesystem and sets the + * location as the full path of the selected file. + */ + protected void handleFileLocationButtonSelected() { + FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE); + fileDialog.setFileName(locationField.getText()); + String text = fileDialog.open(); + if (text != null) { + locationField.setText(text); + } + } + + /** + * Prompts the user for a workspace location within the workspace and sets the + * location as a String containing the workspace_loc variable or + * null if no location was obtained from the user. + */ + protected void handleWorkspaceLocationButtonSelected() { + ResourceSelectionDialog dialog; + dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), + Messages.GenericMainTab_SelectResource); + dialog.open(); + Object[] results = dialog.getResult(); + if (results == null || results.length < 1) { + return; + } + IResource resource = (IResource) results[0]; + locationField.setText(newVariableExpression("workspace_loc", resource.getFullPath().toString())); //$NON-NLS-1$ + } + + /** + * Prompts the user for a working directory location within the workspace and + * sets the working directory as a String containing the workspace_loc variable + * or null if no location was obtained from the user. + */ + protected void handleWorkspaceWorkingDirectoryButtonSelected() { + ContainerSelectionDialog containerDialog; + containerDialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, + Messages.GenericMainTab_SelectWorkingDir); + containerDialog.open(); + Object[] resource = containerDialog.getResult(); + String text = null; + if (resource != null && resource.length > 0) { + text = newVariableExpression("workspace_loc", ((IPath) resource[0]).toString()); //$NON-NLS-1$ + } + if (text != null) { + workDirectoryField.setText(text); + } + } + + /** + * Returns a new variable expression with the given variable and the given + * argument. + * + * @see IStringVariableManager#generateVariableExpression(String, String) + */ + protected String newVariableExpression(String varName, String arg) { + return VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression(varName, arg); + } + + /** + * Prompts the user to choose a working directory from the filesystem. + */ + protected void handleFileWorkingDirectoryButtonSelected() { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SAVE); + dialog.setMessage(Messages.GenericMainTab_SelectWorkingDir); + dialog.setFilterPath(workDirectoryField.getText()); + String text = dialog.open(); + if (text != null) { + workDirectoryField.setText(text); + } + } + + /** + * A variable entry button has been pressed for the given text field. Prompt the + * user for a variable and enter the result in the given field. + */ + private void handleVariablesButtonSelected(Text textField) { + String variable = getVariable(); + if (variable != null) { + textField.insert(variable); + } + } + + /** + * Prompts the user to choose and configure a variable and returns the resulting + * string, suitable to be used as an attribute. + */ + private String getVariable() { + StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell()); + dialog.open(); + return dialog.getVariableExpression(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage() + */ + @Override + public Image getImage() { + return LaunchImages.get(LaunchImages.IMG_VIEW_MAIN_TAB); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug. + * core.ILaunchConfigurationWorkingCopy) + */ + @Override + public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core + * .ILaunchConfigurationWorkingCopy) + */ + @Override + public void activated(ILaunchConfigurationWorkingCopy workingCopy) { + } + + /* + * Fix for Bug 60163 Accessibility: New Builder Dialog missing object info for + * textInput controls + */ + public void addControlAccessibleListener(Control control, String controlName) { + // strip mnemonic (&) + String[] strs = controlName.split("&"); //$NON-NLS-1$ + StringBuffer stripped = new StringBuffer(); + for (int i = 0; i < strs.length; i++) { + stripped.append(strs[i]); + } + control.getAccessible().addAccessibleListener(new ControlAccessibleListener(stripped.toString())); + } + + private class ControlAccessibleListener extends AccessibleAdapter { + private String controlName; + + ControlAccessibleListener(String name) { + controlName = name; + } + + @Override + public void getName(AccessibleEvent e) { + e.result = controlName; + } + + } + +} diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java index 9558c87b9b6..62bea0f1ad7 100644 --- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java +++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java @@ -308,7 +308,7 @@ public class SerialPort { return outputStream; } - public void open() throws IOException { + public synchronized void open() throws IOException { handle = open0(portName, baudRate.getRate(), byteSize.getSize(), parity.ordinal(), stopBits.ordinal()); isOpen = true; @@ -356,18 +356,26 @@ public class SerialPort { } public void pause() throws IOException { - isPaused = true; - close0(handle); - try { - // Sleep for a second since some serial ports take a while to actually close - Thread.sleep(500); - } catch (InterruptedException e) { - // nothing to do + if (!isOpen) { + return; + } + synchronized (pauseMutex) { + isPaused = true; + close0(handle); + try { + // Sleep for a second since some serial ports take a while to actually close + Thread.sleep(500); + } catch (InterruptedException e) { + // nothing to do + } } } public void resume() throws IOException { synchronized (pauseMutex) { + if (!isPaused) { + return; + } isPaused = false; handle = open0(portName, baudRate.getRate(), byteSize.getSize(), parity.ordinal(), stopBits.ordinal()); isOpen = true; diff --git a/pom.xml b/pom.xml index 38812890fa6..ba60d0fd94e 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,10 @@ cross/org.eclipse.cdt.build.crossgcc-feature cross/org.eclipse.cdt.launch.remote cross/org.eclipse.cdt.launch.remote-feature - + cross/org.eclipse.cdt.launch.serial.core + cross/org.eclipse.cdt.launch.serial.ui + cross/org.eclipse.cdt.launch.serial-feature + debug/org.eclipse.cdt.debug.core debug/org.eclipse.cdt.debug.ui -- cgit v1.2.3