diff options
author | Uwe Stieber | 2015-04-21 13:18:21 +0000 |
---|---|---|
committer | Uwe Stieber | 2015-04-21 13:18:21 +0000 |
commit | c96a68bc93de76395dd227e4e0cd977fee660eb2 (patch) | |
tree | 0c29f43449e1c57f874334567c8f34ff521a6701 | |
parent | df8b5472db1628957b6356dcea5786beaaede391 (diff) | |
download | org.eclipse.tcf-c96a68bc93de76395dd227e4e0cd977fee660eb2.tar.gz org.eclipse.tcf-c96a68bc93de76395dd227e4e0cd977fee660eb2.tar.xz org.eclipse.tcf-c96a68bc93de76395dd227e4e0cd977fee660eb2.zip |
Target Explorer: Fix Hidden launch configurations not deleted once the connection is deleted
7 files changed, 161 insertions, 4 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/DeletedEvent.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/DeletedEvent.java new file mode 100644 index 000000000..973a70563 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/DeletedEvent.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2015 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.tcf.core.events; + +import java.util.EventObject; + +import org.eclipse.core.runtime.Assert; + +/** + * Peer node deleted notification event. + */ +public class DeletedEvent extends EventObject { + private static final long serialVersionUID = 109800157682115887L; + private final Object node; + + /** + * Constructor + * + * @param source The event source. Must not be <code>null</code>. + * @param commandId The command id. Must not be <code>null</code>. + */ + public DeletedEvent(Object source, Object node) { + super(source); + + Assert.isNotNull(node); + this.node = node; + } + + /** + * Returns the peer node. + * + * @return The peer node. + */ + public final Object getPeerNode() { + return node; + } +}
\ No newline at end of file diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF index 23d3b356c..a308191ad 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/META-INF/MANIFEST.MF @@ -31,6 +31,7 @@ Export-Package: org.eclipse.tcf.te.tcf.launch.core.activator;x-internal:=true, org.eclipse.tcf.te.tcf.launch.core.filetransfer, org.eclipse.tcf.te.tcf.launch.core.interfaces, org.eclipse.tcf.te.tcf.launch.core.interfaces.steps, + org.eclipse.tcf.te.tcf.launch.core.internal;x-internal:=true, org.eclipse.tcf.te.tcf.launch.core.internal.adapters;x-internal:=true, org.eclipse.tcf.te.tcf.launch.core.internal.services, org.eclipse.tcf.te.tcf.launch.core.lm.delegates, diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml index 761c85133..b39cdd498 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/plugin.xml @@ -41,6 +41,22 @@ <serviceType class="org.eclipse.tcf.te.tcf.core.interfaces.IPathMapService"/> </service> </extension> + +<!-- Event listener contributions --> + <extension point="org.eclipse.tcf.te.runtime.eventListeners"> + <eventListener + class="org.eclipse.tcf.te.tcf.launch.core.internal.EventListener" + forcePluginActivation="true"> + <eventSourceType + class="org.eclipse.tcf.te.tcf.ui.handler.DeleteHandler" + bundleId="org.eclipse.tcf.te.tcf.ui"> + </eventSourceType> + <eventType + class="org.eclipse.tcf.te.tcf.core.events.DeletedEvent" + bundleId="org.eclipse.tcf.te.tcf.core"> + </eventType> + </eventListener> + </extension> <!-- Launch Configuration Type contributions --> <extension point="org.eclipse.debug.core.launchConfigurationTypes"> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListener.java new file mode 100644 index 000000000..98a8f86fd --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/EventListener.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2015 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.tcf.launch.core.internal; + +import java.util.EventObject; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.tcf.core.events.DeletedEvent; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; + +/** + * Event listener implementation. + */ +public class EventListener implements IEventListener { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.runtime.interfaces.events.IEventListener#eventFired(java.util.EventObject) + */ + @Override + public void eventFired(EventObject event) { + if (event instanceof DeletedEvent) { + IPeerNode node = (IPeerNode) ((DeletedEvent) event).getPeerNode(); + ILaunchConfiguration configuration = node != null ? (ILaunchConfiguration) node.getAdapter(ILaunchConfiguration.class) : null; + if (configuration != null) { + try { + configuration.delete(); + } catch (CoreException e) { + e.printStackTrace(); + /* Ignored on purpose */ + } + } + } + } + +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/AttachLaunchConfigAdapter.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/AttachLaunchConfigAdapter.java index b4a191e35..61ba22ac0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/AttachLaunchConfigAdapter.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.launch.core/src/org/eclipse/tcf/te/tcf/launch/core/internal/adapters/AttachLaunchConfigAdapter.java @@ -10,10 +10,16 @@ package org.eclipse.tcf.te.tcf.launch.core.internal.adapters; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.launch.core.lm.LaunchManager; import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchManagerDelegate; import org.eclipse.tcf.te.launch.core.lm.interfaces.ILaunchSpecification; @@ -22,13 +28,24 @@ import org.eclipse.tcf.te.launch.core.selection.RemoteSelectionContext; import org.eclipse.tcf.te.launch.core.selection.interfaces.ILaunchSelection; import org.eclipse.tcf.te.tcf.launch.core.interfaces.ILaunchTypes; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; /** * AttachLaunchConfigAdapter */ public class AttachLaunchConfigAdapter { - public ILaunchConfiguration getAttachLaunchConfig(IPeerNode peer) { + public ILaunchConfiguration getAttachLaunchConfig(final IPeerNode peer) { + final AtomicReference<String> name = new AtomicReference<String>(); + final AtomicBoolean isDeleted = new AtomicBoolean(); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + isDeleted.set(peer.getBooleanProperty(IPeerNodeProperties.PROPERTY_IS_DELETED)); + name.set(peer.getName()); + } + }); + ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(ILaunchTypes.ATTACH); ILaunchSelection launchSelection = new LaunchSelection(ILaunchManager.DEBUG_MODE, new RemoteSelectionContext(peer, true)); ILaunchManagerDelegate delegate = LaunchManager.getInstance().getLaunchManagerDelegate(launchConfigType, ILaunchManager.DEBUG_MODE); @@ -38,15 +55,27 @@ public class AttachLaunchConfigAdapter { try { launchConfigs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(launchConfigType); - launchConfigs = delegate.getMatchingLaunchConfigurations(launchSpec, launchConfigs); + // WB4-5394: Using getMatchingLaunchConfiguration is too heavy weight here as it does a lot + // XML parsing. It's more accurate, but the attach launch configuration has the + // same name as the connection, so we look for the connection name first. + List<ILaunchConfiguration> candidates = new ArrayList<ILaunchConfiguration>(); + for (ILaunchConfiguration candidate : launchConfigs) { + if (candidate.getName().equals(name.get())) { + candidates.add(candidate); + break; + } + } + if (candidates.size() > 0) launchConfigs = candidates.toArray(new ILaunchConfiguration[candidates.size()]); + else launchConfigs = delegate.getMatchingLaunchConfigurations(launchSpec, launchConfigs); } catch (Exception e) { } ILaunchConfiguration config = launchConfigs != null && launchConfigs.length > 0 ? launchConfigs[0] : null; - try { - config = LaunchManager.getInstance().createOrUpdateLaunchConfiguration(config, launchSpec); + if (config != null || !isDeleted.get()) { + config = LaunchManager.getInstance().createOrUpdateLaunchConfiguration(config, launchSpec); + } } catch (Exception e) { } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java index 2fb5956ed..4c3508f8e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerNodeProperties.java @@ -48,6 +48,11 @@ public interface IPeerNodeProperties { public static final String PROPERTY_IS_VALID = "isValid"; //$NON-NLS-1$ /** + * Property: The peer node deleted state. Set to "true" if the peer node got deleted. + */ + public static final String PROPERTY_IS_DELETED = "isDeleted"; //$NON-NLS-1$ + + /** * Property: Error if peer node is not valid (String) */ public static final String PROPERTY_ERROR = "Error"; //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java index 7390874be..a1e2b778d 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.ui/src/org/eclipse/tcf/te/tcf/ui/handler/DeleteHandler.java @@ -33,13 +33,16 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.callback.Callback; +import org.eclipse.tcf.te.runtime.events.EventManager; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; import org.eclipse.tcf.te.runtime.services.ServiceManager; import org.eclipse.tcf.te.runtime.services.ServiceUtils; import org.eclipse.tcf.te.runtime.statushandler.StatusHandlerUtil; import org.eclipse.tcf.te.runtime.utils.StatusHelper; +import org.eclipse.tcf.te.tcf.core.events.DeletedEvent; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; import org.eclipse.tcf.te.tcf.locator.model.ModelManager; import org.eclipse.tcf.te.tcf.ui.help.IContextHelpIds; @@ -147,6 +150,8 @@ public class DeleteHandler extends AbstractHandler { // The operation types public enum TYPE { Remove, Unlink } + // The parent delete handler + public DeleteHandler parentHandler; // The element to operate on public IPeerNode node; // The operation type to perform @@ -179,10 +184,22 @@ public class DeleteHandler extends AbstractHandler { ViewsUtil.setSelection(IUIConstants.ID_EXPLORER, new StructuredSelection(parentCategory)); } + // Mark the peer node as deleted + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + node.setProperty(IPeerNodeProperties.PROPERTY_IS_DELETED, true); + } + }); + // Check if there is a delete handler delegate for the element IDeleteHandlerDelegate delegate = ServiceUtils.getUIServiceDelegate(node, node, IDeleteHandlerDelegate.class); // If a delegate is available, signal the execution of the remove if (delegate != null) delegate.postDelete(node); + + // Send the peer node deleted event to also delete the launch configuration + DeletedEvent event = new DeletedEvent(parentHandler, node); + EventManager.getInstance().fireEvent(event); } else if (TYPE.Unlink.equals(type)) { Assert.isNotNull(parentCategory); @@ -310,6 +327,7 @@ public class DeleteHandler extends AbstractHandler { } op.node = node; op.parentCategory = category; + op.parentHandler = this; operations.add(op); } |