diff options
author | Markus Duft | 2016-12-07 06:54:18 +0000 |
---|---|---|
committer | Sarika Sinha | 2016-12-07 10:20:19 +0000 |
commit | bd6503285deeb6942a57d08ab72922a45cfd045c (patch) | |
tree | 6944276fde45f4b277064052b85491876b98eb09 | |
parent | dfad55953942a8bcd712e7287ddf9d3f809c5ada (diff) | |
download | eclipse.platform.debug-bd6503285deeb6942a57d08ab72922a45cfd045c.tar.gz eclipse.platform.debug-bd6503285deeb6942a57d08ab72922a45cfd045c.tar.xz eclipse.platform.debug-bd6503285deeb6942a57d08ab72922a45cfd045c.zip |
Fix self reference validation even for indirect self referenceI20161207-0800
Bug: 508726
Change-Id: Ia3bcd2355f47cf357fa31e17e28a909db648672f
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
3 files changed, 49 insertions, 3 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java index 93095e320..8839fa73c 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation 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 @@ -242,6 +242,8 @@ public class DebugUIMessages extends NLS { public static String GroupLaunch_Cannot_launch; public static String GroupLaunch_Cycle; public static String GroupLaunch_Error; + public static String GroupLaunchConfigurationSelectionDialog_0; + public static String GroupLaunchConfigurationSelectionDialog_10; public static String GroupLaunchConfigurationSelectionDialog_11; public static String GroupLaunchConfigurationSelectionDialog_12; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties index 04df7fa8d..b8fe2e5cb 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIMessages.properties @@ -116,6 +116,7 @@ GoToAddressDialog_GoToAddress = Go To Address... GroupLaunch_Cannot_launch=Cannot launch ''{0}'' in the ''{1}'' mode GroupLaunch_Cycle=Infinite loop detected for ''{0}'' group GroupLaunch_Error=Error +GroupLaunchConfigurationSelectionDialog_0=The selected launch contains a direct or indirect reference to this group GroupLaunchConfigurationSelectionDialog_4=Launch Mode: GroupLaunchConfigurationSelectionDialog_5=Use default mode when launching GroupLaunchConfigurationSelectionDialog_7=Select a launch configuration diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java index 4c80c80b5..c6f4c58ef 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/groups/GroupLaunchConfigurationSelectionDialog.java @@ -23,6 +23,7 @@ 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.debug.internal.core.groups.GroupLaunchConfigurationDelegate; import org.eclipse.debug.internal.core.groups.GroupLaunchElement; import org.eclipse.debug.internal.core.groups.GroupLaunchElement.GroupElementPostLaunchAction; import org.eclipse.debug.internal.ui.DebugUIMessages; @@ -66,6 +67,8 @@ import org.eclipse.ui.dialogs.PatternFilter; * Dialog to select launch configuration(s) */ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements ISelectionChangedListener { + private static final String GROUP_TYPE_ID = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType"; //$NON-NLS-1$ + private ISelection fSelection; private ILaunchGroup[] launchGroups; private String mode; @@ -78,6 +81,8 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements private Text fDelayAmountWidget; // in seconds private boolean fForEditing; // true if dialog was opened to edit an entry, // otherwise it was opened to add one + private ILaunchConfigurationType groupType; + private ILaunchConfiguration selfRef; public GroupLaunchConfigurationSelectionDialog(Shell shell, String initMode, boolean forEditing, ILaunchConfiguration self) { super(shell); @@ -85,14 +90,17 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements launchGroups = manager.getLaunchGroups(); mode = initMode; fForEditing = forEditing; + selfRef = self; setShellStyle(getShellStyle() | SWT.RESIZE); + + groupType = getLaunchManager().getLaunchConfigurationType(GROUP_TYPE_ID); emptyTypeFilter = new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { try { if (element instanceof ILaunchConfigurationType) { ILaunchConfigurationType type = (ILaunchConfigurationType) element; - if (type.equals(self.getType())) { + if (type.equals(groupType)) { // we're hiding ourselves. if we're the only group, // don't show the type. return getLaunchManager().getLaunchConfigurations(type).length > 1; @@ -101,7 +109,7 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements return getLaunchManager().getLaunchConfigurations(type).length > 0; } else if (element instanceof ILaunchConfiguration) { ILaunchConfiguration c = (ILaunchConfiguration) element; - if (c.getName().equals(self.getName()) && c.getType().equals(self.getType())) { + if (c.getName().equals(self.getName()) && c.getType().equals(groupType)) { return false; } @@ -336,6 +344,18 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements } } + try { + for (ILaunchConfiguration sel : getSelectedLaunchConfigurations()) { + if (isValid && sel.getType().equals(groupType)) { + // check whether there is a recursive reference to self + isValid = !hasSelfRecursive(sel); + setErrorMessage(isValid ? null : DebugUIMessages.GroupLaunchConfigurationSelectionDialog_0); + } + } + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + if (isValid) { if (action == GroupElementPostLaunchAction.DELAY) { isValid = (actionParam instanceof Integer) && ((Integer) actionParam > 0); @@ -348,6 +368,29 @@ class GroupLaunchConfigurationSelectionDialog extends TitleAreaDialog implements } } + private boolean hasSelfRecursive(ILaunchConfiguration c) throws CoreException { + if (c == null) { + return false; + } + + if(c.getType().equals(groupType)) { + // it's a launch group + if (c.getName().equals(selfRef.getName())) { + return true; + } + + // recurse to all elements of the group + for (GroupLaunchElement e : GroupLaunchConfigurationDelegate.createLaunchElements(c)) { + // if any of the contained configs is self + if (hasSelfRecursive(e.data)) { + return true; + } + } + } + + return false; + } + public void setInitialSelection(GroupLaunchElement el) { action = el.action; actionParam = el.actionParam; |