Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2012-02-02 09:09:37 +0000
committerUwe Stieber2012-02-02 13:15:02 +0000
commitdb2934ac51b6c74d4c24470dd8fdbc48fe9f1ea3 (patch)
treeca790231ab99c2b2d938ac6cd81743e490e42e9f /target_explorer/plugins/org.eclipse.tcf.te.launch.core
parent03ea791b691b5242b5ab700b8c2543cc53eaf0de (diff)
downloadorg.eclipse.tcf-db2934ac51b6c74d4c24470dd8fdbc48fe9f1ea3.tar.gz
org.eclipse.tcf-db2934ac51b6c74d4c24470dd8fdbc48fe9f1ea3.tar.xz
org.eclipse.tcf-db2934ac51b6c74d4c24470dd8fdbc48fe9f1ea3.zip
Target Explorer: Add core launch framework implementation
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.launch.core')
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/.options1
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/META-INF/MANIFEST.MF6
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/plugin.xml17
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java14
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/AdapterFactory.java48
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/SelectionContextAdapter.java61
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java369
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/ILaunchBinding.java32
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IOverwritableLaunchBinding.java24
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IVaryableLaunchBinding.java30
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchBinding.java104
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java363
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/OverwritableLaunchBinding.java82
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/VaryableLaunchBinding.java77
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/exceptions/LaunchServiceException.java89
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/extensions/internal/LaunchModeVariantDelegateExtensionPointManager.java91
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/tracing/ITraceIds.java22
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchAttribute.java73
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigHelper.java108
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigSorter.java66
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchManager.java459
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchSpecification.java262
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java728
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java82
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchAttribute.java41
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchManagerDelegate.java196
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchSpecification.java195
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/ExtensionPointManager.java100
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties7
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/DefaultPersistenceDelegate.java347
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/LaunchConfigurationChangedEvent.java107
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java228
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/IPreferenceKeys.java56
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/PreferencesInitializer.java44
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/AbstractSelectionContext.java145
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/LaunchSelection.java122
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/ProjectSelectionContext.java69
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/TargetSelectionContext.java69
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ILaunchSelection.java38
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/IProjectSelectionContext.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ISelectionContext.java50
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ITargetSelectionContext.java25
43 files changed, 5079 insertions, 1 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/.options b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/.options
index fa594cfd9..52e9e7aae 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/.options
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/.options
@@ -1 +1,2 @@
org.eclipse.tcf.te.launch.core/debugmode = 0
+org.eclipse.tcf.te.launch.core/trace/launchConfigurationMatching = false
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 5b606e5f9..4e47107cf 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
@@ -6,7 +6,11 @@ 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.tcf.te.runtime;bundle-version="1.0.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.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
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 b20c874dd..73209e33b 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
@@ -7,4 +7,21 @@
<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"/>
+<!-- Adapter factory contributions -->
+ <extension point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext"
+ class="org.eclipse.tcf.te.launch.core.adapters.internal.AdapterFactory">
+ <adapter type="org.eclipse.core.expressions.IIterable"/>
+ <adapter type="org.eclipse.core.expressions.ICountable"/>
+ </factory>
+ </extension>
+
+<!-- Preference contributions -->
+ <extension point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.tcf.te.launch.core.preferences.PreferencesInitializer">
+ </initializer>
+ </extension>
+
</plugin>
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java
index bfc498f29..69fef9224 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tcf.te.launch.core.activator;
+import org.eclipse.tcf.te.runtime.preferences.ScopedEclipsePreferences;
import org.eclipse.tcf.te.runtime.tracing.TraceHandler;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -19,6 +20,8 @@ import org.osgi.framework.BundleContext;
public class CoreBundleActivator implements BundleActivator {
// The bundle context
private static BundleContext context;
+ // The scoped preferences instance
+ private static ScopedEclipsePreferences scopedPreferences = null;
// The trace handler instance
private static TraceHandler traceHandler;
@@ -42,6 +45,16 @@ public class CoreBundleActivator implements BundleActivator {
}
/**
+ * Return the scoped preferences for this plugin.
+ */
+ public static ScopedEclipsePreferences getScopedPreferences() {
+ if (scopedPreferences == null) {
+ scopedPreferences = new ScopedEclipsePreferences(getUniqueIdentifier());
+ }
+ return scopedPreferences;
+ }
+
+ /**
* Returns the bundles trace handler.
*
* @return The bundles trace handler.
@@ -69,6 +82,7 @@ public class CoreBundleActivator implements BundleActivator {
@Override
public void stop(BundleContext bundleContext) throws Exception {
CoreBundleActivator.context = null;
+ scopedPreferences = null;
traceHandler = null;
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/AdapterFactory.java
new file mode 100644
index 000000000..10b41799f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/AdapterFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.adapters.internal;
+
+import org.eclipse.core.expressions.ICountable;
+import org.eclipse.core.expressions.IIterable;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * Launch core framework adapter factory implementation.
+ */
+public class AdapterFactory implements IAdapterFactory {
+
+ private static final Class<?>[] CLASSES = new Class[] {
+ IIterable.class,
+ ICountable.class
+ };
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+ */
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adaptableObject instanceof ISelectionContext) {
+ if (IIterable.class.equals(adapterType) || ICountable.class.equals(adapterType)) {
+ return new SelectionContextAdapter((ISelectionContext)adaptableObject);
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+ */
+ @Override
+ public Class[] getAdapterList() {
+ return CLASSES;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/SelectionContextAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/SelectionContextAdapter.java
new file mode 100644
index 000000000..177e26fec
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/adapters/internal/SelectionContextAdapter.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.adapters.internal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.eclipse.core.expressions.ICountable;
+import org.eclipse.core.expressions.IIterable;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * Selection context adapter implementation.
+ */
+public class SelectionContextAdapter implements IIterable, ICountable {
+ private final ISelectionContext context;
+
+ /**
+ * Constructor.
+ *
+ * @param context The selection context. Must not be <code>null</code>.
+ */
+ public SelectionContextAdapter(ISelectionContext context) {
+ Assert.isNotNull(context);
+ this.context = context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.expressions.ICountable#count()
+ */
+ @Override
+ public int count() {
+ return context.getSelections() != null ? context.getSelections().length : 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.expressions.IIterable#iterator()
+ */
+ @Override
+ public Iterator iterator() {
+ Iterator<Object> iterator = null;
+
+ if (context.getSelections() != null) {
+ iterator = Arrays.asList(context.getSelections()).iterator();
+ } else {
+ iterator = Collections.emptyList().iterator();
+ }
+
+ return iterator;
+ }
+
+}
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
new file mode 100644
index 000000000..7f308fd19
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/LaunchConfigTypeBindingsManager.java
@@ -0,0 +1,369 @@
+/*******************************************************************************
+ * 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.IContextStep;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IContextStepGroup;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IContextStepper;
+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 IContextStepper getStepper(String typeId, String mode) {
+ Assert.isNotNull(typeId);
+ Assert.isNotNull(mode);
+
+ IContextStepper 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 IContextStepGroup 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 IContextStepGroup 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 IContextStep getLaunchStep(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 isValidLaunchStep(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.Bindings"); //$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);
+ }
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/ILaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/ILaunchBinding.java
new file mode 100644
index 000000000..4560467e3
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/ILaunchBinding.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.interfaces;
+
+
+/**
+ * Interface to be implemented by a launch configuration type binding element.
+ */
+public interface ILaunchBinding {
+
+ /**
+ * Returns the id of the bound element.
+ */
+ public String getId();
+
+ /**
+ * Returns if or if not the given launch mode is handled by this binding.
+ * <p>
+ * <b>Note:</b> The launch mode is considered valid if <code>null</code> or an empty string is passed.
+ *
+ * @param mode The launch mode or <code>null</code>.
+ * @return <code>True</code> if the launch mode is valid, <code>false</code> otherwise.
+ */
+ public boolean isValidLaunchMode(String mode);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IOverwritableLaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IOverwritableLaunchBinding.java
new file mode 100644
index 000000000..1b8586fb1
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IOverwritableLaunchBinding.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.interfaces;
+
+/**
+ * Interface to be implemented by a overwritable launch configuration type binding element.
+ */
+public interface IOverwritableLaunchBinding extends IVaryableLaunchBinding {
+
+ /**
+ * Returns if or if not this binding overwrites the given bindings id.
+ *
+ * @param id The id. Must not be <code>null</code>.
+ * @return <code>True</code> if this binding overwrites the given bindings id, <code>false</code> if not.
+ */
+ public boolean overwrites(String id);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IVaryableLaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IVaryableLaunchBinding.java
new file mode 100644
index 000000000..89528a0ea
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/interfaces/IVaryableLaunchBinding.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.interfaces;
+
+/**
+ * Interface to be implemented by a launch configuration type binding element
+ * which is supporting launch mode variants.
+ */
+public interface IVaryableLaunchBinding extends ILaunchBinding {
+
+ /**
+ * Returns if or if not the given launch mode is handled by this binding.
+ * <p>
+ * <b>Note:</b> The launch mode and launch mode variant are considered valid
+ * if <code>null</code> or an empty string is passed.
+ *
+ * @param mode The launch mode. Must not be <code>null</code>.
+ * @param variant The launch mode variant to check or <code>null</code>.
+ *
+ * @return <code>True</code> if the launch mode is valid, <code>false</code> otherwise.
+ */
+ public boolean isValidLaunchMode(String mode, String variant);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchBinding.java
new file mode 100644
index 000000000..da18a3d0c
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchBinding.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.Assert;
+import org.eclipse.tcf.te.launch.core.bindings.interfaces.ILaunchBinding;
+
+
+/**
+ * Launch configuration type binding element implementation.
+*/
+public class LaunchBinding implements ILaunchBinding {
+ // The id of the bound element
+ private String id;
+ // The launch modes the binding applies to
+ private final String[] modes;
+
+ /**
+ * Constructor.
+ *
+ * @param id The id of the element to bind. Must not be <code>null</code>.
+ * @param modes The launch modes or <code>null</code>
+ */
+ public LaunchBinding(String id, String modes) {
+ Assert.isNotNull(id);
+ this.id = id;
+
+ if (modes != null) this.modes = modes.trim().split("( )*,( )*"); //$NON-NLS-1$
+ else this.modes = new String[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.bindings.interfaces.ILaunchBinding#getId()
+ */
+ @Override
+ public final String getId() {
+ return id;
+ }
+
+ /**
+ * Returns the list of the launch modes this binding applies to.
+ *
+ * @return The list of launch modes or an empty list.
+ */
+ public final String[] getModes() {
+ return modes;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.bindings.interfaces.ILaunchBinding#isValidLaunchMode(java.lang.String)
+ */
+ @Override
+ public boolean isValidLaunchMode(String launchMode) {
+ if (launchMode == null || launchMode.length() == 0)
+ return true;
+
+ for (String candidate : getModes())
+ if (launchMode.equals(candidate)) return true;
+
+ return getModes().length == 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ toString.append("LaunchBinding("); //$NON-NLS-1$
+ toString.append(id);
+ toString.append(", launchModes"); //$NON-NLS-1$
+ toString.append(toString(getModes()));
+ toString.append(")"); //$NON-NLS-1$
+
+ return toString.toString();
+ }
+
+ /**
+ * Creates a string representation of the given string array.
+ *
+ * @param strings The string array or <code>null</code>.
+ * @return The string representation of the array.
+ */
+ protected String toString(String[] strings) {
+ StringBuffer toString = new StringBuffer();
+ toString.append('[');
+ if (strings != null) {
+ for (int i = 0; i < strings.length; i++) {
+ if (i > 0) toString.append(',');
+ toString.append(strings[i]);
+ }
+ }
+ toString.append(']');
+ return toString.toString();
+ }
+}
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
new file mode 100644
index 000000000..1566dbe90
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/LaunchConfigTypeBinding.java
@@ -0,0 +1,363 @@
+/*******************************************************************************
+ * 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$
+ // 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();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/OverwritableLaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/OverwritableLaunchBinding.java
new file mode 100644
index 000000000..b600c68a2
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/OverwritableLaunchBinding.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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.tcf.te.launch.core.bindings.interfaces.IOverwritableLaunchBinding;
+
+/**
+ * Overwritable launch configuration type binding element implementation.
+ */
+public class OverwritableLaunchBinding extends VaryableLaunchBinding implements IOverwritableLaunchBinding {
+
+ private String[] overwrites;
+
+ /**
+ * Constructor.
+ *
+ * @param id The launch binding id. Must not be <code>null</code>.
+ * @param overwrites The overwritten launch binding id's or <code>null</code>.
+ * @param modes The launch modes or <code>null</code>
+ */
+ public OverwritableLaunchBinding(String id, String overwrites, String modes) {
+ this(id, overwrites, modes, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param id The launch binding id. Must not be <code>null</code>.
+ * @param overwrites The overwritten launch binding id's or <code>null</code>.
+ * @param modes The launch modes or <code>null</code>
+ * @param variants The launch mode variants or <code>null</code>.
+ */
+ public OverwritableLaunchBinding(String id, String overwrites, String modes, String variants) {
+ super(id, modes, variants);
+
+ if (overwrites != null) this.overwrites = overwrites.trim().split("( )*,( )*"); //$NON-NLS-1$
+ else this.overwrites = new String[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.bindings.interfaces.IOverwritableLaunchBinding#overwrites(java.lang.String)
+ */
+ @Override
+ public boolean overwrites(String id) {
+ assert id != null;
+ for (int i = 0; i < overwrites.length; i++) {
+ if (id.equals(overwrites[i])) {
+ return true;
+ }
+ }
+ return overwrites.length == 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ toString.append("OverwriteableLaunchBinding("); //$NON-NLS-1$
+ toString.append(getId());
+ toString.append(", launchModes"); //$NON-NLS-1$
+ toString.append(toString(getModes()));
+ if (getVariants().length > 0) {
+ toString.append(", launchModeVariants"); //$NON-NLS-1$
+ toString.append(toString(getVariants()));
+ }
+ toString.append(", overwrites"); //$NON-NLS-1$
+ toString.append(toString(overwrites));
+ 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/VaryableLaunchBinding.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/VaryableLaunchBinding.java
new file mode 100644
index 000000000..1dc77592b
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/bindings/internal/VaryableLaunchBinding.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.tcf.te.launch.core.bindings.interfaces.IVaryableLaunchBinding;
+
+/**
+ * Launch binding supporting launch mode variants.
+ */
+public class VaryableLaunchBinding extends LaunchBinding implements IVaryableLaunchBinding {
+ private final String[] variants;
+
+ /**
+ * Constructor.
+ *
+ * @param id The launch binding id. Must not be <code>null</code>.
+ * @param modes The launch modes or <code>null</code>
+ * @param variants The launch mode variants or <code>null</code>.
+ */
+ public VaryableLaunchBinding(String id, String modes, String variants) {
+ super(id, modes);
+
+ if (variants != null) this.variants = variants.trim().split("( )*,( )*"); //$NON-NLS-1$
+ else this.variants = new String[0];
+ }
+
+ /**
+ * Returns the list of handled variants.
+ *
+ * @return The list of handled variants or an empty list.
+ */
+ public final String[] getVariants() {
+ return variants;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.bindings.interfaces.IVaryableLaunchBinding#isValidLaunchMode(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean isValidLaunchMode(String launchMode, String variant) {
+ boolean valid = isValidLaunchMode(launchMode);
+ if (!valid) return false;
+
+ if (variant == null || variant.length() == 0)
+ return true;
+
+ for (String candidate : getVariants())
+ if (variant.equals(candidate)) return true;
+
+ return getVariants().length == 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ toString.append("LaunchBinding("); //$NON-NLS-1$
+ toString.append(getId());
+ toString.append(", launchModes"); //$NON-NLS-1$
+ toString.append(toString(getModes()));
+ toString.append(", launchModeVariants"); //$NON-NLS-1$
+ toString.append(toString(getVariants()));
+ 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/exceptions/LaunchServiceException.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/exceptions/LaunchServiceException.java
new file mode 100644
index 000000000..fcf9f42e6
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/exceptions/LaunchServiceException.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.exceptions;
+
+/**
+ * Exception thrown by the launch configuration management service to
+ * signal a service failure.
+ */
+public class LaunchServiceException extends Exception {
+
+ private static final long serialVersionUID = 4847722803200503842L;
+
+ /**
+ * Default type for this exception.
+ */
+ public final static int TYPE_NO_DETAILED_REASON = 0;
+
+ /**
+ * Exception type when mandatory attributes in launch configuration is missing.
+ */
+ public final static int TYPE_MISSING_LAUNCH_CONFIG_ATTR = 1;
+
+ /**
+ * Exception type when mandatory attributes in launch specification is missing.
+ */
+ public final static int TYPE_MISSING_LAUNCH_SPEC_ATTR = 2;
+
+ private int typeId = TYPE_NO_DETAILED_REASON;
+
+ /**
+ * Default Constructor.
+ */
+ public LaunchServiceException() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message Additional detail message describing the cause of the exception.
+ */
+ public LaunchServiceException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message Additional detail message describing the cause of the exception.
+ * @param typeId Additional information to distinguish different exceptions thrown from one method.
+ */
+ public LaunchServiceException(String message, int typeId) {
+ super(message);
+ this.typeId = typeId;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause Additional <code>Throwable</code> which was the cause of this exception.
+ */
+ public LaunchServiceException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message Additional detail message describing the cause of the exception.
+ * @param cause Additional <code>Throwable</code> which was the cause of this exception.
+ */
+ public LaunchServiceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Returns the type of this exception.
+ */
+ public int getType() {
+ return typeId;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/extensions/internal/LaunchModeVariantDelegateExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/extensions/internal/LaunchModeVariantDelegateExtensionPointManager.java
new file mode 100644
index 000000000..5ce74fd33
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/extensions/internal/LaunchModeVariantDelegateExtensionPointManager.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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.extensions.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
+import org.eclipse.tcf.te.runtime.stepper.interfaces.IVariantDelegate;
+
+/**
+ * Launch mode variant delegate extension point manager.
+ */
+public class LaunchModeVariantDelegateExtensionPointManager extends AbstractExtensionPointManager<IVariantDelegate> {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstanceHolder {
+ public static LaunchModeVariantDelegateExtensionPointManager instance = new LaunchModeVariantDelegateExtensionPointManager();
+ }
+
+ /**
+ * Returns the singleton instance for the manager.
+ */
+ public static LaunchModeVariantDelegateExtensionPointManager getInstance() {
+ return LazyInstanceHolder.instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ LaunchModeVariantDelegateExtensionPointManager() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "delegate"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.launch.core.launchModeVariantDelegates"; //$NON-NLS-1$
+ }
+
+ /**
+ * Get the list of all registered launch mode variant delegates.
+ */
+ public IVariantDelegate[] getLaunchModeVariantDelegates() {
+ List<IVariantDelegate> delegates = new ArrayList<IVariantDelegate>();
+ for (ExecutableExtensionProxy<IVariantDelegate> proxy : getExtensions().values()) {
+ IExecutableExtension candidate = proxy.getInstance();
+ if (candidate instanceof IVariantDelegate && !delegates.contains(candidate)) {
+ delegates.add((IVariantDelegate)candidate);
+ }
+ }
+
+ return delegates.toArray(new IVariantDelegate[delegates.size()]);
+ }
+
+ /**
+ * Returns the launch mode variant delegate with the given id.
+ *
+ * @param id The id of the launch mode variant delegate. Must not be <code>null</code>.
+ */
+ public IVariantDelegate getLaunchModeVariantDelegate(String id) {
+ assert id != null;
+ IVariantDelegate delegate = null;
+ if (getExtensions().containsKey(id)) {
+ delegate = getExtensions().get(id).getInstance();
+ }
+
+ return delegate;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/tracing/ITraceIds.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/tracing/ITraceIds.java
new file mode 100644
index 000000000..f33c10aad
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/interfaces/tracing/ITraceIds.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * 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.interfaces.tracing;
+
+/**
+ * Launch core plug-in trace slot identifiers.
+ */
+public interface ITraceIds {
+
+ /**
+ * If activated, trace information about matching existing launch configurations to a given
+ * launch spec is printed out.
+ */
+ public static final String TRACE_LAUNCHCONFIGURATIONMATCHING = "trace/launchConfigurationMatching"; //$NON-NLS-1$
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchAttribute.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchAttribute.java
new file mode 100644
index 000000000..f958cf0ff
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchAttribute.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute;
+
+/**
+ * Default launch attribute implementation.
+ */
+public class LaunchAttribute extends PlatformObject implements ILaunchAttribute {
+ private final String key;
+ private final Object value;
+ private final boolean createOnly;
+
+ /**
+ * Constructor.
+ *
+ * @param key The launch attribute key.
+ * @param value The launch attribute value.
+ * @param createOnly <code>true</code> if only for create.
+ */
+ public LaunchAttribute(String key, Object value, boolean createOnly) {
+ super();
+ this.key = key;
+ this.value = value;
+ this.createOnly = createOnly;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute#getKey()
+ */
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute#getValue()
+ */
+ @Override
+ public Object getValue() {
+ return value;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute#isCreateOnlyAttribute()
+ */
+ @Override
+ public boolean isCreateOnlyAttribute() {
+ return createOnly;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
+ buffer.append(createOnly ? " (create only): " : ": "); //$NON-NLS-1$ //$NON-NLS-2$
+ buffer.append(key);
+ buffer.append(" = "); //$NON-NLS-1$
+ buffer.append(value);
+ return buffer.toString();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigHelper.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigHelper.java
new file mode 100644
index 000000000..1a5119fe9
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigHelper.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.ILaunchMode;
+
+/**
+ * Static launch configuration utility implementations.
+ */
+public class LaunchConfigHelper {
+
+ /**
+ * Get a sorted list of all launch modes for the given launch configuration type.
+ *
+ * @param launchConfigType The launch configuration type.
+ * @param reverse If <code>true</code> the sorted list order is reversed.
+ *
+ * @return Sorted list of supported launch modes.
+ */
+ public static String[] getLaunchConfigTypeModes(ILaunchConfigurationType launchConfigType, boolean reverse) {
+ return getLaunchConfigTypeModes(new ILaunchConfigurationType[] { launchConfigType }, reverse);
+ }
+
+ /**
+ * Get a sorted list of all launch modes for the given launch configuration types.
+ *
+ * @param launchConfigTypes The launch configuration types.
+ * @param reverse If <code>true</code> the sorted list order is reversed.
+ *
+ * @return Sorted list of supported launch modes.
+ */
+ public static String[] getLaunchConfigTypeModes(ILaunchConfigurationType[] launchConfigTypes, boolean reverse) {
+ List<String> modes = new ArrayList<String>();
+ for (ILaunchConfigurationType launchConfigType : launchConfigTypes) {
+ for (Object modeCombination : launchConfigType.getSupportedModeCombinations()) {
+ if (((Set<?>) modeCombination).size() == 1) {
+ String mode = (String) ((Set<?>) modeCombination).toArray()[0];
+ if (!modes.contains(mode)) {
+ modes.add(mode);
+ }
+ }
+ }
+ }
+ return getLaunchModesSorted(modes.toArray(new String[modes.size()]), reverse);
+ }
+
+ /**
+ * Gets a sorted list of launch mode identifiers.
+ *
+ * @param launchModes The launch modes. Must not be <code>null</code>.
+ * @param reverse If <code>true</code> the sorted list order is reversed.
+ *
+ * @return Sorted list of launch mode identifiers.
+ */
+ public static String[] getLaunchModesSorted(ILaunchMode[] launchModes, boolean reverse) {
+ Assert.isNotNull(launchModes);
+
+ String[] modes = new String[launchModes.length];
+ for (int i = 0; i < launchModes.length; i++) {
+ modes[i] = launchModes[i].getIdentifier();
+ }
+ return getLaunchModesSorted(modes, reverse);
+ }
+
+ /**
+ * Gets a sorted list of launch mode identifiers.
+ *
+ * @param launchModes The unsorted list of launch modes identifiers. Must not be <code>null</code>.
+ * @param reverse If <code>true</code> the sorted list order is reversed.
+ *
+ * @return Sorted list of launch mode identifiers.
+ */
+ public static String[] getLaunchModesSorted(String[] launchModes, final boolean reverse) {
+ Assert.isNotNull(launchModes);
+
+ // sort the list of launch modes
+ // Run is always the first, followed by Debug.
+ // All other modes are sorted alphabetically at the end of the list.
+ Arrays.sort(launchModes, new Comparator<String>() {
+ @Override
+ public int compare(String o1, String o2) {
+ if (o1.equals(ILaunchManager.RUN_MODE) && !o2.equals(ILaunchManager.RUN_MODE)) return reverse ? 1 : -1;
+ if (o2.equals(ILaunchManager.RUN_MODE) && !o1.equals(ILaunchManager.RUN_MODE)) return reverse ? -1 : 1;
+ if (o1.equals(ILaunchManager.DEBUG_MODE) && !o2.equals(ILaunchManager.DEBUG_MODE)) return reverse ? 1 : -1;
+ if (o2.equals(ILaunchManager.DEBUG_MODE) && !o1.equals(ILaunchManager.DEBUG_MODE)) return reverse ? -1 : 1;
+ return reverse ? o2.compareTo(o1) : o1.compareTo(o2);
+ }
+ });
+
+ return launchModes;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigSorter.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigSorter.java
new file mode 100644
index 000000000..d4ba9c6b7
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchConfigSorter.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+/**
+ * Implementation of the Comparable interface for comparing launch configuration by their ranking.
+ */
+public class LaunchConfigSorter implements Comparable<LaunchConfigSorter> {
+ private final int ranking;
+ private final ILaunchConfiguration config;
+
+ /**
+ * Constructor.
+ *
+ * @param config The launch configuration. Must not be <code>null</code>
+ * @param ranking The launch configuration ranking.
+ */
+ public LaunchConfigSorter(ILaunchConfiguration config, int ranking) {
+ Assert.isNotNull(config);
+
+ this.config = config;
+ this.ranking = ranking;
+ }
+
+ /**
+ * Returns the launch configuration.
+ *
+ * @return The launch configuration.
+ */
+ public ILaunchConfiguration getConfig() {
+ return config;
+ }
+
+ /**
+ * Returns the launch configuration ranking.
+ *
+ * @return The launch configuration ranking.
+ */
+ public int getRanking() {
+ return ranking;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(LaunchConfigSorter other) {
+ if (other.getRanking() > ranking) {
+ return 1;
+ } else if (other.getRanking() == ranking) {
+ return 0;
+ }
+
+ return -1;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchManager.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchManager.java
new file mode 100644
index 000000000..89166f816
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchManager.java
@@ -0,0 +1,459 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+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.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.exceptions.LaunchServiceException;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+import org.eclipse.tcf.te.launch.core.persistence.DefaultPersistenceDelegate;
+
+/**
+ * The Launch Manager is the management interface for the launch configuration storage layer.
+ * Through the launch manager, launch configuration of the several types can be accessed, searched
+ * and initialized. For every possible launch configuration type, a corresponding launch manager
+ * delegate must be registered which is responsible for handling the corresponding attributes of the
+ * specific launch configuration type. In the case the no launch manager delegate is registered for
+ * a launch configuration type, the launch configuration will not be initialized and therefore will
+ * not have any default attribute. If more than one launch manager delegates are contributed for the
+ * same launch configuration type, the first registered launch manager delegates will be used and the
+ * registration of any other delegate for this type will fail!
+ */
+public class LaunchManager extends PlatformObject {
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstanceHolder {
+ public static LaunchManager instance = new LaunchManager();
+ }
+
+ /**
+ * Returns the singleton instance for the manager.
+ */
+ public static LaunchManager getInstance() {
+ return LazyInstanceHolder.instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ LaunchManager() {
+ super();
+ }
+
+ /**
+ * Returns the corresponding launch manager delegate instance responsible for the specified
+ * launch configuration type. The method may return a default launch manager delegate if no
+ * specific launch manager delegate is registered for the specified launch configuration type.
+ *
+ * @param launchConfigType The launch configuration type to get the launch manager delegate for.
+ * Must not be <code>null</code>!
+ * @param launchMode The launch mode to get the launch manager delegate for. Must not be
+ * <code>null</code>.
+ * @return The corresponding launch manager delegate instance.
+ */
+ public ILaunchManagerDelegate getLaunchManagerDelegate(ILaunchConfigurationType launchConfigType, String launchMode) {
+ assert launchConfigType != null && launchMode != null;
+ return LaunchConfigTypeBindingsManager.getInstance().getLaunchManagerDelegate(launchConfigType.getIdentifier(), launchMode);
+ }
+
+ /**
+ * Returns the corresponding launch configuration type for the given launch configuration type
+ * id and the given launch mode.
+ *
+ * @param launchConfigTypeId The unique id of the launch configuration type requested.
+ * @param launchMode The launch mode the launch configuration type must support. See
+ * <code>org.eclipse.debug.core.ILaunchManager</code> for details.
+ * @return The corresponding launch configuration type instance or <code>null</code> if not
+ * found or the specified mode is not supported.
+ */
+ public ILaunchConfigurationType getLaunchConfigType(String launchConfigTypeId, String launchMode) {
+ ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager()
+ .getLaunchConfigurationType(launchConfigTypeId);
+ if (launchConfigType != null && !launchConfigType.supportsMode(launchMode)) {
+ launchConfigType = null;
+ }
+ return launchConfigType;
+ }
+
+ /**
+ * Returns an fully initialized launch configuration. The launch configuration type and the
+ * launch mode required to create or look up the launch configuration, are specified through the
+ * given launch specification. Any launch configuration attribute of the certain type which is
+ * not explicitly overwritten by an attribute specified through the given launch specification
+ * will be initialized with default values.
+ * <p>
+ * If <code>forceNewConfig</code> is <code>false</code>, the method tries to find a matching
+ * existing launch configuration. If no existing launch configuration can be found, a new
+ * launch configuration will created instead.
+ *
+ * @param launchSpec A set of non default launch configuration attributes. Must not be
+ * <code>null</code>, but the list of attributes may empty to get an launch
+ * configuration with all attributes initialized to default values.
+ * @param createNew If <code>true</code>, a new launch configuration will be created if no
+ * available is found.
+ * @return The launch configuration instance matching the given parameters.
+ * @throws <code>LaunchServiceException</code> in case the launch configuration instance
+ * cannot be created, found and/or modified. The exception message describes the failure
+ * details.
+ */
+ public ILaunchConfiguration getLaunchConfiguration(ILaunchSpecification launchSpec, boolean createNew) throws LaunchServiceException {
+ Assert.isNotNull(launchSpec);
+
+ ILaunchConfiguration launchConfig = null;
+ try {
+ // get all launch configurations for launch configuration type id and launch mode
+ String launchConfigTypeId = launchSpec.getLaunchConfigurationTypeId();
+ String launchMode = launchSpec.getLaunchMode();
+ ILaunchConfigurationType launchConfigType = getLaunchConfigType(launchConfigTypeId, launchMode);
+ ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager()
+ .getLaunchConfigurations(launchConfigType);
+
+ // get list of fully and closest matching launch configurations
+ ILaunchConfiguration[] matchingConfigs = getLaunchManagerDelegate(launchConfigType, launchMode)
+ .getMatchingLaunchConfigurations(launchSpec, configs);
+
+ // return best matching launch configuration
+ if (matchingConfigs.length > 0) {
+ launchConfig = matchingConfigs[0];
+ }
+ }
+ catch (LaunchServiceException e) {
+ if (e.getType() == LaunchServiceException.TYPE_MISSING_LAUNCH_SPEC_ATTR) {
+ throw e;
+ }
+ }
+ catch (CoreException e) {
+ throw new LaunchServiceException(e.getMessage());
+ }
+ // return new launch configuration if no matching or best matching configuration is found
+ if (createNew && launchConfig == null) {
+ launchConfig = createOrUpdateLaunchConfiguration(null, launchSpec);
+ }
+ return launchConfig;
+ }
+
+ /**
+ * Create a new or updates an existing launch configuration of the requested type and initialize
+ * the configuration with the given launch specification. Attributes not listed by the given
+ * launch specification will be initialized with default values.
+ *
+ * @param launchConfig A launch configuration to update or <code>null</code> if a new launch
+ * configuration should be created.
+ * @param launchSpec A set of non default launch configuration attributes.
+ * @return The newly create launch configuration instance.
+ *
+ * @throws <code>LaunchServiceException</code> in case the launch configuration instance
+ * cannot be created or mandatory attributes are missing in the launch specification.
+ * The exception message describes the failure details.
+ */
+ public ILaunchConfiguration createOrUpdateLaunchConfiguration(ILaunchConfiguration launchConfig, ILaunchSpecification launchSpec) throws LaunchServiceException {
+ return this.createOrUpdateLaunchConfiguration(launchConfig, launchSpec, true);
+ }
+
+ /**
+ * Create a new or updates an existing launch configuration of the requested type and initialize
+ * the configuration with the given launch specification. Attributes not listed by the given
+ * launch specification will be initialized with default values.
+ *
+ * @param launchConfig A launch config to update or <code>null</code> if a new launch config
+ * should be created.
+ * @param launchSpec A set of non default launch configuration attributes.
+ * @param validateSpec Validate the launch specification in the <code>launchSpec</code>
+ * parameter. If <code>false</code>, it will attempt to create the launch
+ * configuration even if some of the mandatory parameters are missing.
+ * @return The newly create launch configuration instance.
+ *
+ * @throws <code>LaunchServiceException</code> in case the launch configuration instance
+ * cannot be created or mandatory attributes are missing in the launch specification.
+ * The exception message describes the failure details.
+ *
+ * @since 3.2
+ */
+ public ILaunchConfiguration createOrUpdateLaunchConfiguration(ILaunchConfiguration launchConfig, ILaunchSpecification launchSpec, boolean validateSpec) throws LaunchServiceException {
+ assert launchSpec != null;
+
+ String launchConfigTypeId = launchSpec.getLaunchConfigurationTypeId();
+ String launchMode = launchSpec.getLaunchMode();
+
+ ILaunchConfigurationType launchConfigType = getLaunchConfigType(launchConfigTypeId, launchMode);
+ try {
+ if (launchConfigType != null) {
+ // get the launch manager delegate instance for the requested launch configuration
+ // type
+ ILaunchManagerDelegate delegate = getLaunchManagerDelegate(launchConfigType, launchMode);
+ if (validateSpec) {
+ delegate.validate(launchSpec);
+ }
+ ILaunchConfigurationWorkingCopy wc = null;
+ if (launchConfig == null || !launchConfig.getType().getIdentifier()
+ .equals(launchConfigTypeId)) {
+ try {
+ // create the launch configuration working copy instance
+ wc = launchConfigType.newInstance(null, DebugPlugin
+ .getDefault()
+ .getLaunchManager()
+ .generateLaunchConfigurationName(launchSpec
+ .getLaunchConfigName()));
+ // initialize the launch configuration working copy
+ delegate.initLaunchConfigAttributes(wc, launchSpec);
+ // copy all additional attributes set in the launch spec to the working copy
+ ILaunchAttribute[] allAttributes = launchSpec.getAllAttributes();
+ for (ILaunchAttribute attribute : allAttributes) {
+ if (!wc.hasAttribute(attribute.getKey())) {
+ Object value = attribute.getValue();
+ if (value instanceof Boolean) {
+ DefaultPersistenceDelegate.setAttribute(wc, attribute.getKey(), ((Boolean) value).booleanValue());
+ }
+ else if (value instanceof Integer) {
+ DefaultPersistenceDelegate.setAttribute(wc, attribute.getKey(), ((Integer) value).intValue());
+ }
+ else if (value instanceof List<?>) {
+ DefaultPersistenceDelegate.setAttribute(wc, attribute.getKey(), (List<?>) value);
+ }
+ else if (value instanceof Map<?, ?>) {
+ DefaultPersistenceDelegate.setAttribute(wc, attribute.getKey(), (Map<?, ?>) value);
+ }
+ else if (value instanceof String) {
+ DefaultPersistenceDelegate.setAttribute(wc, attribute.getKey(), (String) value);
+ }
+ }
+ }
+ // and save the launch configuration
+ return wc.doSave();
+ }
+ catch (CoreException e) {
+ throw new LaunchServiceException(Messages.LaunchManager_error_failedToCreateConfig);
+ }
+ }
+ try {
+ // get a launch configration working copy
+ if (launchConfig instanceof ILaunchConfigurationWorkingCopy) {
+ wc = (ILaunchConfigurationWorkingCopy) launchConfig;
+ }
+ else {
+ wc = launchConfig.getWorkingCopy();
+ }
+ // update the launch configuration working copy
+ delegate.updateLaunchConfigAttributes(wc, launchSpec);
+ // and save the launch configuration
+ return (wc.isDirty()) ? wc.doSave() : launchConfig;
+ }
+ catch (CoreException e) {
+ throw new LaunchServiceException(NLS.bind(Messages.LaunchManager_error_failedToUpdateConfig, launchConfig.getName()));
+ }
+ }
+ }
+ catch (CoreException e) {
+ // do nothing, because exception is thrown afterwards if this point is reached.
+ }
+ throw new LaunchServiceException(NLS.bind(Messages.LaunchManager_error_noLaunchConfigType, launchMode));
+ }
+
+ /**
+ * Delete the specified launch configuration.
+ * <p>
+ * In case any error occurs during the delete, the exception is logged to the Eclipse error log.
+ *
+ * @param launchConfig The launch configuration to delete.
+ */
+ public void deleteLaunchConfiguration(ILaunchConfiguration launchConfig) {
+ if (launchConfig != null) {
+ try {
+ launchConfig.delete();
+ }
+ catch (CoreException e) {
+ IStatus status = new Status(IStatus.ERROR, CoreBundleActivator.getUniqueIdentifier(),
+ Messages.LaunchManager_error_deleteLaunchConfig, e);
+ Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status);
+ }
+ }
+ }
+
+ /**
+ * Creates an exact copy of the given launch specification.
+ * <p>
+ * <b>Note:</b> The method returns always an launch specification which has not locked out
+ * modifications. The corresponding read-only flag from the original is not duplicated to the
+ * copy!
+ *
+ * @param launchSpec The launch specification to duplication.
+ * @return A new <code>ILaunchSpecification</code> instance containing the same data as the
+ * original, or <code>null</code>.
+ */
+ public ILaunchSpecification duplicate(ILaunchSpecification launchSpec) {
+ if (launchSpec != null) {
+ ILaunchSpecification newLaunchSpec = new LaunchSpecification(launchSpec.getLaunchConfigurationTypeId(), launchSpec.getLaunchMode());
+ if (!launchSpec.isEmpty()) {
+ ILaunchAttribute[] attributes = launchSpec.getAllAttributes();
+ for (ILaunchAttribute attribute : attributes) {
+ newLaunchSpec.addAttribute(attribute.getKey(), attribute.getValue());
+ }
+ }
+ return newLaunchSpec;
+ }
+ return null;
+ }
+
+ /**
+ * Validates a launch configuration.
+ *
+ * @param launchConfig The launch configuration to validate.
+ * @param launchMode The launch mode. Can be <code>null</code>, in this case the launch configuration
+ * is valid when valid for all supported modes.
+ * @return <code>true</code>, if the launch configuration is valid and can be executed (launched).
+ */
+ public boolean validate(ILaunchConfiguration launchConfig, String launchMode) {
+ try {
+ if (launchMode == null) {
+ boolean valid = false;
+ for (String mode : LaunchConfigHelper.getLaunchConfigTypeModes(launchConfig.getType(), false)) {
+ if (launchConfig.supportsMode(mode) && validate(launchConfig, mode)) {
+ valid = true;
+ }
+ }
+ return valid;
+ }
+ ILaunchManagerDelegate delegate = getLaunchManagerDelegate(launchConfig.getType(), launchMode);
+ try {
+ delegate.validate(launchMode, launchConfig);
+ }
+ catch (LaunchServiceException e) {
+ return false;
+ }
+
+ }
+ catch (CoreException e) {
+ }
+ return true;
+ }
+
+ /**
+ * Transform the specified launch configuration into a corresponding launch specification
+ * object. If <code>withDefaultAttributes</code> is not set, the corresponding launch manager
+ * delegate is called to determine if an attribute has a default value or not. If the attribute
+ * has an default value, this attribute is not copied to the launch specification. If
+ * <code>withDefaultAttributes</code> is set, all attributes are copied to the launch
+ * specification object.
+ *
+ * @param launchConfig The launch configuration. Must not be <code>null</code>.
+ * @param launchMode The launch mode the launch specification should be for. See
+ * <code>ILaunchManager</code> for details.
+ * @param withDefaultAttributes Set to <code>true</code> to copy attributes with default value
+ * as well, <code>false</code> otherwise.
+ *
+ * @return The corresponding launch specification object or <code>null</code>.
+ *
+ * @throws <code>LaunchServiceException</code> in case the launch configuration could not be
+ * transformed to a launch specification. The exception message describes the failure
+ * details.
+ */
+ public ILaunchSpecification createSpecFromConfig(ILaunchConfiguration launchConfig, String launchMode, boolean withDefaultAttributes) throws LaunchServiceException {
+ Assert.isNotNull(launchConfig);
+
+ ILaunchSpecification spec = null;
+ try {
+ // extract the launch configuration type
+ ILaunchConfigurationType type = launchConfig.getType();
+ spec = new LaunchSpecification(type.getIdentifier(), launchMode);
+ // get the launch manager delegate for the specific type
+ ILaunchManagerDelegate delegate = getLaunchManagerDelegate(type, launchMode);
+ // get all the launch configuration attributes
+ Map<Object, Object> attributes = launchConfig.getAttributes();
+ // loop over all listed attributes and copy them to the specification
+ Iterator<Object> iterator = attributes.keySet().iterator();
+ while (iterator.hasNext()) {
+ String attributeKey = (String) iterator.next();
+ if (withDefaultAttributes) {
+ // include the default attributes. So, just copy the stuff over.
+ spec.addAttribute(attributeKey, attributes.get(attributeKey));
+ }
+ else {
+ // exclude the default attributes. We have to find out if the attribute is
+ // set with default value.
+ Object attributeValue = attributes.get(attributeKey);
+ if (!delegate.isDefaultAttribute(attributeKey, attributeValue, launchConfig, launchMode)) {
+ spec.addAttribute(attributeKey, attributeValue);
+ }
+ }
+ }
+ }
+ catch (CoreException e) {
+ spec = null;
+ throw new LaunchServiceException(e);
+ }
+ return spec;
+ }
+
+ /**
+ * Launch the specified launch configuration using the corresponding delegate for the specified
+ * launch mode. If <code>buildBeforeLaunch</code> is set to <code>true</code>, the workspace
+ * will be build before the launch.
+ *
+ * @param launchConfig The launch configuration to launch. Must not be <code>null</code>!
+ * @param launchMode The launch mode (@see <code>org.eclipse.debug.core.ILaunchManager</code>.
+ * Must not be <code>null</code>!
+ * @param buildBeforeLaunch Specify <code>true</code> to build the workspace before launch,
+ * <code>false</code> otherwise.
+ *
+ * @return The corresponding <code>ILaunch</code> object associated with this launch.
+ *
+ * @throws <code>LaunchServiceException</code> in case of any problem occurs during the launch sequence.
+ */
+ public ILaunch launch(ILaunchConfiguration launchConfig, String launchMode, boolean buildBeforeLaunch, IProgressMonitor monitor) throws LaunchServiceException {
+ Assert.isNotNull(launchConfig);
+ Assert.isNotNull(launchMode);
+
+ try {
+ ILaunchManagerDelegate delegate = getLaunchManagerDelegate(launchConfig.getType(), launchMode);
+ delegate.validate(launchMode, launchConfig);
+ return launchConfig.launch(launchMode, monitor, buildBeforeLaunch);
+ }
+ catch (CoreException e) {
+ // re-pack into a launch service exception
+ throw new LaunchServiceException(e);
+ }
+ }
+
+ /**
+ * Remove all illegal characters in the launch configuration name candidate.
+ *
+ * @param candidate The launch configuration name candidate.
+ * @return The unified launch configuration name.
+ */
+ public static String getUnifiedLaunchConfigName(String candidate) {
+ if (candidate != null) {
+ candidate = candidate.replaceAll("[/\\\"&?:@*]", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return candidate;
+ }
+
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchSpecification.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchSpecification.java
new file mode 100644
index 000000000..be2cda09c
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/LaunchSpecification.java
@@ -0,0 +1,262 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+
+/**
+ * Default launch specification implementation.
+ */
+public class LaunchSpecification extends PlatformObject implements ILaunchSpecification {
+ private final Map<String, ILaunchAttribute> attributes = new Hashtable<String, ILaunchAttribute>();
+ private final String typeId;
+ private final String mode;
+ private String launchConfigName;
+ private String launchActionLabel;
+ private boolean readOnly;
+ private boolean valid = true;
+ private String errorMessage = null;
+
+ /**
+ * Constructor.
+ * <p>
+ * Creates a new launch specification instance for the specified launch configuration type
+ * id and the specified launch mode. The launch specification is not locked against modifications
+ * by default!
+ *
+ * @param typeId The launch configuration type id of the described launch configuration.
+ * @param mode The launch mode. @see <code>org.eclipse.debug.core.ILaunchManager</code>!
+ */
+ public LaunchSpecification(String typeId, String mode) {
+ super();
+ this.typeId = typeId;
+ this.mode = mode;
+ this.attributes.clear();
+ setReadOnly(false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getLaunchConfigurationTypeId()
+ */
+ @Override
+ public String getLaunchConfigurationTypeId() {
+ return typeId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getLaunchMode()
+ */
+ @Override
+ public String getLaunchMode() {
+ return mode;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#isReadOnly()
+ */
+ @Override
+ public boolean isReadOnly() {
+ return readOnly;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#setReadOnly(boolean)
+ */
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ this.readOnly = readOnly;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#addAttribute(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public void addAttribute(String key, Object value) {
+ addAttribute(key, value, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#addAttribute(java.lang.String, java.lang.Object, boolean)
+ */
+ @Override
+ public void addAttribute(String key, Object value, boolean createOnly) {
+ Assert.isNotNull(key);
+
+ if (isReadOnly()) return;
+
+ // Attention: If the value == null -> remove the key from the map!!!
+ if (value != null) {
+ attributes.put(key, new LaunchAttribute(key, value, createOnly));
+ }
+ else {
+ attributes.remove(key);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#hasAttribute(java.lang.String)
+ */
+ @Override
+ public boolean hasAttribute(String key) {
+ assert key != null;
+ return attributes.containsKey(key);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#removeAttribute(java.lang.String)
+ */
+ @Override
+ public Object removeAttribute(String key) {
+ assert key != null;
+ if (isReadOnly()) return null;
+ return attributes.remove(key);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#isCreateOnlyAttribute(java.lang.String)
+ */
+ @Override
+ public boolean isCreateOnlyAttribute(String key) {
+ assert key != null;
+ ILaunchAttribute attribute = getAttribute(key);
+ return attribute != null && attribute.isCreateOnlyAttribute();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getAttribute(java.lang.String, java.lang.Object)
+ */
+ @Override
+ public Object getAttribute(String key, Object defaultValue) {
+ assert key != null;
+ ILaunchAttribute attribute = getAttribute(key);
+ return (attribute != null && attribute.getValue() != null) ? attribute.getValue() : defaultValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#clear()
+ */
+ @Override
+ public void clear() {
+ if (isReadOnly()) {
+ return;
+ }
+ attributes.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#size()
+ */
+ @Override
+ public int size() {
+ return attributes.size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#isEmpty()
+ */
+ @Override
+ public boolean isEmpty() {
+ return attributes.isEmpty();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getAttribute(java.lang.String)
+ */
+ @Override
+ public ILaunchAttribute getAttribute(String key) {
+ assert key != null;
+ return attributes.get(key);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getAllAttributes()
+ */
+ @Override
+ public ILaunchAttribute[] getAllAttributes() {
+ return attributes.values().toArray(new ILaunchAttribute[attributes.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getLaunchActionLabel()
+ */
+ @Override
+ public String getLaunchActionLabel() {
+ return launchActionLabel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getLaunchConfigName()
+ */
+ @Override
+ public String getLaunchConfigName() {
+ return launchConfigName != null ? launchConfigName : Messages.DefaultLaunchManagerDelegate_defaultLaunchName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#setLaunchActionLabel(java.lang.String)
+ */
+ @Override
+ public void setLaunchActionLabel(String launchActionLabel) {
+ this.launchActionLabel = launchActionLabel;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#setLaunchConfigName(java.lang.String)
+ */
+ @Override
+ public void setLaunchConfigName(String launchConfigName) {
+ this.launchConfigName = LaunchManager.getUnifiedLaunchConfigName(launchConfigName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#isValid()
+ */
+ @Override
+ public boolean isValid() {
+ return valid;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#setIsValid(boolean)
+ */
+ @Override
+ public void setIsValid(boolean valid) {
+ this.valid = valid;
+ if (valid) {
+ errorMessage = null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#getErrorMessage()
+ */
+ @Override
+ public String getErrorMessage() {
+ if (!isValid()) {
+ return errorMessage;
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification#setErrorMessage(java.lang.String)
+ */
+ @Override
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java
new file mode 100644
index 000000000..e771e0b47
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/delegates/DefaultLaunchManagerDelegate.java
@@ -0,0 +1,728 @@
+/*******************************************************************************
+ * 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.delegates;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+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.exceptions.LaunchServiceException;
+import org.eclipse.tcf.te.launch.core.interfaces.tracing.ITraceIds;
+import org.eclipse.tcf.te.launch.core.lm.LaunchConfigSorter;
+import org.eclipse.tcf.te.launch.core.lm.LaunchSpecification;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchAttribute;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification;
+import org.eclipse.tcf.te.launch.core.nls.Messages;
+import org.eclipse.tcf.te.launch.core.preferences.IPreferenceKeys;
+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.ExecutableExtension;
+
+/**
+ * Default launch manager delegate implementation.
+ */
+public class DefaultLaunchManagerDelegate extends ExecutableExtension implements ILaunchManagerDelegate {
+ protected final static int NO_MATCH = 0;
+ protected final static int PARTIAL_MATCH = 1;
+ protected final static int FULL_MATCH = 2;
+
+ protected String errorMessage = null;
+
+ /**
+ * Constructor.
+ */
+ public DefaultLaunchManagerDelegate() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#initLaunchConfigAttributes(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public void initLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec) {
+ assert wc != null && launchSpec != null;
+ validateLaunchSpecification(launchSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#updateLaunchConfigAttributes(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy, org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public void updateLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec) {
+ assert wc != null && launchSpec != null;
+ validateLaunchSpecification(launchSpec);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#isDefaultAttribute(java.lang.String, java.lang.Object, org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
+ */
+ @Override
+ public boolean isDefaultAttribute(String attributeKey, Object attributeValue, ILaunchConfiguration launchConfig, String launchMode) {
+ assert attributeKey != null && launchConfig != null && launchMode != null;
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getMatchingLaunchConfigurations(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification, org.eclipse.debug.core.ILaunchConfiguration[])
+ */
+ @Override
+ public final ILaunchConfiguration[] getMatchingLaunchConfigurations(ILaunchSpecification launchSpec, ILaunchConfiguration[] launchConfigs) throws LaunchServiceException {
+ if (launchConfigs == null || launchConfigs.length == 0) {
+ return new ILaunchConfiguration[0];
+ }
+ else if (launchSpec != null) {
+ List<LaunchConfigSorter> rankedList = new ArrayList<LaunchConfigSorter>();
+ for (ILaunchConfiguration launchConfig : launchConfigs) {
+ if (CoreBundleActivator.getTraceHandler()
+ .isSlotEnabled(0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING)) {
+ System.out.println("\n***\n"); //$NON-NLS-1$
+ }
+
+ int ranking = 0;
+ try {
+ ranking = getLaunchConfigRanking(launchSpec, launchConfig);
+ }
+ catch (LaunchServiceException e) {
+ switch (e.getType()) {
+ case LaunchServiceException.TYPE_MISSING_LAUNCH_CONFIG_ATTR:
+ ranking = 0;
+ break;
+ default:
+ throw e;
+ }
+ }
+
+ int fullMatchRanking = getFullMatchRanking();
+
+ if (CoreBundleActivator.getTraceHandler()
+ .isSlotEnabled(0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING)) {
+ StringBuilder message = new StringBuilder("Ranking launch spec ("); //$NON-NLS-1$
+ message.append(launchSpec.getLaunchConfigName());
+ message.append(") vs launch configuration ("); //$NON-NLS-1$
+ message.append(launchConfig.getName());
+ message.append(") = "); //$NON-NLS-1$
+ message.append(ranking);
+ message.append(" ; full match ranking = "); //$NON-NLS-1$
+ message.append(fullMatchRanking);
+
+ CoreBundleActivator
+ .getTraceHandler()
+ .trace(message.toString(), 0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING, IStatus.INFO, this);
+ }
+
+ if (ranking >= fullMatchRanking) {
+ rankedList.add(new LaunchConfigSorter(launchConfig, ranking));
+ }
+ }
+
+ // sort results and write back into array
+ Collections.sort(rankedList);
+ ILaunchConfiguration[] matchingConfigs = new ILaunchConfiguration[rankedList.size()];
+ for (int i = 0; i < rankedList.size(); i++) {
+ matchingConfigs[i] = rankedList.get(i).getConfig();
+ }
+
+ return matchingConfigs;
+ }
+ else {
+ return launchConfigs;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getLaunchSpecification(java.lang.String, org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection)
+ */
+ @Override
+ public final ILaunchSpecification getLaunchSpecification(String launchConfigTypeId, ILaunchSelection launchSelection) {
+ return getLaunchSpecification(launchConfigTypeId, launchSelection, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getLaunchSpecification(java.lang.String, org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection, java.lang.String)
+ */
+ @Override
+ public final ILaunchSpecification getLaunchSpecification(String launchConfigTypeId, ILaunchSelection launchSelection, String variant) {
+ ILaunchSpecification spec = null;
+
+ if (isValidLaunchSelection(launchSelection)) {
+ spec = new LaunchSpecification(launchConfigTypeId, launchSelection.getLaunchMode());
+ spec.addAttribute(ICommonLaunchAttributes.ATTR_DELEGATE_VARIANT, variant, true);
+
+ for (ISelectionContext selectionContext : launchSelection.getSelectedContexts()) {
+ // For launch specifications, all selection contexts needs to be set as preferred
+ // for full validation.
+ // otherwise "not preferred" contexts are valid even if they are not for a give
+ // launch configuration type id.
+ selectionContext.setIsPreferredContext(true);
+ if (LaunchConfigTypeBindingsManager
+ .getInstance()
+ .isValidLaunchConfigType(launchConfigTypeId, launchSelection.getLaunchMode(), selectionContext)) {
+ spec = addLaunchSpecAttributes(spec, launchConfigTypeId, selectionContext);
+ }
+ }
+
+ // If the number of selected contexts is 0, we have to call addLaunchSpecAttributes
+ // one time to add the selection independent attributes.
+ if (launchSelection.getSelectedContexts().length == 0) {
+ spec = addLaunchSpecAttributes(spec, launchConfigTypeId, null);
+ }
+ }
+
+ return spec;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getDefaultLaunchName(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public String getDefaultLaunchName(ILaunchSpecification launchSpec) {
+ return Messages.DefaultLaunchManagerDelegate_defaultLaunchName;
+ }
+
+ /**
+ * Add all needed selections to the launch specification.
+ * <p>
+ * Subclasses needs to override and super-call this method!
+ * <p>
+ * <b>Note:</b> The selection context can be <code>null</code>. In this case, the method
+ * implementation is expected to add only selection independent attributes!
+ *
+ * @param launchSpec The launch specification to add selections to. Must not be
+ * <code>null</code>.
+ * @param launchConfigTypeId The launch configuration type id. Must not be <code>null</code>.
+ * @param selectionContext The validated selection context with the selection(s) or
+ * <code>null</code>
+ *
+ * @return The launch specification with attributes from the selection context.
+ */
+ protected ILaunchSpecification addLaunchSpecAttributes(ILaunchSpecification launchSpec, String launchConfigTypeId, ISelectionContext selectionContext) {
+ assert launchSpec != null && launchConfigTypeId != null;
+ return launchSpec;
+ }
+
+ /**
+ * Returns the ranking of the launch configuration compared to the launch specification.
+ * <p>
+ * If all attributes of the launch specification matches with the corresponding attributes of
+ * the launch configuration, the ranking should be at least as high as the number of attributes
+ * in the launch specification. The ranking should grow with every additional attribute value
+ * that is set to default.
+ * <p>
+ * If only a set of attributes matches, the ranking should be less than the number of attributes
+ * in the launch specification.
+ * <p>
+ * If no attribute matches zero should be returned.
+ *
+ * @param launchSpec The launch specification the launch configuration should be compared to.
+ * @param launchConfig The launch configuration to find a ranking for.
+ * @return The ranking of the launch configuration.
+ * @throws <code>LaunchServiceException</code> exception when mandatory attributes are missing
+ */
+ private int getLaunchConfigRanking(ILaunchSpecification launchSpec, ILaunchConfiguration launchConfig) throws LaunchServiceException {
+ int ranking = 0;
+ int mandatorys = 0;
+ Map<?, ?> configAttributes = null;
+ Set<?> configKeys = null;
+ try {
+ configAttributes = launchConfig.getAttributes();
+ configKeys = configAttributes.keySet();
+ }
+ catch (Exception e) {
+ return 0;
+ }
+
+ // Read the launch configuration matching mode from the preferences
+ int mode = CoreBundleActivator.getScopedPreferences()
+ .getInt(IPreferenceKeys.PREF_LAUNCH_CONFIG_FIND_CREATE_MODE);
+ if (launchSpec.getAttribute(IPreferenceKeys.PREF_LAUNCH_CONFIG_FIND_CREATE_MODE, null) instanceof Integer) {
+ mode = ((Integer) launchSpec
+ .getAttribute(IPreferenceKeys.PREF_LAUNCH_CONFIG_FIND_CREATE_MODE, null))
+ .intValue();
+ }
+
+ if (CoreBundleActivator.getTraceHandler()
+ .isSlotEnabled(0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING)) {
+ StringBuilder message = new StringBuilder("Ranking launch spec ("); //$NON-NLS-1$
+ message.append(launchSpec.getLaunchConfigName());
+ message.append(") vs launch configuration ("); //$NON-NLS-1$
+ message.append(launchConfig.getName());
+ message.append("): Matching mode = "); //$NON-NLS-1$
+ if (mode == IPreferenceKeys.MODE_ALWAYS_NEW) {
+ message.append(" ALWAYS_NEW "); //$NON-NLS-1$
+ }
+ else if (mode == IPreferenceKeys.MODE_FIRST_MATCHING) {
+ message.append(" FIRST_MATCHING "); //$NON-NLS-1$
+ }
+ else if (mode == IPreferenceKeys.MODE_FULL_MATCH_TARGET) {
+ message.append(" FULL_MATCH_TARGET "); //$NON-NLS-1$
+ }
+ else if (mode == IPreferenceKeys.MODE_FULL_MATCH_LAUNCH_CONFIG) {
+ message.append(" FULL_MATCH_LAUNCH_CONFIG "); //$NON-NLS-1$
+ }
+
+ CoreBundleActivator
+ .getTraceHandler()
+ .trace(message.toString(), 0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING, IStatus.INFO, this);
+ }
+
+ for (ILaunchAttribute specAttribute : launchSpec.getAllAttributes()) {
+ if (!specAttribute.isCreateOnlyAttribute()) {
+ String key = specAttribute.getKey();
+ Object specValue = specAttribute.getValue();
+ Object configValue = configAttributes.get(key);
+ int match = compareAttributeValues(key, specValue, configValue, launchSpec, launchConfig);
+
+ if (CoreBundleActivator.getTraceHandler()
+ .isSlotEnabled(0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING)) {
+ StringBuilder message = new StringBuilder("Launch spec attribute '"); //$NON-NLS-1$
+ message.append(specAttribute.getKey());
+ message.append("': mandatory = "); //$NON-NLS-1$
+ message.append(isMandatoryAttribute(key));
+ message.append("; match = "); //$NON-NLS-1$
+ if (match == NO_MATCH) {
+ message.append("NO_MATCH"); //$NON-NLS-1$
+ }
+ else if (match == PARTIAL_MATCH) {
+ message.append("PARTIAL_MATCH"); //$NON-NLS-1$
+ }
+ else if (match == FULL_MATCH) {
+ message.append("FULL_MATCH"); //$NON-NLS-1$
+ }
+ if (match != FULL_MATCH) {
+ message.append("\n\t\tspecValue = "); //$NON-NLS-1$
+ message.append(specValue != null ? specValue.toString() : "null"); //$NON-NLS-1$
+ message.append("\n\t\tconfigValue = "); //$NON-NLS-1$
+ message.append(configValue != null ? configValue.toString() : "null"); //$NON-NLS-1$
+ }
+
+ CoreBundleActivator
+ .getTraceHandler()
+ .trace(message.toString(), 0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING, IStatus.INFO, this);
+ }
+
+ if (match == PARTIAL_MATCH && mode == IPreferenceKeys.MODE_FULL_MATCH_LAUNCH_CONFIG) {
+ return 0;
+ }
+ if (match > NO_MATCH) {
+ int attrRanking = getAttributeRanking(key);
+ ranking += attrRanking * (attrRanking > 1 ? 4 : 1);
+ if (match == FULL_MATCH) {
+ ranking += attrRanking * (attrRanking > 1 ? 2 : 1);
+ }
+ configKeys.remove(key);
+ if (isMandatoryAttribute(key)) {
+ mandatorys++;
+ }
+ }
+ else {
+ return 0;
+ }
+ }
+ else {
+ if (CoreBundleActivator.getTraceHandler()
+ .isSlotEnabled(0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING)) {
+ StringBuilder message = new StringBuilder("Skipped launch spec attribute '"); //$NON-NLS-1$
+ message.append(specAttribute.getKey());
+ message.append("': is create only attribute"); //$NON-NLS-1$
+
+ CoreBundleActivator
+ .getTraceHandler()
+ .trace(message.toString(), 0, ITraceIds.TRACE_LAUNCHCONFIGURATIONMATCHING, IStatus.INFO, this);
+ }
+ }
+ }
+ if (mandatorys < getNumMandatoryAttributes()) {
+ throw new LaunchServiceException("missing mandatory attribute in ILaunchSpecification", //$NON-NLS-1$
+ LaunchServiceException.TYPE_MISSING_LAUNCH_SPEC_ATTR);
+ }
+
+ Iterator<?> configIt = configKeys.iterator();
+ while (configIt.hasNext()) {
+ String key = (String) configIt.next();
+ Object specValue = launchSpec.getAttribute(key, null);
+ Object configValue = configAttributes.get(key);
+
+ int match = compareAttributeValues(key, specValue, configValue, launchSpec, launchConfig);
+ if (match > NO_MATCH) {
+ int attrRanking = getAttributeRanking(key);
+ ranking += attrRanking * (attrRanking > 1 ? 4 : 1);
+ if (match == FULL_MATCH) {
+ ranking += attrRanking * (attrRanking > 1 ? 2 : 1);
+ }
+ }
+ }
+
+ return ranking;
+ }
+
+ /**
+ * Returns the number of defined attributes for this launch manager delegate.
+ *
+ * @see #getAttributeRanking(String)
+ */
+ protected int getNumAttributes() {
+ return 0;
+ }
+
+ /**
+ * Returns the list of mandatory attributes for a launch specification handled by this launch
+ * manager delegate.
+ * <p>
+ * The returned value must not be <code>null</code>, if no attributes are mandatory, an empty
+ * list should be returned.
+ *
+ * @see #getAttributeRanking(String)
+ */
+ protected List<String> getMandatoryAttributes() {
+ return Collections.emptyList();
+ }
+
+ private boolean validateLaunchSpecification(ILaunchSpecification launchSpec) {
+ boolean valid = true;
+ if (launchSpec == null || !launchSpec.isValid()) {
+ return false;
+ }
+ for (String attribute : getMandatoryAttributes()) {
+ if (!launchSpec.hasAttribute(attribute)) {
+ valid = false;
+ break;
+ }
+ }
+ launchSpec.setIsValid(valid);
+ return valid;
+ }
+
+ /**
+ * Method for basic launch selection validations like checking the number of project or target
+ * contexts.
+ * <p>
+ * The default implementation returns always <code>true</code>.
+ *
+ * @param launchSelection The launch selection to check.
+ * @return <code>True</code> if the launch selection is valid, <code>false</code> otherwise.
+ */
+ protected boolean isValidLaunchSelection(ILaunchSelection launchSelection) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#validate(java.lang.String, org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ @Override
+ public void validate(String launchMode, ILaunchConfiguration launchConfig) throws LaunchServiceException {
+ String missingAttributes = null;
+ for (String attribute : getMandatoryAttributes()) {
+ if (!isValidAttribute(attribute, launchConfig, launchMode)) {
+ missingAttributes = (missingAttributes == null) ? attribute : missingAttributes + ", " + attribute; //$NON-NLS-1$
+ }
+ }
+ if (missingAttributes != null) {
+ throw new LaunchServiceException("Missing launch configuration attributes: " + '\n' + missingAttributes, LaunchServiceException.TYPE_MISSING_LAUNCH_CONFIG_ATTR); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Validate a single attribute for a given launch configuration and a launch mode. This method
+ * needs to be overwritten when contributing new launch modes which does not need all attributes.
+ *
+ * @param attributeKey The attribute key.
+ * @param launchConfig The launch configuration.
+ * @param launchMode The launch mode.
+ *
+ * @return <code>True</code>, if the attribute value is valid.
+ */
+ protected boolean isValidAttribute(String attributeKey, ILaunchConfiguration launchConfig, String launchMode) {
+ try {
+ if (launchConfig == null || !launchConfig.hasAttribute(attributeKey)) {
+ return false;
+ }
+ }
+ catch (CoreException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#validate(org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification)
+ */
+ @Override
+ public void validate(ILaunchSpecification launchSpec) throws LaunchServiceException {
+ String missingAttributes = null;
+ for (String attribute : getMandatoryAttributes()) {
+ if (launchSpec == null || !launchSpec.hasAttribute(attribute)) {
+ // Remember the missing attribute for adding the list to the exception.
+ missingAttributes = (missingAttributes == null) ? attribute : missingAttributes + ", " + attribute; //$NON-NLS-1$
+ }
+ }
+ if (missingAttributes != null) {
+ throw new LaunchServiceException("Missing launch specification attributes: " + '\n' + missingAttributes, LaunchServiceException.TYPE_MISSING_LAUNCH_SPEC_ATTR); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns the number of defined mandatory attributes.
+ *
+ * @see #getMandatoryAttributes()
+ * @see #getAttributeRanking(String)
+ */
+ protected final int getNumMandatoryAttributes() {
+ return getMandatoryAttributes().size();
+ }
+
+ /**
+ * Returns true if the attribute key is in the list of mandatory attributes.
+ *
+ * @see #getMandatoryAttributes()
+ * @see #getAttributeRanking(String)
+ */
+ protected final boolean isMandatoryAttribute(String attributeKey) {
+ return getMandatoryAttributes().contains(attributeKey);
+ }
+
+ /**
+ * Returns the ranking for the given attribute key.
+ * <p>
+ * The default ranking is 1, ranking of mandatory and other fundamental attributes should be
+ * coded as <code>2^n</code>.
+ * <p>
+ * The more important an attribute is the higher <code>n</code> should be, <code>n</code> should
+ * never be less than the number of attributes with a lower ranking.
+ * <p>
+ * Multiple attributes can have an equal ranking when one attribute can compensate the absence
+ * of an other attribute with the same ranking.
+ *
+ * <pre>
+ * Example:
+ *
+ * Attributes a through f
+ * Attributes a and b are mandatory, b is more important than a.
+ * The attributes c and d should be higher prior than e and f, but should have equal ranking.
+ *
+ * The ranking looks like the following:
+ * Attribute Ranking
+ * b 32 (2^5)
+ * a 16 (2^4)
+ * c, d 4 (2^2)
+ * e, f 1 (2^0)
+ *
+ * With this rankings it is not possible to compensate a missing higher prior attribute with
+ * one or more lower prior attributes.
+ *
+ * Additional methods returns the following values for this example:
+ *
+ * getNumAttributes() == 6
+ * getMandatoryAttibutes() == {a, b}
+ * getNumMandatoryAttributes() == 2
+ * getFullMatchRanking() >= 48 (the value can be greater than 48 depending
+ * on the implementation of the launch manager delegate)
+ * </pre>
+ *
+ * @param attributeKey The attribute key for which the ranking should be returned
+ */
+ protected int getAttributeRanking(String attributeKey) {
+ return 1;
+ }
+
+ /**
+ * Minimum ranking for a launch configuration to be handled as full match when comparing to a
+ * launch specification.
+ * <p>
+ * Should be overwritten when the method {@link #getAttributeRanking(String)} was overwritten.
+ *
+ * @see #getAttributeRanking(String)
+ */
+ protected int getFullMatchRanking() {
+ return 0;
+ }
+
+ /**
+ * Compares an attribute value of launch configuration and specification.
+ *
+ * If both values are not null, calls {@link #equals(String, Object, Object, ILaunchSpecification, ILaunchConfiguration, String)}
+ * to compare the values. If one of the values is <code>null</code>, and the not <code>null</code> value is default, <code>true</code>
+ * is returned. If both values are <code>null</code>, <code>true</code> is returned.
+ *
+ * @param attributeKey The attribute key. Must not be <code>null</code>.
+ * @param specValue The launch specification value.
+ * @param confValue The launch configuration value.
+ * @param launchSpec The launch specification which is the source of the <code>specValue</code>. Must not be <code>null</code>.
+ * @param launchConfig The launch configuration which is the source of the <code>confValue</code>. Must not be <code>null</code>.
+ * @return NO_MATCH, PARTIAL_MATCH or FULL_MATCH
+ */
+ protected int compareAttributeValues(String attributeKey, Object specValue, Object confValue, ILaunchSpecification launchSpec, ILaunchConfiguration launchConfig) {
+ Assert.isNotNull(attributeKey);
+ Assert.isNotNull(launchSpec);
+ Assert.isNotNull(launchConfig);
+
+ // values are equal if both are null
+ if (specValue == null && confValue == null) {
+ return FULL_MATCH;
+ }
+ // if launch specification value is null,
+ // values are equal if launch configuration value is default
+ else if (specValue == null) {
+ assert confValue != null;
+ return isDefaultAttribute(attributeKey, confValue, launchConfig, launchSpec.getLaunchMode()) ? FULL_MATCH : NO_MATCH;
+ }
+ // if launch configuration value is default,
+ // values are equal if launch specification value is default too
+ else if (isDefaultAttribute(attributeKey, confValue, launchConfig, launchSpec.getLaunchMode()) || confValue == null) {
+ assert specValue != null;
+ return isDefaultAttribute(attributeKey, specValue, launchConfig, launchSpec.getLaunchMode()) ? FULL_MATCH : NO_MATCH;
+ }
+ // use object.equals as default
+ else {
+ assert specValue != null && confValue != null;
+ return equals(attributeKey, specValue, confValue, launchSpec, launchConfig, launchSpec.getLaunchMode());
+ }
+ }
+
+ /**
+ * Compares the attribute value of launch configuration and launch specification.
+ * <p>
+ * The handling of null values is implemented in the calling private method
+ * {@link #compareAttributeValues(String, Object, Object, ILaunchSpecification, ILaunchConfiguration)}.
+ * When overwriting this method the implementor can be certain both values are not <code>null</code>.
+ *
+ * @param attributeKey The attribute key
+ * @param specValue The launch specification value. Must not be <code>null</code>.
+ * @param confValue The launch configuration value. Must not be <code>null</code>.
+ * @param launchSpec The launch specification.
+ * @param launchConfig The launch configuration which is the source of the <code>confValue</code>.
+ * @param launchMode The current launch mode.
+ *
+ * @return NO_MATCH, PARTIAL_MATCH or FULL_MATCH
+ */
+ protected int equals(String attributeKey, Object specValue, Object confValue, ILaunchSpecification launchSpec, ILaunchConfiguration launchConfig, String launchMode) {
+ Assert.isNotNull(specValue);
+ Assert.isNotNull(confValue);
+
+ if (ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD.equals(attributeKey)) {
+ // get match of list objects
+ int match = specValue.equals(confValue) ? FULL_MATCH : NO_MATCH;
+ // compare objects in the list when they are not already equal
+ if (match != FULL_MATCH && specValue instanceof List<?> && confValue instanceof List<?>) {
+ List<?> specProject = (List<?>) specValue;
+ List<?> confProject = (List<?>) confValue;
+ match = (specProject.isEmpty() || confProject.isEmpty()) ? PARTIAL_MATCH : NO_MATCH;
+ List<?> refProjects = null;
+ try {
+ refProjects = launchConfig.getAttribute(ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<?>) null);
+ }
+ catch (CoreException e) {
+ // ignore
+ }
+ for (int i = 0; i < specProject.size(); i++) {
+ Object specObject = specProject.get(i);
+ if (specObject != null && confProject.contains(specObject)) {
+ // spec object can be found in the configuration
+ if (match == NO_MATCH) {
+ // full match on first element in the spec list,
+ // otherwise partial match
+ match = (i == 0) ? FULL_MATCH : PARTIAL_MATCH;
+ }
+ }
+ else if (specObject != null && refProjects != null && refProjects.contains(specObject)) {
+ // spec object can be found in the configuration
+ if (match == NO_MATCH) {
+ match = PARTIAL_MATCH;
+ }
+ }
+ else if (match == FULL_MATCH) {
+ // reduce full to partial match when spec object wasn't found
+ match = PARTIAL_MATCH;
+ }
+ }
+ // reduce full to partial match when list size is not equal
+ // but all spec values where found in the configuration project list
+ if (match == FULL_MATCH && specProject.size() != confProject.size()) {
+ match = PARTIAL_MATCH;
+ }
+ }
+ return match;
+ }
+
+ return specValue.equals(confValue) ? FULL_MATCH : NO_MATCH;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#showLaunchDialog(int)
+ */
+ @Override
+ public boolean showLaunchDialog(int situation) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#showLaunchConfigOnly()
+ */
+ @Override
+ public boolean showLaunchConfigOnly() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#showLaunchConfigSelectionDialog(org.eclipse.debug.core.ILaunchConfigurationType, org.eclipse.debug.core.ILaunchConfiguration[])
+ */
+ @Override
+ public boolean showLaunchConfigSelectionDialog(ILaunchConfigurationType type, ILaunchConfiguration[] launchConfigs) {
+ if (type != null) {
+ String key = type.getIdentifier() + ".hideLaunchConfigSelectionDialog"; //$NON-NLS-1$
+ return !CoreBundleActivator.getScopedPreferences().getBoolean(key);
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getErrorMessage()
+ */
+ @Override
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#getVariants(org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection)
+ */
+ @Override
+ public String[] getVariants(ILaunchSelection launchSelection) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#equals(org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext, org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext)
+ */
+ @Override
+ public boolean equals(ISelectionContext ctx1, ISelectionContext ctx2) {
+ return (ctx1 == null && ctx2 == null) || (ctx1 != null && ctx1.equals(ctx2));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate#useDefaultConnection()
+ */
+ @Override
+ public boolean useDefaultConnection() {
+ return true;
+ }
+}
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
new file mode 100644
index 000000000..e702164e3
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ICommonLaunchAttributes.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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/ILaunchAttribute.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchAttribute.java
new file mode 100644
index 000000000..bbb7d9a30
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchAttribute.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * Launch attributes encapsulate an <code>String</code>-typed attribute key and an
+ * <code>Object</code>-typed attribute value.
+ */
+public interface ILaunchAttribute extends IAdaptable {
+
+ /**
+ * Returns the attribute key.
+ *
+ * @return The attribute key.
+ */
+ public String getKey();
+
+ /**
+ * Returns the attribute value.
+ *
+ * @return The attribute value.
+ */
+ public Object getValue();
+
+ /**
+ * Returns <code>true</code> if this attribute should be used only for creating launch
+ * configurations and not for finding them.
+ *
+ * @return <code>true</code> if only for create and not for find.
+ */
+ public boolean isCreateOnlyAttribute();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchManagerDelegate.java
new file mode 100644
index 000000000..f9e1c202e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchManagerDelegate.java
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.exceptions.LaunchServiceException;
+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.interfaces.extensions.IExecutableExtension;
+
+/**
+ * Describes the interface used by the <code>LaunchManager</code> to create
+ * and manage the different types of possible launch configurations in a generalized,
+ * simple and abstract way. A <code>ILaunchManagerDelegate</code> is strictly bound
+ * to one specific <code>ILaunchConfigurationType</code> and is capable and responsible
+ * to initializing and handling launch configurations of this type. A launch manager
+ * delegate is contribute through the <code>org.eclipse.tcf.te.launch.core.launchManagerDelegates</code>
+ * extension point!
+ */
+public interface ILaunchManagerDelegate extends IExecutableExtension {
+
+ public static final int SITUATION_BEFORE_LAUNCH = 0;
+ public static final int SITUATION_AFTER_LAUNCH_FAILED = 99;
+
+ // Constants for signaling the type of found matches
+
+ /**
+ * Constant to signal to ignore this matching.
+ */
+ public final static int IGNORE = -1;
+
+ /**
+ * Constant to signal a no match (no attributes are matching).
+ */
+ public final static int NO_MATCH = 0;
+
+ /**
+ * Constant to signal a partial match (some attributes are matching).
+ */
+ public final static int PARTIAL_MATCH = 1;
+
+ /**
+ * Constant to signal a full match (all attributes are matching).
+ */
+ public final static int FULL_MATCH = 2;
+
+ /**
+ * Initialize the launch configuration attributes based on the specified launch specification. If an launch
+ * configuration attribute is not listed within the specified launch specification, the corresponding attribute is
+ * initialized with an default.
+ *
+ * @param wc The launch configuration working copy to initialize. Must not be <code>null</code>!
+ * @param launchSpec The launch specification. Must not be <code>null</code>!
+ */
+ public void initLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec);
+
+ /**
+ * Updates a found launch configuration based on the specified launch specification.
+ *
+ * @param wc The launch configuration working copy to initialize. Must not be <code>null</code>!
+ * @param launchSpec The launch specification. Must not be <code>null</code>!
+ */
+ public void updateLaunchConfigAttributes(ILaunchConfigurationWorkingCopy wc, ILaunchSpecification launchSpec);
+
+ /**
+ * Test the specified attribute if or if not the specified attribute value is an default value or not.
+ *
+ * @param attributeKey The attribute key/name. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to test.
+ * @param launchConfig The original launch configuration. Needed to access relevant attributes for default value
+ * calculation. Must not be <code>null</code>!
+ * @param launchMode The launch mode. Default values may differ for different launch modes. Must not be
+ * <code>null</code>!
+ * @return <code>true</code> if the specified attribute value is the default value, <code>false</code> otherwise.
+ */
+ public boolean isDefaultAttribute(String attributeKey, Object attributeValue, ILaunchConfiguration launchConfig, String launchMode);
+
+ /**
+ * Returns a ranked list of launch configurations that best matches the given launch specification. In case of no
+ * results or a given empty or null launch configuration list an empty list should be returned. If no launch specification
+ * is given, the original list should be returned.
+ *
+ * @param launchSpec The launch specification the launch configurations should match.
+ * @param launchConfigs A full list of launch configurations to check for best matching.
+ * @return List of matching launch configurations starting with best match on first index.
+ * @throws LaunchServiceException
+ */
+ public ILaunchConfiguration[] getMatchingLaunchConfigurations(ILaunchSpecification launchSpec, ILaunchConfiguration[] launchConfigs) throws LaunchServiceException;
+
+ /**
+ * Get the default launch configuration name.
+ *
+ * @param launchSpec The launch specification to create a default name for the launch config. Must not be <code>null</code>.
+ * @return The default launch configuration name.
+ */
+ public String getDefaultLaunchName(ILaunchSpecification launchSpec);
+
+ /**
+ * Get a launch specification with all needed attributes for this delegate taken from the selection to find or create a new
+ * launch configuration.
+ *
+ * @param launchConfigTypeId The launch configuration type id.
+ * @param launchSelection The selected contexts.
+ * @return Launch specification with attributes set from selected contexts.
+ * @throws LaunchServiceException
+ */
+ public ILaunchSpecification getLaunchSpecification(String launchConfigTypeId, ILaunchSelection launchSelection);
+
+ /**
+ * Get a launch spec with all needed attributes for this delegate and variant taken from the selection to find or create a new
+ * launch configuration.
+ *
+ * @param launchConfigTypeId The launch configuration type id.
+ * @param launchSelection The selected contexts.
+ * @param variant The delegate variant.
+ * @return Launch spec with attributes set from selected contexts.
+ * @throws LaunchServiceException
+ */
+ public ILaunchSpecification getLaunchSpecification(String launchConfigTypeId, ILaunchSelection launchSelection, String variant);
+
+ /**
+ * Validates a launch specification.
+ *
+ * @param launchSpec The launch specification to validate.
+ * @throws LaunchServiceException If validation fails with further information about the reason (e.q. missing
+ * attributes)
+ */
+ public void validate(ILaunchSpecification launchSpec) throws LaunchServiceException;
+
+ /**
+ * Validates a launch configuration.
+ *
+ * @param launchConfig The launch configuration to validate.
+ * @param launchMode The launch mode.
+ * @throws LaunchServiceException If validation fails with further information about the reason (e.q. missing
+ * attributes)
+ */
+ public void validate(String launchMode, ILaunchConfiguration launchConfig) throws LaunchServiceException;
+
+ /**
+ * Returns true, if the launch dialog should be shown before launch.
+ * @param situation The situation (before launch, after launch, ..)
+ */
+ public boolean showLaunchDialog(int situation);
+
+ /**
+ * Returns true, if the launch dialog should only show the given launch configuration (no launch configuration type tree).
+ */
+ public boolean showLaunchConfigOnly();
+
+ /**
+ * Returns <code>true</code> if a dialog should pop up when at least one matching
+ * launch configuration was found.
+ * If <code>false</code> is returned, the first matching launch configuration will be used.
+ *
+ * @param type The launch configuration type to check.
+ */
+ public boolean showLaunchConfigSelectionDialog(ILaunchConfigurationType type, ILaunchConfiguration[] launchConfigs);
+
+ /**
+ * Returns the error message when not valid, otherwise <code>null</code>.
+ */
+ public String getErrorMessage();
+
+ /**
+ * Return the list of variants or null.
+ *
+ * @param launchSelection The launch selection or <code>null</code>.
+ */
+ public String[] getVariants(ILaunchSelection launchSelection);
+
+ /**
+ * Return <code>true</code> if the two selection contexts are equal
+ * for this launch configuration type.
+ *
+ * @param ctx1 The first launch selection context or <code>null</code>.
+ * @param ctx2 The second launch selection context or <code>null</code>.
+ *
+ * @return <code>True</code> if the two selection contexts are equal for this launch configuration type, <code>false</code> otherwise.
+ */
+ public boolean equals(ISelectionContext ctx1, ISelectionContext ctx2);
+
+ /**
+ * Return <code>true</code> if a default connection should be used when the connection selection is empty.
+ */
+ public boolean useDefaultConnection();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchSpecification.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchSpecification.java
new file mode 100644
index 000000000..bb497f719
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/interfaces/ILaunchSpecification.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * The launch specification interface describes a common API to handle launch configuration
+ * attributes in a generic way. This allow to write compact generic launch configuration handling
+ * code without the need to know what exact type of launch configuration it is.
+ */
+public interface ILaunchSpecification extends IAdaptable {
+
+ /**
+ * Returns the unique launch configuration type id for the launch configuration described by
+ * this launch specification.
+ *
+ * @return The unique launch configuration type id.
+ */
+ public String getLaunchConfigurationTypeId();
+
+ /**
+ * Returns the launch mode. @see <code>org.eclipse.debug.core.ILaunchManager</code> for valid id's.
+ *
+ * @return The launch mode.
+ */
+ public String getLaunchMode();
+
+ /**
+ * Returns the name proposal for a new generated launch configuration. The name doesn't need to
+ * be unique! Can return <code>null</code>.
+ */
+ public String getLaunchConfigName();
+
+ /**
+ * Set the name for a new generated launch configuration.
+ *
+ * @param launchConfigName The name for a new generated launch configuration or <code>null</code>.
+ */
+ public void setLaunchConfigName(String launchConfigName);
+
+ /**
+ * Returns the label proposal for the launch action that uses this launch specification. The
+ * label should _NEVER_ start with the launch mode (Run/Debug <label>). Can return <code>null</code>.
+ */
+ public String getLaunchActionLabel();
+
+ /**
+ * Set the label for the launch action that uses this launch specification.
+ *
+ * @param launchActionLabel The label for the launch action. Can be <code>null</code>.
+ */
+ public void setLaunchActionLabel(String launchActionLabel);
+
+ /**
+ * Add the specified launch configuration attribute value to this specification using the
+ * specified launch configuration attribute key. If the launch specification has been locked,
+ * the method will do nothing. If the specified value is <code>
+ * null</code>, this method has the same effect as <code>removeAttribute(key)</code>.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @param value The launch configuration attribute value or <code>null</code>.
+ * @param createOnly <code>true</code> if this attribute should only be used for create.
+ */
+ public void addAttribute(String key, Object value, boolean createOnly);
+
+ /**
+ * Add the specified launch configuration attribute value to this specification using the
+ * specified launch configuration attribute key. If the launch specification has been locked,
+ * the method will do nothing. If the specified value is <code>
+ * null</code>, this method has the same effect as <code>removeAttribute(key)</code>.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @param value The launch configuration attribute value or <code>null</code>.
+ */
+ public void addAttribute(String key, Object value);
+
+ /**
+ * Checks if the launch configuration attribute with the specified key is known to this launch
+ * specification.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @return <code>true</code> if the attribute is known, <code>false</code> otherwise.
+ */
+ public boolean hasAttribute(String key);
+
+ /**
+ * Removes the launch configuration attribute with the specified key. If the launch
+ * specification has been locked, the method will do nothing
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @return The attribute value stored for the specified key or <code>null</code>.
+ */
+ public Object removeAttribute(String key);
+
+ /**
+ * Returns the attribute value for the given attribute key. If the key is not known or the value
+ * is not set, the specified default value will be returned instead.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @param defaultValue The default value.
+ * @return The launch configuration attribute value or the default value.
+ */
+ public Object getAttribute(String key, Object defaultValue);
+
+ /**
+ * Returns the launch attribute the given attribute key. If the key is not known or the value is
+ * not set, <code>null</code> will be returned.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @return The launch configuration attribute or <code>null</code>.
+ */
+ public ILaunchAttribute getAttribute(String key);
+
+ /**
+ * Returns <code>true</code> if the attribute is set and the <code>createOnly</code> flag of the
+ * attribute key is set.
+ *
+ * @param key The launch configuration attribute key. Must not be <code>null</code>!
+ * @return The <code>createOnly</code> flag of the attribute key.
+ */
+ public boolean isCreateOnlyAttribute(String key);
+
+ /**
+ * Locks or unlocks the launch specification for modification. If the read only state is set to
+ * <code>true</code>, every modifying method call will return immediately and change nothing!
+ *
+ * @param readOnly <code>true</code> to lock the launch specification, <code>false</code> to unlock.
+ */
+ public void setReadOnly(boolean readOnly);
+
+ /**
+ * Returns the current lock state of the launch specification.
+ *
+ * @return <code>true</code> if launch specification is locked, <code>false</code> otherwise.
+ */
+ public boolean isReadOnly();
+
+ /**
+ * Remove all known launch attributes from this launch specification. If the launch
+ * specification has been locked, the method will do nothing.
+ */
+ public void clear();
+
+ /**
+ * Returns the number of launch attributes known to this launch specification.
+ */
+ public int size();
+
+ /**
+ * Returns <code>true</code> if this launch specification does not contain any attribute.
+ */
+ public boolean isEmpty();
+
+ /**
+ * Returns an array containing all launch configuration attributes known to this launch
+ * specification.
+ *
+ * @return An array with elements of type <code>ILaunchAttribute</code>. The returned array may
+ * empty but never <code>null</code>.
+ */
+ public ILaunchAttribute[] getAllAttributes();
+
+ /**
+ * Returns <code>true</code> if this launch spec is valid.
+ */
+ public boolean isValid();
+
+ /**
+ * Sets the result of a validation. Validation is normally made through launch manager
+ * delegates.
+ *
+ * @param valid <code>true</code> if this launch spec is valid.
+ */
+ public void setIsValid(boolean valid);
+
+ /**
+ * Returns the error message when not valid, otherwise <code>null</code>.
+ */
+ public String getErrorMessage();
+
+ /**
+ * Sets the error message after validation fails.
+ *
+ * @param errorMessage The error message.
+ */
+ public void setErrorMessage(String errorMessage);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/ExtensionPointManager.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/ExtensionPointManager.java
new file mode 100644
index 000000000..9f9fc34fd
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/ExtensionPointManager.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate;
+import org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager;
+import org.eclipse.tcf.te.runtime.extensions.ExecutableExtensionProxy;
+import org.eclipse.tcf.te.runtime.interfaces.extensions.IExecutableExtension;
+
+/**
+ * Launch manager delegate extension point manager.
+ */
+public class ExtensionPointManager extends AbstractExtensionPointManager<ILaunchManagerDelegate> {
+
+ private final ILaunchManagerDelegate defaultDelegate = new DefaultLaunchManagerDelegate();
+
+ /*
+ * Thread save singleton instance creation.
+ */
+ private static class LazyInstanceHolder {
+ public static ExtensionPointManager instance = new ExtensionPointManager();
+ }
+
+ /**
+ * Returns the singleton instance for the manager.
+ */
+ public static ExtensionPointManager getInstance() {
+ return LazyInstanceHolder.instance;
+ }
+
+ /**
+ * Constructor.
+ */
+ ExtensionPointManager() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getConfigurationElementName()
+ */
+ @Override
+ protected String getConfigurationElementName() {
+ return "delegate"; //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.runtime.extensions.AbstractExtensionPointManager#getExtensionPointId()
+ */
+ @Override
+ protected String getExtensionPointId() {
+ return "org.eclipse.tcf.te.launch.core.launchManagerDelegates"; //$NON-NLS-1$
+ }
+
+ /**
+ * Get the list of all registered launch manager delegates.
+ */
+ public ILaunchManagerDelegate[] getLaunchManagerDelegates() {
+ List<ILaunchManagerDelegate> delegates = new ArrayList<ILaunchManagerDelegate>();
+ for (ExecutableExtensionProxy<ILaunchManagerDelegate> proxy : getExtensions().values()) {
+ IExecutableExtension candidate = proxy.getInstance();
+ if (candidate instanceof ILaunchManagerDelegate && !delegates.contains(candidate)) {
+ delegates.add((ILaunchManagerDelegate)candidate);
+ }
+ }
+
+ return delegates.toArray(new ILaunchManagerDelegate[delegates.size()]);
+ }
+
+ /**
+ * Returns the launch manager delegate with the given id.
+ * @param id The id of the launch manager delegate.
+ */
+ public ILaunchManagerDelegate getLaunchManagerDelegate(String id) {
+ assert id != null;
+ ILaunchManagerDelegate delegate = null;
+ if (getExtensions().containsKey(id)) {
+ delegate = getExtensions().get(id).getInstance();
+ }
+
+ return delegate != null ? delegate : getDefaultLaunchManagerDelegate();
+ }
+
+ /**
+ * Returns the default dummy launch manager delegate.
+ */
+ public ILaunchManagerDelegate getDefaultLaunchManagerDelegate() {
+ return defaultDelegate;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
index 6caa47de2..bf2d4ddbf 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.java
@@ -29,4 +29,12 @@ public class Messages extends NLS {
// **** Declare externalized string id's down here *****
+ public static String DefaultLaunchManagerDelegate_defaultLaunchName;
+
+ public static String LaunchManager_error_invalidExtensionPoint;
+ public static String LaunchManager_error_noLaunchConfigType;
+ public static String LaunchManager_error_failedToCreateConfig;
+ public static String LaunchManager_error_failedToUpdateConfig;
+ public static String LaunchManager_error_deleteLaunchConfig;
+
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
index 5192a3c8f..6480e158a 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/nls/Messages.properties
@@ -3,3 +3,10 @@
# Externalized Strings.
#
+DefaultLaunchManagerDelegate_defaultLaunchName=New configuration
+
+LaunchManager_error_invalidExtensionPoint=Failed to instantiate the executable extension from extension point ''{0}''.
+LaunchManager_error_noLaunchConfigType=No launch configuration type (id = ) is available for launch mode ''{0}''.
+LaunchManager_error_failedToCreateConfig=Failed to create and initialize new launch configuration.
+LaunchManager_error_failedToUpdateConfig=Failed to update existing launch configuration ''{0}''.
+LaunchManager_error_deleteLaunchConfig=Failed to delete launch configuration.
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/DefaultPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/DefaultPersistenceDelegate.java
new file mode 100644
index 000000000..f858bb0c3
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/DefaultPersistenceDelegate.java
@@ -0,0 +1,347 @@
+/*******************************************************************************
+ * 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.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.runtime.events.EventManager;
+
+/**
+ * Launch framework default persistence delegate.
+ */
+public class DefaultPersistenceDelegate {
+
+ // **** Interface methods to apply attributes only if changed.
+ // ****
+ // **** By default, calling a setAttribute method of the ILaunchConfigurationWorkingCopy
+ // **** interface, marks the ILaunchConfiguration as dirty independent of the fact that the
+ // **** real attribute value may not have changed at all. This basically leads to the UI
+ // **** question if or if not to apply the changes made to a launch configuration by just
+ // **** switching through the launch configuration tabs. However, it is desired functionality
+ // **** to modify the launch configuration only if some attributes have really changed.
+ // **** These methods here read and compare the attribute before really writing something
+ // **** to the given ILaunchConfigurationWorkingCopy. All methods here are based on the
+ // **** corresponding method declaration in ILaunchConfigurationWorkingCopy.
+
+ /**
+ * Checks if the given attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet. If the attribute value is <code>null</code>,
+ * the attribute id will be checked if it may need to get removed from the given launch
+ * configuration working copy.
+ *
+ * @param wc The launch configuration working copy instance to check the attributes against. Must not be <code>null</code>.
+ * @param attributeId The attribute id. Must not be <code>null</code>.
+ * @param attributeValue The attribute value.
+ *
+ * @return <code>true</code> if the attribute value has changed compared to it's old value, <code>false</code> otherwise.
+ */
+ public final static boolean isAttributeChanged(ILaunchConfigurationWorkingCopy wc, String attributeId, Object attributeValue) {
+ boolean changed = false;
+
+ Assert.isNotNull(wc);
+ Assert.isNotNull(attributeId);
+
+ try {
+
+ // Read the old attribute value from the launch configuration.
+ Map<?,?> attributes = wc.getAttributes();
+ // Case: If new attribute value == null and attribute id exists
+ // --> Remove the attribute from the launch configuration.
+ if (attributeValue == null && attributes.containsKey(attributeId)) {
+ changed = true;
+ } else {
+ // Case: If new attribute value != null and attribute id does not exists
+ // --> Store the attribute to the launch configuration.
+ if (attributeValue != null && !attributes.containsKey(attributeId)) {
+ changed = true;
+ } else {
+ // Case: If new attribute value != null and attribute id exists
+ // --> Compare new value with old value and if not equal,
+ // store the attribute to the launch configuration.
+ if (attributeValue != null && attributes.containsKey(attributeId)) {
+ Object oldAttributeValue = attributes.get(attributeId);
+ if (! attributeValue.equals(oldAttributeValue)) {
+ changed = true;
+ }
+ }
+ }
+ }
+ } catch (CoreException e) { /* ignored */ }
+
+ return changed;
+ }
+
+ /**
+ * Stores the given boolean attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet.
+ *
+ * @param wc The launch configuration working copy instance to apply the attribute to. Must not be <code>null</code>.
+ * @param attributeId The attribute id to store the attribute value under. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to store under the given attribute id.
+ */
+ public final static void setAttribute(ILaunchConfigurationWorkingCopy wc, String attributeId, boolean attributeValue) {
+ if (wc == null || attributeId == null) return;
+ if (isAttributeChanged(wc, attributeId, Boolean.valueOf(attributeValue))) {
+ // Determine the old attribute value
+ Object oldValue = null;
+ if (hasAttribute(wc, attributeId)) try { oldValue = wc.getAttributes().get(attributeId); } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Set the new value to the launch configuration
+ wc.setAttribute(attributeId, attributeValue);
+
+ // And fire an notification event
+ EventManager.getInstance().fireEvent(new LaunchConfigurationChangedEvent(wc, attributeId, oldValue, Boolean.valueOf(attributeValue)));
+ }
+ }
+
+ /**
+ * Stores the given integer attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet.
+ *
+ * @param wc The launch configuration working copy instance to apply the attribute to. Must not be <code>null</code>.
+ * @param attributeId The attribute id to store the attribute value under. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to store under the given attribute id.
+ */
+ public final static void setAttribute(ILaunchConfigurationWorkingCopy wc, String attributeId, int attributeValue) {
+ if (wc == null || attributeId == null) return;
+ if (isAttributeChanged(wc, attributeId, new Integer(attributeValue))) {
+ // Determine the old attribute value
+ Object oldValue = null;
+ if (hasAttribute(wc, attributeId)) try { oldValue = wc.getAttributes().get(attributeId); } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Set the new value to the launch configuration
+ wc.setAttribute(attributeId, attributeValue);
+
+ // And fire an notification event
+ EventManager.getInstance().fireEvent(new LaunchConfigurationChangedEvent(wc, attributeId, oldValue, Integer.valueOf(attributeValue)));
+ }
+ }
+
+ /**
+ * Stores the given string attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet. If the attribute value is <code>null</code>,
+ * the attribute id will be removed from the given launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy instance to apply the attribute to. Must not be <code>null</code>.
+ * @param attributeId The attribute id to store the attribute value under. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to store under the given attribute id.
+ */
+ public final static void setAttribute(ILaunchConfigurationWorkingCopy wc, String attributeId, String attributeValue) {
+ if (wc == null || attributeId == null) return;
+ if (isAttributeChanged(wc, attributeId, attributeValue)) {
+ // Determine the old attribute value
+ Object oldValue = null;
+ if (hasAttribute(wc, attributeId)) try { oldValue = wc.getAttributes().get(attributeId); } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Set the new value to the launch configuration
+ wc.setAttribute(attributeId, attributeValue);
+
+ // And fire an notification event
+ EventManager.getInstance().fireEvent(new LaunchConfigurationChangedEvent(wc, attributeId, oldValue, attributeValue));
+ }
+ }
+
+ /**
+ * Stores the given list attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet. If the attribute value is <code>null</code>,
+ * the attribute id will be removed from the given launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy instance to apply the attribute to. Must not be <code>null</code>.
+ * @param attributeId The attribute id to store the attribute value under. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to store under the given attribute id.
+ */
+ public final static void setAttribute(ILaunchConfigurationWorkingCopy wc, String attributeId, List<?> attributeValue) {
+ if (wc == null || attributeId == null) return;
+ if (isAttributeChanged(wc, attributeId, attributeValue)) {
+ // Determine the old attribute value
+ Object oldValue = null;
+ if (hasAttribute(wc, attributeId)) try { oldValue = wc.getAttributes().get(attributeId); } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Set the new value to the launch configuration
+ wc.setAttribute(attributeId, attributeValue);
+
+ // And fire an notification event
+ EventManager.getInstance().fireEvent(new LaunchConfigurationChangedEvent(wc, attributeId, oldValue, attributeValue));
+ }
+ }
+
+ /**
+ * Stores the given map attribute value under the given attribute id if the value
+ * has changed compared to the already stored value under the given attribute id or
+ * if the attribute id has not been stored yet. If the attribute value is <code>null</code>,
+ * the attribute id will be removed from the given launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy instance to apply the attribute to. Must not be <code>null</code>.
+ * @param attributeId The attribute id to store the attribute value under. Must not be <code>null</code>.
+ * @param attributeValue The attribute value to store under the given attribute id.
+ */
+ public final static void setAttribute(ILaunchConfigurationWorkingCopy wc, String attributeId, Map<?, ?> attributeValue) {
+ if (wc == null || attributeId == null) return;
+ if (isAttributeChanged(wc, attributeId, attributeValue)) {
+ // Determine the old attribute value
+ Object oldValue = null;
+ if (hasAttribute(wc, attributeId)) try { oldValue = wc.getAttributes().get(attributeId); } catch (CoreException e) { /* ignored on purpose */ }
+
+ // Set the new value to the launch configuration
+ wc.setAttribute(attributeId, attributeValue);
+
+ // And fire an notification event
+ EventManager.getInstance().fireEvent(new LaunchConfigurationChangedEvent(wc, attributeId, oldValue, attributeValue));
+ }
+ }
+
+ /**
+ * Returns the boolean attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The boolean attribute or the default value.
+ */
+ public final static boolean getAttribute(ILaunchConfiguration lc, String attributeName, boolean defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ boolean value = defaultValue;
+ try { value = lc.getAttribute(attributeName, defaultValue); } catch (CoreException e) { /* ignored on purpose */ }
+ return value;
+ }
+
+ /**
+ * Returns the int attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The int attribute or the default value.
+ */
+ public final static int getAttribute(ILaunchConfiguration lc, String attributeName, int defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ int value = defaultValue;
+ try { value = lc.getAttribute(attributeName, defaultValue); } catch (CoreException e) { /* ignored on purpose */ }
+ return value;
+ }
+
+ /**
+ * Returns the list attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The list attribute or the default value.
+ */
+ public final static List<?> getAttribute(ILaunchConfiguration lc, String attributeName, List<?> defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ List<?> value = defaultValue;
+ try { value = lc.getAttribute(attributeName, defaultValue); } catch (CoreException e) { /* ignored on purpose */ }
+ return value;
+ }
+
+ /**
+ * Returns the set attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The set attribute or the default value.
+ */
+ public final static Set<?> getAttribute(ILaunchConfiguration lc, String attributeName, Set<?> defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ Set<?> value = defaultValue;
+ try { value = lc.getAttribute(attributeName, defaultValue); } catch (CoreException e) { /* ignored on purpose */ }
+ return value;
+ }
+
+
+ /**
+ * Returns the map attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The map attribute or the default value.
+ */
+ public final static Map<?,?> getAttribute(ILaunchConfiguration lc, String attributeName, Map<?,?> defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ Map<?,?> value = defaultValue;
+ try { value = lc.getAttribute(attributeName, defaultValue); } catch (CoreException e) { /* ignored on purpose */ }
+ return value;
+ }
+
+ /**
+ * Returns the string attribute stored under the given attribute name or
+ * the default value if the attribute does not exist or the read failed.
+ *
+ * @param lc The launch configuration to read the attribute from. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ * @param defaultValue The default value.
+ *
+ * @return The string attribute or the default value.
+ */
+ public final static String getAttribute(ILaunchConfiguration lc, String attributeName, String defaultValue) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ String value = defaultValue;
+ try {
+ value = lc.getAttribute(attributeName, defaultValue);
+ }
+ catch (CoreException e) {
+ /* ignored on purpose */
+ }
+ return value;
+ }
+
+ /**
+ * Returns whether the given launch configuration contains an attribute of the given name.
+ *
+ * @param lc The launch configuration. Must not be <code>null</code>.
+ * @param attributeName The attribute name. Must not be <code>null</code>.
+ *
+ * @return <code>True</code> if the launch configuration contains the attribute, <code>false</code> otherwise.
+ */
+ public final static boolean hasAttribute(ILaunchConfiguration lc, String attributeName) {
+ Assert.isNotNull(lc);
+ Assert.isNotNull(attributeName);
+
+ boolean hasAttribute = false;
+ try { hasAttribute = lc.hasAttribute(attributeName); } catch (CoreException e) { /* ignored on purpose */ }
+ return hasAttribute;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/LaunchConfigurationChangedEvent.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/LaunchConfigurationChangedEvent.java
new file mode 100644
index 000000000..1aab7e305
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/LaunchConfigurationChangedEvent.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.util.EventObject;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.tcf.te.runtime.events.EventManager;
+
+/**
+ * Launch configuration changed event.
+ * <p>
+ * This event will be fired by the {@link DefaultPersistenceDelegate} if
+ * an attribute of a launch configuration has changed.
+ */
+public class LaunchConfigurationChangedEvent extends EventObject {
+ private static final long serialVersionUID = 1934509221613969948L;
+
+ private final String attributeName;
+ private final Object oldValue;
+ private final Object newValue;
+
+ /**
+ * Constructor.
+ *
+ * @param source The changed launch configuration. Must not be <code>null</code>.
+ * @param attributeName The name of the changed launch configuration attribute. Must not be <code>null</code>.
+ * @param oldValue The old attribute value or <code>null</code>.
+ * @param newValue The new attribute value or <code>null</code>.
+ */
+ public LaunchConfigurationChangedEvent(ILaunchConfiguration source, String attributeName, Object oldValue, Object newValue) {
+ super(source);
+
+ assert attributeName != null;
+ this.attributeName = attributeName;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ /**
+ * Returns the changed launch configuration.
+ *
+ * @return The changed launch configuration.
+ */
+ public ILaunchConfiguration getLaunchConfiguration() {
+ return (ILaunchConfiguration)getSource();
+ }
+
+ /**
+ * Returns the name of the changed launch configuration.
+ *
+ * @return The name of the changed launch configuration.
+ */
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ /**
+ * Returns the old attribute value.
+ *
+ * @return The old attribute value or <code>null</code>.
+ */
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ /**
+ * Returns the new attribute value.
+ *
+ * @return The new attribute value or <code>null</code>.
+ */
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ /* (non-Javadoc)
+ * @see com.windriver.ide.common.core.event.WRAbstractNotificationEvent#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer(getClass().getName());
+
+ String prefix = ""; //$NON-NLS-1$
+ // if tracing the event, formating them a little bit better readable.
+ if (EventManager.isTracingEnabled())
+ prefix = "\n\t\t"; //$NON-NLS-1$
+
+ toString.append(prefix + "{launch configuration="); //$NON-NLS-1$
+ toString.append(getLaunchConfiguration().getName());
+ toString.append("," + prefix + "attributeName="); //$NON-NLS-1$ //$NON-NLS-2$
+ toString.append(getAttributeName());
+ toString.append("," + prefix + "old value="); //$NON-NLS-1$ //$NON-NLS-2$
+ toString.append(getOldValue());
+ toString.append("," + prefix + "new value="); //$NON-NLS-1$ //$NON-NLS-2$
+ toString.append(getNewValue());
+ 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/persistence/ReferencedProjectsPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java
new file mode 100644
index 000000000..26d308f1f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/persistence/ReferencedProjectsPersistenceDelegate.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes;
+
+/**
+ * Launch framework referenced projects persistence delegate.
+ */
+public class ReferencedProjectsPersistenceDelegate {
+
+ /**
+ * Interface declaring the public accessible attributes or a project reference.
+ */
+ public static interface IProjectReference {
+
+ /**
+ * Returns the name of the referenced project.
+ *
+ * @return The name of the referenced project.
+ */
+ public String getName();
+
+ /**
+ * Returns the referenced project instance.
+ *
+ * @return The referenced project instance or <code>null</code> if not in the workspace.
+ */
+ public IProject getProject();
+
+ /**
+ * Returns the enabled state of the project reference.
+ *
+ * @return <code>True</code> if the project reference is enabled, <code>false</code> otherwise.
+ */
+ public boolean isEnabled();
+
+ /**
+ * Set's the project reference enabled state.
+ *
+ * @param enabled <code>True</code> to enable the project reference, <code>false</code> otherwise.
+ */
+ public void setEnabled(boolean enabled);
+ }
+
+ /**
+ * Internal default {@link IProjectReference} implementation.
+ */
+ private static class ProjectReference implements IProjectReference {
+ private final String name;
+ private boolean enabled;
+ private final IProject project;
+
+ /**
+ * Constructor
+ *
+ * @param name The project name. Must not be <code>null</code>.
+ * @param project The project instance or <code>null</code>.
+ * @param enabled The enabled state.
+ */
+ public ProjectReference(String name, IProject project, boolean enabled) {
+ Assert.isNotNull(name);
+
+ this.name = name;
+ this.enabled = enabled;
+ this.project = project;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#getName()
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#getProject()
+ */
+ @Override
+ public IProject getProject() {
+ return project;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.persistence.ReferencedProjectsPersistenceDelegate.IProjectReference#setEnabled(boolean)
+ */
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof IProjectReference) {
+ return name.equals(((IProjectReference)obj).getName());
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Returns a new project reference instance.
+ *
+ * @param name The project name. Must not be <code>null</code>.
+ * @param project The project instance or <code>null</code>.
+ * @param enabled The enabled state.
+ *
+ * @return The new project reference instance.
+ */
+ public static IProjectReference create(String name, IProject project, boolean enabled) {
+ return new ProjectReference(name, project, enabled);
+ }
+
+ /**
+ * Read the list of project name from the launch configuration attributes and transforms
+ * it into a list of project references.
+ *
+ * @param launchConfig The launch configuration. Must not be <code>null</code>.
+ *
+ * @return The list of project references or an empty list.
+ */
+ public static List<IProjectReference> getProjects(ILaunchConfiguration launchConfig) {
+ Assert.isNotNull(launchConfig);
+
+ List<IProjectReference> references = new ArrayList<IProjectReference>();
+
+ // Get the list of referenced project from the launch configuration
+ List<String> projects = (List<String>)DefaultPersistenceDelegate.getAttribute(launchConfig, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
+ if (projects != null) {
+ // Loop over the found project names and lookup the corresponding project instance.
+ for (String name : projects) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ IProjectReference ref = create(name, project, false);
+ if (!references.contains(ref)) {
+ references.add(ref);
+ }
+ }
+ }
+
+ // Get the list of referenced project and enabled for build from the launch configuration
+ projects = (List<String>)DefaultPersistenceDelegate.getAttribute(launchConfig, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<String>)null);
+ if (projects != null) {
+ // Loop over the found project names and lookup the corresponding project instance.
+ for (String name : projects) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ IProjectReference ref = create(name, project, true);
+ // If already referenced, but not enabled, enable now.
+ int i = references.indexOf(ref);
+ if (i >= 0) {
+ references.get(i).setEnabled(true);
+ }
+ else {
+ references.add(ref);
+ }
+ }
+ }
+
+ return references;
+ }
+
+ /**
+ * Writes the list of referenced projects to the given launch configuration working copy.
+ *
+ * @param wc The launch configuration working copy. Must not be <code>null</code>.
+ * @param projects The list of referenced projects or <code>null</code>.
+ */
+ public static void setProjects(ILaunchConfigurationWorkingCopy wc, List<IProjectReference> projects) {
+ Assert.isNotNull(wc);
+
+ // If the project list is null or empty, we reset the attributes to use the default value
+ if (projects == null || projects.isEmpty()) {
+ DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
+ DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, (List<String>)null);
+ return;
+ }
+
+ // The list instances
+ List<String> projectsForBuild = new ArrayList<String>();
+ List<String> refProjects = new ArrayList<String>();
+
+ // Loop all project references and find the referenced projects and
+ // the projects enabled for build before launch
+ for (IProjectReference projectRef : projects) {
+ refProjects.add(projectRef.getName());
+ if (projectRef.isEnabled()) {
+ projectsForBuild.add(projectRef.getName());
+ }
+ }
+
+ // The attribute "projects for build" is set always.
+ DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_PROJECTS_FOR_BUILD, projectsForBuild);
+ // The referenced projects list contains only the excluded/disabled projects. Therefore
+ // reset the attribute if the lists are equal
+ if (projectsForBuild.size() == refProjects.size()) {
+ DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, (List<String>)null);
+ }
+ else {
+ DefaultPersistenceDelegate.setAttribute(wc, ICommonLaunchAttributes.ATTR_REFERENCED_PROJECTS, refProjects);
+ }
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/IPreferenceKeys.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/IPreferenceKeys.java
new file mode 100644
index 000000000..cee4ca5d8
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/IPreferenceKeys.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.preferences;
+
+
+/**
+ * The locator model bundle preference key identifiers.
+ */
+public interface IPreferenceKeys {
+ /**
+ * Common prefix for all core preference keys
+ */
+ public final String PREFIX = "te.launch.core."; //$NON-NLS-1$
+
+ /**
+ * Launch configuration find/create mode: Always create new launch configurations.
+ */
+ public static final int MODE_ALWAYS_NEW = 0;
+
+ /**
+ * Launch configuration find/create mode: Re-use launch configuration if all attributes are matching.
+ */
+ public static final int MODE_FULL_MATCH_LAUNCH_CONFIG = 1;
+
+ /**
+ * Launch configuration find/create mode: Re-use launch configuration if the target ID matches.
+ */
+ public static final int MODE_FULL_MATCH_TARGET = 2;
+
+ /**
+ * Launch configuration find/create mode: Re-use first matching launch configuration.
+ */
+ public static final int MODE_FIRST_MATCHING = 3;
+
+ /**
+ * Launch configuration find/create mode. See the <code>MODE_*</code> constants.
+ */
+ public static final String PREF_LAUNCH_CONFIG_FIND_CREATE_MODE = PREFIX + "launchConfigFindCreateMode"; //$NON-NLS-1$
+
+ /**
+ * If set to <code>true</code>, project references will be added by default to newly created launch configurations.
+ */
+ public static final String PREF_ADD_PROJECT_TO_NEW_LAUNCH_CONFIG = PREFIX + "addProjectToNewLaunchConfig"; //$NON-NLS-1$
+
+ /**
+ * If set to <code>true</code>, launches are sorted by their last launched time stamp.
+ */
+ public static final String PREF_SORT_LAUNCHES_BY_LAST_LAUNCHED = PREFIX + ".sortLaunchesByLastLaunched"; //$NON-NLS-1$
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/PreferencesInitializer.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/PreferencesInitializer.java
new file mode 100644
index 000000000..66ef5238e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/preferences/PreferencesInitializer.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator;
+import org.eclipse.tcf.te.runtime.preferences.ScopedEclipsePreferences;
+
+/**
+ * Launch core framework preferences initializer implementation.
+ */
+public class PreferencesInitializer extends AbstractPreferenceInitializer {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ @Override
+ public void initializeDefaultPreferences() {
+ // Get the preferences store
+ ScopedEclipsePreferences store = CoreBundleActivator.getScopedPreferences();
+
+ /**
+ * Launch configuration find/create mode: default <code>MODE_FIRST_MATCHING</code>.
+ */
+ store.putDefaultInt(IPreferenceKeys.PREF_LAUNCH_CONFIG_FIND_CREATE_MODE, IPreferenceKeys.MODE_FIRST_MATCHING);
+
+ /**
+ * Add project references to newly created launch configurations: default <code>true</code>.
+ */
+ store.putDefaultBoolean(IPreferenceKeys.PREF_ADD_PROJECT_TO_NEW_LAUNCH_CONFIG, true);
+
+ /**
+ * Sort launches by their last launched time stamp: default <code>true</code>.
+ */
+ store.putDefaultBoolean(IPreferenceKeys.PREF_SORT_LAUNCHES_BY_LAST_LAUNCHED, true);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/AbstractSelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/AbstractSelectionContext.java
new file mode 100644
index 000000000..ab2d0193e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/AbstractSelectionContext.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * 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.selection;
+
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * Abstract selection context implementation.
+ */
+public abstract class AbstractSelectionContext implements ISelectionContext {
+ // The selection context type
+ protected String type = null;
+ // The selected objects
+ private Object[] selections;
+ // Preferred selection context marker
+ private boolean isPreferred = false;
+
+ /**
+ * Constructor.
+ *
+ * @param selections The selected objects or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public AbstractSelectionContext(Object[] selections, boolean isPreferred) {
+ this.selections = selections != null ? selections : new Object[0];
+ this.isPreferred = isPreferred;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param type The selection context type or <code>null</code>.
+ * @param selections The selected objects or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public AbstractSelectionContext(String type, Object[] selections, boolean isPreferred) {
+ this.type = type;
+ this.selections = selections != null ? selections : new Object[0];
+ this.isPreferred = isPreferred;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext#getType()
+ */
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext#getSelections()
+ */
+ @Override
+ public Object[] getSelections() {
+ return selections;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext#setIsPreferredContext(boolean)
+ */
+ @Override
+ public void setIsPreferredContext(boolean isPreferred) {
+ this.isPreferred = isPreferred;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext#isPreferredContext()
+ */
+ @Override
+ public boolean isPreferredContext() {
+ return isPreferred;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ boolean equals = obj instanceof ISelectionContext;
+
+ if (equals) {
+ ISelectionContext otherContext = (ISelectionContext)obj;
+
+ equals &= type == null && otherContext.getType() == null || type != null && type.equals(otherContext.getType());
+ equals &= isPreferred == otherContext.isPreferredContext();
+
+ Object[] otherSelections = otherContext.getSelections();
+ equals &= selections == null && otherSelections == null || selections != null && otherSelections != null;
+
+ int i = 0;
+ int length = selections != null ? selections.length : -1;
+ int otherLength = otherSelections != null ? otherSelections.length : -1;
+ equals &= (length == otherLength);
+
+ while (equals && i < length) {
+ equals &= selections[i] == null && otherSelections[i] == null || selections[i] != null && selections[i].equals(otherSelections[i]);
+ i++;
+ }
+ }
+
+ return equals;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+
+ if (type != null) {
+ hashCode ^= type.hashCode() << 8;
+ }
+ hashCode ^= Boolean.valueOf(isPreferred).hashCode();
+
+ if (selections != null) {
+ hashCode ^= selections.hashCode();
+ }
+
+ return hashCode;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ if (type != null){
+ toString.append(type);
+ }
+
+ return toString.toString();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/LaunchSelection.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/LaunchSelection.java
new file mode 100644
index 000000000..32a089814
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/LaunchSelection.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * 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.selection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ISelectionContext;
+
+/**
+ * Launch selection implementation.
+ */
+public class LaunchSelection implements ILaunchSelection {
+ // The launch mode the selection has been created for
+ private String mode;
+ // The selection contexts
+ private ISelectionContext[] contexts = null;
+
+ /**
+ * Constructor.
+ *
+ * @param mode The launch mode or <code>null</code>.
+ * @param context The selection context or <code>null</code>.
+ */
+ public LaunchSelection(String mode, ISelectionContext context) {
+ this(mode, context != null ? new ISelectionContext[] { context } : null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param mode The launch mode or <code>null</code>.
+ */
+ public LaunchSelection(String mode, ISelectionContext[] contexts) {
+ this.mode = mode;
+ this.contexts = contexts;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection#getLaunchMode()
+ */
+ @Override
+ public final String getLaunchMode() {
+ return mode;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection#getSelectedContexts()
+ */
+ @Override
+ public ISelectionContext[] getSelectedContexts() {
+ return contexts != null ? contexts : new ISelectionContext[0];
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection#getSelectedContexts(java.lang.Class)
+ */
+ @Override
+ public ISelectionContext[] getSelectedContexts(Class<?> type) {
+ List<ISelectionContext> contexts = new ArrayList<ISelectionContext>();
+
+ for (ISelectionContext selectionContext : getSelectedContexts()) {
+ if (type.isInstance(selectionContext)) {
+ contexts.add(selectionContext);
+ }
+ }
+
+ return contexts.toArray(new ISelectionContext[contexts.size()]);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ boolean equals = obj instanceof ILaunchSelection;
+
+ if (equals) {
+ ILaunchSelection otherSelection = (ILaunchSelection)obj;
+ // Launch mode must be the same
+ equals &= mode == null && otherSelection.getLaunchMode() == null || mode != null && mode.equals(otherSelection.getLaunchMode());
+
+ // And all selection contexts must be the same
+ ISelectionContext[] c1 = getSelectedContexts();
+ ISelectionContext[] c2 = otherSelection.getSelectedContexts();
+
+ equals &= c1.length == c2.length;
+
+ int i = 0;
+ while (equals && i < c1.length) {
+ equals &= c1[i].equals(c2[i]);
+ i++;
+ }
+ }
+
+ return equals;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ int hashCode = 0;
+
+ if (mode != null) hashCode = mode.hashCode() << 16;
+
+ for (ISelectionContext context : getSelectedContexts()) {
+ hashCode = hashCode ^ context.hashCode();
+ }
+
+ return hashCode;
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/ProjectSelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/ProjectSelectionContext.java
new file mode 100644
index 000000000..eb40a2e31
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/ProjectSelectionContext.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.selection;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.IProjectSelectionContext;
+
+/**
+ * Project launch selection context implementation.
+*/
+public class ProjectSelectionContext extends AbstractSelectionContext implements IProjectSelectionContext {
+ // The projectCtx context
+ private IProject projectCtx;
+
+ /**
+ * Constructor.
+ *
+ * @param project The project context or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public ProjectSelectionContext(IProject project, boolean isPreferred) {
+ this(project, null, isPreferred);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param project The project context or <code>null</code>.
+ * @param selections The selected objects or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public ProjectSelectionContext(IProject project, Object[] selections, boolean isPreferred) {
+ super(selections, isPreferred);
+ this.projectCtx = project;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.IProjectSelectionContext#getProjectCtx()
+ */
+ @Override
+ public IProject getProjectCtx() {
+ return projectCtx;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ if (projectCtx != null) {
+ toString.append(projectCtx.getName());
+ }
+ toString.append(toString.length() > 0 ? " " : ""); //$NON-NLS-1$ //$NON-NLS-2$
+ toString.append(super.toString());
+
+ return toString.toString();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/TargetSelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/TargetSelectionContext.java
new file mode 100644
index 000000000..fc274a83a
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/TargetSelectionContext.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.selection;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.tcf.te.launch.core.selection.interfaces.ITargetSelectionContext;
+
+/**
+ * Target selection context implementation.
+ */
+public class TargetSelectionContext extends AbstractSelectionContext implements ITargetSelectionContext {
+ // The target context
+ private IAdaptable targetCtx = null;
+
+ /**
+ * Constructor.
+ *
+ * @param target The target context or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public TargetSelectionContext(IAdaptable target, boolean isPreferred) {
+ this(target, null, isPreferred);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param target The target context or <code>null</code>.
+ * @param selections The selected objects or <code>null</code>.
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public TargetSelectionContext(IAdaptable target, Object[] selections, boolean isPreferred) {
+ super(selections, isPreferred);
+ this.targetCtx = target;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.launch.core.selection.interfaces.ITargetSelectionContext#getTargetCtx()
+ */
+ @Override
+ public IAdaptable getTargetCtx() {
+ return targetCtx;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuffer toString = new StringBuffer();
+
+ if (targetCtx != null) {
+ toString.append(targetCtx.toString());
+ }
+ toString.append(toString.length() > 0 ? " " : ""); //$NON-NLS-1$ //$NON-NLS-2$
+ toString.append(super.toString());
+
+ return toString.toString();
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ILaunchSelection.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ILaunchSelection.java
new file mode 100644
index 000000000..11c34cd19
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ILaunchSelection.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.selection.interfaces;
+
+
+/**
+ * A launch selection.
+ */
+public interface ILaunchSelection {
+
+ /**
+ * Returns the launch mode for which the selection has been created.
+ *
+ * @return The launch mode or <code>null</code>
+ */
+ public String getLaunchMode();
+
+ /**
+ * Returns all contexts for this selection.
+ *
+ * @return An array with all selection contexts or an empty array.
+ */
+ public ISelectionContext[] getSelectedContexts();
+
+ /**
+ * Returns all contexts of a specified type for this selection.
+ *
+ * @return An array with all selection contexts of the specified type, or an empty array.
+ */
+ public ISelectionContext[] getSelectedContexts(Class<?> type);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/IProjectSelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/IProjectSelectionContext.java
new file mode 100644
index 000000000..558fb669f
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/IProjectSelectionContext.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.selection.interfaces;
+
+import org.eclipse.core.resources.IProject;
+
+/**
+ * A selection context providing the project context for the launch.
+ */
+public interface IProjectSelectionContext extends ISelectionContext {
+
+ /**
+ * Returns the project context.
+ *
+ * @return The project context or <code>null</code>.
+ */
+ public IProject getProjectCtx();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ISelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ISelectionContext.java
new file mode 100644
index 000000000..67b4b5549
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ISelectionContext.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.selection.interfaces;
+
+/**
+ * A selection context.
+ */
+public interface ISelectionContext {
+
+ /**
+ * Returns all selected objects within the selected context.
+ *
+ * @param An array containing all selected objects, or <code>null</code>.
+ */
+ public Object[] getSelections();
+
+ /**
+ * Returns the type of this selection context.
+ *
+ * @param The type or <code>null</code>.
+ */
+ public String getType();
+
+ /**
+ * Sets the preferred context flag.
+ *
+ * @param isPreferred <code>True</code> to mark the selection context the preferred context,
+ * <code>false</code> otherwise.
+ */
+ public void setIsPreferredContext(boolean isPreferred);
+
+ /**
+ * Return <code>true</code>, if this context is the preferred one. Preferred contexts always
+ * needs to be positively validated. If a context is _NOT_ marked as preferred, a selection
+ * should be valid even when this context is not valid.
+ * <p>
+ * The mechanism of preferred contexts is used for launch action enablement and to find/create
+ * launch configurations. A launch action should be enabled if at least the preferred contexts
+ * are valid, but for find/create, also not preferred contexts are used if valid. If not valid
+ * they should be ignored.
+ */
+ public boolean isPreferredContext();
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ITargetSelectionContext.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ITargetSelectionContext.java
new file mode 100644
index 000000000..ea345599e
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/selection/interfaces/ITargetSelectionContext.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.selection.interfaces;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * A selection context providing the target context for the launch.
+ */
+public interface ITargetSelectionContext extends ISelectionContext {
+
+ /**
+ * Returns the target context.
+ *
+ * @return The target context or <code>null</code>.
+ */
+ public IAdaptable getTargetCtx();
+}

Back to the top