Skip to main content
summaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorKen Ryall2006-11-17 20:48:56 +0000
committerKen Ryall2006-11-17 20:48:56 +0000
commit6bb8c371a602d13a52cbee84140fc626c9e4981a (patch)
tree4ddae41d0818fbd49e1a251505e636d76afb33ad /debug
parentf9e33d53fcb53718bc252ef72be8b4068b357296 (diff)
downloadorg.eclipse.cdt-6bb8c371a602d13a52cbee84140fc626c9e4981a.tar.gz
org.eclipse.cdt-6bb8c371a602d13a52cbee84140fc626c9e4981a.tar.xz
org.eclipse.cdt-6bb8c371a602d13a52cbee84140fc626c9e4981a.zip
Allow import executable wizards to select the default binary parsers. Let the user's file choice auto select a binary parser. Some other cleanup too.
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/AbstractImportExecutableWizard.java137
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutablePageOne.java113
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/importexecutable/ImportExecutableWizard.java34
3 files changed, 116 insertions, 168 deletions
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 7a46b81554a..9a3b0edbe04 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
@@ -11,19 +11,12 @@
package org.eclipse.cdt.debug.ui.importexecutable;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.model.IBinary;
-import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.ICDescriptor;
+import org.eclipse.cdt.core.ICDescriptorOperation;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
-import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
-import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
-import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -37,15 +30,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.ISourceLocator;
-import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
-import org.eclipse.debug.core.sourcelookup.ISourceContainer;
-import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -71,12 +57,16 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
protected ImportExecutablePageTwo pageTwo;
- /**
- * Override this method to add the correct binary parsers to the project.
- * @param newProject - the project created by the wizard
- * @throws CoreException
- */
- public abstract void addBinaryParsers(IProject newProject) throws CoreException;
+ public void addBinaryParsers(IProject newProject) throws CoreException {
+ ICDescriptorOperation op = new ICDescriptorOperation() {
+
+ public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
+ descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
+ descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, pageOne.getSelectedBinaryParserId());
+ }
+ };
+ CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(newProject.getProject(), op, null);
+ }
/**
* Adds the executables to a new or existing project. The executables are
@@ -108,82 +98,6 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
addPage(pageTwo);
}
- private void addSourceLocation(ISourceLocator locator, AbstractSourceLookupDirector director, IPath unitLocation)
- {
- if (unitLocation.toFile().exists()) {
- boolean found = false;
- String unitLocationPathString = unitLocation.toOSString();
- if (locator instanceof ICSourceLocator)
- found = (((ICSourceLocator) locator).findSourceElement(unitLocationPathString) != null);
- else if (locator instanceof CSourceLookupDirector)
- found = ((CSourceLookupDirector) locator).contains(unitLocationPathString);
-
- if (!found) {
-
- DirectorySourceContainer directoryContainer = new DirectorySourceContainer(
- unitLocation.removeLastSegments(1), false);
- ArrayList containerList = new ArrayList(Arrays.asList(director
- .getSourceContainers()));
- containerList.add(directoryContainer);
- director.setSourceContainers((ISourceContainer[]) containerList
- .toArray(new ISourceContainer[containerList.size()]));
- }
- }
- }
-
- protected void addSourceLocations(IBinary[] binaries, ILaunchConfigurationWorkingCopy configuration) {
-
- String memento = null;
- String type = null;
- try {
- memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null);
- type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null);
- if (type == null) {
- type = configuration.getType().getSourceLocatorId();
- }
-
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ISourceLocator locator = launchManager.newSourceLocator(type);
- if (locator instanceof AbstractSourceLookupDirector) {
- AbstractSourceLookupDirector director = (AbstractSourceLookupDirector) locator;
- if (memento == null) {
- director.initializeDefaults(configuration);
- } else {
- director.initializeFromMemento(memento, configuration);
- }
-
- for (int i = 0; i < binaries.length; i++) {
- IBinary binary = binaries[i];
- if (!binary.getPath().lastSegment().startsWith(".")) {
- addSourceLocation(locator, director, binary.getUnderlyingResource().getLocation());
- List sourceFiles;
- sourceFiles = binary.getChildrenOfType(ICElement.C_UNIT);
- if (sourceFiles.size() == 0)
- {
- sourceFiles = binary.getChildrenOfType(ICElement.C_UNIT);
- }
- for (Iterator iter = sourceFiles.iterator(); iter.hasNext();) {
- Object element = (Object) iter.next();
- if (element instanceof ExternalTranslationUnit) {
- ExternalTranslationUnit unit = (ExternalTranslationUnit) element;
- IPath unitLocation = unit.getLocation();
- addSourceLocation(locator, director, unitLocation);
- }
-
- }
-
- }
- }
- configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, director.getMemento());
- configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, director.getId());
-
- }
- } catch (CoreException e) {
- return;
- }
-
- }
-
public IProject createCProjectForExecutable(String projectName) throws OperationCanceledException, CoreException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
@@ -207,7 +121,6 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, new File(getImportExecutablePage()
.getSelectedExecutables()[0]).getName());
- addSourceLocations(targetProject.getBinaryContainer().getBinaries(), wc);
setConfigurationDefaults(wc);
final IStructuredSelection selection = new StructuredSelection(wc.doSave());
@@ -256,8 +169,6 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
setWindowTitle(getDefaultWindowTitle());
setNeedsProgressMonitor(true);
}
-
- public abstract boolean isExecutableFile(File file);
public boolean performFinish() {
@@ -314,4 +225,28 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
public abstract boolean supportsConfigurationType(
ILaunchConfigurationType type);
+ /**
+ * Return true if you want the wizard to ask the user to select
+ * the binary parser. Otherwise it will only use the default one.
+ * A subclass can specify the default parser by overriding
+ * getDefaultBinaryParserID.
+ * @return - If the binary parser selection combo should be displayed.
+ */
+ public boolean userSelectsBinaryParser() {
+ return true;
+ }
+
+ /** Get the default binary parser the wizard will use to determine if
+ * single file selections are valid and to filter the list for multi
+ * file selection.
+ * @return
+ */
+ public String getDefaultBinaryParserID() {
+ String defaultBinaryParserId = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_BINARY_PARSER);
+ if (defaultBinaryParserId == null || defaultBinaryParserId.length() == 0) {
+ defaultBinaryParserId = CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID;
+ }
+ return defaultBinaryParserId;
+ }
+
}
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 abd3aa62af6..29cd9c111fe 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
@@ -90,6 +90,10 @@ public class ImportExecutablePageOne extends WizardPage {
private String selectedBinaryParserId;
private IBinaryParser selectedBinaryParser;
+
+ private IExtension[] binaryParserExtensions;
+
+ private Combo binaryParserCombo;
public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) {
super("ImportApplicationPageOne");
@@ -98,10 +102,7 @@ public class ImportExecutablePageOne extends WizardPage {
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;
- }
+ selectedBinaryParserId = wizard.getDefaultBinaryParserID();
try {
// should return the parser for the above id
@@ -109,6 +110,23 @@ public class ImportExecutablePageOne extends WizardPage {
} catch (CoreException e) {
CDebugUIPlugin.log(e);
}
+
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID);
+ if (point != null)
+ {
+ IExtension[] exts = point.getExtensions();
+ ArrayList extensionsInUse = new ArrayList();
+ for (int i = 0; i < exts.length; i++) {
+ if (isExtensionVisible(exts[i])) {
+ extensionsInUse.add(exts[i]);
+ if (exts[i].getUniqueIdentifier().equals(selectedBinaryParserId))
+ selectedBinaryParser = instantiateBinaryParser(exts[i]);
+ }
+ }
+ binaryParserExtensions = (IExtension[]) extensionsInUse.toArray(new IExtension[extensionsInUse.size()]);
+ }
+
+
}
public String getSelectedBinaryParserId() {
@@ -134,15 +152,13 @@ public class ImportExecutablePageOne extends WizardPage {
return false;
monitor.subTask(directory.getPath());
File[] contents = directory.listFiles();
- // first look for project description files
for (int i = 0; i < contents.length; i++) {
File file = contents[i];
- if (file.isFile() && isBinary(file)) {
+ if (file.isFile() && isBinary(file, selectedBinaryParser)) {
files.add(file);
}
}
- // no project description found, so recurse into sub-directories
for (int i = 0; i < contents.length; i++) {
if (contents[i].isDirectory())
collectExecutableFiles(files, contents[i], monitor);
@@ -170,7 +186,8 @@ public class ImportExecutablePageOne extends WizardPage {
selectExecutableGroup.setLayoutData(new GridData(
GridData.FILL_HORIZONTAL));
- createSelectBinaryParser(selectExecutableGroup);
+ if (wizard.userSelectsBinaryParser())
+ createSelectBinaryParser(selectExecutableGroup);
createSelectExecutable(selectExecutableGroup);
createExecutablesRoot(selectExecutableGroup);
createExecutablesList(workArea);
@@ -289,31 +306,27 @@ 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)
+
+ if (binaryParserExtensions.length == 0)
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;
+ binaryParserCombo = new Combo(workArea, SWT.READ_ONLY);
+ final IExtension[] exts = binaryParserExtensions;
+ for (int i = 0; i < exts.length; i++) {
+ binaryParserCombo.add(exts[i].getLabel());
+ if (selectedBinaryParserId.equals(exts[i].getUniqueIdentifier()))
+ binaryParserCombo.select(i);
}
- }
- combo.addSelectionListener(new SelectionListener() {
+
+ binaryParserCombo.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
- instantiateBinaryParser(exts[combo.getSelectionIndex()]);
+ selectedBinaryParser = instantiateBinaryParser(exts[binaryParserCombo.getSelectionIndex()]);
if (selectSingleFile) {
String path = singleExecutablePathField.getText();
if (path.length() > 0)
@@ -325,8 +338,6 @@ public class ImportExecutablePageOne extends WizardPage {
}
});
- combo.select(0);
-
// Dummy to fill out the third column
new Label(workArea, SWT.NONE);
}
@@ -349,20 +360,20 @@ public class ImportExecutablePageOne extends WizardPage {
return false; // invalid extension definition (must have at least cextension elements)
}
- private void instantiateBinaryParser(IExtension ext) {
+ private IBinaryParser instantiateBinaryParser(IExtension ext) {
+ IBinaryParser parser = null;
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");
+ parser = (IBinaryParser)children[j].createExecutableExtension("class");
} catch (CoreException e) {
CDebugUIPlugin.log(e);
}
- if (selectedBinaryParser != null)
- return;
}
}
+ return parser;
}
private void createSelectExecutable(Composite workArea) {
@@ -555,11 +566,11 @@ public class ImportExecutablePageOne extends WizardPage {
executablesViewer.setCheckedElements(executables);
setPageComplete(executables.length > 0);
}
-
- private boolean isBinary(File file) {
- if (selectedBinaryParser != null) {
+
+ private boolean isBinary(File file, IBinaryParser parser) {
+ if (parser != null) {
try {
- IBinaryParser.IBinaryFile bin = selectedBinaryParser.getBinary(new Path(file.getAbsolutePath()));
+ IBinaryParser.IBinaryFile bin = parser.getBinary(new Path(file.getAbsolutePath()));
return bin.getType() == IBinaryParser.IBinaryFile.EXECUTABLE
|| bin.getType() == IBinaryParser.IBinaryFile.SHARED;
} catch (IOException e) {
@@ -568,6 +579,42 @@ public class ImportExecutablePageOne extends WizardPage {
} else
return false;
}
+
+ /**
+ * Checks to see if the file is a valid binary recognized by any of the
+ * available binary parsers. If the currently selected parser doesn't work
+ * it checks the other parsers. If another recognizes the file then the
+ * selected binary parser is changed accordingly.
+ * The effect is to allow the user's file choice to trump the binary
+ * parser selection since most people will have a better idea of what
+ * file they want to select and may not know which binary parser to try.
+ * @param file - the executable file.
+ * @return - is it recognized by any of the binary parsers?
+ */
+ private boolean isBinary(File file) {
+ if (selectedBinaryParser != null) {
+ if (isBinary(file, selectedBinaryParser))
+ return true;
+ else
+ {
+ // See if any of the other parsers will work with this file.
+ // If so, pick the first one that will.
+ for (int i = 0; i < binaryParserExtensions.length; i++) {
+ IBinaryParser parser = instantiateBinaryParser(binaryParserExtensions[i]);
+ if (isBinary(file, parser))
+ {
+ selectedBinaryParserId = binaryParserExtensions[i].getUniqueIdentifier();
+ selectedBinaryParser = parser;
+ if (binaryParserCombo != null)
+ binaryParserCombo.select(i);
+ return true;
+ }
+ }
+ return false;
+ }
+ } else
+ return false;
+ }
private void validateExe(String path) {
setErrorMessage(null);
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 b0ce7a5c667..c517fb22fc1 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
@@ -10,15 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.debug.ui.importexecutable;
-import java.io.File;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.ICDescriptor;
-import org.eclipse.cdt.core.ICDescriptorOperation;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.swt.widgets.FileDialog;
@@ -49,17 +40,6 @@ public class ImportExecutableWizard extends AbstractImportExecutableWizard {
dialog.setFilterNames(new String[] { Messages.ImportExecutableWizard_AllFiles, Messages.ImportExecutableWizard_Applications, Messages.ImportExecutableWizard_LIbaries });
}
- public void addBinaryParsers(IProject newProject) throws CoreException {
- ICDescriptorOperation op = new ICDescriptorOperation() {
-
- public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
- descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
- 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")
// Just for fun, lets support QNX launches too.
@@ -67,18 +47,4 @@ public class ImportExecutableWizard extends AbstractImportExecutableWizard {
|| 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))
- return true; // File extension not needed on Mac OS.
- if (filename.endsWith(".exe") || filename.endsWith(".dll")
- || filename.endsWith(".elf"))
- return true;
- return false;
- }
-
}

Back to the top