From 833f436400f758d2cb0dc3517c2b2c800400f18f Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Wed, 8 Apr 2009 22:43:46 +0000 Subject: [PATCH] Bug 202006. --- .../cdt/launch/AbstractCLaunchDelegate.java | 17 +----- .../org/eclipse/cdt/launch/LaunchUtils.java | 55 +++++++++++++++++++ .../eclipse/cdt/launch/ui/CDebuggerTab.java | 31 +---------- .../org/eclipse/cdt/launch/ui/CMainTab.java | 17 +----- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java index 77f7d83e342..01caa800fba 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java @@ -800,26 +800,11 @@ abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegat * @throws CoreException */ protected IBinaryObject verifyBinary(ICProject proj, IPath exePath) throws CoreException { - ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(proj.getProject()); - for (int i = 0; i < parserRef.length; i++) { - try { - IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension(); - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); - if (exe != null) { - return exe; - } - } catch (ClassCastException e) { - } catch (IOException e) { - } - } - IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser(); Exception exception; try { - return (IBinaryObject)parser.getBinary(exePath); + return LaunchUtils.getBinary(proj.getProject(), exePath); } catch (ClassCastException e) { exception = e; - } catch (IOException e) { - exception = e; } Status status = new Status(IStatus.ERROR,getPluginID(), ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY, diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java index 149aec8bb4b..d616f693bc5 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/LaunchUtils.java @@ -10,12 +10,22 @@ *******************************************************************************/ package org.eclipse.cdt.launch; +import java.io.IOException; + import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.utils.CommandLineUtil; +import org.eclipse.core.resources.IProject; +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.variables.IStringVariableManager; import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.ICExtensionReference; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; /** * Utility methods. @@ -40,7 +50,52 @@ public class LaunchUtils { } return args; } + + public static IBinaryObject getBinary(IProject project, IPath exePath) throws CoreException { + ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project); + for (int i = 0; i < parserRef.length; i++) { + try { + IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension(); + IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); + if (exe != null) { + return exe; + } + } catch (ClassCastException e) { + } catch (IOException e) { + } + } + IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser(); + try { + IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); + return exe; + } catch (ClassCastException e) { + } catch (IOException e) { + } + return null; + } + + public static IBinaryObject getBinary(String programName, String projectName) + throws CoreException + { + if (programName != null ) { + IPath exePath = new Path(programName); + IProject project = null; + if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$ + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (project == null || project.getLocation() == null) + { + return null; + } + if (!exePath.isAbsolute()) { + exePath = project.getLocation().append(exePath); + } + } + return getBinary(project, exePath); + } + return null; + } + /** * Convenience method. */ diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java index 0357677ba6b..74c823d9b39 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CDebuggerTab.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; import org.eclipse.cdt.debug.core.ICDebugConstants; import org.eclipse.cdt.debug.ui.ICDebuggerPage; +import org.eclipse.cdt.launch.LaunchUtils; import org.eclipse.cdt.launch.internal.ui.AbstractCDebuggerTab; import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; @@ -372,35 +373,7 @@ public class CDebuggerTab extends AbstractCDebuggerTab { } catch (CoreException e) { } if (programName != null ) { - IPath exePath = new Path(programName); - if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$ - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - if (!project.isAccessible()) { - return null; - } - if (!exePath.isAbsolute()) { - exePath = project.getLocation().append(exePath); - } - ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project); - for (int i = 0; i < parserRef.length; i++) { - try { - IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension(); - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); - if (exe != null) { - return exe; - } - } catch (ClassCastException e) { - } catch (IOException e) { - } - } - } - IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser(); - try { - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); - return exe; - } catch (ClassCastException e) { - } catch (IOException e) { - } + return LaunchUtils.getBinary(programName, projectName); } return null; } diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java index 8e4c9dbb07c..ad5b86a7f8a 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.launch.LaunchUtils; import org.eclipse.cdt.launch.internal.ui.LaunchImages; import org.eclipse.cdt.launch.internal.ui.LaunchMessages; import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin; @@ -679,24 +680,10 @@ public class CMainTab extends CLaunchConfigurationTab { * @throws CoreException */ protected boolean isBinary(IProject project, IPath exePath) throws CoreException { - ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project); - for (int i = 0; i < parserRef.length; i++) { - try { - IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension(); - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); - if (exe != null) { - return true; - } - } catch (ClassCastException e) { - } catch (IOException e) { - } - } - IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser(); try { - IBinaryObject exe = (IBinaryObject)parser.getBinary(exePath); + IBinaryObject exe = LaunchUtils.getBinary(project, exePath); return exe != null; } catch (ClassCastException e) { - } catch (IOException e) { } return false; }