diff options
author | Mike Rennie | 2013-04-02 17:33:10 +0000 |
---|---|---|
committer | Mike Rennie | 2013-04-02 17:33:10 +0000 |
commit | ea106a0637026d8f1ea946efe04f3687fb96109e (patch) | |
tree | 9b010bd121ab01c030bafbff1702acce8ba291f7 | |
parent | 6ccab5a548647c64ae02fa6140841177c473fef9 (diff) | |
download | eclipse.platform.debug-ea106a0637026d8f1ea946efe04f3687fb96109e.tar.gz eclipse.platform.debug-ea106a0637026d8f1ea946efe04f3687fb96109e.tar.xz eclipse.platform.debug-ea106a0637026d8f1ea946efe04f3687fb96109e.zip |
Bug 395441 - An IAE exception from WorkspaceRoot breaks launch history
toolbar menu
2 files changed, 123 insertions, 16 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java index 7970718ab..9b6f73d1a 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 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 @@ -526,20 +526,22 @@ public class LaunchConfiguration extends PlatformObject implements ILaunchConfig IPath path = Path.fromPortableString(pathStr); IResource res = null; switch (type) { - case IResource.FILE: - res = root.getFile(path); - break; - case IResource.PROJECT: - res = root.getProject(pathStr); - break; - case IResource.FOLDER: - res = root.getFolder(path); - break; - case IResource.ROOT: - res = root; - break; - default: - throw new CoreException(newStatus(DebugCoreMessages.LaunchConfiguration_0, DebugPlugin.ERROR, null)); + case IResource.FILE: + res = root.getFile(path); + break; + case IResource.PROJECT: + if(Path.ROOT.isValidSegment(pathStr)) { + res = root.getProject(pathStr); + } + break; + case IResource.FOLDER: + res = root.getFolder(path); + break; + case IResource.ROOT: + res = root; + break; + default: + throw new CoreException(newStatus(DebugCoreMessages.LaunchConfiguration_0, DebugPlugin.ERROR, null)); } if(res != null) { list.add(res); diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java index 02c6da201..40a148746 100644 --- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java +++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/launching/LaunchConfigurationTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2013 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 @@ -42,6 +42,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; @@ -49,6 +50,7 @@ import org.eclipse.debug.core.ILaunchConfigurationListener; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.internal.core.LaunchConfiguration; import org.eclipse.debug.internal.core.LaunchManager; import org.eclipse.debug.tests.TestsPlugin; import org.eclipse.debug.ui.DebugUITools; @@ -76,6 +78,19 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau protected ILaunchConfiguration fAdded; protected ILaunchConfiguration fRemoved; + /** + * Class to hold resource description infos + * @since 3.9.0 + */ + class ResourceItem { + public ResourceItem(String path, Integer type) { + this.path = path; + this.type = type; + } + String path; + Integer type; + } + class Listener implements ILaunchConfigurationListener { private List addedList = new ArrayList(); @@ -1400,4 +1415,94 @@ public class LaunchConfigurationTests extends AbstractLaunchTest implements ILau assertNotNull("The image descriptior type.image.2 must exist", descriptor); assertNotSame("The image descriptor is not type.image.2", ImageDescriptor.getMissingImageDescriptor(), descriptor); } + + /** + * Tests that we can get a project handle from a project name + * + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395441 + * @throws Exception + * @since 3.9.0 + */ + public void testGetProjectMappedResource1() throws Exception { + ILaunchConfiguration lc = newConfiguration(null, "test.project.resource.mapping"); + try { + ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy(); + assertNotNull("Should have a working copy of the testig launch configuration", wc); + setResourceMappings(wc, new ResourceItem[] {new ResourceItem("test.project", new Integer(IResource.PROJECT))}); + IResource[] res = wc.getMappedResources(); + assertNotNull("There should be mapped resources", res); + assertTrue("There should be one project", res.length == 1); + } + finally { + lc.delete(); + } + } + + /** + * Tests that we can get a project handle from a bogus project name + * + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395441 + * @throws Exception + * @since 3.9.0 + */ + public void testGetProjectMappedResource2() throws Exception { + ILaunchConfiguration lc = newConfiguration(null,"test.project.resource.mapping"); + try { + ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy(); + assertNotNull("Should have a working copy of the testig launch configuration", wc); + setResourceMappings(wc, new ResourceItem[] {new ResourceItem("test/project", new Integer(IResource.PROJECT))}); + IResource[] res = wc.getMappedResources(); + assertNull("There should be no mapped resources", res); + } + finally { + lc.delete(); + } + } + + /** + * Tests that we can get a project handle from a bogus project name + * + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395441 + * @throws Exception + * @since 3.9.0 + */ + public void testGetProjectMappedResource3() throws Exception { + ILaunchConfiguration lc = newConfiguration(null,"test.project.resource.mapping"); + try { + ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy(); + assertNotNull("Should have a working copy of the testig launch configuration", wc); + setResourceMappings(wc, new ResourceItem[] {new ResourceItem("test\\project", new Integer(IResource.PROJECT))}); + IResource[] res = wc.getMappedResources(); + if(Platform.OS_WIN32.equals(Platform.getOS())) { + assertNull("There should be no mapped resources", res); + } + else { + assertNotNull("There should be mapped resources", res); + } + } + finally { + lc.delete(); + } + } + + /** + * Proxy to set resource paths, allowing invalid resource paths to be set + * @param resources + * @since 3.9.0 + */ + protected void setResourceMappings(ILaunchConfigurationWorkingCopy config, ResourceItem[] resources) { + List/*<String>*/ paths = null; + List/*<String>*/ types = null; + int size = resources.length; + if(resources != null && size > 0) { + paths = new ArrayList(size); + types = new ArrayList(size); + for(int i = 0; i < size; i++) { + paths.add(resources[i].path); + types.add(resources[i].type.toString()); + } + } + config.setAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_PATHS, paths); + config.setAttribute(LaunchConfiguration.ATTR_MAPPED_RESOURCE_TYPES, types); + } } |