| author | Tobias Schwarz | 2012-07-19 03:45:32 (EDT) |
|---|---|---|
| committer | Uwe Stieber | 2012-07-19 05:15:54 (EDT) |
| commit | 9d7bcf759ff6cdce47259c4547bcd82ae4d13c46 (patch) (side-by-side diff) | |
| tree | c6ddd89f9a4b21c6e5089dd0b3f0c5fe3b563a4c | |
| parent | 1588da08dfedec83e025f8a893cc974d03dd0432 (diff) | |
| download | org.eclipse.tcf-9d7bcf759ff6cdce47259c4547bcd82ae4d13c46.zip org.eclipse.tcf-9d7bcf759ff6cdce47259c4547bcd82ae4d13c46.tar.gz org.eclipse.tcf-9d7bcf759ff6cdce47259c4547bcd82ae4d13c46.tar.bz2 | |
Target Explorer: ADD update peer when attach launch config changes
| -rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/activator/CoreBundleActivator.java | 190 | ||||
| -rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/internal/LaunchConfigurationListenerDelegate.java | 83 | ||||
| -rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/LaunchConfigurationDelegate.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java) | 3 | ||||
| -rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java | 2 | ||||
| -rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java | 77 |
5 files changed, 263 insertions, 92 deletions
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 824fe6f..f4606ec 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 @@ -1,89 +1,101 @@ -/*******************************************************************************
- * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
- * This program and the accompanying materials are made available under the terms
- * of the Eclipse Public License v1.0 which accompanies this distribution, and is
- * available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-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;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class CoreBundleActivator implements BundleActivator {
- // The bundle context
- private static BundleContext context;
- // The scoped preferences instance
- private static volatile ScopedEclipsePreferences scopedPreferences;
- // The trace handler instance
- private static volatile TraceHandler traceHandler;
-
- /**
- * Returns the bundle context
- *
- * @return the bundle context
- */
- public static BundleContext getContext() {
- return context;
- }
-
- /**
- * Convenience method which returns the unique identifier of this plugin.
- */
- public static String getUniqueIdentifier() {
- if (getContext() != null && getContext().getBundle() != null) {
- return getContext().getBundle().getSymbolicName();
- }
- return "org.eclipse.tcf.te.launch.core"; //$NON-NLS-1$
- }
-
- /**
- * 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.
- */
- public static TraceHandler getTraceHandler() {
- if (traceHandler == null) {
- traceHandler = new TraceHandler(getUniqueIdentifier());
- }
- return traceHandler;
- }
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext bundleContext) throws Exception {
- CoreBundleActivator.context = bundleContext;
- }
-
- /*
- * (non-Javadoc)
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext bundleContext) throws Exception {
- CoreBundleActivator.context = null;
- scopedPreferences = null;
- traceHandler = null;
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.launch.core.activator; + +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.tcf.te.launch.core.internal.LaunchConfigurationListenerDelegate; +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; + +/** + * The activator class controls the plug-in life cycle + */ +public class CoreBundleActivator implements BundleActivator { + // The bundle context + private static BundleContext context; + // The scoped preferences instance + private static volatile ScopedEclipsePreferences scopedPreferences; + // The trace handler instance + private static volatile TraceHandler traceHandler; + // The launch config listener to delegate launch config changes to the launch manager delegate + private ILaunchConfigurationListener launchConfigListener; + + + /** + * Returns the bundle context + * + * @return the bundle context + */ + public static BundleContext getContext() { + return context; + } + + /** + * Convenience method which returns the unique identifier of this plugin. + */ + public static String getUniqueIdentifier() { + if (getContext() != null && getContext().getBundle() != null) { + return getContext().getBundle().getSymbolicName(); + } + return "org.eclipse.tcf.te.launch.core"; //$NON-NLS-1$ + } + + /** + * 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. + */ + public static TraceHandler getTraceHandler() { + if (traceHandler == null) { + traceHandler = new TraceHandler(getUniqueIdentifier()); + } + return traceHandler; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext bundleContext) throws Exception { + CoreBundleActivator.context = bundleContext; + + launchConfigListener = new LaunchConfigurationListenerDelegate(); + DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(launchConfigListener); + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext bundleContext) throws Exception { + CoreBundleActivator.context = null; + scopedPreferences = null; + traceHandler = null; + + DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(launchConfigListener); + launchConfigListener = null; + } + +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/internal/LaunchConfigurationListenerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/internal/LaunchConfigurationListenerDelegate.java new file mode 100644 index 0000000..338294e --- a/dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/internal/LaunchConfigurationListenerDelegate.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ + +package org.eclipse.tcf.te.launch.core.internal; + +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.tcf.te.launch.core.lm.LaunchManager; +import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate; + +/** + * LaunchConfigurationListenerDelegate + */ +public class LaunchConfigurationListenerDelegate implements ILaunchConfigurationListener { + + /** + * Constructor. + */ + public LaunchConfigurationListenerDelegate() { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationAdded(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + if (configuration instanceof ILaunchConfigurationWorkingCopy) { + return; + } + ILaunchConfigurationListener listener = getListeningDelegate(configuration); + if (listener != null) { + listener.launchConfigurationAdded(configuration); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationChanged(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + if (configuration instanceof ILaunchConfigurationWorkingCopy) { + return; + } + ILaunchConfigurationListener listener = getListeningDelegate(configuration); + if (listener != null) { + listener.launchConfigurationChanged(configuration); + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationRemoved(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + if (configuration instanceof ILaunchConfigurationWorkingCopy) { + return; + } + ILaunchConfigurationListener listener = getListeningDelegate(configuration); + if (listener != null) { + listener.launchConfigurationRemoved(configuration); + } + } + + private ILaunchConfigurationListener getListeningDelegate(ILaunchConfiguration configuration) { + try { + ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(configuration.getType(), ""); //$NON-NLS-1$ + if (delegate instanceof ILaunchConfigurationListener) { + return (ILaunchConfigurationListener)delegate; + } + } + catch (Exception e) { + } + return null; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/LaunchConfigurationDelegate.java index 5612da6..5b3fd9d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/delegates/LaunchConfigurationDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.launch.core/src/org/eclipse/tcf/te/launch/core/lm/internal/LaunchConfigurationDelegate.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.launch.core.delegates; +package org.eclipse.tcf.te.launch.core.lm.internal; import java.util.ArrayList; import java.util.Date; @@ -36,6 +36,7 @@ import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.osgi.util.NLS; import org.eclipse.tcf.te.launch.core.activator.CoreBundleActivator; import org.eclipse.tcf.te.launch.core.bindings.LaunchConfigTypeBindingsManager; +import org.eclipse.tcf.te.launch.core.delegates.Launch; import org.eclipse.tcf.te.launch.core.interfaces.IReferencedProjectItem; import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes; import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java index 0828722..bd49a0f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/delegates/LaunchConfigurationDelegate.java @@ -34,7 +34,7 @@ import org.eclipse.tcf.util.TCFTask; * <li>The launch configuration delegate creates launches of type {@link Launch}.</li> * </ul> */ -public class LaunchConfigurationDelegate extends org.eclipse.tcf.te.launch.core.delegates.LaunchConfigurationDelegate { +public class LaunchConfigurationDelegate extends org.eclipse.tcf.te.launch.core.lm.internal.LaunchConfigurationDelegate { /* (non-Javadoc) * @see org.eclipse.tcf.te.launch.core.delegates.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java index 9c80438..107c630 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/lm/delegates/AttachLaunchManagerDelegate.java @@ -12,11 +12,18 @@ package org.eclipse.tcf.te.tcf.launch.core.lm.delegates; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationListener; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.tcf.core.AbstractPeer; +import org.eclipse.tcf.core.TransientPeer; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.launch.core.lm.delegates.DefaultLaunchManagerDelegate; import org.eclipse.tcf.te.launch.core.lm.interfaces.ICommonLaunchAttributes; import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchContextLaunchAttributes; @@ -30,13 +37,17 @@ import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistenceDelegate; import org.eclipse.tcf.te.runtime.services.ServiceManager; import org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService; import org.eclipse.tcf.te.runtime.services.interfaces.constants.IPropertiesAccessServiceConstants; +import org.eclipse.tcf.te.tcf.core.peers.Peer; import org.eclipse.tcf.te.tcf.launch.core.interfaces.IPeerModelProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; +import org.eclipse.tcf.te.tcf.locator.model.Model; +import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; /** * RemoteAppLaunchManagerDelegate */ -public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate { +public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate implements ILaunchConfigurationListener { private static final String[] MANDATORY_CONFIG_ATTRIBUTES = new String[] { ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS @@ -184,4 +195,68 @@ public class AttachLaunchManagerDelegate extends DefaultLaunchManagerDelegate { } return 1; } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationAdded(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationChanged(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + try { + IModelNode[] contexts = LaunchContextsPersistenceDelegate.getLaunchContexts(configuration); + if (contexts != null && contexts.length == 1 && contexts[0] instanceof IPeerModel) { + final IPeerModel peerModel = (IPeerModel)contexts[0]; + @SuppressWarnings({ "unchecked", "rawtypes" }) + Map<?,?> attributes = new LinkedHashMap(configuration.getAttributes()); + attributes.remove(ILaunchContextLaunchAttributes.ATTR_LAUNCH_CONTEXTS); + attributes.remove(ICommonLaunchAttributes.ATTR_UUID); + attributes.remove(ICommonLaunchAttributes.ATTR_LAST_LAUNCHED); + attributes.remove(ICommonLaunchAttributes.ATTR_CAPTURE_IN_FILE); + attributes.remove(ICommonLaunchAttributes.ATTR_CAPTURE_OUTPUT); + + String oldLaunchConfigAttributes = peerModel.getPeer().getAttributes().get(IPeerModelProperties.PROP_LAUNCH_CONFIG_ATTRIBUTES); + oldLaunchConfigAttributes = oldLaunchConfigAttributes == null ? "" : oldLaunchConfigAttributes.trim(); //$NON-NLS-1$ + + IPersistenceDelegate delegate = PersistenceManager.getInstance().getDelegate(Map.class, String.class, false); + final String launchConfigAttributes = attributes.isEmpty() ? "" : (String)delegate.write(attributes, String.class, null); //$NON-NLS-1$ + + if (!launchConfigAttributes.equals(oldLaunchConfigAttributes)) { + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + IPeer oldPeer = peerModel.getPeer(); + Map<String, String> attributes = new HashMap<String, String>(peerModel.getPeer().getAttributes()); + if (launchConfigAttributes.trim().length() == 0) { + attributes.remove(IPeerModelProperties.PROP_LAUNCH_CONFIG_ATTRIBUTES); + } + else { + attributes.put(IPeerModelProperties.PROP_LAUNCH_CONFIG_ATTRIBUTES, launchConfigAttributes); + } + IPeer newPeer = new Peer(attributes); + if (oldPeer instanceof TransientPeer && !(oldPeer instanceof AbstractPeer || oldPeer instanceof PeerRedirector || oldPeer instanceof Peer)) { + peerModel.setProperty(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModelProperties.PROP_INSTANCE, newPeer); + } else { + Model.getModel().getService(ILocatorModelUpdateService.class).mergeUserDefinedAttributes(peerModel, newPeer, false); + } + } + }); + } + } + } + catch (Exception e) { + } + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationRemoved(org.eclipse.debug.core.ILaunchConfiguration) + */ + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + } } |

