Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2008-09-25 17:36:25 -0400
committereutarass2008-09-25 17:36:25 -0400
commitc6d9344ab3988164cf6008d45fc80f83036a5f51 (patch)
treedfa526ecb45363f3f7cd3df4dcab43ce41ee5a34 /plugins/org.eclipse.tm.tcf.cdt.ui
parenta3e68f01b6d211fc5832e695037a562a7a65af2d (diff)
downloadorg.eclipse.tcf-c6d9344ab3988164cf6008d45fc80f83036a5f51.tar.gz
org.eclipse.tcf-c6d9344ab3988164cf6008d45fc80f83036a5f51.tar.xz
org.eclipse.tcf-c6d9344ab3988164cf6008d45fc80f83036a5f51.zip
New extension point: org.eclipse.tm.tcf.debug.ui.launch.context - for integration with development tools.
New plug-in: org.eclipse.tm.tcf.cdt.ui - contains TCF/CDT integration code. TCF Launch Configuration is improved: now supports: default values from current CDT project, search of executable files in CDT projects, download of executable file to remote target.
Diffstat (limited to 'plugins/org.eclipse.tm.tcf.cdt.ui')
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/.classpath7
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/.project28
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.core.prefs18
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.ui.prefs4
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/META-INF/MANIFEST.MF19
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/about.html28
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/build.properties9
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/plugin.properties12
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/plugin.xml9
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/Activator.java76
-rw-r--r--plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/TCFLaunchContext.java326
11 files changed, 536 insertions, 0 deletions
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/.classpath b/plugins/org.eclipse.tm.tcf.cdt.ui/.classpath
new file mode 100644
index 000000000..64c5e31b7
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/.project b/plugins/org.eclipse.tm.tcf.cdt.ui/.project
new file mode 100644
index 000000000..5cbeef203
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.tm.tcf.cdt.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..e115508c0
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,18 @@
+#Mon Sep 22 12:28:22 PDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.cleanOutputFolder=clean
+org.eclipse.jdt.core.builder.duplicateResourceTask=warning
+org.eclipse.jdt.core.builder.invalidClasspath=abort
+org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore
+org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch,.svn/
+org.eclipse.jdt.core.circularClasspath=error
+org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
+org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.incompatibleJDKLevel=ignore
+org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 000000000..547f1a097
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,4 @@
+#Tue Sep 23 17:25:53 PDT 2008
+eclipse.preferences.version=1
+formatter_profile=_Java STD
+formatter_settings_version=11
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.tm.tcf.cdt.ui/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..6837b4167
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.tm.tcf.cdt.ui;singleton:=true
+Bundle-Version: 0.2.0
+Bundle-Activator: org.eclipse.tm.internal.tcf.cdt.ui.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.debug.core,
+ org.eclipse.cdt.core,
+ org.eclipse.core.resources,
+ org.eclipse.cdt.debug.core,
+ org.eclipse.debug.ui,
+ org.eclipse.cdt.ui,
+ org.eclipse.tm.tcf.debug,
+ org.eclipse.tm.tcf.debug.ui
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/about.html b/plugins/org.eclipse.tm.tcf.cdt.ui/about.html
new file mode 100644
index 000000000..6c5b3615b
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>January 10, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/build.properties b/plugins/org.eclipse.tm.tcf.cdt.ui/build.properties
new file mode 100644
index 000000000..43883590f
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ about.html,\
+ plugin.properties
+src.includes = about.html
+ \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.properties b/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.properties
new file mode 100644
index 000000000..c4fbf4d03
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.properties
@@ -0,0 +1,12 @@
+###############################################################################
+# Copyright (c) 2007, 2008 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 implementation
+###############################################################################
+pluginName=TCF/CDT Integration UI (Incubation)
+providerName=Eclipse.org
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.xml b/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.xml
new file mode 100644
index 000000000..3871f04ea
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/plugin.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+ <extension point="org.eclipse.tm.tcf.debug.ui.launch_context">
+ <class name="org.eclipse.tm.internal.tcf.cdt.ui.TCFLaunchContext" />
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/Activator.java b/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/Activator.java
new file mode 100644
index 000000000..9a5060fcd
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/Activator.java
@@ -0,0 +1,76 @@
+package org.eclipse.tm.internal.tcf.cdt.ui;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.tm.tcf.cdt.ui";
+ private static Activator plugin;
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
+ }
+
+ public static IWorkbenchWindow getActiveWorkbenchWindow() {
+ return getDefault().getWorkbench().getActiveWorkbenchWindow();
+ }
+
+ public static IWorkbenchPage getActivePage() {
+ IWorkbenchWindow w = getActiveWorkbenchWindow();
+ if (w != null) {
+ return w.getActivePage();
+ }
+ return null;
+ }
+
+ public static Shell getActiveWorkbenchShell() {
+ IWorkbenchWindow window = getActiveWorkbenchWindow();
+ if (window != null) {
+ return window.getShell();
+ }
+ return null;
+ }
+
+ public static void errorDialog(String message, IStatus status) {
+ log(status);
+ Shell shell = getActiveWorkbenchShell();
+ if (shell == null) return;
+ ErrorDialog.openError(shell, "Error", message, status);
+ }
+
+ public static void errorDialog(String message, Throwable t) {
+ log(t);
+ Shell shell = getActiveWorkbenchShell();
+ if (shell == null) return;
+ IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, 1, t.getMessage(), null);
+ ErrorDialog.openError(shell, "Error", message, status);
+ }
+}
diff --git a/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/TCFLaunchContext.java b/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/TCFLaunchContext.java
new file mode 100644
index 000000000..83c5fb75a
--- /dev/null
+++ b/plugins/org.eclipse.tm.tcf.cdt.ui/src/org/eclipse/tm/internal/tcf/cdt/ui/TCFLaunchContext.java
@@ -0,0 +1,326 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tm.internal.tcf.cdt.ui;
+
+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;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.IBinary;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tm.internal.tcf.debug.launch.TCFLaunchDelegate;
+import org.eclipse.tm.internal.tcf.debug.ui.launch.ITCFLaunchContext;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.dialogs.TwoPaneElementSelector;
+
+public class TCFLaunchContext implements ITCFLaunchContext {
+
+ public boolean isActive() {
+ return getContext(null) != null;
+ }
+
+ public boolean isSupportedProject(IProject project) {
+ return CoreModel.getDefault().getCModel().getCProject(project.getName()) != null;
+ }
+
+ public void setDefaults(ILaunchConfigurationDialog dlg, ILaunchConfigurationWorkingCopy config) {
+ ICElement cElement = getContext(config);
+ if (cElement != null) {
+ initializeCProject(cElement, config);
+ initializeProgramName(cElement, dlg, config);
+ }
+ }
+
+ /**
+ * Returns the current C element context from which to initialize default
+ * settings, or <code>null</code> if none. Note, if possible we will
+ * return the IBinary based on configuration entry as this may be more useful then
+ * just the project.
+ *
+ * @return C element context.
+ */
+ private ICElement getContext(ILaunchConfiguration config) {
+ String projectName = null;
+ String programName = null;
+ if (config != null) {
+ try {
+ projectName = config.getAttribute(TCFLaunchDelegate.ATTR_PROJECT_NAME, (String)null);
+ programName = config.getAttribute(TCFLaunchDelegate.ATTR_LOCAL_PROGRAM_FILE, (String)null);
+ }
+ catch (CoreException e) {
+ Activator.log(e);
+ }
+ }
+ Object obj = null;
+ IWorkbenchPage page = Activator.getActivePage();
+ if (projectName != null && !projectName.equals("")) { //$NON-NLS-1$
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ ICProject cProject = CCorePlugin.getDefault().getCoreModel().create(project);
+ if (cProject != null && cProject.exists()) obj = cProject;
+ }
+ else {
+ if (page != null) {
+ ISelection selection = page.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ if (!ss.isEmpty()) obj = ss.getFirstElement();
+ }
+ }
+ }
+ if (obj instanceof IResource) {
+ ICElement ce = CoreModel.getDefault().create((IResource)obj);
+ if (ce == null) {
+ IProject pro = ((IResource)obj).getProject();
+ ce = CoreModel.getDefault().create(pro);
+ }
+ obj = ce;
+ }
+ if (obj instanceof ICElement) {
+ if (programName == null || programName.equals("")) { //$NON-NLS-1$
+ return (ICElement)obj;
+ }
+ ICElement ce = (ICElement)obj;
+ IProject project;
+ project = (IProject)ce.getCProject().getResource();
+ IPath programFile = project.getFile(programName).getLocation();
+ ce = CCorePlugin.getDefault().getCoreModel().create(programFile);
+ if (ce != null && ce.exists()) return ce;
+ return (ICElement)obj;
+ }
+ IEditorPart part = page.getActiveEditor();
+ if (part != null) {
+ IEditorInput input = part.getEditorInput();
+ return (ICElement)input.getAdapter(ICElement.class);
+ }
+ return null;
+ }
+
+ /**
+ * Set the C project attribute based on the ICElement.
+ */
+ private void initializeCProject(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
+ ICProject cProject = cElement.getCProject();
+ String name = null;
+ if (cProject != null && cProject.exists()) {
+ name = cProject.getElementName();
+ config.setMappedResources(new IResource[] {cProject.getProject()});
+ }
+ config.setAttribute(TCFLaunchDelegate.ATTR_PROJECT_NAME, name);
+ }
+
+ /**
+ * Set the program name attributes on the working copy based on the ICElement
+ */
+ private void initializeProgramName(ICElement cElement, ILaunchConfigurationDialog dlg, ILaunchConfigurationWorkingCopy config) {
+
+ boolean renamed = false;
+
+ if (!(cElement instanceof IBinary)) {
+ cElement = cElement.getCProject();
+ }
+
+ if (cElement instanceof ICProject) {
+
+ IProject project = cElement.getCProject().getProject();
+ String name = project.getName();
+ ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
+ if (projDes != null) {
+ String buildConfigName = projDes.getActiveConfiguration().getName();
+ name = name + " " + buildConfigName; //$NON-NLS-1$
+ }
+ name = dlg.generateName(name);
+ config.rename(name);
+ renamed = true;
+ }
+
+ IBinary binary = null;
+ if (cElement instanceof ICProject) {
+ IBinary[] bins = getBinaryFiles((ICProject)cElement);
+ if (bins != null && bins.length == 1) {
+ binary = bins[0];
+ }
+ }
+ else if (cElement instanceof IBinary) {
+ binary = (IBinary)cElement;
+ }
+
+ if (binary != null) {
+ String path;
+ path = binary.getResource().getProjectRelativePath().toOSString();
+ config.setAttribute(TCFLaunchDelegate.ATTR_LOCAL_PROGRAM_FILE, path);
+ if (!renamed)
+ {
+ String name = binary.getElementName();
+ int index = name.lastIndexOf('.');
+ if (index > 0) {
+ name = name.substring(0, index);
+ }
+ name = dlg.generateName(name);
+ config.rename(name);
+ renamed = true;
+ }
+ }
+
+ if (!renamed) {
+ String name = dlg.generateName(cElement.getCProject().getElementName());
+ config.rename(name);
+ }
+ }
+
+ public String getBuildConfigID(IProject project) {
+ ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
+ if (projDes == null) return null;
+ return projDes.getActiveConfiguration().getId();
+ }
+
+ /**
+ * Iterate through and suck up all of the executable files that we can find.
+ */
+ private IBinary[] getBinaryFiles(final ICProject cproject) {
+ if (cproject == null || !cproject.exists()) return null;
+ final Display display = Display.getCurrent();
+ final Object[] ret = new Object[1];
+ BusyIndicator.showWhile(display, new Runnable() {
+
+ public void run() {
+ try {
+ ret[0] = cproject.getBinaryContainer().getBinaries();
+ }
+ catch (CModelException e) {
+ Activator.errorDialog("Launch UI internal error", e);
+ }
+ }
+ });
+ return (IBinary[])ret[0];
+ }
+
+ /**
+ * Return true if given file path names a binary file.
+ * @param project
+ * @param exePath
+ * @return true if binary file.
+ * @throws CoreException
+ */
+ public 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();
+ if ((IBinaryObject)parser.getBinary(exePath) != null) return true;
+ }
+ catch (Exception e) {
+ }
+ }
+ IBinaryParser parser = CCorePlugin.getDefault().getDefaultBinaryParser();
+ try {
+ return (IBinaryObject)parser.getBinary(exePath) != null;
+ }
+ catch (Exception e) {
+ }
+ return false;
+ }
+
+ public String chooseBinary(Shell shell, IProject project) {
+ ILabelProvider programLabelProvider = new CElementLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getPath().lastSegment());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (! (element instanceof ICElement)) {
+ return super.getImage(element);
+ }
+ ICElement celement = (ICElement)element;
+
+ if (celement.getElementType() == ICElement.C_BINARY) {
+ IBinary belement = (IBinary)celement;
+ if (belement.isExecutable()) {
+ return DebugUITools.getImage(IDebugUIConstants.IMG_ACT_RUN);
+ }
+ }
+
+ return super.getImage(element);
+ }
+ };
+
+ ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof IBinary) {
+ IBinary bin = (IBinary)element;
+ StringBuffer name = new StringBuffer();
+ name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); //$NON-NLS-1$ //$NON-NLS-2$
+ name.append(" - "); //$NON-NLS-1$
+ name.append(bin.getPath().toString());
+ return name.toString();
+ }
+ return super.getText(element);
+ }
+ };
+
+ TwoPaneElementSelector dialog = new TwoPaneElementSelector(shell, programLabelProvider, qualifierLabelProvider);
+ dialog.setElements(getBinaryFiles(getCProject(project.getName())));
+ dialog.setMessage("Choose program to run");
+ dialog.setTitle("Program Selection");
+ dialog.setUpperListLabel("Binaries:");
+ dialog.setLowerListLabel("Qualifier:");
+ dialog.setMultipleSelection(false);
+ // dialog.set
+ if (dialog.open() != Window.OK) return null;
+ IBinary binary = (IBinary)dialog.getFirstResult();
+ return binary.getResource().getProjectRelativePath().toString();
+ }
+
+ /**
+ * Return the ICProject corresponding to the project name in the project name text field, or
+ * null if the text does not match a project name.
+ */
+ private ICProject getCProject(String name) {
+ String projectName = name.trim();
+ if (projectName.length() < 1) return null;
+ return CoreModel.getDefault().getCModel().getCProject(projectName);
+ }
+}

Back to the top