mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 05:45:58 +02:00
Improvements to the import executable wizard.
This commit is contained in:
parent
79b98179f3
commit
d5061c1162
3 changed files with 196 additions and 218 deletions
|
@ -11,19 +11,12 @@
|
||||||
package org.eclipse.cdt.debug.ui.importexecutable;
|
package org.eclipse.cdt.debug.ui.importexecutable;
|
||||||
|
|
||||||
import java.io.File;
|
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.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.IBinary;
|
import org.eclipse.cdt.core.ICDescriptor;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.ICDescriptorOperation;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
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.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -36,16 +29,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.core.runtime.jobs.IJobManager;
|
||||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
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.debug.ui.DebugUITools;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.jface.viewers.StructuredSelection;
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
|
@ -71,12 +60,44 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
|
|
||||||
protected ImportExecutablePageTwo pageTwo;
|
protected ImportExecutablePageTwo pageTwo;
|
||||||
|
|
||||||
/**
|
private String parserID;
|
||||||
* Override this method to add the correct binary parsers to the project.
|
|
||||||
* @param newProject - the project created by the wizard
|
|
||||||
* @throws CoreException
|
private void waitForJob(String name)
|
||||||
*/
|
{
|
||||||
public abstract void addBinaryParsers(IProject newProject) throws CoreException;
|
IJobManager jobMan = Platform.getJobManager();
|
||||||
|
Job[] jobs = jobMan.find(null);
|
||||||
|
|
||||||
|
for (int i = 0; i < jobs.length; i++) {
|
||||||
|
if (jobs[i].getName().equals(name)) {
|
||||||
|
try {
|
||||||
|
jobs[i].join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitForDescSave() {
|
||||||
|
String taskName = CCorePlugin.getResourceString("CDescriptorManager.async_updater"); //$NON-NLS-1$
|
||||||
|
waitForJob(taskName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBinaryParsers(IProject newProject) throws CoreException {
|
||||||
|
ICDescriptorOperation op = new ICDescriptorOperation() {
|
||||||
|
|
||||||
|
public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
|
||||||
|
descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, parserID);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
String[] parserIDs = pageOne.getSupportedBinaryParserIds();
|
||||||
|
for (int i = 0; i < parserIDs.length; i++) {
|
||||||
|
parserID = parserIDs[i];
|
||||||
|
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(newProject.getProject(), op, null);
|
||||||
|
waitForDescSave();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the executables to a new or existing project. The executables are
|
* Adds the executables to a new or existing project. The executables are
|
||||||
|
@ -108,82 +129,6 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
addPage(pageTwo);
|
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 {
|
public IProject createCProjectForExecutable(String projectName) throws OperationCanceledException, CoreException {
|
||||||
|
|
||||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
@ -203,12 +148,7 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
ILaunchConfigurationWorkingCopy wc = this.getSelectedLaunchConfigurationType().newInstance(null,
|
ILaunchConfigurationWorkingCopy wc = this.getSelectedLaunchConfigurationType().newInstance(null,
|
||||||
this.getImportExecutablePage2().getNewConfigurationName());
|
this.getImportExecutablePage2().getNewConfigurationName());
|
||||||
|
|
||||||
wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, targetProject.getProject().getName());
|
setConfigurationDefaults(wc, targetProject);
|
||||||
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());
|
final IStructuredSelection selection = new StructuredSelection(wc.doSave());
|
||||||
final String identifier = new String("org.eclipse.debug.ui.launchGroup.debug");
|
final String identifier = new String("org.eclipse.debug.ui.launchGroup.debug");
|
||||||
|
@ -257,8 +197,6 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
setNeedsProgressMonitor(true);
|
setNeedsProgressMonitor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isExecutableFile(File file);
|
|
||||||
|
|
||||||
public boolean performFinish() {
|
public boolean performFinish() {
|
||||||
|
|
||||||
ICProject targetProject = null;
|
ICProject targetProject = null;
|
||||||
|
@ -291,10 +229,16 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses should override this method to modify the launch configuration
|
* Subclasses should override this method to modify the launch configuration
|
||||||
* created by the wizard. The default implementation does nothing.
|
* created by the wizard. The default implementation sets up the project
|
||||||
|
* and program names.
|
||||||
* @param config the launch configuration created by the wizard
|
* @param config the launch configuration created by the wizard
|
||||||
|
* @param targetProject
|
||||||
*/
|
*/
|
||||||
public void setConfigurationDefaults(ILaunchConfigurationWorkingCopy config) {
|
public void setConfigurationDefaults(ILaunchConfigurationWorkingCopy config, ICProject project) {
|
||||||
|
|
||||||
|
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getProject().getName());
|
||||||
|
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, new File(getImportExecutablePage()
|
||||||
|
.getSelectedExecutables()[0]).getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,4 +258,28 @@ public abstract class AbstractImportExecutableWizard extends Wizard implements I
|
||||||
public abstract boolean supportsConfigurationType(
|
public abstract boolean supportsConfigurationType(
|
||||||
ILaunchConfigurationType type);
|
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[] getDefaultBinaryParserIDs() {
|
||||||
|
String defaultBinaryParserId = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_BINARY_PARSER);
|
||||||
|
if (defaultBinaryParserId == null || defaultBinaryParserId.length() == 0) {
|
||||||
|
defaultBinaryParserId = CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID;
|
||||||
|
}
|
||||||
|
return new String[] { defaultBinaryParserId };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IBinaryParser;
|
import org.eclipse.cdt.core.IBinaryParser;
|
||||||
|
@ -27,6 +26,7 @@ import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
import org.eclipse.jface.dialogs.Dialog;
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
||||||
|
@ -88,8 +88,12 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
|
|
||||||
private AbstractImportExecutableWizard wizard;
|
private AbstractImportExecutableWizard wizard;
|
||||||
|
|
||||||
private String selectedBinaryParserId;
|
private String[] supportedBinaryParserIds;
|
||||||
private IBinaryParser selectedBinaryParser;
|
private IBinaryParser[] supportedBinaryParsers;
|
||||||
|
|
||||||
|
private IExtension[] binaryParserExtensions;
|
||||||
|
|
||||||
|
private Combo binaryParserCombo;
|
||||||
|
|
||||||
public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) {
|
public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) {
|
||||||
super("ImportApplicationPageOne");
|
super("ImportApplicationPageOne");
|
||||||
|
@ -98,21 +102,33 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
setTitle(wizard.getPageOneTitle());
|
setTitle(wizard.getPageOneTitle());
|
||||||
setDescription(wizard.getPageOneDescription());
|
setDescription(wizard.getPageOneDescription());
|
||||||
|
|
||||||
selectedBinaryParserId = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_BINARY_PARSER);
|
supportedBinaryParserIds = wizard.getDefaultBinaryParserIDs();
|
||||||
if (selectedBinaryParserId == null || selectedBinaryParserId.length() == 0) {
|
|
||||||
selectedBinaryParserId = CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID;
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
binaryParserExtensions = (IExtension[]) extensionsInUse.toArray(new IExtension[extensionsInUse.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
supportedBinaryParsers = new IBinaryParser[supportedBinaryParserIds.length];
|
||||||
// should return the parser for the above id
|
for (int i = 0; i < supportedBinaryParserIds.length; i++) {
|
||||||
selectedBinaryParser = CCorePlugin.getDefault().getDefaultBinaryParser();
|
for (int j = 0; j < binaryParserExtensions.length; j++) {
|
||||||
} catch (CoreException e) {
|
if (binaryParserExtensions[j].getUniqueIdentifier().equals(supportedBinaryParserIds[i]))
|
||||||
CDebugUIPlugin.log(e);
|
supportedBinaryParsers[i] = instantiateBinaryParser(binaryParserExtensions[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelectedBinaryParserId() {
|
}
|
||||||
return selectedBinaryParserId;
|
|
||||||
|
public String[] getSupportedBinaryParserIds() {
|
||||||
|
return supportedBinaryParserIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkControlState() {
|
private void checkControlState() {
|
||||||
|
@ -132,21 +148,22 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
|
|
||||||
if (monitor.isCanceled())
|
if (monitor.isCanceled())
|
||||||
return false;
|
return false;
|
||||||
monitor.subTask(directory.getPath());
|
|
||||||
File[] contents = directory.listFiles();
|
File[] contents = directory.listFiles();
|
||||||
// first look for project description files
|
monitor.subTask(directory.getPath());
|
||||||
|
SubProgressMonitor sm = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||||
|
sm.beginTask(directory.getPath(), contents.length);
|
||||||
for (int i = 0; i < contents.length; i++) {
|
for (int i = 0; i < contents.length; i++) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return false;
|
||||||
File file = contents[i];
|
File file = contents[i];
|
||||||
if (file.isFile() && isBinary(file)) {
|
sm.worked(1);
|
||||||
|
if (contents[i].isDirectory())
|
||||||
|
collectExecutableFiles(files, contents[i], monitor);
|
||||||
|
else if (file.isFile() && isBinary(file, false)) {
|
||||||
files.add(file);
|
files.add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no project description found, so recurse into sub-directories
|
sm.done();
|
||||||
for (int i = 0; i < contents.length; i++) {
|
|
||||||
if (contents[i].isDirectory())
|
|
||||||
collectExecutableFiles(files, contents[i], monitor);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +187,7 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
selectExecutableGroup.setLayoutData(new GridData(
|
selectExecutableGroup.setLayoutData(new GridData(
|
||||||
GridData.FILL_HORIZONTAL));
|
GridData.FILL_HORIZONTAL));
|
||||||
|
|
||||||
|
if (wizard.userSelectsBinaryParser())
|
||||||
createSelectBinaryParser(selectExecutableGroup);
|
createSelectBinaryParser(selectExecutableGroup);
|
||||||
createSelectExecutable(selectExecutableGroup);
|
createSelectExecutable(selectExecutableGroup);
|
||||||
createExecutablesRoot(selectExecutableGroup);
|
createExecutablesRoot(selectExecutableGroup);
|
||||||
|
@ -253,12 +271,14 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
|
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
checkControlState();
|
checkControlState();
|
||||||
|
String selectedDirectory = multipleExecutablePathField
|
||||||
|
.getText().trim();
|
||||||
|
setErrorMessage(null);
|
||||||
|
|
||||||
if (!selectSingleFile) {
|
if (selectedDirectory.length() == 0) {
|
||||||
singleExecutablePathField.setText("");
|
|
||||||
noFilesSelected();
|
noFilesSelected();
|
||||||
}
|
} else
|
||||||
|
updateExecutablesList(selectedDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -289,44 +309,38 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSelectBinaryParser(Composite workArea) {
|
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;
|
return;
|
||||||
|
|
||||||
Label label = new Label(workArea, SWT.NONE);
|
Label label = new Label(workArea, SWT.NONE);
|
||||||
label.setText(Messages.ImportExecutablePageOne_SelectBinaryParser);
|
label.setText(Messages.ImportExecutablePageOne_SelectBinaryParser);
|
||||||
|
|
||||||
final Combo combo = new Combo(workArea, SWT.READ_ONLY);
|
binaryParserCombo = new Combo(workArea, SWT.READ_ONLY);
|
||||||
|
final IExtension[] exts = binaryParserExtensions;
|
||||||
final IExtension[] exts = point.getExtensions();
|
for (int i = 0; i < exts.length; i++) {
|
||||||
for (int i = 0, j = 0; i < exts.length; i++) {
|
binaryParserCombo.add(exts[i].getLabel());
|
||||||
if (isExtensionVisible(exts[i])) {
|
if (supportedBinaryParserIds[0].equals(exts[i].getUniqueIdentifier()))
|
||||||
exts[j] = exts[i];
|
binaryParserCombo.select(i);
|
||||||
combo.add(exts[j].getLabel());
|
|
||||||
if (selectedBinaryParserId.equals(exts[j].getUniqueIdentifier()))
|
|
||||||
combo.select(j);
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
combo.addSelectionListener(new SelectionListener() {
|
|
||||||
|
binaryParserCombo.addSelectionListener(new SelectionListener() {
|
||||||
public void widgetDefaultSelected(SelectionEvent e) {
|
public void widgetDefaultSelected(SelectionEvent e) {
|
||||||
}
|
}
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
instantiateBinaryParser(exts[combo.getSelectionIndex()]);
|
supportedBinaryParsers[0] = instantiateBinaryParser(exts[binaryParserCombo.getSelectionIndex()]);
|
||||||
if (selectSingleFile) {
|
if (selectSingleFile) {
|
||||||
String path = singleExecutablePathField.getText();
|
String path = singleExecutablePathField.getText();
|
||||||
if (path.length() > 0)
|
if (path.length() > 0)
|
||||||
validateExe(path);
|
validateExe(path);
|
||||||
} else {
|
} else {
|
||||||
previouslySearchedDirectory = null;
|
previouslySearchedDirectory = null;
|
||||||
updateExecutablesList(multipleExecutablePathField.getText());
|
updateExecutablesList(multipleExecutablePathField.getText().trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
combo.select(0);
|
|
||||||
|
|
||||||
// Dummy to fill out the third column
|
// Dummy to fill out the third column
|
||||||
new Label(workArea, SWT.NONE);
|
new Label(workArea, SWT.NONE);
|
||||||
}
|
}
|
||||||
|
@ -349,20 +363,20 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
return false; // invalid extension definition (must have at least cextension elements)
|
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();
|
IConfigurationElement[] elements = ext.getConfigurationElements();
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
IConfigurationElement[] children = elements[i].getChildren("run"); //$NON-NLS-1$
|
IConfigurationElement[] children = elements[i].getChildren("run"); //$NON-NLS-1$
|
||||||
for (int j = 0; j < children.length; j++) {
|
for (int j = 0; j < children.length; j++) {
|
||||||
try {
|
try {
|
||||||
selectedBinaryParser = (IBinaryParser)children[j].createExecutableExtension("class");
|
parser = (IBinaryParser)children[j].createExecutableExtension("class");
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CDebugUIPlugin.log(e);
|
CDebugUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
if (selectedBinaryParser != null)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSelectExecutable(Composite workArea) {
|
private void createSelectExecutable(Composite workArea) {
|
||||||
|
@ -374,8 +388,10 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
checkControlState();
|
checkControlState();
|
||||||
if (selectSingleFile) {
|
if (selectSingleFile) {
|
||||||
multipleExecutablePathField.setText("");
|
if (singleExecutablePathField.getText().trim().length() == 0)
|
||||||
noFilesSelected();
|
noFilesSelected();
|
||||||
|
else
|
||||||
|
validateExe(singleExecutablePathField.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -433,7 +449,7 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
selectAll.setText(Messages.ImportExecutablePageOne_SelectAll);
|
selectAll.setText(Messages.ImportExecutablePageOne_SelectAll);
|
||||||
selectAll.addSelectionListener(new SelectionAdapter() {
|
selectAll.addSelectionListener(new SelectionAdapter() {
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
executablesViewer.setCheckedElements(executables);
|
executablesViewer.setAllChecked(true);
|
||||||
setPageComplete(executables.length > 0);
|
setPageComplete(executables.length > 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -445,7 +461,7 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
deselectAll.addSelectionListener(new SelectionAdapter() {
|
deselectAll.addSelectionListener(new SelectionAdapter() {
|
||||||
public void widgetSelected(SelectionEvent e) {
|
public void widgetSelected(SelectionEvent e) {
|
||||||
|
|
||||||
executablesViewer.setCheckedElements(new Object[0]);
|
executablesViewer.setAllChecked(false);
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -502,7 +518,7 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
protected void noFilesSelected() {
|
protected void noFilesSelected() {
|
||||||
executables = new File[0];
|
executables = new File[0];
|
||||||
executablesViewer.refresh(true);
|
executablesViewer.refresh(true);
|
||||||
executablesViewer.setCheckedElements(executables);
|
executablesViewer.setAllChecked(false);
|
||||||
previouslySearchedDirectory = "";
|
previouslySearchedDirectory = "";
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
}
|
}
|
||||||
|
@ -521,27 +537,16 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
getContainer().run(true, true, new IRunnableWithProgress() {
|
getContainer().run(true, true, new IRunnableWithProgress() {
|
||||||
public void run(IProgressMonitor monitor) {
|
public void run(IProgressMonitor monitor) {
|
||||||
|
|
||||||
monitor.beginTask(Messages.ImportExecutablePageOne_Searching, 100);
|
monitor.beginTask(Messages.ImportExecutablePageOne_Searching, IProgressMonitor.UNKNOWN);
|
||||||
File directory = new File(path);
|
File directory = new File(path);
|
||||||
executables = new File[0];
|
executables = new File[0];
|
||||||
monitor.worked(10);
|
|
||||||
if (directory.isDirectory()) {
|
if (directory.isDirectory()) {
|
||||||
|
|
||||||
Collection files = new ArrayList();
|
Collection files = new ArrayList();
|
||||||
if (!collectExecutableFiles(files, directory, monitor))
|
if (!collectExecutableFiles(files, directory, monitor))
|
||||||
return;
|
return;
|
||||||
Iterator filesIterator = files.iterator();
|
executables = (File[]) files.toArray(new File[files.size()]);
|
||||||
executables = new File[files.size()];
|
|
||||||
int index = 0;
|
|
||||||
monitor.worked(50);
|
|
||||||
monitor.subTask(Messages.ImportExecutablePageOne_ProcessingResults);
|
|
||||||
while (filesIterator.hasNext()) {
|
|
||||||
File file = (File) filesIterator.next();
|
|
||||||
executables[index] = file;
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
monitor.worked(60);
|
|
||||||
monitor.done();
|
monitor.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,16 +557,18 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
executablesViewer.refresh(true);
|
executablesViewer.refresh(true);
|
||||||
executablesViewer.setCheckedElements(executables);
|
executablesViewer.setAllChecked(true);
|
||||||
setPageComplete(executables.length > 0);
|
setPageComplete(executables.length > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBinary(File file) {
|
private boolean isBinary(File file, IBinaryParser parser) {
|
||||||
if (selectedBinaryParser != null) {
|
if (parser != null) {
|
||||||
try {
|
try {
|
||||||
IBinaryParser.IBinaryFile bin = selectedBinaryParser.getBinary(new Path(file.getAbsolutePath()));
|
IBinaryParser.IBinaryFile bin = parser.getBinary(new Path(file
|
||||||
return bin.getType() == IBinaryParser.IBinaryFile.EXECUTABLE
|
.getAbsolutePath()));
|
||||||
|| bin.getType() == IBinaryParser.IBinaryFile.SHARED;
|
return bin != null
|
||||||
|
&& (bin.getType() == IBinaryParser.IBinaryFile.EXECUTABLE || bin
|
||||||
|
.getType() == IBinaryParser.IBinaryFile.SHARED);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -569,13 +576,50 @@ public class ImportExecutablePageOne extends WizardPage {
|
||||||
return false;
|
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, boolean checkOthers) {
|
||||||
|
|
||||||
|
for (int i = 0; i < supportedBinaryParsers.length; i++) {
|
||||||
|
if (isBinary(file, supportedBinaryParsers[i]))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// See if any of the other parsers will work with this file.
|
||||||
|
// If so, pick the first one that will. Only do this if the user
|
||||||
|
// is picking the binary parser.
|
||||||
|
if (checkOthers && binaryParserCombo != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < binaryParserExtensions.length; i++) {
|
||||||
|
IBinaryParser parser = instantiateBinaryParser(binaryParserExtensions[i]);
|
||||||
|
if (isBinary(file, parser))
|
||||||
|
{
|
||||||
|
supportedBinaryParserIds[0] = binaryParserExtensions[i].getUniqueIdentifier();
|
||||||
|
supportedBinaryParsers[0] = parser;
|
||||||
|
binaryParserCombo.select(i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void validateExe(String path) {
|
private void validateExe(String path) {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
setPageComplete(false);
|
setPageComplete(false);
|
||||||
if (path.length() > 0) {
|
if (path.length() > 0) {
|
||||||
File testFile = new File(path);
|
File testFile = new File(path);
|
||||||
if (testFile.exists()) {
|
if (testFile.exists()) {
|
||||||
if (isBinary(testFile))
|
if (isBinary(testFile, true))
|
||||||
{
|
{
|
||||||
executables = new File[1];
|
executables = new File[1];
|
||||||
executables[0] = testFile;
|
executables[0] = testFile;
|
||||||
|
|
|
@ -10,15 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.debug.ui.importexecutable;
|
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.debug.core.ILaunchConfigurationType;
|
||||||
import org.eclipse.swt.widgets.FileDialog;
|
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 });
|
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) {
|
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.
|
// Just for fun, lets support QNX launches too.
|
||||||
|
@ -67,18 +47,4 @@ public class ImportExecutableWizard extends AbstractImportExecutableWizard {
|
||||||
|| type.getIdentifier().startsWith("com.qnx");
|
|| 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue