From 7549d7cec2fc94556c78934259fb58cabef7ea16 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 25 Aug 2006 20:26:05 +0000 Subject: [PATCH] Propogated Import Executable improvements from CDT 3.1. --- debug/org.eclipse.cdt.debug.ui/.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 1 + .../AbstractImportExecutableWizard.java | 4 +- .../ImportExecutablePageOne.java | 161 +++++++++++++++--- .../ImportExecutableWizard.java | 14 +- .../debug/ui/importexecutable/Messages.java | 2 + .../ui/importexecutable/messages.properties | 1 + 8 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/.settings/org.eclipse.jdt.core.prefs diff --git a/debug/org.eclipse.cdt.debug.ui/.classpath b/debug/org.eclipse.cdt.debug.ui/.classpath index 065ac06e197..ce73933404a 100644 --- a/debug/org.eclipse.cdt.debug.ui/.classpath +++ b/debug/org.eclipse.cdt.debug.ui/.classpath @@ -1,7 +1,7 @@ + - diff --git a/debug/org.eclipse.cdt.debug.ui/.settings/org.eclipse.jdt.core.prefs b/debug/org.eclipse.cdt.debug.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..3de7f23405c --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Aug 23 13:41:09 EDT 2006 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning +org.eclipse.jdt.core.compiler.source=1.3 diff --git a/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF index 12e4a3ae5ca..e07c9fb7597 100644 --- a/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF @@ -36,3 +36,4 @@ Require-Bundle: org.eclipse.ui.ide, org.eclipse.ui.console, org.eclipse.ui.views Eclipse-LazyStart: true +Bundle-RequiredExecutionEnvironment: J2SE-1.4 diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/AbstractImportExecutableWizard.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/AbstractImportExecutableWizard.java index 48e972cb439..7a46b81554a 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/AbstractImportExecutableWizard.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/AbstractImportExecutableWizard.java @@ -67,9 +67,9 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I public static final String DEBUG_PROJECT_ID = "org.eclipse.cdt.debug"; //$NON-NLS-1$ - private ImportExecutablePageOne pageOne; + protected ImportExecutablePageOne pageOne; - private ImportExecutablePageTwo pageTwo; + protected ImportExecutablePageTwo pageTwo; /** * Override this method to add the correct binary parsers to the project. diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutablePageOne.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutablePageOne.java index 98f6c7f87a5..abd3aa62af6 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutablePageOne.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutablePageOne.java @@ -11,11 +11,19 @@ package org.eclipse.cdt.debug.ui.importexecutable; import java.io.File; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; @@ -35,9 +43,11 @@ import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.FileDialog; @@ -78,14 +88,33 @@ public class ImportExecutablePageOne extends WizardPage { private AbstractImportExecutableWizard wizard; + private String selectedBinaryParserId; + private IBinaryParser selectedBinaryParser; + public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) { super("ImportApplicationPageOne"); this.wizard = wizard; setPageComplete(false); setTitle(wizard.getPageOneTitle()); setDescription(wizard.getPageOneDescription()); + + selectedBinaryParserId = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_BINARY_PARSER); + if (selectedBinaryParserId == null || selectedBinaryParserId.length() == 0) { + selectedBinaryParserId = CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID; + } + + try { + // should return the parser for the above id + selectedBinaryParser = CCorePlugin.getDefault().getDefaultBinaryParser(); + } catch (CoreException e) { + CDebugUIPlugin.log(e); + } } + public String getSelectedBinaryParserId() { + return selectedBinaryParserId; + } + private void checkControlState() { selectSingleFile = selectSingleButton.getSelection(); singleExecutablePathField.setEnabled(selectSingleFile); @@ -109,7 +138,7 @@ public class ImportExecutablePageOne extends WizardPage { for (int i = 0; i < contents.length; i++) { File file = contents[i]; - if (file.isFile() && wizard.isExecutableFile(file)) { + if (file.isFile() && isBinary(file)) { files.add(file); } } @@ -141,6 +170,7 @@ public class ImportExecutablePageOne extends WizardPage { selectExecutableGroup.setLayoutData(new GridData( GridData.FILL_HORIZONTAL)); + createSelectBinaryParser(selectExecutableGroup); createSelectExecutable(selectExecutableGroup); createExecutablesRoot(selectExecutableGroup); createExecutablesList(workArea); @@ -258,6 +288,83 @@ public class ImportExecutablePageOne extends WizardPage { } + private void createSelectBinaryParser(Composite workArea) { + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID); + if (point == null) + return; + + Label label = new Label(workArea, SWT.NONE); + label.setText(Messages.ImportExecutablePageOne_SelectBinaryParser); + + final Combo combo = new Combo(workArea, SWT.READ_ONLY); + + final IExtension[] exts = point.getExtensions(); + for (int i = 0, j = 0; i < exts.length; i++) { + if (isExtensionVisible(exts[i])) { + exts[j] = exts[i]; + combo.add(exts[j].getLabel()); + if (selectedBinaryParserId.equals(exts[j].getUniqueIdentifier())) + combo.select(j); + ++j; + } + } + + combo.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + } + public void widgetSelected(SelectionEvent e) { + instantiateBinaryParser(exts[combo.getSelectionIndex()]); + if (selectSingleFile) { + String path = singleExecutablePathField.getText(); + if (path.length() > 0) + validateExe(path); + } else { + previouslySearchedDirectory = null; + updateExecutablesList(multipleExecutablePathField.getText()); + } + } + }); + + combo.select(0); + + // Dummy to fill out the third column + new Label(workArea, SWT.NONE); + } + + private static boolean isExtensionVisible(IExtension ext) { + IConfigurationElement[] elements = ext.getConfigurationElements(); + for (int i = 0; i < elements.length; i++) { + IConfigurationElement[] children = elements[i].getChildren("filter"); //$NON-NLS-1$ + for (int j = 0; j < children.length; j++) { + String name = children[j].getAttribute("name"); //$NON-NLS-1$ + if (name != null && name.equals("visibility")) { //$NON-NLS-1$ + String value = children[j].getAttribute("value"); //$NON-NLS-1$ + if (value != null && value.equals("private")) { //$NON-NLS-1$ + return false; + } + } + } + return true; + } + return false; // invalid extension definition (must have at least cextension elements) + } + + private void instantiateBinaryParser(IExtension ext) { + IConfigurationElement[] elements = ext.getConfigurationElements(); + for (int i = 0; i < elements.length; i++) { + IConfigurationElement[] children = elements[i].getChildren("run"); //$NON-NLS-1$ + for (int j = 0; j < children.length; j++) { + try { + selectedBinaryParser = (IBinaryParser)children[j].createExecutableExtension("class"); + } catch (CoreException e) { + CDebugUIPlugin.log(e); + } + if (selectedBinaryParser != null) + return; + } + } + } + private void createSelectExecutable(Composite workArea) { // project specification group @@ -280,24 +387,7 @@ public class ImportExecutablePageOne extends WizardPage { singleExecutablePathField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - setErrorMessage(null); - setPageComplete(false); - String path = singleExecutablePathField.getText(); - if (path.length() > 0) { - File testFile = new File(path); - if (testFile.exists()) { - if (wizard.isExecutableFile(testFile)) - { - executables = new File[1]; - executables[0] = testFile; - setPageComplete(true); - } - else - setErrorMessage(Messages.ImportExecutablePageOne_NoteAnEXE); - } else { - setErrorMessage(Messages.ImportExecutablePageOne_NoSuchFile); - } - } + validateExe(singleExecutablePathField.getText()); } }); @@ -465,4 +555,37 @@ public class ImportExecutablePageOne extends WizardPage { executablesViewer.setCheckedElements(executables); setPageComplete(executables.length > 0); } + + private boolean isBinary(File file) { + if (selectedBinaryParser != null) { + try { + IBinaryParser.IBinaryFile bin = selectedBinaryParser.getBinary(new Path(file.getAbsolutePath())); + return bin.getType() == IBinaryParser.IBinaryFile.EXECUTABLE + || bin.getType() == IBinaryParser.IBinaryFile.SHARED; + } catch (IOException e) { + return false; + } + } else + return false; + } + + private void validateExe(String path) { + setErrorMessage(null); + setPageComplete(false); + if (path.length() > 0) { + File testFile = new File(path); + if (testFile.exists()) { + if (isBinary(testFile)) + { + executables = new File[1]; + executables[0] = testFile; + setPageComplete(true); + } + else + setErrorMessage(Messages.ImportExecutablePageOne_NoteAnEXE); + } else { + setErrorMessage(Messages.ImportExecutablePageOne_NoSuchFile); + } + } + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutableWizard.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutableWizard.java index 62f99f32cd3..b0ce7a5c667 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutableWizard.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutableWizard.java @@ -54,19 +54,23 @@ public class ImportExecutableWizard extends AbstractImportExecutableWizard { public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException { descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID); - if (Platform.getOS().equals(Platform.OS_MACOSX)) - descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, "org.eclipse.cdt.core.MachO"); - else - descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, "org.eclipse.cdt.core.PE"); + descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, pageOne.getSelectedBinaryParserId()); } }; CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(newProject.getProject(), op, null); } public boolean supportsConfigurationType(ILaunchConfigurationType type) { - return type.getIdentifier().startsWith("org.eclipse.cdt.launch"); + return type.getIdentifier().startsWith("org.eclipse.cdt.launch") + // Just for fun, lets support QNX launches too. + // Really points at something missing, no? + || type.getIdentifier().startsWith("com.qnx"); } + /** + * @deprecated this has been replaced by a check of the binary + * parser down in the Wizard page. + */ public boolean isExecutableFile(File file) { String filename = file.getName().toLowerCase(); if (Platform.getOS().equals(Platform.OS_MACOSX)) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/Messages.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/Messages.java index 875719b57d9..4140b156359 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/Messages.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/Messages.java @@ -87,4 +87,6 @@ public class Messages extends NLS { public static String AbstractImportExecutableWizard_windowTitle; public static String AbstractImportExecutableWizard_CreateLaunchConfiguration; + + public static String ImportExecutablePageOne_SelectBinaryParser; } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/messages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/messages.properties index 8a3a18dc747..042ee663fb3 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/messages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/messages.properties @@ -11,6 +11,7 @@ ImportExecutableWizard_pageOneTitle=Import C/C++ Executable Files ImportExecutableWizard_pageOneDescription=Select a file or a directory to search for C/C++ executable files. +ImportExecutablePageOne_SelectBinaryParser=Select binary parser: ImportExecutablePageOne_SelectExecutable=Select executable: ImportExecutablePageOne_SelectADirectory=Select a directory to search for C/C++ executable files. ImportExecutablePageTwo_EnterProjectName=Enter a project name.