1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +02:00

Propogated Import Executable improvements from CDT 3.1.

This commit is contained in:
Doug Schaefer 2006-08-25 20:26:05 +00:00
parent e89a4f0149
commit 7549d7cec2
8 changed files with 165 additions and 27 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -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

View file

@ -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

View file

@ -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.

View file

@ -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,12 +88,31 @@ 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() {
@ -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);
}
}
}
}

View file

@ -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))

View file

@ -87,4 +87,6 @@ public class Messages extends NLS {
public static String AbstractImportExecutableWizard_windowTitle;
public static String AbstractImportExecutableWizard_CreateLaunchConfiguration;
public static String ImportExecutablePageOne_SelectBinaryParser;
}

View file

@ -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.