1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <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.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </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.console,
org.eclipse.ui.views org.eclipse.ui.views
Eclipse-LazyStart: true 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$ 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. * 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; package org.eclipse.cdt.debug.ui.importexecutable;
import java.io.File; import java.io.File;
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 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.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;
@ -35,9 +43,11 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.FileDialog;
@ -78,14 +88,33 @@ public class ImportExecutablePageOne extends WizardPage {
private AbstractImportExecutableWizard wizard; private AbstractImportExecutableWizard wizard;
private String selectedBinaryParserId;
private IBinaryParser selectedBinaryParser;
public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) { public ImportExecutablePageOne(AbstractImportExecutableWizard wizard) {
super("ImportApplicationPageOne"); super("ImportApplicationPageOne");
this.wizard = wizard; this.wizard = wizard;
setPageComplete(false); setPageComplete(false);
setTitle(wizard.getPageOneTitle()); setTitle(wizard.getPageOneTitle());
setDescription(wizard.getPageOneDescription()); 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() { private void checkControlState() {
selectSingleFile = selectSingleButton.getSelection(); selectSingleFile = selectSingleButton.getSelection();
singleExecutablePathField.setEnabled(selectSingleFile); singleExecutablePathField.setEnabled(selectSingleFile);
@ -109,7 +138,7 @@ public class ImportExecutablePageOne extends WizardPage {
for (int i = 0; i < contents.length; i++) { for (int i = 0; i < contents.length; i++) {
File file = contents[i]; File file = contents[i];
if (file.isFile() && wizard.isExecutableFile(file)) { if (file.isFile() && isBinary(file)) {
files.add(file); files.add(file);
} }
} }
@ -141,6 +170,7 @@ public class ImportExecutablePageOne extends WizardPage {
selectExecutableGroup.setLayoutData(new GridData( selectExecutableGroup.setLayoutData(new GridData(
GridData.FILL_HORIZONTAL)); GridData.FILL_HORIZONTAL));
createSelectBinaryParser(selectExecutableGroup);
createSelectExecutable(selectExecutableGroup); createSelectExecutable(selectExecutableGroup);
createExecutablesRoot(selectExecutableGroup); createExecutablesRoot(selectExecutableGroup);
createExecutablesList(workArea); 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) { private void createSelectExecutable(Composite workArea) {
// project specification group // project specification group
@ -280,24 +387,7 @@ public class ImportExecutablePageOne extends WizardPage {
singleExecutablePathField.addModifyListener(new ModifyListener() { singleExecutablePathField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) { public void modifyText(ModifyEvent e) {
setErrorMessage(null); validateExe(singleExecutablePathField.getText());
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);
}
}
} }
}); });
@ -465,4 +555,37 @@ public class ImportExecutablePageOne extends WizardPage {
executablesViewer.setCheckedElements(executables); executablesViewer.setCheckedElements(executables);
setPageComplete(executables.length > 0); 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 { public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID); descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
if (Platform.getOS().equals(Platform.OS_MACOSX)) descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, pageOne.getSelectedBinaryParserId());
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");
} }
}; };
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(newProject.getProject(), op, null); 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.
// 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) { public boolean isExecutableFile(File file) {
String filename = file.getName().toLowerCase(); String filename = file.getName().toLowerCase();
if (Platform.getOS().equals(Platform.OS_MACOSX)) 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_windowTitle;
public static String AbstractImportExecutableWizard_CreateLaunchConfiguration; public static String AbstractImportExecutableWizard_CreateLaunchConfiguration;
public static String ImportExecutablePageOne_SelectBinaryParser;
} }

View file

@ -11,6 +11,7 @@
ImportExecutableWizard_pageOneTitle=Import C/C++ Executable Files ImportExecutableWizard_pageOneTitle=Import C/C++ Executable Files
ImportExecutableWizard_pageOneDescription=Select a file or a directory to search for 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_SelectExecutable=Select executable:
ImportExecutablePageOne_SelectADirectory=Select a directory to search for C/C++ executable files. ImportExecutablePageOne_SelectADirectory=Select a directory to search for C/C++ executable files.
ImportExecutablePageTwo_EnterProjectName=Enter a project name. ImportExecutablePageTwo_EnterProjectName=Enter a project name.