Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.launch.core')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF75
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.properties28
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml26
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/schema/launchConfigTypeBindings.exsd28
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java701
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java700
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/PropertyTester.java40
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java651
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java165
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IContextSelectorLaunchAttributes.java5
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java1099
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java46
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/RemoveLaunchStep.java45
13 files changed, 1854 insertions, 1755 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
index 81f5a00f6..694deca1b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF
@@ -1,36 +1,39 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.tcf.te.launch.core;singleton:=true
-Bundle-Version: 1.0.0.qualifier
-Bundle-Activator: org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator
-Bundle-Vendor: %providerName
-Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
- org.eclipse.core.expressions;bundle-version="3.4.300",
- org.eclipse.debug.core;bundle-version="3.7.0",
- org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.concurrent;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.model;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.0.0",
- org.eclipse.tcf.te.runtime.stepper;bundle-version="1.0.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Bundle-ActivationPolicy: lazy
-Bundle-Localization: plugin
-Export-Package: org.eclipse.tcf.te.launch.core.activator;x-internal:=true,
- org.eclipse.tcf.te.launch.core.adapters.internal;x-internal:=true,
- org.eclipse.tcf.te.launch.core.bindings,
- org.eclipse.tcf.te.launch.core.bindings.interfaces,
- org.eclipse.tcf.te.launch.core.bindings.internal;x-friends:="org.eclipse.tcf.te.launch.ui",
- org.eclipse.tcf.te.launch.core.delegates,
- org.eclipse.tcf.te.launch.core.exceptions,
- org.eclipse.tcf.te.launch.core.extensions.internal;x-internal:=true,
- org.eclipse.tcf.te.launch.core.interfaces.tracing,
- org.eclipse.tcf.te.launch.core.lm,
- org.eclipse.tcf.te.launch.core.lm.delegates,
- org.eclipse.tcf.te.launch.core.lm.interfaces,
- org.eclipse.tcf.te.launch.core.lm.internal;x-internal:=true,
- org.eclipse.tcf.te.launch.core.nls;x-internal:=true,
- org.eclipse.tcf.te.launch.core.persistence,
- org.eclipse.tcf.te.launch.core.preferences,
- org.eclipse.tcf.te.launch.core.selection,
- org.eclipse.tcf.te.launch.core.selection.interfaces
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.tcf.te.launch.core;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.core.expressions;bundle-version="3.4.300",
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.tcf.te.runtime;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.concurrent;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.model;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.statushandler;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.stepper;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.persistence;bundle-version="1.0.0",
+ org.eclipse.tcf.te.runtime.services;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Export-Package: org.eclipse.tcf.te.launch.core.activator;x-internal:=true,
+ org.eclipse.tcf.te.launch.core.adapters.internal;x-internal:=true,
+ org.eclipse.tcf.te.launch.core.bindings,
+ org.eclipse.tcf.te.launch.core.bindings.interfaces,
+ org.eclipse.tcf.te.launch.core.bindings.internal;x-friends:="org.eclipse.tcf.te.launch.ui",
+ org.eclipse.tcf.te.launch.core.delegates,
+ org.eclipse.tcf.te.launch.core.exceptions,
+ org.eclipse.tcf.te.launch.core.extensions.internal;x-internal:=true,
+ org.eclipse.tcf.te.launch.core.interfaces.tracing,
+ org.eclipse.tcf.te.launch.core.lm,
+ org.eclipse.tcf.te.launch.core.lm.delegates,
+ org.eclipse.tcf.te.launch.core.lm.interfaces,
+ org.eclipse.tcf.te.launch.core.lm.internal;x-internal:=true,
+ org.eclipse.tcf.te.launch.core.nls;x-internal:=true,
+ org.eclipse.tcf.te.launch.core.persistence,
+ org.eclipse.tcf.te.launch.core.preferences,
+ org.eclipse.tcf.te.launch.core.selection,
+ org.eclipse.tcf.te.launch.core.selection.interfaces,
+ org.eclipse.tcf.te.launch.core.steps
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.properties
index a3934d8d4..a2c59bb53 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.properties
@@ -1,12 +1,16 @@
-##################################################################################
-# Copyright (c) 2011, 2012 Wind River Systems, Inc. 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
-#
-# Contributors:
-# Wind River Systems - initial API and implementation
-##################################################################################
-
-pluginName = Target Explorer, Launching, Core
-providerName = Eclipse.org - TCF
+##################################################################################
+# Copyright (c) 2011, 2012 Wind River Systems, Inc. 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
+#
+# Contributors:
+# Wind River Systems - initial API and implementation
+##################################################################################
+
+pluginName = Target Explorer, Launching, Core
+providerName = Eclipse.org - TCF
+
+Extension.LaunchConfigTypeBindings.name=Launch Configuration Type Bindings
+Extension.LaunchManagerDelegates.name=Launch Manager Delegates
+Extension.LaunchModeVariantDelegates.name=Launch Mode Variant Delegates
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml
index 73209e33b..72bf67db3 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml
@@ -3,9 +3,9 @@
<plugin>
<!-- Extension points -->
- <extension-point id="launchConfigTypeBindings" name="Launch Configuration Type Bindings" schema="schema/launchConfigTypeBindings.exsd"/>
- <extension-point id="launchManagerDelegates" name="Launch Manager Delegates" schema="schema/launchManagerDelegates.exsd"/>
- <extension-point id="launchModeVariantDelegates" name="Launch Mode Variant Delegates" schema="schema/launchModeVariantDelegates.exsd"/>
+ <extension-point id="launchConfigTypeBindings" name="%Extension.LaunchConfigTypeBindings.name" schema="schema/launchConfigTypeBindings.exsd"/>
+ <extension-point id="launchManagerDelegates" name="%Extension.LaunchManagerDelegates.name" schema="schema/launchManagerDelegates.exsd"/>
+ <extension-point id="launchModeVariantDelegates" name="%Extension.LaunchModeVariantDelegates.name" schema="schema/launchModeVariantDelegates.exsd"/>
<!-- Adapter factory contributions -->
<extension point="org.eclipse.core.runtime.adapters">
@@ -24,4 +24,24 @@
</initializer>
</extension>
+<!-- Property tester contributions -->
+ <extension point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.tcf.te.launch.core.bindings.internal.PropertyTester"
+ id="org.eclipse.tcf.te.launch.core.PropertyTester"
+ namespace="org.eclipse.tcf.te.launch.core"
+ properties="launchMode,launchConfigTypeId"
+ type="org.eclipse.debug.core.ILaunch">
+ </propertyTester>
+ </extension>
+
+<!-- Launch Step contributions -->
+ <extension point="org.eclipse.tcf.te.runtime.stepper.steps">
+ <step
+ class="org.eclipse.tcf.te.launch.core.steps.RemoveLaunchStep"
+ id="org.eclipse.tcf.te.launch.core.removeLaunchStep"
+ label="%LaunchStep.RemoveLaunch.name">
+ </step>
+ </extension>
+
</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/schema/launchConfigTypeBindings.exsd b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/schema/launchConfigTypeBindings.exsd
index e2f9cbf94..eb9008325 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/schema/launchConfigTypeBindings.exsd
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/schema/launchConfigTypeBindings.exsd
@@ -60,7 +60,6 @@
<element ref="launchManagerDelegate" minOccurs="0" maxOccurs="unbounded"/>
<element ref="launchModeVariantDelegate" minOccurs="0" maxOccurs="unbounded"/>
<element ref="stepper" minOccurs="0" maxOccurs="unbounded"/>
- <element ref="step" minOccurs="0" maxOccurs="unbounded"/>
<element ref="stepGroup" minOccurs="0" maxOccurs="unbounded"/>
<element ref="enablement" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
@@ -179,33 +178,6 @@
</complexType>
</element>
- <element name="step">
- <annotation>
- <documentation>
- A step could be bound to a launch configuration type for each available launch mode. If no launch mode is specified, the step is used for all launch modes the launch configuration type supports.
- </documentation>
- </annotation>
- <complexType>
- <attribute name="id" type="string" use="required">
- <annotation>
- <documentation>
- The id of the step to use.
- </documentation>
- <appinfo>
- <meta.attribute kind="identifier" basedOn="org.eclipse.tcf.te.runtime.stepper.steps/step/@id"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="modes" type="string">
- <annotation>
- <documentation>
- The comma separated list of launch modes to use the step for. If not specified, the step is used for all undefined launch modes, for which the launch configuration type can be used.
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
<element name="stepGroup">
<annotation>
<documentation>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java
index 31a95d8c5..1ed089acf 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java
@@ -1,369 +1,332 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.launch.core.bindings;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.expressions.EvaluationResult;
-import org.eclipse.core.expressions.Expression;
-import org.eclipse.core.expressions.ExpressionConverter;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.tcf.te.launch.core.bindings.internal.LaunchBinding;
-import org.eclipse.tcf.te.launch.core.bindings.internal.LaunchConfigTypeBinding;
-import org.eclipse.tcf.te.launch.core.bindings.internal.OverwritableLaunchBinding;
-import org.eclipse.tcf.te.launch.core.extensions.internal.LaunchModeVariantDelegateExtensionPointManager;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
-import org.eclipse.tcf.te.launch.core.lm.internal.ExtensionPointManager;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
-import org.eclipse.tcf.te.runtime.extensions.ExtensionPointComparator;
-import org.eclipse.tcf.te.runtime.stepper.StepperManager;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IStep;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepGroup;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IVariantDelegate;
-
-
-/**
- * Manager that controls the launch configuration type bindings.
- */
-public class LaunchConfigTypeBindingsManager {
- // Map of all launch configuration type bindings by id
- private final Map<String, LaunchConfigTypeBinding> bindings = new Hashtable<String, LaunchConfigTypeBinding>();
-
- /*
- * Thread save singleton instance creation.
- */
- private static class LazyInstanceHolder {
- public static LaunchConfigTypeBindingsManager instance = new LaunchConfigTypeBindingsManager();
- }
-
- /**
- * Returns the singleton instance.
- */
- public static LaunchConfigTypeBindingsManager getInstance() {
- return LazyInstanceHolder.instance;
- }
-
- /**
- * Constructor.
- */
- LaunchConfigTypeBindingsManager() {
- // Load the launch configuration type bindings on instantiation.
- loadBindingsExtensions();
- }
-
- /**
- * Get all valid launch configuration type id's for the given selection.
- *
- * @param selection The selection or <code>null</code>.
- * @return The list of valid launch configuration type id's for the selection or an empty list.
- */
- public String[] getValidLaunchConfigTypes(ILaunchSelection selection) {
- Set<String> validLaunchTypes = new HashSet<String>();
- if (selection != null && selection.getSelectedContexts() != null && selection.getSelectedContexts().length > 0) {
- for (String launchConfigTypeId : bindings.keySet()) {
- if (isValidLaunchConfigType(launchConfigTypeId, selection)) {
- validLaunchTypes.add(launchConfigTypeId);
- }
- }
- }
- return validLaunchTypes.toArray(new String[validLaunchTypes.size()]);
- }
-
- /**
- * Validates the given launch selection.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param selection The selection. Must not be <code>null</code>.
- */
- public boolean isValidLaunchConfigType(String typeId, ILaunchSelection selection) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(selection);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
- return (launchConfigType != null && launchConfigType.isPublic() &&
- (selection.getLaunchMode() == null || launchConfigType.supportsMode(selection.getLaunchMode())) &&
- binding != null && binding.validate(selection) != EvaluationResult.FALSE);
- }
-
- /**
- * Validates the given launch selection.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode or <code>null</code>.
- * @param context The selection context. Must not be <code>null</code>.
- */
- public boolean isValidLaunchConfigType(String typeId, String mode, ISelectionContext context) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(context);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
- return (launchConfigType != null && launchConfigType.isPublic() &&
- (mode == null || launchConfigType.supportsMode(mode)) &&
- binding != null && binding.validate(mode, context) != EvaluationResult.FALSE);
- }
-
- /**
- * Get the registered launch manager delegate for the given launch configuration type and launch mode.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- *
- * @return The launch manager delegate, or a default delegate if no delegate is registered for the
- * given launch configuration type id and launch mode.
- */
- public ILaunchManagerDelegate getLaunchManagerDelegate(String typeId, String mode) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(mode);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- if (binding != null) {
- String id = binding.getLaunchManagerDelegate(mode);
- if (id != null) {
- return ExtensionPointManager.getInstance().getLaunchManagerDelegate(id);
- }
- }
- return ExtensionPointManager.getInstance().getDefaultLaunchManagerDelegate();
- }
-
- /**
- * Get the registered launch mode variant delegate for the given launch configuration type and launch mode.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- *
- * @return The launch mode variant delegate, or a <code>null</code> if no delegate is registered for the
- * given launch configuration type id and launch mode.
- */
- public IVariantDelegate getLaunchModeVariantDelegate(String typeId, String mode) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(mode);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- if (binding != null) {
- String id = binding.getLaunchModeVariantDelegate(mode);
- if (id != null) {
- return LaunchModeVariantDelegateExtensionPointManager.getInstance().getLaunchModeVariantDelegate(id);
- }
- }
- return null;
- }
-
- /**
- * Get the registered stepper for the given launch configuration type id and launch mode.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
-
- * @return The stepper or <code>null</code> if no stepper is registered for the
- * given launch configuration type id and launch mode.
- */
- public IStepper getStepper(String typeId, String mode) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(mode);
-
- IStepper stepper = null;
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- if (binding != null) {
- String id = binding.getStepper(mode);
- if (id != null) {
- stepper = StepperManager.getInstance().getStepperExtManager().getStepper(id, false);
- }
- }
-
- return stepper;
- }
-
- /**
- * Get the registered step group for the given launch configuration type and launch mode.
- *
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- * @param variant The launch mode variant or <code>null</code>.
- *
- * @return The launch step group or <code>null</code> if no step group is registered for the
- * given launch configuration type id and launch mode.
- */
- public IStepGroup getStepGroup(String typeId, String mode, String variant) {
- Assert.isNotNull(typeId);
- Assert.isNotNull(mode);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- if (binding != null) {
- String id = binding.getStepGroup(mode, variant);
- if (id != null) {
- return getStepGroup(id);
- }
- }
- return null;
- }
-
- /**
- * Get the registered step group identified by the specified unique id.
- *
- * @param id The step group id. Must not be <code>null</code>.
- * @return The step group or <code>null</code>, if no step group is registered for the specified id.
- */
- public IStepGroup getStepGroup(String id) {
- Assert.isNotNull(id);
- return StepperManager.getInstance().getStepGroupExtManager().getStepGroup(id, true);
- }
-
- /**
- * Get the registered step identified by the specified unique id.
- *
- * @param id The launch step id. Must not be <code>null</code>.
- * @return The launch step or <code>null</code> if no step is registered for the specified id.
- */
- public IStep getStep(String id) {
- Assert.isNotNull(id);
- return StepperManager.getInstance().getStepExtManager().getStep(id, true);
- }
-
- /**
- * Returns if or if not the given step id is valid for the given combination
- * of launch configuration type id and launch mode. A launch step is invalid if not
- * bound to the launch configuration type for the given launch mode.
- *
- * @param id The launch step id. Must not be <code>null</code>.
- * @param typeId The launch configuration type id. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- *
- * @return <code>True</code> if the launch step id is valid, <code>false</code> otherwise.
- */
- public boolean isValidStep(String id, String typeId, String mode) {
- Assert.isNotNull(id);
- Assert.isNotNull(typeId);
- Assert.isNotNull(mode);
-
- LaunchConfigTypeBinding binding = bindings.get(typeId);
- if (binding != null) {
- String[] steps = binding.getSteps(mode);
- for (String stepId : steps) {
- if (id.equals(stepId)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /*
- * Load and register all launch configuration type bindings.
- */
- private void loadBindingsExtensions() {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint point = registry.getExtensionPoint("org.eclipse.tcf.te.launch.core.launchConfigTypeBindings"); //$NON-NLS-1$
- if (point != null) {
- IExtension[] bindings = point.getExtensions();
- Arrays.sort(bindings, new ExtensionPointComparator());
- for (IExtension binding : bindings) {
- IConfigurationElement[] elements = binding.getConfigurationElements();
- for (IConfigurationElement element : elements) {
- loadBinding(element);
- }
- }
- }
- }
-
- /**
- * Load a single launch configuration type binding.
- *
- * @param element The configuration element. Must not be <code>null</code>.
- */
- private void loadBinding(IConfigurationElement element) {
- Assert.isNotNull(element);
-
- if (!element.getName().equals("launchConfigTypeBinding")) { //$NON-NLS-1$
- return;
- }
-
- String launchConfigTypeId = element.getAttribute("launchConfigTypeId"); //$NON-NLS-1$
- if (!bindings.containsKey(launchConfigTypeId)) {
- bindings.put(launchConfigTypeId, new LaunchConfigTypeBinding(launchConfigTypeId));
- }
- LaunchConfigTypeBinding binding = bindings.get(launchConfigTypeId);
-
- IConfigurationElement[] lmDelegateBindings = element.getChildren("launchManagerDelegate"); //$NON-NLS-1$
- for (IConfigurationElement lmDelegateBinding : lmDelegateBindings) {
- String id = lmDelegateBinding.getAttribute("id"); //$NON-NLS-1$
- String overwrites = lmDelegateBinding.getAttribute("overwrites"); //$NON-NLS-1$
- String modes = lmDelegateBinding.getAttribute("modes"); //$NON-NLS-1$
-
- binding.addLaunchManagerDelegate(new OverwritableLaunchBinding(id, overwrites, modes));
- }
-
- IConfigurationElement[] launchModeVariantDelegateBindings = element.getChildren("launchModeVariantDelegate"); //$NON-NLS-1$
- for (IConfigurationElement launchModeVariantDelegateBinding : launchModeVariantDelegateBindings) {
- String id = launchModeVariantDelegateBinding.getAttribute("id"); //$NON-NLS-1$
- String overwrites = launchModeVariantDelegateBinding.getAttribute("overwrites"); //$NON-NLS-1$
- String modes = launchModeVariantDelegateBinding.getAttribute("modes"); //$NON-NLS-1$
-
- binding.addLaunchModeVariantDelegate(new OverwritableLaunchBinding(id, overwrites, modes));
- }
-
- IConfigurationElement[] stepperBindings = element.getChildren("stepper"); //$NON-NLS-1$
- for (IConfigurationElement stepperBinding : stepperBindings) {
- String id = stepperBinding.getAttribute("id"); //$NON-NLS-1$
- String overwrites = stepperBinding.getAttribute("overwrites"); //$NON-NLS-1$
- String modes = stepperBinding.getAttribute("modes"); //$NON-NLS-1$
-
- binding.addStepper(new OverwritableLaunchBinding(id, overwrites, modes));
- }
-
- IConfigurationElement[] stepBindings = element.getChildren("step"); //$NON-NLS-1$
- for (IConfigurationElement stepBinding : stepBindings) {
- String id = stepBinding.getAttribute("id"); //$NON-NLS-1$
- String modes = stepBinding.getAttribute("modes"); //$NON-NLS-1$
-
- binding.addStep(new LaunchBinding(id, modes));
- }
-
- IConfigurationElement[] stepGroupBindings = element.getChildren("stepGroup"); //$NON-NLS-1$
- for (IConfigurationElement stepGroupBinding : stepGroupBindings) {
- String id = stepGroupBinding.getAttribute("id"); //$NON-NLS-1$
- String overwrites = stepGroupBinding.getAttribute("overwrites"); //$NON-NLS-1$
- String modes = stepGroupBinding.getAttribute("modes"); //$NON-NLS-1$
- String variants = stepGroupBinding.getAttribute("variants"); //$NON-NLS-1$
-
- binding.addStepGroup(new OverwritableLaunchBinding(id, overwrites, modes, variants));
- }
-
- IConfigurationElement[] enablements = element.getChildren("enablement"); //$NON-NLS-1$
- for (IConfigurationElement enablement : enablements) {
- Expression expression = null;
- try {
- expression = ExpressionConverter.getDefault().perform(enablement);
- } catch (CoreException e) {
- if (Platform.inDebugMode()) e.printStackTrace();
- }
-
- if (expression != null) binding.addEnablement(expression);
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.bindings;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.expressions.ExpressionConverter;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.tcf.te.launch.core.bindings.internal.LaunchConfigTypeBinding;
+import org.eclipse.tcf.te.launch.core.bindings.internal.OverwritableLaunchBinding;
+import org.eclipse.tcf.te.launch.core.extensions.internal.LaunchModeVariantDelegateExtensionPointManager;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.internal.ExtensionPointManager;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+import org.eclipse.tcf.te.runtime.extensions.ExtensionPointComparator;
+import org.eclipse.tcf.te.runtime.stepper.StepperManager;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStep;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepGroup;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IVariantDelegate;
+
+
+/**
+ * Manager that controls the launch configuration type bindings.
+ */
+public class LaunchConfigTypeBindingsManager {
+ // Map of all launch configuration type bindings by id
+ private final Map<String, LaunchConfigTypeBinding> bindings = new Hashtable<String, LaunchConfigTypeBinding>();
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstanceHolder {
+ public static LaunchConfigTypeBindingsManager instance = new LaunchConfigTypeBindingsManager();
+ }
+
+ /**
+ * Returns the singleton instance.
+ */
+ public static LaunchConfigTypeBindingsManager getInstance() {
+ return LazyInstanceHolder.instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ LaunchConfigTypeBindingsManager() {
+ // Load the launch configuration type bindings on instantiation.
+ loadBindingsExtensions();
+ }
+
+ /**
+ * Get all valid launch configuration type id's for the given selection.
+ *
+ * @param selection The selection or <code>null</code>.
+ * @return The list of valid launch configuration type id's for the selection or an empty list.
+ */
+ public String[] getValidLaunchConfigTypes(ILaunchSelection selection) {
+ Set<String> validLaunchTypes = new HashSet<String>();
+ if (selection != null && selection.getSelectedContexts() != null && selection.getSelectedContexts().length > 0) {
+ for (String launchConfigTypeId : bindings.keySet()) {
+ if (isValidLaunchConfigType(launchConfigTypeId, selection)) {
+ validLaunchTypes.add(launchConfigTypeId);
+ }
+ }
+ }
+ return validLaunchTypes.toArray(new String[validLaunchTypes.size()]);
+ }
+
+ /**
+ * Validates the given launch selection.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param selection The selection. Must not be <code>null</code>.
+ */
+ public boolean isValidLaunchConfigType(String typeId, ILaunchSelection selection) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(selection);
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
+ return (launchConfigType != null && launchConfigType.isPublic() &&
+ (selection.getLaunchMode() == null || launchConfigType.supportsMode(selection.getLaunchMode())) &&
+ binding != null && binding.validate(selection) != EvaluationResult.FALSE);
+ }
+
+ /**
+ * Validates the given launch selection.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param mode The launch mode or <code>null</code>.
+ * @param context The selection context. Must not be <code>null</code>.
+ */
+ public boolean isValidLaunchConfigType(String typeId, String mode, ISelectionContext context) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(context);
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(typeId);
+ return (launchConfigType != null && launchConfigType.isPublic() &&
+ (mode == null || launchConfigType.supportsMode(mode)) &&
+ binding != null && binding.validate(mode, context) != EvaluationResult.FALSE);
+ }
+
+ /**
+ * Get the registered launch manager delegate for the given launch configuration type and launch mode.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ *
+ * @return The launch manager delegate, or a default delegate if no delegate is registered for the
+ * given launch configuration type id and launch mode.
+ */
+ public ILaunchManagerDelegate getLaunchManagerDelegate(String typeId, String mode) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(mode);
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ if (binding != null) {
+ String id = binding.getLaunchManagerDelegate(mode);
+ if (id != null) {
+ return ExtensionPointManager.getInstance().getLaunchManagerDelegate(id);
+ }
+ }
+ return ExtensionPointManager.getInstance().getDefaultLaunchManagerDelegate();
+ }
+
+ /**
+ * Get the registered launch mode variant delegate for the given launch configuration type and launch mode.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ *
+ * @return The launch mode variant delegate, or a <code>null</code> if no delegate is registered for the
+ * given launch configuration type id and launch mode.
+ */
+ public IVariantDelegate getLaunchModeVariantDelegate(String typeId, String mode) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(mode);
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ if (binding != null) {
+ String id = binding.getLaunchModeVariantDelegate(mode);
+ if (id != null) {
+ return LaunchModeVariantDelegateExtensionPointManager.getInstance().getLaunchModeVariantDelegate(id);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the registered stepper for the given launch configuration type id and launch mode.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+
+ * @return The stepper or <code>null</code> if no stepper is registered for the
+ * given launch configuration type id and launch mode.
+ */
+ public IStepper getStepper(String typeId, String mode) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(mode);
+
+ IStepper stepper = null;
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ if (binding != null) {
+ String id = binding.getStepper(mode);
+ if (id != null) {
+ stepper = StepperManager.getInstance().getStepperExtManager().getStepper(id, false);
+ }
+ }
+
+ return stepper;
+ }
+
+ /**
+ * Get the registered step group id for the given launch configuration type, launch mode and variant.
+ *
+ * @param typeId The launch configuration type id. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param variant The launch mode variant or <code>null</code>.
+ *
+ * @return The launch step group id or <code>null</code> if no step group is registered for the
+ * given launch configuration type id, launch mode and variant.
+ */
+ public String getStepGroupId(String typeId, String mode, String variant) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(mode);
+
+ LaunchConfigTypeBinding binding = bindings.get(typeId);
+ if (binding != null) {
+ return binding.getStepGroupId(mode, variant);
+ }
+ return null;
+ }
+
+ /**
+ * Get the registered step group identified by the specified unique id.
+ *
+ * @param id The step group id. Must not be <code>null</code>.
+ * @return The step group or <code>null</code>, if no step group is registered for the specified id.
+ */
+ public IStepGroup getStepGroup(String id) {
+ Assert.isNotNull(id);
+ return StepperManager.getInstance().getStepGroupExtManager().getStepGroup(id, true);
+ }
+
+ /**
+ * Get the registered step identified by the specified unique id.
+ *
+ * @param id The launch step id. Must not be <code>null</code>.
+ * @return The launch step or <code>null</code> if no step is registered for the specified id.
+ */
+ public IStep getStep(String id) {
+ Assert.isNotNull(id);
+ return StepperManager.getInstance().getStepExtManager().getStep(id, true);
+ }
+
+ /*
+ * Load and register all launch configuration type bindings.
+ */
+ private void loadBindingsExtensions() {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint point = registry.getExtensionPoint("org.eclipse.tcf.te.launch.core.launchConfigTypeBindings"); //$NON-NLS-1$
+ if (point != null) {
+ IExtension[] bindings = point.getExtensions();
+ Arrays.sort(bindings, new ExtensionPointComparator());
+ for (IExtension binding : bindings) {
+ IConfigurationElement[] elements = binding.getConfigurationElements();
+ for (IConfigurationElement element : elements) {
+ loadBinding(element);
+ }
+ }
+ }
+ }
+
+ /**
+ * Load a single launch configuration type binding.
+ *
+ * @param element The configuration element. Must not be <code>null</code>.
+ */
+ private void loadBinding(IConfigurationElement element) {
+ Assert.isNotNull(element);
+
+ if (!element.getName().equals("launchConfigTypeBinding")) { //$NON-NLS-1$
+ return;
+ }
+
+ String launchConfigTypeId = element.getAttribute("launchConfigTypeId"); //$NON-NLS-1$
+ if (!bindings.containsKey(launchConfigTypeId)) {
+ bindings.put(launchConfigTypeId, new LaunchConfigTypeBinding(launchConfigTypeId));
+ }
+ LaunchConfigTypeBinding binding = bindings.get(launchConfigTypeId);
+
+ IConfigurationElement[] lmDelegateBindings = element.getChildren("launchManagerDelegate"); //$NON-NLS-1$
+ for (IConfigurationElement lmDelegateBinding : lmDelegateBindings) {
+ String id = lmDelegateBinding.getAttribute("id"); //$NON-NLS-1$
+ String overwrites = lmDelegateBinding.getAttribute("overwrites"); //$NON-NLS-1$
+ String modes = lmDelegateBinding.getAttribute("modes"); //$NON-NLS-1$
+
+ binding.addLaunchManagerDelegate(new OverwritableLaunchBinding(id, overwrites, modes));
+ }
+
+ IConfigurationElement[] launchModeVariantDelegateBindings = element.getChildren("launchModeVariantDelegate"); //$NON-NLS-1$
+ for (IConfigurationElement launchModeVariantDelegateBinding : launchModeVariantDelegateBindings) {
+ String id = launchModeVariantDelegateBinding.getAttribute("id"); //$NON-NLS-1$
+ String overwrites = launchModeVariantDelegateBinding.getAttribute("overwrites"); //$NON-NLS-1$
+ String modes = launchModeVariantDelegateBinding.getAttribute("modes"); //$NON-NLS-1$
+
+ binding.addLaunchModeVariantDelegate(new OverwritableLaunchBinding(id, overwrites, modes));
+ }
+
+ IConfigurationElement[] stepperBindings = element.getChildren("stepper"); //$NON-NLS-1$
+ for (IConfigurationElement stepperBinding : stepperBindings) {
+ String id = stepperBinding.getAttribute("id"); //$NON-NLS-1$
+ String overwrites = stepperBinding.getAttribute("overwrites"); //$NON-NLS-1$
+ String modes = stepperBinding.getAttribute("modes"); //$NON-NLS-1$
+
+ binding.addStepper(new OverwritableLaunchBinding(id, overwrites, modes));
+ }
+
+ IConfigurationElement[] stepGroupBindings = element.getChildren("stepGroup"); //$NON-NLS-1$
+ for (IConfigurationElement stepGroupBinding : stepGroupBindings) {
+ String id = stepGroupBinding.getAttribute("id"); //$NON-NLS-1$
+ String overwrites = stepGroupBinding.getAttribute("overwrites"); //$NON-NLS-1$
+ String modes = stepGroupBinding.getAttribute("modes"); //$NON-NLS-1$
+ String variants = stepGroupBinding.getAttribute("variants"); //$NON-NLS-1$
+
+ binding.addStepGroup(new OverwritableLaunchBinding(id, overwrites, modes, variants));
+ }
+
+ IConfigurationElement[] enablements = element.getChildren("enablement"); //$NON-NLS-1$
+ for (IConfigurationElement enablement : enablements) {
+ Expression expression = null;
+ try {
+ expression = ExpressionConverter.getDefault().perform(enablement);
+ } catch (CoreException e) {
+ if (Platform.inDebugMode()) {
+ e.printStackTrace();
+ }
+ }
+
+ if (expression != null) {
+ binding.addEnablement(expression);
+ }
+ }
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java
index 47fca5653..0c3998b70 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java
@@ -1,365 +1,335 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.launch.core.bindings.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.expressions.EvaluationContext;
-import org.eclipse.core.expressions.EvaluationResult;
-import org.eclipse.core.expressions.Expression;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.launch.core.bindings.interfaces.ILaunchBinding;
-import org.eclipse.tcf.te.launch.core.bindings.interfaces.IOverwritableLaunchBinding;
-import org.eclipse.tcf.te.launch.core.bindings.interfaces.IVaryableLaunchBinding;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
-import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
-
-/**
- * Launch configuration type binding implementation.
- */
-public class LaunchConfigTypeBinding {
- // The launch configuration type id
- private final String typeId;
-
- // Lists of sub bindings
- private final List<ILaunchBinding> lmDelegateBindings = new ArrayList<ILaunchBinding>();
- private final List<ILaunchBinding> stepperBindings = new ArrayList<ILaunchBinding>();
- private final List<ILaunchBinding> stepBindings = new ArrayList<ILaunchBinding>();
- private final List<ILaunchBinding> stepGroupBindings = new ArrayList<ILaunchBinding>();
- private final List<ILaunchBinding> variantDelegateBindings = new ArrayList<ILaunchBinding>();
-
- // The list of enablement expressions
- private final List<Expression> expressions = new ArrayList<Expression>();
-
- /**
- * Constructor.
- *
- * @param typeId The launch configuration type id the binding applies to. Must not be
- * <code>null</code>.
- */
- public LaunchConfigTypeBinding(String typeId) {
- Assert.isNotNull(typeId);
- this.typeId = typeId;
- }
-
- /**
- * Returns the launch configuration type id the binding applies to.
- *
- * @return The launch configuration type id.
- */
- public String getTypeId() {
- return typeId;
- }
-
- /**
- * Returns the launch manager delegate id for the given launch mode.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @return The launch manager delegate id or <code>null</code>.
- */
- public String getLaunchManagerDelegate(String mode) {
- Assert.isNotNull(mode);
-
- ILaunchBinding binding = getBinding(lmDelegateBindings, mode);
- return binding != null ? binding.getId() : null;
- }
-
- /**
- * Adds the given launch manager delegate binding.
- *
- * @param binding The binding. Must not be <code>null</code>.
- */
- public void addLaunchManagerDelegate(IOverwritableLaunchBinding binding) {
- Assert.isNotNull(binding);
- if (!lmDelegateBindings.contains(binding)) lmDelegateBindings.add(binding);
- }
-
- /**
- * Returns the launch mode variant delegate id for the given launch mode.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @return The launch mode variant delegate id or <code>null</code>.
- */
- public String getLaunchModeVariantDelegate(String mode) {
- Assert.isNotNull(mode);
-
- ILaunchBinding binding = getBinding(variantDelegateBindings, mode);
- return binding != null ? binding.getId() : null;
- }
-
- /**
- * Adds the given launch mode variant delegate binding.
- *
- * @param binding The binding. Must not be <code>null</code>.
- */
- public void addLaunchModeVariantDelegate(IOverwritableLaunchBinding binding) {
- Assert.isNotNull(binding);
- if (!variantDelegateBindings.contains(binding)) variantDelegateBindings.add(binding);
- }
-
- /**
- * Returns the stepper id for the given launch mode.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @return The stepper id or <code>null</code>.
- */
- public String getStepper(String mode) {
- Assert.isNotNull(mode);
-
- ILaunchBinding binding = getBinding(stepperBindings, mode);
- return binding != null ? binding.getId() : null;
- }
-
- /**
- * Adds the given stepper binding.
- *
- * @param binding The binding. Must not be <code>null</code>.
- */
- public void addStepper(IOverwritableLaunchBinding binding) {
- Assert.isNotNull(binding);
- if (!stepperBindings.contains(binding)) stepperBindings.add(binding);
- }
-
- /**
- * Returns the list of available step id's bound the given launch mode.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @return The list of available launch step id's or an empty list.
- */
- public String[] getSteps(String mode) {
- Assert.isNotNull(mode);
-
- List<ILaunchBinding> bindings = getBindings(stepBindings, mode);
- List<String> candidates = new ArrayList<String>();
- for (ILaunchBinding binding : bindings) {
- if (!candidates.contains(binding.getId())) candidates.add(binding.getId());
- }
- return candidates.toArray(new String[candidates.size()]);
- }
-
- /**
- * Adds the given step binding.
- *
- * @param binding The binding. Must not be <code>null</code>.
- */
- public void addStep(ILaunchBinding binding) {
- Assert.isNotNull(binding);
- if (!stepBindings.contains(binding)) stepBindings.add(binding);
- }
-
- /**
- * Returns the step group id for the given launch mode and variant.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @param variant The launch mode variant or <code>null</code>.
- *
- * @return The stepper id or <code>null</code>.
- */
- public String getStepGroup(String mode, String variant) {
- ILaunchBinding binding = getBinding(stepGroupBindings, mode, variant);
- return binding != null ? binding.getId() : null;
- }
-
- /**
- * Adds the given step group binding.
- *
- * @param binding The binding. Must not be <code>null</code>.
- */
- public void addStepGroup(ILaunchBinding binding) {
- Assert.isNotNull(binding);
- if (!stepGroupBindings.contains(binding)) stepGroupBindings.add(binding);
- }
-
- /**
- * Adds the given enablement expression.
- *
- * @param enablement The enablement expression. Must not be <code>null</code>.
- */
- public void addEnablement(Expression expression) {
- Assert.isNotNull(expression);
- if (!expressions.contains(expression)) expressions.add(expression);
- }
-
- /**
- * Evaluates the enablement expressions with the given launch selection.
- *
- * @param selection The launch selection. Must not be <code>null</code>.
- * @return The result of the enablement expression evaluation.
- */
- public EvaluationResult validate(ILaunchSelection selection) {
- Assert.isNotNull(selection);
-
- EvaluationResult result = EvaluationResult.NOT_LOADED;
-
- EvaluationResult valresult;
- for (ISelectionContext context : selection.getSelectedContexts()) {
- if (context.isPreferredContext()) {
- valresult = validate(selection.getLaunchMode(), context);
- if (valresult == EvaluationResult.FALSE) {
- return EvaluationResult.FALSE;
- }
- else if (valresult != EvaluationResult.NOT_LOADED) {
- result = valresult;
- }
- }
- }
- return result;
- }
-
- /**
- * Evaluates the enablement expressions with the given launch mode and selection context.
- *
- * @param mode The launch mode. Must not be <code>null</code>.
- * @param context The launch selection context or <code>null</code>.
- *
- * @return The result of the enablement expression evaluation.
- */
- public EvaluationResult validate(String mode, ISelectionContext context) {
- EvaluationResult result = context.isPreferredContext() ? EvaluationResult.FALSE : EvaluationResult.NOT_LOADED;
-
- if (expressions.isEmpty()) {
- return EvaluationResult.TRUE;
- }
- EvaluationResult valresult;
- for (Expression expression : expressions) {
- // Set the default variable and "selection" is the selection context
- EvaluationContext evalContext = new EvaluationContext(null, context);
- evalContext.addVariable("selection", context); //$NON-NLS-1$
- evalContext.addVariable("mode", mode); //$NON-NLS-1$
- // Allow plugin activation
- evalContext.setAllowPluginActivation(true);
- // Evaluate the expression
- try {
- valresult = expression.evaluate(evalContext);
- } catch (CoreException e) {
- valresult = EvaluationResult.FALSE;
-
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getLocalizedMessage(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
-
- if (valresult == EvaluationResult.TRUE) {
- return EvaluationResult.TRUE;
- }
- if (valresult != EvaluationResult.NOT_LOADED) {
- result = valresult;
- }
- }
-
- return result;
- }
-
- /**
- * Returns the list of bindings valid for the given launch mode.
- *
- * @param bindings The list of available bindings. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- *
- * @return The list of valid bindings for the given launch mode or an empty list.
- */
- private List<ILaunchBinding> getBindings(List<ILaunchBinding> bindings, String mode) {
- return getBindings(bindings, mode, null);
- }
-
- /**
- * Returns the list of bindings valid for the given launch mode.
- *
- * @param bindings The list of available bindings. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- * @param variant The launch mode variant or <code>null</code>.
- *
- * @return The list of valid bindings for the given launch mode or an empty list.
- */
- private List<ILaunchBinding> getBindings(List<ILaunchBinding> bindings, String mode, String variant) {
- Assert.isNotNull(bindings);
- Assert.isNotNull(mode);
-
- List<ILaunchBinding> candidates = new ArrayList<ILaunchBinding>();
- for (ILaunchBinding binding : bindings) {
- if (binding instanceof IVaryableLaunchBinding) {
- if (((IVaryableLaunchBinding) binding).isValidLaunchMode(mode, variant)) {
- candidates.add(binding);
- }
- }
- else if (binding.isValidLaunchMode(mode)) {
- candidates.add(binding);
- }
- }
-
- return candidates;
- }
-
- /**
- * Returns the resolved binding in case of overwritable bindings.
- *
- * @param bindings The list of available bindings. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- *
- * @return The resolved binding or <code>null</code>.
- */
- private ILaunchBinding getBinding(List<ILaunchBinding> bindings, String mode) {
- return getBinding(bindings, mode, null);
- }
-
- /**
- * Returns the resolved binding in case of overwritable bindings.
- *
- * @param bindings The list of available bindings. Must not be <code>null</code>.
- * @param mode The launch mode. Must not be <code>null</code>.
- * @param variant The launch mode variant or <code>null</code>.
- *
- * @return The resolved binding or <code>null</code>.
- */
- private ILaunchBinding getBinding(List<ILaunchBinding> bindings, String mode, String variant) {
- Assert.isNotNull(bindings);
- Assert.isNotNull(mode);
-
- ILaunchBinding binding = null;
-
- List<ILaunchBinding> candidates = getBindings(bindings, mode, variant);
- for (int i = 0; i < candidates.size(); i++) {
- if (binding == null) {
- binding = candidates.get(i);
- }
- for (int j = 0; j < candidates.size(); j++) {
- ILaunchBinding cj = candidates.get(j);
- if (cj instanceof IOverwritableLaunchBinding
- && ((IOverwritableLaunchBinding) cj).overwrites(binding.getId())) {
- binding = cj;
- }
- }
- }
-
- return binding;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- StringBuffer toString = new StringBuffer();
-
- toString.append("LaunchConfigTypeBinding("); //$NON-NLS-1$
- toString.append(typeId);
- toString.append(")"); //$NON-NLS-1$
-
- return toString.toString();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.bindings.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.expressions.EvaluationContext;
+import org.eclipse.core.expressions.EvaluationResult;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.launch.core.bindings.interfaces.ILaunchBinding;
+import org.eclipse.tcf.te.launch.core.bindings.interfaces.IOverwritableLaunchBinding;
+import org.eclipse.tcf.te.launch.core.bindings.interfaces.IVaryableLaunchBinding;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * Launch configuration type binding implementation.
+ */
+public class LaunchConfigTypeBinding {
+ // The launch configuration type id
+ private final String typeId;
+
+ // Lists of sub bindings
+ private final List<ILaunchBinding> lmDelegateBindings = new ArrayList<ILaunchBinding>();
+ private final List<ILaunchBinding> stepperBindings = new ArrayList<ILaunchBinding>();
+ private final List<ILaunchBinding> stepGroupBindings = new ArrayList<ILaunchBinding>();
+ private final List<ILaunchBinding> variantDelegateBindings = new ArrayList<ILaunchBinding>();
+
+ // The list of enablement expressions
+ private final List<Expression> expressions = new ArrayList<Expression>();
+
+ /**
+ * Constructor.
+ *
+ * @param typeId The launch configuration type id the binding applies to. Must not be
+ * <code>null</code>.
+ */
+ public LaunchConfigTypeBinding(String typeId) {
+ Assert.isNotNull(typeId);
+ this.typeId = typeId;
+ }
+
+ /**
+ * Returns the launch configuration type id the binding applies to.
+ *
+ * @return The launch configuration type id.
+ */
+ public String getTypeId() {
+ return typeId;
+ }
+
+ /**
+ * Returns the launch manager delegate id for the given launch mode.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @return The launch manager delegate id or <code>null</code>.
+ */
+ public String getLaunchManagerDelegate(String mode) {
+ Assert.isNotNull(mode);
+
+ ILaunchBinding binding = getBinding(lmDelegateBindings, mode);
+ return binding != null ? binding.getId() : null;
+ }
+
+ /**
+ * Adds the given launch manager delegate binding.
+ *
+ * @param binding The binding. Must not be <code>null</code>.
+ */
+ public void addLaunchManagerDelegate(IOverwritableLaunchBinding binding) {
+ Assert.isNotNull(binding);
+ if (!lmDelegateBindings.contains(binding)) {
+ lmDelegateBindings.add(binding);
+ }
+ }
+
+ /**
+ * Returns the launch mode variant delegate id for the given launch mode.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @return The launch mode variant delegate id or <code>null</code>.
+ */
+ public String getLaunchModeVariantDelegate(String mode) {
+ Assert.isNotNull(mode);
+
+ ILaunchBinding binding = getBinding(variantDelegateBindings, mode);
+ return binding != null ? binding.getId() : null;
+ }
+
+ /**
+ * Adds the given launch mode variant delegate binding.
+ *
+ * @param binding The binding. Must not be <code>null</code>.
+ */
+ public void addLaunchModeVariantDelegate(IOverwritableLaunchBinding binding) {
+ Assert.isNotNull(binding);
+ if (!variantDelegateBindings.contains(binding)) {
+ variantDelegateBindings.add(binding);
+ }
+ }
+
+ /**
+ * Returns the stepper id for the given launch mode.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @return The stepper id or <code>null</code>.
+ */
+ public String getStepper(String mode) {
+ Assert.isNotNull(mode);
+
+ ILaunchBinding binding = getBinding(stepperBindings, mode);
+ return binding != null ? binding.getId() : null;
+ }
+
+ /**
+ * Adds the given stepper binding.
+ *
+ * @param binding The binding. Must not be <code>null</code>.
+ */
+ public void addStepper(IOverwritableLaunchBinding binding) {
+ Assert.isNotNull(binding);
+ if (!stepperBindings.contains(binding)) {
+ stepperBindings.add(binding);
+ }
+ }
+
+ /**
+ * Returns the step group id for the given launch mode and variant.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param variant The launch mode variant or <code>null</code>.
+ *
+ * @return The step group id or <code>null</code>.
+ */
+ public String getStepGroupId(String mode, String variant) {
+ ILaunchBinding binding = getBinding(stepGroupBindings, mode, variant);
+ return binding != null ? binding.getId() : null;
+ }
+
+ /**
+ * Adds the given step group binding.
+ *
+ * @param binding The binding. Must not be <code>null</code>.
+ */
+ public void addStepGroup(ILaunchBinding binding) {
+ Assert.isNotNull(binding);
+ if (!stepGroupBindings.contains(binding)) {
+ stepGroupBindings.add(binding);
+ }
+ }
+
+ /**
+ * Adds the given enablement expression.
+ *
+ * @param enablement The enablement expression. Must not be <code>null</code>.
+ */
+ public void addEnablement(Expression expression) {
+ Assert.isNotNull(expression);
+ if (!expressions.contains(expression)) {
+ expressions.add(expression);
+ }
+ }
+
+ /**
+ * Evaluates the enablement expressions with the given launch selection.
+ *
+ * @param selection The launch selection. Must not be <code>null</code>.
+ * @return The result of the enablement expression evaluation.
+ */
+ public EvaluationResult validate(ILaunchSelection selection) {
+ Assert.isNotNull(selection);
+
+ EvaluationResult result = EvaluationResult.NOT_LOADED;
+
+ EvaluationResult valresult;
+ for (ISelectionContext context : selection.getSelectedContexts()) {
+ if (context.isPreferredContext()) {
+ valresult = validate(selection.getLaunchMode(), context);
+ if (valresult == EvaluationResult.FALSE) {
+ return EvaluationResult.FALSE;
+ }
+ else if (valresult != EvaluationResult.NOT_LOADED) {
+ result = valresult;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Evaluates the enablement expressions with the given launch mode and selection context.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param context The launch selection context or <code>null</code>.
+ *
+ * @return The result of the enablement expression evaluation.
+ */
+ public EvaluationResult validate(String mode, ISelectionContext context) {
+ EvaluationResult result = context.isPreferredContext() ? EvaluationResult.FALSE : EvaluationResult.NOT_LOADED;
+
+ if (expressions.isEmpty()) {
+ return EvaluationResult.TRUE;
+ }
+ EvaluationResult valresult;
+ for (Expression expression : expressions) {
+ // Set the default variable and "selection" is the selection context
+ EvaluationContext evalContext = new EvaluationContext(null, context);
+ evalContext.addVariable("selection", context); //$NON-NLS-1$
+ evalContext.addVariable("mode", mode); //$NON-NLS-1$
+ // Allow plugin activation
+ evalContext.setAllowPluginActivation(true);
+ // Evaluate the expression
+ try {
+ valresult = expression.evaluate(evalContext);
+ } catch (CoreException e) {
+ valresult = EvaluationResult.FALSE;
+
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getLocalizedMessage(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ if (valresult == EvaluationResult.TRUE) {
+ return EvaluationResult.TRUE;
+ }
+ if (valresult != EvaluationResult.NOT_LOADED) {
+ result = valresult;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the list of bindings valid for the given launch mode.
+ *
+ * @param bindings The list of available bindings. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param variant The launch mode variant or <code>null</code>.
+ *
+ * @return The list of valid bindings for the given launch mode or an empty list.
+ */
+ private List<ILaunchBinding> getBindings(List<ILaunchBinding> bindings, String mode, String variant) {
+ Assert.isNotNull(bindings);
+ Assert.isNotNull(mode);
+
+ List<ILaunchBinding> candidates = new ArrayList<ILaunchBinding>();
+ for (ILaunchBinding binding : bindings) {
+ if (binding instanceof IVaryableLaunchBinding) {
+ if (((IVaryableLaunchBinding) binding).isValidLaunchMode(mode, variant)) {
+ candidates.add(binding);
+ }
+ }
+ else if (binding.isValidLaunchMode(mode)) {
+ candidates.add(binding);
+ }
+ }
+
+ return candidates;
+ }
+
+ /**
+ * Returns the resolved binding in case of overwritable bindings.
+ *
+ * @param bindings The list of available bindings. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ *
+ * @return The resolved binding or <code>null</code>.
+ */
+ private ILaunchBinding getBinding(List<ILaunchBinding> bindings, String mode) {
+ return getBinding(bindings, mode, null);
+ }
+
+ /**
+ * Returns the resolved binding in case of overwritable bindings.
+ *
+ * @param bindings The list of available bindings. Must not be <code>null</code>.
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param variant The launch mode variant or <code>null</code>.
+ *
+ * @return The resolved binding or <code>null</code>.
+ */
+ private ILaunchBinding getBinding(List<ILaunchBinding> bindings, String mode, String variant) {
+ Assert.isNotNull(bindings);
+ Assert.isNotNull(mode);
+
+ ILaunchBinding binding = null;
+
+ List<ILaunchBinding> candidates = getBindings(bindings, mode, variant);
+ for (int i = 0; i < candidates.size(); i++) {
+ if (binding == null) {
+ binding = candidates.get(i);
+ }
+ for (int j = 0; j < candidates.size(); j++) {
+ ILaunchBinding cj = candidates.get(j);
+ if (cj instanceof IOverwritableLaunchBinding
+ && ((IOverwritableLaunchBinding) cj).overwrites(binding.getId())) {
+ binding = cj;
+ }
+ }
+ }
+
+ return binding;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ toString.append("LaunchConfigTypeBinding("); //$NON-NLS-1$
+ toString.append(typeId);
+ toString.append(")"); //$NON-NLS-1$
+
+ return toString.toString();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/PropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/PropertyTester.java
new file mode 100644
index 000000000..3d55f1c07
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/PropertyTester.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.bindings.internal;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunch;
+
+/**
+ * Launch property tester.
+ */
+public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
+ */
+ @Override
+ public boolean test(final Object receiver, String property, Object[] args, Object expectedValue) {
+
+ if (receiver instanceof ILaunch) {
+ if ("launchMode".equals(property) && expectedValue instanceof String) { //$NON-NLS-1$
+ return ((ILaunch)receiver).getLaunchMode().equalsIgnoreCase((String)expectedValue);
+ }
+ if ("launchConfigTypeid".equals(property) && expectedValue instanceof String) { //$NON-NLS-1$
+ try {
+ return ((ILaunch)receiver).getLaunchConfiguration().getType().getIdentifier().equalsIgnoreCase((String)expectedValue);
+ }
+ catch (CoreException e) {
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
index 3e0509f55..457356626 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java
@@ -1,316 +1,335 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.launch.core.delegates;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.IStatusHandler;
-import org.eclipse.debug.core.model.IBreakpoint;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.launch.core.bindings.LaunchConfigTypeBindingsManager;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
-import org.eclipse.tcf.te.launch.core.nls.Messages;
-import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
-import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil;
-import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
-import org.eclipse.tcf.te.runtime.interfaces.ISharedConstants;
-import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
-import org.eclipse.tcf.te.runtime.stepper.FullQualifiedId;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.tracing.ITraceIds;
-
-/**
- * Default launch configuration delegate implementation.
- * <p>
- * The launch configuration delegate implements the bridge between the native Eclipse launch
- * configuration framework and the stepper engine. The delegate is standard for all
- * launch configurations which supports extensible and modularized launching.
- * <p>
- * <b>Implementation Details</b>:<br>
- * <ul>
- * <li>The launch configuration delegate signals the completion of the launch sequence via
- * the custom {@link ILaunch} attribute {@link ICommonLaunchAttributes#ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED}.</li>
- * <li>The launch configuration delegates enforces the removal of the launch from the Eclipse
- * debug platforms launch manager if the progress monitor is set to canceled or an status with
- * severity {@link IStatus#CANCEL} had been thrown by the stepper implementation.</li>
- * <li>The launch configuration delegate creates launches of type {@link Launch}.</li>
- * </ul>
- */
-public class LaunchConfigurationDelegate extends AbstractLaunchConfigurationDelegate {
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
- Assert.isNotNull(configuration);
- Assert.isNotNull(mode);
- Assert.isNotNull(launch);
-
- // Note: This method is typically called within a worker thread from the launch configuration framework.
-
- long startTime = System.currentTimeMillis();
- ILaunchConfigurationWorkingCopy launchConfig = configuration.getWorkingCopy();
- launchConfig.setAttribute(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED, Long.toString(startTime));
- launchConfig.doSave();
-
- CoreBundleActivator.getTraceHandler().trace("LaunchConfigurationDelegate#launch: *** ENTERED" //$NON-NLS-1$
- + " (" + configuration.getName() + ")", //$NON-NLS-1$ //$NON-NLS-2$
- 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this);
- CoreBundleActivator.getTraceHandler().trace(" [" + ISharedConstants.TIME_FORMAT.format(new Date(startTime)) + "]" //$NON-NLS-1$ //$NON-NLS-2$
- + " ***", //$NON-NLS-1$
- 0, ITraceIds.PROFILE_STEPPING, IStatus.WARNING, this);
-
- // Reset the attribute to tell if the launch sequence has been completed. Clients cannot
- // use ILaunch.isTerminated() as this is passing through to a possibly associated IProcess
- // object. We need to know when the launch itself has finished the job, not when the process
- // might have died.
- launch.setAttribute(ICommonLaunchAttributes.ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED, Boolean.FALSE.toString());
-
- // The stepper instance to be used
- IStepper stepper = null;
- IStatus status = null;
-
- try {
- // Get the launch configuration type from the launch configuration.
- // This may throw an CoreException if the launch configuration type
- // cannot be retrieved or instantiated.
- ILaunchConfigurationType type = configuration.getType();
-
- // Get the associated stepper for this launch
- stepper = LaunchConfigTypeBindingsManager.getInstance().getStepper(type.getIdentifier(), mode);
- if (stepper == null) {
- // Failed to retrieve stepper for this launch -> throw a CoreException
- throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- NLS.bind(Messages.LaunchConfigurationDelegate_error_failedToGetStepper, type.getIdentifier(), mode)));
- }
-
- // In case the stepper is already busy with another launch, we need a second instance
- if (stepper.isInitialized()) {
- try {
- // Create a new stepper instance
- IStepper candidate = stepper.getClass().newInstance();
- // Note: If the stepper is an instance of ExecutableExtension, the candidate has to be too.
- if (stepper instanceof ExecutableExtension) {
- ((ExecutableExtension)stepper).cloneInitializationData((ExecutableExtension)candidate);
- }
- // Force to use the newly created instance
- stepper = candidate;
- } catch (Exception e) {
- // Failed to clone already initialized stepper -> throw a CoreException
- throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- NLS.bind(Messages.LaunchConfigurationDelegate_error_failedToCloneStepper, type.getIdentifier(), mode)));
- }
- }
-
- IFullQualifiedId fullQualifiedId = new FullQualifiedId(IStepper.ID_TYPE_STEPPER_ID, stepper.getId(), null);
- // Get the launch properties container
- IPropertiesContainer properties = (IPropertiesContainer)launch.getAdapter(IPropertiesContainer.class);
- Assert.isNotNull(properties);
- // Initialize the stepper
- stepper.initialize(properties, fullQualifiedId, monitor != null ? monitor : new NullProgressMonitor());
-
- // Execute
- stepper.execute();
-
- // Wait for the stepper to be finished
- ExecutorsUtil.waitAndExecute(0, new IStepper.ExecutionFinishedConditionTester(stepper));
- } catch (CoreException e) {
- // We have to catch the CoreException here as we do want to open the
- // launch configurations dialog on ERROR only.
- status = e.getStatus();
-
- ILaunchManagerDelegate delegate = LaunchConfigTypeBindingsManager.getInstance().getLaunchManagerDelegate(configuration.getType().getIdentifier(), mode);
-
- if (status == null || (status.getSeverity() == IStatus.ERROR && delegate.showLaunchDialog(ILaunchManagerDelegate.SITUATION_AFTER_LAUNCH_FAILED))) {
- // just pass on the exception as is
- throw e;
- }
-
- // Try to get a handler for the status
- IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
- // If we cannot get a handler, pass on the exception
- if (handler == null) {
- throw e;
- }
-
- // Invoke the handler directly and drop the exception
- handler.handleStatus(status, this);
-
- // Mimic the original launch configuration behavior if an exception occurred
- // by removing the launch, if empty, and setting the progress monitor canceled.
- // @see LaunchConfiguration#launch(String, IProgressMonitor, boolean, boolean), line #768
- if (!launch.hasChildren()) {
- DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
- if (monitor != null) {
- monitor.setCanceled(true);
- }
- }
- } finally {
- // Mimic the original launch configuration behavior if monitor is set
- // canceled and make sure that the launch get's removed.
- if (monitor == null || monitor.isCanceled()) {
- DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
- }
-
- // Cleanup the stepper
- if (stepper != null) {
- stepper.cleanup();
- }
-
- // Set the launch completed here. Doesn't matter if the launch might completed with error or not.
- launch.setAttribute(ICommonLaunchAttributes.ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED, Boolean.TRUE.toString());
-
- long endTime = System.currentTimeMillis();
- CoreBundleActivator.getTraceHandler().trace("LaunchConfigurationDelegate#launch: *** DONE" //$NON-NLS-1$
- + " (" + configuration.getName() + ")", //$NON-NLS-1$ //$NON-NLS-2$
- 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this);
- CoreBundleActivator.getTraceHandler().trace(" [" + ISharedConstants.TIME_FORMAT.format(new Date(endTime)) //$NON-NLS-1$
- + " , delay = " + (endTime - startTime) + " ms]" //$NON-NLS-1$ //$NON-NLS-2$
- + " ***", //$NON-NLS-1$
- 0, ITraceIds.PROFILE_STEPPING, IStatus.WARNING, this);
-
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
- */
- @Override
- public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
- return new Launch(configuration, mode, null);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getProjectsForProblemSearch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
- */
- @Override
- protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode) throws CoreException {
- // Return the same list of projects as we have to build
- return getBuildOrder(configuration, mode);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
- */
- @Override
- protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
- // The result list. Return always an empty list at least. If returning null,
- // the super implementation will perform a incremental workspace build.
- List<IProject> projects = new ArrayList<IProject>();
-
- // Return the projects to build within the order the user configured within
- // the corresponding UI launch tab.
- List<String> projectNames = (List<String>)DefaultPersistenceDelegate.getAttribute(configuration, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<?>)null);
- if (projectNames != null) {
- projects.addAll(findProjectResources(projectNames));
- }
-
- // If the list of projects is not empty, we have to check for duplicates
- // and possible sub projects. As we cannot pre check if a project must
- // be build, we have to avoid building the same project again and again.
- checkForDuplicatesAndSubProjects(projects);
-
- return projects.toArray(new IProject[projects.size()]);
- }
-
- /**
- * Lookup the corresponding project resources for the given list of project
- * names. If one of the referenced projects cannot be found or is closed,
- * a {@link CoreException} will be thrown.
- *
- * @param projectNames The list of project names. Must be not <code>null</code>.
- * @return The list of project resources or an empty list.
- */
- protected List<IProject> findProjectResources(List<String> projectNames) throws CoreException {
- Assert.isNotNull(projectNames);
-
- List<IProject> projects = new ArrayList<IProject>();
-
- // Project resources are stored with the workspace root
- IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
- for (String projectName : projectNames) {
- // Query the project resource from the workspace root.
- IProject project = root.getProject(projectName);
- if (!project.isAccessible()) {
- // Not accessible -> means the project does either not exist or
- // is closed.
- throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- NLS.bind(Messages.LaunchConfigurationDelegate_error_inaccessibleReferencedProject, projectName)
- ));
- }
-
- // add the project resource to the list
- projects.add(project);
- }
-
- return projects;
- }
-
- /**
- * Check for duplicates and sub projects in the given list of project
- * resources.
- *
- * @param projects The list of project resources. Must be not <code>null</code>.
- */
- protected void checkForDuplicatesAndSubProjects(List<IProject> projects) {
- Assert.isNotNull(projects);
-
- // The list of already processed project names
- List<String> processedProjectNames = new ArrayList<String>();
-
- // Loop the project list and determine the duplicates. Use an
- // iterator here as we manipulate the list directly.
- ListIterator<IProject> iterator = projects.listIterator();
- while (iterator.hasNext()) {
- IProject project = iterator.next();
- // If the project name is within the list of already processed
- // projects, the project will be deleted from the list.
- if (processedProjectNames.contains(project.getName())) {
- iterator.remove();
- continue;
- }
-
- // Add the project name to the list of processed project names
- processedProjectNames.add(project.getName());
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBreakpoints(org.eclipse.debug.core.ILaunchConfiguration)
- *
- * Note: Redefined to be public accessible. Needed to access the breakpoints without
- * duplicating the super implementation.
- */
- @Override
- public IBreakpoint[] getBreakpoints(ILaunchConfiguration configuration) {
- return super.getBreakpoints(configuration);
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.delegates;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.IStatusHandler;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.launch.core.bindings.LaunchConfigTypeBindingsManager;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+import org.eclipse.tcf.te.launch.core.persistence.ContextSelectorPersistenceDelegate;
+import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
+import org.eclipse.tcf.te.runtime.concurrent.util.ExecutorsUtil;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtension;
+import org.eclipse.tcf.te.runtime.interfaces.ISharedConstants;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.stepper.FullQualifiedId;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepper;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepperProperties;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.tracing.ITraceIds;
+
+/**
+ * Default launch configuration delegate implementation.
+ * <p>
+ * The launch configuration delegate implements the bridge between the native Eclipse launch
+ * configuration framework and the stepper engine. The delegate is standard for all
+ * launch configurations which supports extensible and modularized launching.
+ * <p>
+ * <b>Implementation Details</b>:<br>
+ * <ul>
+ * <li>The launch configuration delegate signals the completion of the launch sequence via
+ * the custom {@link ILaunch} attribute {@link ICommonLaunchAttributes#ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED}.</li>
+ * <li>The launch configuration delegates enforces the removal of the launch from the Eclipse
+ * debug platforms launch manager if the progress monitor is set to canceled or an status with
+ * severity {@link IStatus#CANCEL} had been thrown by the stepper implementation.</li>
+ * <li>The launch configuration delegate creates launches of type {@link Launch}.</li>
+ * </ul>
+ */
+public class LaunchConfigurationDelegate extends AbstractLaunchConfigurationDelegate {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ Assert.isNotNull(configuration);
+ Assert.isNotNull(mode);
+ Assert.isNotNull(launch);
+
+ // Note: This method is typically called within a worker thread from the launch configuration framework.
+
+ long startTime = System.currentTimeMillis();
+ ILaunchConfigurationWorkingCopy launchConfig = configuration.getWorkingCopy();
+ launchConfig.setAttribute(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED, Long.toString(startTime));
+ launchConfig.doSave();
+
+ CoreBundleActivator.getTraceHandler().trace("LaunchConfigurationDelegate#launch: *** ENTERED" //$NON-NLS-1$
+ + " (" + configuration.getName() + ")", //$NON-NLS-1$ //$NON-NLS-2$
+ 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this);
+ CoreBundleActivator.getTraceHandler().trace(" [" + ISharedConstants.TIME_FORMAT.format(new Date(startTime)) + "]" //$NON-NLS-1$ //$NON-NLS-2$
+ + " ***", //$NON-NLS-1$
+ 0, ITraceIds.PROFILE_STEPPING, IStatus.WARNING, this);
+
+ // Reset the attribute to tell if the launch sequence has been completed. Clients cannot
+ // use ILaunch.isTerminated() as this is passing through to a possibly associated IProcess
+ // object. We need to know when the launch itself has finished the job, not when the process
+ // might have died.
+ launch.setAttribute(ICommonLaunchAttributes.ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED, Boolean.FALSE.toString());
+
+ // The stepper instance to be used
+ IStepper stepper = null;
+ IStatus status = null;
+
+ try {
+ // Get the launch configuration type from the launch configuration.
+ // This may throw an CoreException if the launch configuration type
+ // cannot be retrieved or instantiated.
+ ILaunchConfigurationType type = configuration.getType();
+
+ // Get the associated stepper for this launch
+ stepper = LaunchConfigTypeBindingsManager.getInstance().getStepper(type.getIdentifier(), mode);
+ if (stepper == null) {
+ // Failed to retrieve stepper for this launch -> throw a CoreException
+ throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.LaunchConfigurationDelegate_error_failedToGetStepper, type.getIdentifier(), mode)));
+ }
+
+ // In case the stepper is already busy with another launch, we need a second instance
+ if (stepper.isInitialized()) {
+ try {
+ // Create a new stepper instance
+ IStepper candidate = stepper.getClass().newInstance();
+ // Note: If the stepper is an instance of ExecutableExtension, the candidate has to be too.
+ if (stepper instanceof ExecutableExtension) {
+ ((ExecutableExtension)stepper).cloneInitializationData((ExecutableExtension)candidate);
+ }
+ // Force to use the newly created instance
+ stepper = candidate;
+ } catch (Exception e) {
+ // Failed to clone already initialized stepper -> throw a CoreException
+ throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.LaunchConfigurationDelegate_error_failedToCloneStepper, type.getIdentifier(), mode)));
+ }
+ }
+
+ IFullQualifiedId fullQualifiedId = new FullQualifiedId(IStepper.ID_TYPE_STEPPER_ID, stepper.getId(), null);
+ // Get the launch properties container
+ IPropertiesContainer properties = (IPropertiesContainer)launch.getAdapter(IPropertiesContainer.class);
+ Assert.isNotNull(properties);
+
+ // Add some information to the stepper data
+ properties.setProperty(IStepperProperties.PROP_NAME, launchConfig.getName());
+ properties.setProperty(IStepperProperties.PROP_STEP_GROUP_ID,
+ LaunchConfigTypeBindingsManager.getInstance().getStepGroupId(
+ launchConfig.getType().getIdentifier(),
+ launch.getLaunchMode(),
+ properties.getStringProperty(ICommonLaunchAttributes.ATTR_DELEGATE_VARIANT)));
+
+ IModelNode[] contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(
+ launchConfig.getAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String)null));
+ properties.setProperty(IContextSelectorLaunchAttributes.ATTR_ACTIVE_LAUNCH_CONTEXT, contexts != null && contexts.length > 0 ? contexts[0] : null);
+
+ // Initialize the stepper
+ IStepContext context = (IStepContext)launch.getAdapter(IStepContext.class);
+ stepper.initialize(context, properties, fullQualifiedId, monitor != null ? monitor : new NullProgressMonitor());
+
+ // Execute
+ stepper.execute();
+
+ // Wait for the stepper to be finished
+ ExecutorsUtil.waitAndExecute(0, new IStepper.ExecutionFinishedConditionTester(stepper));
+ } catch (CoreException e) {
+ // We have to catch the CoreException here as we do want to open the
+ // launch configurations dialog on ERROR only.
+ status = e.getStatus();
+
+ ILaunchManagerDelegate delegate = LaunchConfigTypeBindingsManager.getInstance().getLaunchManagerDelegate(configuration.getType().getIdentifier(), mode);
+
+ if (status == null || (status.getSeverity() == IStatus.ERROR && delegate.showLaunchDialog(ILaunchManagerDelegate.SITUATION_AFTER_LAUNCH_FAILED))) {
+ // just pass on the exception as is
+ throw e;
+ }
+
+ // Try to get a handler for the status
+ IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
+ // If we cannot get a handler, pass on the exception
+ if (handler == null) {
+ throw e;
+ }
+
+ // Invoke the handler directly and drop the exception
+ handler.handleStatus(status, this);
+
+ // Mimic the original launch configuration behavior if an exception occurred
+ // by removing the launch, if empty, and setting the progress monitor canceled.
+ // @see LaunchConfiguration#launch(String, IProgressMonitor, boolean, boolean), line #768
+ if (!launch.hasChildren()) {
+ DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
+ if (monitor != null) {
+ monitor.setCanceled(true);
+ }
+ }
+ } finally {
+ // Mimic the original launch configuration behavior if monitor is set
+ // canceled and make sure that the launch get's removed.
+ if (monitor == null || monitor.isCanceled()) {
+ DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
+ }
+
+ // Cleanup the stepper
+ if (stepper != null) {
+ stepper.cleanup();
+ }
+
+ // Set the launch completed here. Doesn't matter if the launch might completed with error or not.
+ launch.setAttribute(ICommonLaunchAttributes.ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED, Boolean.TRUE.toString());
+
+ long endTime = System.currentTimeMillis();
+ CoreBundleActivator.getTraceHandler().trace("LaunchConfigurationDelegate#launch: *** DONE" //$NON-NLS-1$
+ + " (" + configuration.getName() + ")", //$NON-NLS-1$ //$NON-NLS-2$
+ 0, ITraceIds.TRACE_STEPPING, IStatus.WARNING, this);
+ CoreBundleActivator.getTraceHandler().trace(" [" + ISharedConstants.TIME_FORMAT.format(new Date(endTime)) //$NON-NLS-1$
+ + " , delay = " + (endTime - startTime) + " ms]" //$NON-NLS-1$ //$NON-NLS-2$
+ + " ***", //$NON-NLS-1$
+ 0, ITraceIds.PROFILE_STEPPING, IStatus.WARNING, this);
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
+ */
+ @Override
+ public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
+ return new Launch(configuration, mode, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getProjectsForProblemSearch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
+ */
+ @Override
+ protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode) throws CoreException {
+ // Return the same list of projects as we have to build
+ return getBuildOrder(configuration, mode);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
+ */
+ @Override
+ protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
+ // The result list. Return always an empty list at least. If returning null,
+ // the super implementation will perform a incremental workspace build.
+ List<IProject> projects = new ArrayList<IProject>();
+
+ // Return the projects to build within the order the user configured within
+ // the corresponding UI launch tab.
+ List<String> projectNames = (List<String>)DefaultPersistenceDelegate.getAttribute(configuration, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<?>)null);
+ if (projectNames != null) {
+ projects.addAll(findProjectResources(projectNames));
+ }
+
+ // If the list of projects is not empty, we have to check for duplicates
+ // and possible sub projects. As we cannot pre check if a project must
+ // be build, we have to avoid building the same project again and again.
+ checkForDuplicatesAndSubProjects(projects);
+
+ return projects.toArray(new IProject[projects.size()]);
+ }
+
+ /**
+ * Lookup the corresponding project resources for the given list of project
+ * names. If one of the referenced projects cannot be found or is closed,
+ * a {@link CoreException} will be thrown.
+ *
+ * @param projectNames The list of project names. Must be not <code>null</code>.
+ * @return The list of project resources or an empty list.
+ */
+ protected List<IProject> findProjectResources(List<String> projectNames) throws CoreException {
+ Assert.isNotNull(projectNames);
+
+ List<IProject> projects = new ArrayList<IProject>();
+
+ // Project resources are stored with the workspace root
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ for (String projectName : projectNames) {
+ // Query the project resource from the workspace root.
+ IProject project = root.getProject(projectName);
+ if (!project.isAccessible()) {
+ // Not accessible -> means the project does either not exist or
+ // is closed.
+ throw new CoreException(new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ NLS.bind(Messages.LaunchConfigurationDelegate_error_inaccessibleReferencedProject, projectName)
+ ));
+ }
+
+ // add the project resource to the list
+ projects.add(project);
+ }
+
+ return projects;
+ }
+
+ /**
+ * Check for duplicates and sub projects in the given list of project
+ * resources.
+ *
+ * @param projects The list of project resources. Must be not <code>null</code>.
+ */
+ protected void checkForDuplicatesAndSubProjects(List<IProject> projects) {
+ Assert.isNotNull(projects);
+
+ // The list of already processed project names
+ List<String> processedProjectNames = new ArrayList<String>();
+
+ // Loop the project list and determine the duplicates. Use an
+ // iterator here as we manipulate the list directly.
+ ListIterator<IProject> iterator = projects.listIterator();
+ while (iterator.hasNext()) {
+ IProject project = iterator.next();
+ // If the project name is within the list of already processed
+ // projects, the project will be deleted from the list.
+ if (processedProjectNames.contains(project.getName())) {
+ iterator.remove();
+ continue;
+ }
+
+ // Add the project name to the list of processed project names
+ processedProjectNames.add(project.getName());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBreakpoints(org.eclipse.debug.core.ILaunchConfiguration)
+ *
+ * Note: Redefined to be public accessible. Needed to access the breakpoints without
+ * duplicating the super implementation.
+ */
+ @Override
+ public IBreakpoint[] getBreakpoints(ILaunchConfiguration configuration) {
+ return super.getBreakpoints(configuration);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
index e702164e3..63582ad78 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
@@ -1,82 +1,83 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.launch.core.lm.interfaces;
-
-/**
- * Defines the common attribute id's used to access launch configuration properties.
- */
-public interface ICommonLaunchAttributes {
-
- /**
- * Define the prefix used by all other attribute id's as prefix.
- */
- public static final String ATTR_PREFIX = "org.eclipse.tcf.te.launch"; //$NON-NLS-1$
-
- /**
- * Launch configuration attribute: List of projects which must be build before executing the launch.
- */
- public static final String ATTR_PROJECTS_FOR_BUILD = ATTR_PREFIX + ".projectsForBuild"; //$NON-NLS-1$
- /**
- * Launch configuration attribute: List of referenced projects.
- */
- public static final String ATTR_REFERENCED_PROJECTS = ATTR_PREFIX + ".referencedProjects"; //$NON-NLS-1$
-
- /**
- * Time stamp when last launched.
- */
- public static final String ATTR_LAST_LAUNCHED = ATTR_PREFIX + ".lastLaunched"; //$NON-NLS-1$
-
- /**
- * Launch mode variant id.
- */
- public static final String ATTR_DELEGATE_VARIANT = ATTR_PREFIX + ".delegateVariant"; //$NON-NLS-1$
-
- /**
- * Attribute used exclusively with <code>ILaunch.setAttribute</code> to mark when
- * then launch sequence finished. The attribute does not tell if an error occurred
- * during the launch!
- */
- public static final String ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED = "launchSequenceCompleted"; //$NON-NLS-1$
-
- // Copied from IDebugUIConstants to make them available for non-UI plugin's.
-
- /**
- * Debug UI plug-in identifier (value <code>"org.eclipse.debug.ui"</code>).
- */
- public static final String PLUGIN_ID_DEBUG_UI = "org.eclipse.debug.ui"; //$NON-NLS-1$;
-
- /**
- * Debug CORE plug-in identifier (value <code>"org.eclipse.debug.core"</code>).
- */
- public static final String PLUGIN_ID_DEBUG_CORE = "org.eclipse.debug.core"; //$NON-NLS-1$;
-
- /**
- * Launch configuration boolean attribute specifying whether output from the launched process will
- * be captured and written to the console. Default value is <code>true</code>.
- *
- * @since 3.4
- */
- public static final String ATTR_CAPTURE_OUTPUT = PLUGIN_ID_DEBUG_CORE + ".capture_output"; //$NON-NLS-1$
-
- /**
- * Launch configuration attribute specifying a file name that console output should
- * be written to or <code>null</code> if none. Default value is <code>null</code>.
- * When specified, all output from the launched process will be written to the file.
- * The file name attribute may contain variables which will be resolved by the
- * {@link org.eclipse.core.variables.IStringVariableManager}.
- *
- * @see IDebugUIConstants
- * @since 3.1
- */
- public static final String ATTR_CAPTURE_IN_FILE = PLUGIN_ID_DEBUG_UI + ".ATTR_CAPTURE_IN_FILE"; //$NON-NLS-1$
-}
-
-
-
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.lm.interfaces;
+
+/**
+ * Defines the common attribute id's used to access launch configuration properties.
+ */
+public interface ICommonLaunchAttributes {
+
+ /**
+ * Define the prefix used by all other attribute id's as prefix.
+ */
+ public static final String ATTR_PREFIX = "org.eclipse.tcf.te.launch"; //$NON-NLS-1$
+
+ /**
+ * Launch configuration attribute: List of projects which must be build before executing the launch.
+ */
+ public static final String ATTR_PROJECTS_FOR_BUILD = ATTR_PREFIX + ".projectsForBuild"; //$NON-NLS-1$
+
+ /**
+ * Launch configuration attribute: List of referenced projects.
+ */
+ public static final String ATTR_REFERENCED_PROJECTS = ATTR_PREFIX + ".referencedProjects"; //$NON-NLS-1$
+
+ /**
+ * Time stamp when last launched.
+ */
+ public static final String ATTR_LAST_LAUNCHED = ATTR_PREFIX + ".lastLaunched"; //$NON-NLS-1$
+
+ /**
+ * Launch mode variant id.
+ */
+ public static final String ATTR_DELEGATE_VARIANT = ATTR_PREFIX + ".delegateVariant"; //$NON-NLS-1$
+
+ /**
+ * Attribute used exclusively with <code>ILaunch.setAttribute</code> to mark when
+ * then launch sequence finished. The attribute does not tell if an error occurred
+ * during the launch!
+ */
+ public static final String ILAUNCH_ATTRIBUTE_LAUNCH_SEQUENCE_COMPLETED = "launchSequenceCompleted"; //$NON-NLS-1$
+
+ // Copied from IDebugUIConstants to make them available for non-UI plugin's.
+
+ /**
+ * Debug UI plug-in identifier (value <code>"org.eclipse.debug.ui"</code>).
+ */
+ public static final String PLUGIN_ID_DEBUG_UI = "org.eclipse.debug.ui"; //$NON-NLS-1$;
+
+ /**
+ * Debug CORE plug-in identifier (value <code>"org.eclipse.debug.core"</code>).
+ */
+ public static final String PLUGIN_ID_DEBUG_CORE = "org.eclipse.debug.core"; //$NON-NLS-1$;
+
+ /**
+ * Launch configuration boolean attribute specifying whether output from the launched process will
+ * be captured and written to the console. Default value is <code>true</code>.
+ *
+ * @since 3.4
+ */
+ public static final String ATTR_CAPTURE_OUTPUT = PLUGIN_ID_DEBUG_CORE + ".capture_output"; //$NON-NLS-1$
+
+ /**
+ * Launch configuration attribute specifying a file name that console output should
+ * be written to or <code>null</code> if none. Default value is <code>null</code>.
+ * When specified, all output from the launched process will be written to the file.
+ * The file name attribute may contain variables which will be resolved by the
+ * {@link org.eclipse.core.variables.IStringVariableManager}.
+ *
+ * @see IDebugUIConstants
+ * @since 3.1
+ */
+ public static final String ATTR_CAPTURE_IN_FILE = PLUGIN_ID_DEBUG_UI + ".ATTR_CAPTURE_IN_FILE"; //$NON-NLS-1$
+}
+
+
+
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IContextSelectorLaunchAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IContextSelectorLaunchAttributes.java
index f1730858c..5f9026565 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IContextSelectorLaunchAttributes.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/IContextSelectorLaunchAttributes.java
@@ -15,6 +15,11 @@ package org.eclipse.tcf.te.launch.core.lm.interfaces;
public interface IContextSelectorLaunchAttributes {
/**
+ * Launch configuration attribute: The active launch context the launch is operating with.
+ */
+ public static final String ATTR_ACTIVE_LAUNCH_CONTEXT = ICommonLaunchAttributes.ATTR_PREFIX + ".active_launch_context"; //$NON-NLS-1$
+
+ /**
* Launch configuration attribute: The launch contexts the launch is operating with. Use
* {@link ContextSelectorPersistanceDelegate} to access
* this attribute within a launch configuration.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java
index f81436419..0d12273ab 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ContextSelectorPersistenceDelegate.java
@@ -1,544 +1,555 @@
-/*******************************************************************************
- * Copyright (c) 2012 Wind River Systems, Inc. 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
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.tcf.te.launch.core.persistence;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
-import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
-import org.eclipse.tcf.te.runtime.model.factory.Factory;
-import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
-import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
-import org.osgi.framework.Bundle;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/**
- * Context selector persistence delegate.
- */
-public class ContextSelectorPersistenceDelegate {
- // The read cache for step contexts. Avoid running time consuming
- // re-parsing of an already parsed step context description again and again.
- private final static Map<String, List<IStepContext>> readCache = new LinkedHashMap<String, List<IStepContext>>();
- // The write cache for target contexts. Avoids re-generating the XML again and again.
- private final static Map<String, String> writeCache = new LinkedHashMap<String, String>();
-
- // Limit the read cache to the last 10 read step contexts
- private final static int READ_CACHE_MAX_CAPACITY = 25;
- // Limit the write cache to the last 10 written step contexts
- private final static int WRITE_CACHE_MAX_CAPACITY = 25;
-
- /**
- * Saves the selected launch contexts to the specified launch configuration working copy. If the
- * selected launch contexts are <code>null</code> or empty, the attribute will be removed from
- * the specified launch configuration working copy.
- *
- * @param wc The launch configuration working copy. Must not be <code>null</code>.
- * @param contexts The launch contexts to save or <code>null</code>.
- */
- public final static void setLaunchContexts(ILaunchConfigurationWorkingCopy wc, IStepContext[] contexts) {
- Assert.isNotNull(wc);
-
- if (contexts == null || contexts.length == 0) {
- DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
- return;
- }
-
- // Get the encoded XML representation
- String xml = encodeLaunchContexts(contexts);
- // And save them to the launch configuration. If XML == null, the
- // launch contexts will be removed from the launch configuration
- DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
- }
-
- /**
- * Saves the selected launch contexts to the specified launch specification. If the selected
- * launch contexts are <code>null</code> or empty, the attribute will be removed from the
- * specified launch specification.
- *
- * @param launchSpec The launch specification. Must not be <code>null</code>.
- * @param contexts The launch contexts to save or <code>null</code>.
- */
- public final static void setLaunchContexts(ILaunchSpecification launchSpec, IStepContext[] contexts) {
- Assert.isNotNull(launchSpec);
-
- if (contexts == null || contexts.length == 0) {
- launchSpec.removeAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS);
- return;
- }
-
- // Get the encoded XML representation
- String xml = encodeLaunchContexts(contexts);
- // And save them to the launch specification. If XML == null, the
- // launch contexts will be removed from the launch specification
- launchSpec.addAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
- }
-
- /**
- * Writes the given launch contexts into a string encoded in XML.
- *
- * @param contexts The launch contexts to encode. Must not be <code>null</code>.
- * @return The full XML representation of the given contexts or <code>null</code>.
- */
- public final static String encodeLaunchContexts(IStepContext[] contexts) {
- Assert.isNotNull(contexts);
-
- // The final result
- String result = null;
-
- // Generate the write cache key
- String writeCacheKey = makeWriteCacheKey(contexts);
-
- // Check if we have the contexts already generated before
- synchronized (writeCache) {
- if (writeCache.containsKey(writeCacheKey)) {
- result = writeCache.get(writeCacheKey);
- }
- }
-
- // If no cache hit, generate from scratch
- if (result == null) {
- // First, we write the selected contexts as XML representation into a string
- StringWriter writer = new StringWriter();
-
- try {
- // Write the header and get the initial indentation
- String indentation = writeHeader(writer);
- // Iterate over the given selected step contexts and write them out.
- for (IStepContext node : contexts) {
- writeStepContext(writer, indentation, node);
- }
- // Write the footer
- writeFooter(writer);
-
- // Convert into a string
- result = writer.toString();
-
- synchronized (writeCache) {
- // Limit the write cache capacity
- checkCacheCapacity(writeCache, WRITE_CACHE_MAX_CAPACITY);
- // And put it into the write cache
- writeCache.put(writeCacheKey, result);
- }
- }
- catch (IOException e) {
- // Export to the string writer failed --> remove attribute from launch configuration
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- result = null;
- }
- finally {
- try {
- writer.close();
- }
- catch (IOException e) { /* ignored on purpose */
- }
- }
- }
-
- return result;
- }
-
- /**
- * Generates a write cache key from the given contexts.
- *
- * @param contexts The contexts
- * @return The corresponding write key cache.
- */
- private static String makeWriteCacheKey(IStepContext[] contexts) {
- Assert.isNotNull(contexts);
-
- StringBuffer key = new StringBuffer();
- for (IStepContext context : contexts) {
- key.append(Integer.toHexString(context.hashCode()));
- key.append(':');
- }
- if (key.charAt(key.length() - 1) == ':') {
- key.setCharAt(key.length() - 1, ' ');
- }
- return key.toString().trim();
- }
-
- /**
- * Writes the header to the given writer and returns the indentation to be used for following
- * elements.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @throws IOException in case the write failed.
- */
- private static String writeHeader(Writer writer) throws IOException {
- Assert.isNotNull(writer);
- writer.write("<contexts>\n"); //$NON-NLS-1$
- return "\t"; //$NON-NLS-1$
- }
-
- /**
- * Writes the footer to the given writer and returns the indentation to be used for following
- * elements.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @throws IOException in case the write failed.
- */
- private static String writeFooter(Writer writer) throws IOException {
- Assert.isNotNull(writer);
- writer.write("</contexts>\n"); //$NON-NLS-1$
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Writes the step context element to the given writer.
- *
- * @param writer The writer instance. Must not be <code>null</code>.
- * @param indentation The indentation to prefix each exported line with. Must not be <code>null</code>.
- * @param context The step context instance. Must not be <code>null</code>.
- *
- * @throws IOException in case the write failed.
- */
- private static void writeStepContext(Writer writer, String indentation, IStepContext context) throws IOException {
- Assert.isNotNull(writer);
- Assert.isNotNull(indentation);
- Assert.isNotNull(context);
-
- writer.write(indentation + "<context type=\"" + context.getEncodedClassName() + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.write(indentation + "\t" + context.encode() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.write(indentation + "</context>\n"); //$NON-NLS-1$
- }
-
- /**
- * Reads the selected launch contexts from the given XML encoded string.
- *
- * @param encodedContexts The selected launch contexts encoded as XML string. Must not be <code>null</code>.
- * @return The selected launch contexts or an empty array.
- */
- public final static IStepContext[] decodeLaunchContexts(String encodedContexts) {
- Assert.isNotNull(encodedContexts);
-
- List<IStepContext> contexts = null;
-
- if (!"".equals(encodedContexts.trim())) { //$NON-NLS-1$
- synchronized (readCache) {
- // Check if we have the contexts already parsed before
- if (readCache.containsKey(encodedContexts)) {
- // Take the result from the cache
- contexts = readCache.get(encodedContexts);
- // check sanity. If empty or we cannot find the step context,
- // drop the cache value and decode again.
- ListIterator<IStepContext> iterator = contexts.listIterator();
- while (iterator.hasNext()) {
- IStepContext node = iterator.next();
- if (!node.exists()) {
- contexts = null;
- readCache.remove(encodedContexts);
- break;
- }
- }
-
- if (contexts != null && contexts.isEmpty()) {
- readCache.remove(encodedContexts);
- contexts = null;
- }
- }
- }
-
- if (contexts == null || contexts.isEmpty()) {
- contexts = new ArrayList<IStepContext>();
- // We have to parse the contexts from the string
- InputStream input = new ByteArrayInputStream(encodedContexts.getBytes());
- // Instantiate the XML parser
- LaunchContextXMLParser xmlParser = new LaunchContextXMLParser();
- xmlParser.initXMLParser();
- xmlParser.setContexts(contexts);
- try {
- xmlParser.getXMLReader().parse(input, xmlParser);
- if (!contexts.isEmpty()) {
- synchronized (readCache) {
- // Limit the read cache capacity
- checkCacheCapacity(readCache, READ_CACHE_MAX_CAPACITY);
- // Put the result into the read cache
- readCache.put(encodedContexts, contexts);
- }
- }
- }
- catch (Exception e) {
- // Import failed --> remove attribute from launch configuration
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- contexts = null;
- }
- }
- }
-
- return contexts != null ? contexts.toArray(new IStepContext[contexts.size()]) : new IStepContext[0];
- }
-
- /**
- * Internal helper method to ensure a maximum capacity of the caches.
- */
- private final static void checkCacheCapacity(Map<String, ?> cache, int maxCapacity) {
- if (cache.size() < maxCapacity) {
- return;
- }
- // Get all keys
- String[] keys = cache.keySet().toArray(new String[cache.keySet().size()]);
- // And remove all keys starting with the eldest till the
- // capacity is fine again.
- for (String key : keys) {
- cache.remove(key);
- if (cache.size() < maxCapacity / 2) {
- break;
- }
- }
- }
-
- private final static class LaunchContextXMLParser extends DefaultHandler {
- private final int IN_CONTEXTS_DEFINITION = 1;
- private final int IN_CONTEXT_DEFINITION = 2;
-
- private SAXParser parser;
-
- private int parseState;
- private String lastData;
- private String lastType;
- private List<IStepContext> contexts;
-
- /**
- * Constructor
- */
- public LaunchContextXMLParser() {
- super();
-
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(false);
- factory.setValidating(false);
- try {
- parser = factory.newSAXParser();
- }
- catch (ParserConfigurationException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- catch (SAXException e) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
-
- /**
- * Returns the associated XML parser instance.
- */
- protected SAXParser getXMLReader() {
- return parser;
- }
-
- /**
- * Reset the XML parser to a defined start point.
- */
- protected void initXMLParser() {
- parseState = 0;
- lastData = null;
- lastType = null;
- contexts = null;
- }
-
- /**
- * Associate the list instance to store the identified contexts.
- */
- protected void setContexts(List<IStepContext> contexts) {
- this.contexts = contexts;
- }
-
- /*
- * (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
- * java.lang.String)
- */
- @Override
- public void endElement(String uri, String localName, String name) throws SAXException {
- if ("contexts".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
- parseState ^= IN_CONTEXTS_DEFINITION;
- }
- if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXT_DEFINITION) == IN_CONTEXT_DEFINITION) { //$NON-NLS-1$
- parseState ^= IN_CONTEXT_DEFINITION;
-
- // The context encoded string is in last data
- if (lastType != null && lastData != null) {
- Class<IModelNode> clazz = null;
- try {
- clazz = (Class<IModelNode>)CoreBundleActivator.getContext().getBundle().loadClass(lastType);
- } catch (ClassNotFoundException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
-
- // If the class could not be loaded by our own bundle class loader, try to find
- // the bundle from the class name and try to load the class through the bundle.
- if (clazz == null) {
- String bundleId = lastType;
- Bundle bundle = null;
- while (bundleId != null && bundle == null) {
- bundle = Platform.getBundle(bundleId);
- if (bundle == null) {
- int i = bundleId.lastIndexOf('.');
- if (i != -1) {
- bundleId = bundleId.substring(0, i);
- } else {
- bundleId = null;
- }
- }
- }
-
- if (bundle != null) {
- try {
- clazz = (Class<IModelNode>)bundle.loadClass(lastType);
- } catch (ClassNotFoundException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
- }
- }
-
- if (clazz != null) {
- // Create an instance of this class and try to load the step context
- Object object = Factory.getInstance().newInstance(clazz);
- if (object != null) {
- IStepContext context = (IStepContext)Platform.getAdapterManager().loadAdapter(object, IStepContext.class.getName());
- if (context != null) {
- try {
- // Decodes the context object
- context.decode(lastData);
- if (!contexts.contains(context)) {
- contexts.add(context);
- }
- } catch (IOException e) {
- if (Platform.inDebugMode()) {
- IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
- "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
- Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
- }
- }
- }
- }
- }
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- @Override
- public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
- // Each time we start a new element, throw away the lastData content
- lastData = null;
-
- if ("contexts".equalsIgnoreCase(name)) { //$NON-NLS-1$
- parseState |= IN_CONTEXTS_DEFINITION;
- }
- if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
- parseState |= IN_CONTEXT_DEFINITION;
- lastType = attributes.getValue("type"); //$NON-NLS-1$
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
- */
- @Override
- public void characters(char ch[], int start, int length) {
- if (lastData == null) {
- lastData = new String(ch, start, length).trim();
- }
- else {
- lastData += new String(ch, start, length).trim();
- }
- }
- }
-
- /**
- * Returns the list of configured launch contexts from the given launch configuration.
- * <p>
- * If the given launch configuration is <code>null</code> and the method will return an empty
- * array.
- *
- * @param configuration The launch configuration or <code>null</code>.
- * @return The list of configured launch contexts or an empty array.
- */
- public static final IStepContext[] getLaunchContexts(ILaunchConfiguration configuration) {
- IStepContext[] contexts = new IStepContext[0];
-
- // First read the contexts written by the launch context selector control.
- if (configuration != null) {
- // Read the context attribute from the launch configuration
- String encodedContexts = DefaultPersistenceDelegate.getAttribute(configuration, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
- if (encodedContexts != null) {
- contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
- }
- }
-
- return contexts;
- }
-
- /**
- * Returns the list of configured launch contexts from the given launch specification.
- * <p>
- * If the given launch specification is <code>null</code> and the method will return an empty
- * array.
- *
- * @param launchSpec The launch specification or <code>null</code>.
- * @return The list of configured launch contexts or an empty array.
- */
- public static final IStepContext[] getLaunchContexts(ILaunchSpecification launchSpec) {
- IStepContext[] contexts = new IStepContext[0];
-
- // First read the contexts written by the launch context selector control.
- if (launchSpec != null) {
- // Read the context attribute from the launch specification
- String encodedContexts = (String) launchSpec.getAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, null);
- if (encodedContexts != null) {
- contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
- }
- }
-
- return contexts;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. 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
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.launch.core.persistence;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.runtime.model.factory.Factory;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistable2;
+import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService;
+import org.osgi.framework.Bundle;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Context selector persistence delegate.
+ */
+public class ContextSelectorPersistenceDelegate {
+ // The read cache for step contexts. Avoid running time consuming
+ // re-parsing of an already parsed step context description again and again.
+ private final static Map<String, List<IModelNode>> readCache = new LinkedHashMap<String, List<IModelNode>>();
+ // The write cache for target contexts. Avoids re-generating the XML again and again.
+ private final static Map<String, String> writeCache = new LinkedHashMap<String, String>();
+
+ // Limit the read cache to the last 10 read step contexts
+ private final static int READ_CACHE_MAX_CAPACITY = 25;
+ // Limit the write cache to the last 10 written step contexts
+ private final static int WRITE_CACHE_MAX_CAPACITY = 25;
+
+ /**
+ * Saves the selected launch contexts to the specified launch configuration working copy. If the
+ * selected launch contexts are <code>null</code> or empty, the attribute will be removed from
+ * the specified launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param contexts The launch contexts to save or <code>null</code>.
+ */
+ public final static void setLaunchContexts(ILaunchConfigurationWorkingCopy wc, IModelNode[] contexts) {
+ Assert.isNotNull(wc);
+
+ if (contexts == null || contexts.length == 0) {
+ DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
+ return;
+ }
+
+ // Get the encoded XML representation
+ String xml = encodeLaunchContexts(contexts);
+ // And save them to the launch configuration. If XML == null, the
+ // launch contexts will be removed from the launch configuration
+ DefaultPersistenceDelegate.setAttribute(wc, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
+ }
+
+ /**
+ * Saves the selected launch contexts to the specified launch specification. If the selected
+ * launch contexts are <code>null</code> or empty, the attribute will be removed from the
+ * specified launch specification.
+ *
+ * @param launchSpec The launch specification. Must not be <code>null</code>.
+ * @param contexts The launch contexts to save or <code>null</code>.
+ */
+ public final static void setLaunchContexts(ILaunchSpecification launchSpec, IModelNode[] contexts) {
+ Assert.isNotNull(launchSpec);
+
+ if (contexts == null || contexts.length == 0) {
+ launchSpec.removeAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS);
+ return;
+ }
+
+ // Get the encoded XML representation
+ String xml = encodeLaunchContexts(contexts);
+ // And save them to the launch specification. If XML == null, the
+ // launch contexts will be removed from the launch specification
+ launchSpec.addAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, xml);
+ }
+
+ /**
+ * Writes the given launch contexts into a string encoded in XML.
+ *
+ * @param contexts The launch contexts to encode. Must not be <code>null</code>.
+ * @return The full XML representation of the given contexts or <code>null</code>.
+ */
+ public final static String encodeLaunchContexts(IModelNode[] contexts) {
+ Assert.isNotNull(contexts);
+
+ // The final result
+ String result = null;
+
+ // Generate the write cache key
+ String writeCacheKey = makeWriteCacheKey(contexts);
+
+ // Check if we have the contexts already generated before
+ synchronized (writeCache) {
+ if (writeCache.containsKey(writeCacheKey)) {
+ result = writeCache.get(writeCacheKey);
+ }
+ }
+
+ // If no cache hit, generate from scratch
+ if (result == null) {
+ // First, we write the selected contexts as XML representation into a string
+ StringWriter writer = new StringWriter();
+
+ try {
+ // Write the header and get the initial indentation
+ String indentation = writeHeader(writer);
+ // Iterate over the given selected step contexts and write them out.
+ for (IModelNode node : contexts) {
+ writeStepContext(writer, indentation, node);
+ }
+ // Write the footer
+ writeFooter(writer);
+
+ // Convert into a string
+ result = writer.toString();
+
+ synchronized (writeCache) {
+ // Limit the write cache capacity
+ checkCacheCapacity(writeCache, WRITE_CACHE_MAX_CAPACITY);
+ // And put it into the write cache
+ writeCache.put(writeCacheKey, result);
+ }
+ }
+ catch (IOException e) {
+ // Export to the string writer failed --> remove attribute from launch configuration
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ result = null;
+ }
+ finally {
+ try {
+ writer.close();
+ }
+ catch (IOException e) { /* ignored on purpose */
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Generates a write cache key from the given contexts.
+ *
+ * @param contexts The contexts
+ * @return The corresponding write key cache.
+ */
+ private static String makeWriteCacheKey(IModelNode[] contexts) {
+ Assert.isNotNull(contexts);
+
+ StringBuffer key = new StringBuffer();
+ for (IModelNode context : contexts) {
+ key.append(Integer.toHexString(context.hashCode()));
+ key.append(':');
+ }
+ if (key.charAt(key.length() - 1) == ':') {
+ key.setCharAt(key.length() - 1, ' ');
+ }
+ return key.toString().trim();
+ }
+
+ /**
+ * Writes the header to the given writer and returns the indentation to be used for following
+ * elements.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @throws IOException in case the write failed.
+ */
+ private static String writeHeader(Writer writer) throws IOException {
+ Assert.isNotNull(writer);
+ writer.write("<contexts>\n"); //$NON-NLS-1$
+ return "\t"; //$NON-NLS-1$
+ }
+
+ /**
+ * Writes the footer to the given writer and returns the indentation to be used for following
+ * elements.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @throws IOException in case the write failed.
+ */
+ private static String writeFooter(Writer writer) throws IOException {
+ Assert.isNotNull(writer);
+ writer.write("</contexts>\n"); //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Writes the step context element to the given writer.
+ *
+ * @param writer The writer instance. Must not be <code>null</code>.
+ * @param indentation The indentation to prefix each exported line with. Must not be <code>null</code>.
+ * @param context The step context instance. Must not be <code>null</code>.
+ *
+ * @throws IOException in case the write failed.
+ */
+ private static void writeStepContext(Writer writer, String indentation, IModelNode context) throws IOException {
+ Assert.isNotNull(writer);
+ Assert.isNotNull(indentation);
+ Assert.isNotNull(context);
+
+ IPersistable2 adapter = (IPersistable2)context.getAdapter(IPersistable2.class);
+
+ writer.write(indentation + "<context type=\"" + adapter.getEncodedClassName(context) + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ writer.write(indentation + "\t" + adapter.exportStringFrom(context) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ writer.write(indentation + "</context>\n"); //$NON-NLS-1$
+ }
+
+ /**
+ * Reads the selected launch contexts from the given XML encoded string.
+ *
+ * @param encodedContexts The selected launch contexts encoded as XML string. Must not be <code>null</code>.
+ * @return The selected launch contexts or an empty array.
+ */
+ public final static IModelNode[] decodeLaunchContexts(String encodedContexts) {
+ Assert.isNotNull(encodedContexts);
+
+ List<IModelNode> contexts = null;
+
+ if (!"".equals(encodedContexts.trim())) { //$NON-NLS-1$
+ synchronized (readCache) {
+ // Check if we have the contexts already parsed before
+ if (readCache.containsKey(encodedContexts)) {
+ // Take the result from the cache
+ contexts = readCache.get(encodedContexts);
+ // check sanity. If empty or we cannot find the step context,
+ // drop the cache value and decode again.
+ ListIterator<IModelNode> iterator = contexts.listIterator();
+ while (iterator.hasNext()) {
+ IModelNode node = iterator.next();
+ IPropertiesAccessService service = ServiceManager.getInstance().getService(node, IPropertiesAccessService.class);
+ boolean isGhost = false;
+ if (service != null) {
+ Object value = service.getProperty(node, IModelNode.PROPERTY_IS_GHOST);
+ if (value instanceof Boolean) {
+ isGhost = ((Boolean)value).booleanValue();
+ }
+ }
+ if (isGhost) {
+ contexts = null;
+ readCache.remove(encodedContexts);
+ break;
+ }
+ }
+
+ if (contexts != null && contexts.isEmpty()) {
+ readCache.remove(encodedContexts);
+ contexts = null;
+ }
+ }
+ }
+
+ if (contexts == null || contexts.isEmpty()) {
+ contexts = new ArrayList<IModelNode>();
+ // We have to parse the contexts from the string
+ InputStream input = new ByteArrayInputStream(encodedContexts.getBytes());
+ // Instantiate the XML parser
+ LaunchContextXMLParser xmlParser = new LaunchContextXMLParser();
+ xmlParser.initXMLParser();
+ xmlParser.setContexts(contexts);
+ try {
+ xmlParser.getXMLReader().parse(input, xmlParser);
+ if (!contexts.isEmpty()) {
+ synchronized (readCache) {
+ // Limit the read cache capacity
+ checkCacheCapacity(readCache, READ_CACHE_MAX_CAPACITY);
+ // Put the result into the read cache
+ readCache.put(encodedContexts, contexts);
+ }
+ }
+ }
+ catch (Exception e) {
+ // Import failed --> remove attribute from launch configuration
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ contexts = null;
+ }
+ }
+ }
+
+ return contexts != null ? contexts.toArray(new IModelNode[contexts.size()]) : new IModelNode[0];
+ }
+
+ /**
+ * Internal helper method to ensure a maximum capacity of the caches.
+ */
+ private final static void checkCacheCapacity(Map<String, ?> cache, int maxCapacity) {
+ if (cache.size() < maxCapacity) {
+ return;
+ }
+ // Get all keys
+ String[] keys = cache.keySet().toArray(new String[cache.keySet().size()]);
+ // And remove all keys starting with the eldest till the
+ // capacity is fine again.
+ for (String key : keys) {
+ cache.remove(key);
+ if (cache.size() < maxCapacity / 2) {
+ break;
+ }
+ }
+ }
+
+ private final static class LaunchContextXMLParser extends DefaultHandler {
+ private final int IN_CONTEXTS_DEFINITION = 1;
+ private final int IN_CONTEXT_DEFINITION = 2;
+
+ private SAXParser parser;
+
+ private int parseState;
+ private String lastData;
+ private String lastType;
+ private List<IModelNode> contexts;
+
+ /**
+ * Constructor
+ */
+ public LaunchContextXMLParser() {
+ super();
+
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(false);
+ factory.setValidating(false);
+ try {
+ parser = factory.newSAXParser();
+ }
+ catch (ParserConfigurationException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ catch (SAXException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(), e.getClass().getName(), e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ /**
+ * Returns the associated XML parser instance.
+ */
+ protected SAXParser getXMLReader() {
+ return parser;
+ }
+
+ /**
+ * Reset the XML parser to a defined start point.
+ */
+ protected void initXMLParser() {
+ parseState = 0;
+ lastData = null;
+ lastType = null;
+ contexts = null;
+ }
+
+ /**
+ * Associate the list instance to store the identified contexts.
+ */
+ protected void setContexts(List<IModelNode> contexts) {
+ this.contexts = contexts;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public void endElement(String uri, String localName, String name) throws SAXException {
+ if ("contexts".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
+ parseState ^= IN_CONTEXTS_DEFINITION;
+ }
+ if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXT_DEFINITION) == IN_CONTEXT_DEFINITION) { //$NON-NLS-1$
+ parseState ^= IN_CONTEXT_DEFINITION;
+
+ // The context encoded string is in last data
+ if (lastType != null && lastData != null) {
+ Class<IModelNode> clazz = null;
+ try {
+ clazz = (Class<IModelNode>)CoreBundleActivator.getContext().getBundle().loadClass(lastType);
+ } catch (ClassNotFoundException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.WARNING, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+
+ // If the class could not be loaded by our own bundle class loader, try to find
+ // the bundle from the class name and try to load the class through the bundle.
+ if (clazz == null) {
+ String bundleId = lastType;
+ Bundle bundle = null;
+ while (bundleId != null && bundle == null) {
+ bundle = Platform.getBundle(bundleId);
+ if (bundle == null) {
+ int i = bundleId.lastIndexOf('.');
+ if (i != -1) {
+ bundleId = bundleId.substring(0, i);
+ } else {
+ bundleId = null;
+ }
+ }
+ }
+
+ if (bundle != null) {
+ try {
+ clazz = (Class<IModelNode>)bundle.loadClass(lastType);
+ } catch (ClassNotFoundException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ }
+ }
+
+ if (clazz != null) {
+ // Create an instance of this class and try to load the step context
+ Object object = Factory.getInstance().newInstance(clazz);
+ if (object instanceof IAdaptable) {
+ try {
+ IPersistable2 adapter = (IPersistable2)((IAdaptable)object).getAdapter(IPersistable2.class);
+ // Decodes the context object
+ IModelNode context = (IModelNode)adapter.importFrom(lastData);
+ if (!contexts.contains(context)) {
+ contexts.add(context);
+ }
+ } catch (IOException e) {
+ if (Platform.inDebugMode()) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ "Launch framework internal error: " + e.getLocalizedMessage(), e); //$NON-NLS-1$
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ @Override
+ public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
+ // Each time we start a new element, throw away the lastData content
+ lastData = null;
+
+ if ("contexts".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ parseState |= IN_CONTEXTS_DEFINITION;
+ }
+ if ("context".equalsIgnoreCase(name) && (parseState & IN_CONTEXTS_DEFINITION) == IN_CONTEXTS_DEFINITION) { //$NON-NLS-1$
+ parseState |= IN_CONTEXT_DEFINITION;
+ lastType = attributes.getValue("type"); //$NON-NLS-1$
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+ */
+ @Override
+ public void characters(char ch[], int start, int length) {
+ if (lastData == null) {
+ lastData = new String(ch, start, length).trim();
+ }
+ else {
+ lastData += new String(ch, start, length).trim();
+ }
+ }
+ }
+
+ /**
+ * Returns the list of configured launch contexts from the given launch configuration.
+ * <p>
+ * If the given launch configuration is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param configuration The launch configuration or <code>null</code>.
+ * @return The list of configured launch contexts or an empty array.
+ */
+ public static final IModelNode[] getLaunchContexts(ILaunchConfiguration configuration) {
+ IModelNode[] contexts = new IModelNode[0];
+
+ // First read the contexts written by the launch context selector control.
+ if (configuration != null) {
+ // Read the context attribute from the launch configuration
+ String encodedContexts = DefaultPersistenceDelegate.getAttribute(configuration, IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, (String) null);
+ if (encodedContexts != null) {
+ contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
+ }
+ }
+
+ return contexts;
+ }
+
+ /**
+ * Returns the list of configured launch contexts from the given launch specification.
+ * <p>
+ * If the given launch specification is <code>null</code> and the method will return an empty
+ * array.
+ *
+ * @param launchSpec The launch specification or <code>null</code>.
+ * @return The list of configured launch contexts or an empty array.
+ */
+ public static final IModelNode[] getLaunchContexts(ILaunchSpecification launchSpec) {
+ IModelNode[] contexts = new IModelNode[0];
+
+ // First read the contexts written by the launch context selector control.
+ if (launchSpec != null) {
+ // Read the context attribute from the launch specification
+ String encodedContexts = (String) launchSpec.getAttribute(IContextSelectorLaunchAttributes.ATTR_LAUNCH_CONTEXTS, null);
+ if (encodedContexts != null) {
+ contexts = ContextSelectorPersistenceDelegate.decodeLaunchContexts(encodedContexts);
+ }
+ }
+
+ return contexts;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java
new file mode 100644
index 000000000..8b425d9e4
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/AbstractLaunchStep.java
@@ -0,0 +1,46 @@
+/*
+ * AbstractLaunchStep.java
+ * Created on 22.02.2012
+ *
+ * Copyright 2012 Wind River Systems Inc. All rights reserved.
+ */
+package org.eclipse.tcf.te.launch.core.steps;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.IContextSelectorLaunchAttributes;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.model.interfaces.IModelNode;
+import org.eclipse.tcf.te.runtime.stepper.extensions.AbstractStep;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
+
+/**
+ * AbstractLaunchStep
+ * @author tobias.schwarz@windriver.com
+ */
+public abstract class AbstractLaunchStep extends AbstractStep {
+
+ /**
+ * Rteurns the launch object for the given step context.
+ *
+ * @param context The step context.
+ * @return The launch or <code>null</code>.
+ */
+ protected ILaunch getLaunch(IStepContext context) {
+ Assert.isNotNull(context);
+ return (ILaunch)context.getAdapter(ILaunch.class);
+ }
+
+ /**
+ * Returns the active launch context model node that is currently used.
+ *
+ * @param data The data giving object. Must not be <code>null</code>.
+ * @return The active launch context model node.
+ */
+ protected IModelNode getActiveLaunchContext(IPropertiesContainer data) {
+ Assert.isNotNull(data);
+ Object context = data.getProperty(IContextSelectorLaunchAttributes.ATTR_ACTIVE_LAUNCH_CONTEXT);
+ Assert.isTrue(context instanceof IModelNode);
+ return (IModelNode)context;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/RemoveLaunchStep.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/RemoveLaunchStep.java
new file mode 100644
index 000000000..eaedffede
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/steps/RemoveLaunchStep.java
@@ -0,0 +1,45 @@
+/*
+ * RemoveLaunchStep.java
+ * Created on 28.02.2012
+ *
+ * Copyright 2012 Wind River Systems Inc. All rights reserved.
+ */
+package org.eclipse.tcf.te.launch.core.steps;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
+
+/**
+ * RemoveLaunchStep
+ * @author tobias.schwarz@windriver.com
+ */
+public class RemoveLaunchStep extends AbstractLaunchStep {
+
+ /**
+ * Constructor.
+ */
+ public RemoveLaunchStep() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IExtendedStep#validateExecute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback)
+ */
+ @Override
+ public void execute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor, ICallback callback) {
+ DebugPlugin.getDefault().getLaunchManager().removeLaunch(getLaunch(context));
+ callback.done(this, Status.OK_STATUS);
+ }
+}

Back to the top