diff options
author | Markus Duft | 2017-01-20 12:35:20 +0000 |
---|---|---|
committer | Sarika Sinha | 2017-02-06 08:46:20 +0000 |
commit | ab220976ddfb22a8b3230f3598f6dc0a2baac501 (patch) | |
tree | bfe409dc90926d6224e1d7eadca48fd70e5ddd73 | |
parent | 11d8e4118051e4830ab9676c41821f63848387e5 (diff) | |
download | eclipse.platform.debug-ab220976ddfb22a8b3230f3598f6dc0a2baac501.tar.gz eclipse.platform.debug-ab220976ddfb22a8b3230f3598f6dc0a2baac501.tar.xz eclipse.platform.debug-ab220976ddfb22a8b3230f3598f6dc0a2baac501.zip |
Bug 508718 - Allow groups to catch up with renames in launch configs
This change registers a global listener in the LaunchManager that
handles updating launch groups whenever a member of that group is
renamed.
This relies on the workings of the ILaunchmanager#getMovedFrom method.
Change-Id: Ie1a617b6e826b0a1b6adb0a1b962dc18484f071a
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
3 files changed, 85 insertions, 14 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java index 4009f9a54..fd39a0972 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/core/DebugPlugin.java @@ -68,6 +68,7 @@ import org.eclipse.debug.internal.core.MemoryBlockManager; import org.eclipse.debug.internal.core.Preferences; import org.eclipse.debug.internal.core.StepFilterManager; import org.eclipse.debug.internal.core.commands.CommandAdapterFactory; +import org.eclipse.debug.internal.core.groups.GroupMemberChangeListener; import org.eclipse.debug.internal.core.sourcelookup.SourceLookupUtils; import org.eclipse.osgi.service.environment.Constants; import org.osgi.framework.BundleContext; @@ -713,6 +714,9 @@ public class DebugPlugin extends Plugin { manager.registerAdapters(actionFactory, ILaunch.class); manager.registerAdapters(actionFactory, IProcess.class); manager.registerAdapters(actionFactory, IDebugElement.class); + + // monitor launch configuration renames for launch groups + getLaunchManager().addLaunchConfigurationListener(new GroupMemberChangeListener()); } /** diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/groups/GroupMemberChangeListener.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/groups/GroupMemberChangeListener.java new file mode 100644 index 000000000..84c8eee5d --- /dev/null +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/groups/GroupMemberChangeListener.java @@ -0,0 +1,63 @@ +package org.eclipse.debug.internal.core.groups; + +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationListener; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchManager; + +/** + * Manages renames of launch configurations that are members of group launches + * + * @since 3.11 + */ +public class GroupMemberChangeListener implements ILaunchConfigurationListener { + + private static final String GROUP_TYPE_ID = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType"; //$NON-NLS-1$ + + @Override + public void launchConfigurationAdded(ILaunchConfiguration configuration) { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfiguration original = launchManager.getMovedFrom(configuration); + if (original != null) { + ILaunchConfigurationType type = launchManager.getLaunchConfigurationType(GROUP_TYPE_ID); + if (type == null) { + DebugPlugin.logMessage("cannot find group launch configuration type", null); //$NON-NLS-1$ + return; + } + try { + for (ILaunchConfiguration c : DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type)) { + List<GroupLaunchElement> elements = GroupLaunchConfigurationDelegate.createLaunchElements(c); + boolean updated = false; + for (GroupLaunchElement e : elements) { + if (e.name.equals(original.getName())) { + updated = true; + e.name = configuration.getName(); + } + } + + if (updated) { + ILaunchConfigurationWorkingCopy workingCopy = c.getWorkingCopy(); + GroupLaunchConfigurationDelegate.storeLaunchElements(workingCopy, elements); + workingCopy.doSave(); + } + } + } catch (CoreException e) { + DebugPlugin.log(e); + } + } + } + + @Override + public void launchConfigurationChanged(ILaunchConfiguration configuration) { + } + + @Override + public void launchConfigurationRemoved(ILaunchConfiguration configuration) { + } + +} diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java index b2bb6ce27..41cfda559 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java @@ -5,9 +5,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.core.runtime.CoreException; @@ -274,17 +272,22 @@ public class LaunchGroupTests extends AbstractLaunchTest { assertTrue("history[2] should be Test1", history[2].contentsEqual(t1)); //$NON-NLS-1$ } - protected Set<ILaunch> findRunningLaunch(ILaunchConfiguration cfg) { - Set<ILaunch> result = new HashSet<>(); - for (ILaunch l : getLaunchManager().getLaunches()) { - if (l.isTerminated()) { - continue; - } - if (l.getLaunchConfiguration().equals(cfg)) { - result.add(l); - } - } - return result; + public void testRename() throws Exception { + ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ + ILaunchConfiguration t2 = getLaunchConfiguration("Test2"); //$NON-NLS-1$ + ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, false), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null, false)); + + ILaunchConfigurationWorkingCopy workingCopy = t1.getWorkingCopy(); + workingCopy.rename("AnotherTest"); //$NON-NLS-1$ + workingCopy.doSave(); + + assertTrue("name should not be transiently updated", grp.getName().equals(DEF_GRP_NAME)); //$NON-NLS-1$ + + // need to re-fetch configuration + grp = getLaunchConfiguration(DEF_GRP_NAME); + List<GroupLaunchElement> elements = GroupLaunchConfigurationDelegate.createLaunchElements(grp); + + assertTrue("group element should be updated", elements.get(0).name.equals("AnotherTest")); //$NON-NLS-1$//$NON-NLS-2$ } private static DummyStream attachDummyProcess(final ILaunch l) { @@ -382,8 +385,9 @@ public class LaunchGroupTests extends AbstractLaunchTest { @Override public void launchAdded(ILaunch launch) { - if (launch.getLaunchConfiguration().equals(cfg)) + if (launch.getLaunchConfiguration().equals(cfg)) { stream = attachDummyProcess(launch); + } } @Override |