1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 22:05:44 +02:00

Implementing the BinaryParser proposal using

the CDescriptor class.
This commit is contained in:
Alain Magloire 2003-02-28 21:29:53 +00:00
parent e1a571ea79
commit f123f58b2f
12 changed files with 511 additions and 447 deletions

View file

@ -12,7 +12,6 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class CoreModel { public class CoreModel {
@ -145,36 +144,20 @@ public class CoreModel {
return manager.hasCNature(project); return manager.hasCNature(project);
} }
/**
* Return true if project has C++ nature.
*/
public boolean hasCCNature(IProject project){ public boolean hasCCNature(IProject project){
return manager.hasCCNature(project); return manager.hasCCNature(project);
} }
/** /**
* Return the binaryParser of the Project. * TODO: this is a temporary hack until, the CDescriptor manager is
* in place and could fire deltas of Parser change.
* @deprecated this function will be removed shortly.
*/ */
public String getBinaryParserFormat(IProject project) { public void resetBinaryParser(IProject project) {
return manager.getBinaryParserFormat(project); manager.resetBinaryParser(project);
}
/**
* Set the binaryParser of the Project.
*/
public void setBinaryParserFormat(IProject project, String format, IProgressMonitor monitor) {
manager.setBinaryParserFormat(project, format, monitor);
}
/**
* Return the default BinaryParser format
*/
public String getDefaultBinaryParserFormat() {
return manager.getDefaultBinaryParserFormat();
}
/**
* Set the default binaryParser.
*/
public void setDefaultBinaryParserFormat(String format) {
manager.setDefaultBinaryParserFormat(format);
} }
/** /**

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
@ -32,7 +31,6 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ICResource; import org.eclipse.cdt.core.model.ICResource;
import org.eclipse.cdt.core.model.ICRoot; import org.eclipse.cdt.core.model.ICRoot;
import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.internal.core.model.parser.ElfParser;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -47,19 +45,12 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
public class CModelManager implements IResourceChangeListener { public class CModelManager implements IResourceChangeListener {
private Map fParsedResources = Collections.synchronizedMap(new HashMap()); private Map fParsedResources = Collections.synchronizedMap(new HashMap());
final static String BINARY_PARSER= "binaryparser"; //private static HashMap fParsers = new HashMap();
static QualifiedName binaryParserKey = new QualifiedName(CoreModel.CORE_MODEL_ID, BINARY_PARSER);
private static HashMap fParsers = new HashMap();
private static IBinaryParser defaultBinaryParser = new ElfParser();
//private static IBinaryParser defaultBinaryParser = new PEParser();
/** /**
* Used to convert <code>IResourceDelta</code>s into <code>IJavaElementDelta</code>s. * Used to convert <code>IResourceDelta</code>s into <code>IJavaElementDelta</code>s.
@ -379,82 +370,124 @@ public class CModelManager implements IResourceChangeListener {
} }
public IBinaryParser getBinaryParser(IProject project) { public IBinaryParser getBinaryParser(IProject project) {
// It is in the property of the project of the cdtproject
// For now the default is Elf.
IBinaryParser parser = (IBinaryParser)fParsers.get(project);
if (parser == null) {
String format = getBinaryParserFormat(project);
if (format == null || format.length() == 0) {
format = getDefaultBinaryParserFormat();
}
if (format != null && format.length() > 0) {
parser = CCorePlugin.getDefault().getBinaryParser(format);
}
if (parser == null) {
parser = defaultBinaryParser;
}
fParsers.put(project, parser);
}
return parser;
}
public String getDefaultBinaryParserFormat() {
String format = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(BINARY_PARSER);
if (format == null || format.length() == 0) {
return "ELF";
}
return format;
}
public String getBinaryParserFormat(IProject project) {
// It can be in the property of the project or in the .cdtproject
String format = null;
// FIXME: Ask the .cdtproject.
try { try {
if (project != null) { return CCorePlugin.getDefault().getBinaryParser(project);
format = project.getPersistentProperty(binaryParserKey);
}
} catch (CoreException e) { } catch (CoreException e) {
} }
return format; return new NullBinaryParser();
} }
public void setDefaultBinaryParserFormat(String format) { // public IBinaryParser getBinaryParser(IProject project) {
CCorePlugin.getDefault().getPluginPreferences().setDefault(BINARY_PARSER, format); // // It is in the property of the project of the cdtproject
} // // For now the default is Elf.
// IBinaryParser parser = (IBinaryParser)fParsers.get(project);
// if (parser == null) {
// String format = getBinaryParserFormat(project);
// if (format == null || format.length() == 0) {
// format = getDefaultBinaryParserFormat();
// }
// if (format != null && format.length() > 0) {
// parser = CCorePlugin.getDefault().getBinaryParser(format);
// }
// if (parser == null) {
// parser = defaultBinaryParser;
// }
// fParsers.put(project, parser);
// }
// return parser;
// }
public void setBinaryParserFormat(IProject project, String format, IProgressMonitor monitor) { // public String getDefaultBinaryParserFormat() {
try { // String format = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(BINARY_PARSER);
if (project != null) { // if (format == null || format.length() == 0) {
project.setPersistentProperty(binaryParserKey, format); // return "ELF";
fParsers.remove(project); // }
IPath projPath = project.getFullPath(); // return format;
if (projPath != null) { // }
Collection c = fParsedResources.values();
ArrayList list = new ArrayList(); // public String getBinaryParserFormat(IProject project) {
synchronized (c) { // // It can be in the property of the project or in the .cdtproject
Iterator values = c.iterator(); // String format = null;
while (values.hasNext()) { // // FIXME: Ask the .cdtproject.
ICElement ce = (ICElement)values.next(); // try {
if (!(ce instanceof ICRoot || ce instanceof ICProject)) { // if (project != null) {
if (ce.getCProject().getProject().equals(project)) { // format = project.getPersistentProperty(binaryParserKey);
list.add(ce); // }
} // } catch (CoreException e) {
// }
// return format;
// }
// public void setDefaultBinaryParserFormat(String format) {
// CCorePlugin.getDefault().getPluginPreferences().setDefault(BINARY_PARSER, format);
// }
//
// public void setBinaryParserFormat(IProject project, String format, IProgressMonitor monitor) {
// try {
// if (project != null) {
// project.setPersistentProperty(binaryParserKey, format);
// fParsers.remove(project);
// IPath projPath = project.getFullPath();
// if (projPath != null) {
// Collection c = fParsedResources.values();
// ArrayList list = new ArrayList();
// synchronized (c) {
// Iterator values = c.iterator();
// while (values.hasNext()) {
// ICElement ce = (ICElement)values.next();
// if (!(ce instanceof ICRoot || ce instanceof ICProject)) {
// if (ce.getCProject().getProject().equals(project)) {
// list.add(ce);
// }
// }
// }
// }
// for (int i = 0; i < list.size(); i++) {
// ICElement ce = (ICElement)list.get(i);
// releaseCElement(ce);
// }
// }
// // Fired and ICElementDelta.PARSER_CHANGED
// CElementDelta delta = new CElementDelta(getCRoot());
// delta.binaryParserChanged(create(project));
// registerCModelDelta(delta);
// fire();
// }
// } catch (CoreException e) {
// }
// }
/**
* TODO: this is a temporary hack until, the CDescriptor manager is
* in place and could fire deltas of Parser change.
*/
public void resetBinaryParser(IProject project) {
if (project != null) {
IPath projPath = project.getFullPath();
if (projPath != null) {
Collection c = fParsedResources.values();
ArrayList list = new ArrayList();
synchronized (c) {
Iterator values = c.iterator();
while (values.hasNext()) {
ICElement ce = (ICElement)values.next();
if (!(ce instanceof ICRoot || ce instanceof ICProject)) {
if (ce.getCProject().getProject().equals(project)) {
list.add(ce);
} }
} }
} }
for (int i = 0; i < list.size(); i++) {
ICElement ce = (ICElement)list.get(i);
releaseCElement(ce);
}
} }
// Fired and ICElementDelta.PARSER_CHANGED for (int i = 0; i < list.size(); i++) {
CElementDelta delta = new CElementDelta(getCRoot()); ICElement ce = (ICElement)list.get(i);
delta.binaryParserChanged(create(project)); releaseCElement(ce);
registerCModelDelta(delta); }
fire();
} }
} catch (CoreException e) { // Fired and ICElementDelta.PARSER_CHANGED
CElementDelta delta = new CElementDelta(getCRoot());
delta.binaryParserChanged(create(project));
registerCModelDelta(delta);
fire();
} }
} }
@ -464,7 +497,6 @@ public class CModelManager implements IResourceChangeListener {
IBinaryFile bin = parser.getBinary(file.getLocation()); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.SHARED); return (bin.getType() == IBinaryFile.SHARED);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace();
} }
return false; return false;
} }
@ -475,7 +507,6 @@ public class CModelManager implements IResourceChangeListener {
IBinaryFile bin = parser.getBinary(file.getLocation()); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.OBJECT); return (bin.getType() == IBinaryFile.OBJECT);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace();
} }
return false; return false;
} }
@ -500,7 +531,6 @@ public class CModelManager implements IResourceChangeListener {
|| bin.getType() == IBinaryFile.SHARED || bin.getType() == IBinaryFile.SHARED
|| bin.getType() == IBinaryFile.CORE); || bin.getType() == IBinaryFile.CORE);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace();
} }
return false; return false;
} }
@ -511,7 +541,6 @@ public class CModelManager implements IResourceChangeListener {
IBinaryFile bin = parser.getBinary(file.getLocation()); IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.ARCHIVE); return (bin.getType() == IBinaryFile.ARCHIVE);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace();
} }
return false; return false;
} }

View file

@ -0,0 +1,35 @@
package org.eclipse.cdt.internal.core.model;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.io.IOException;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.core.runtime.IPath;
/**
* @author alain
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NullBinaryParser implements IBinaryParser {
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getBinary(org.eclipse.core.runtime.IPath)
*/
public IBinaryFile getBinary(IPath path) throws IOException {
throw new IOException("not a binary file");
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.IBinaryParser#getFormat()
*/
public String getFormat() {
return "Null Format";
}
}

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.internal.core.model.parser;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.elf.AR; import org.eclipse.cdt.utils.elf.AR;
import org.eclipse.cdt.utils.elf.Elf; import org.eclipse.cdt.utils.elf.Elf;
@ -14,7 +15,7 @@ import org.eclipse.core.runtime.IPath;
/** /**
*/ */
public class ElfParser implements IBinaryParser { public class ElfParser extends AbstractCExtension implements IBinaryParser {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath) * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IPath)

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.internal.core.model.parser;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.coff.PE; import org.eclipse.cdt.utils.coff.PE;
import org.eclipse.cdt.utils.coff.PEArchive; import org.eclipse.cdt.utils.coff.PEArchive;
@ -14,7 +15,7 @@ import org.eclipse.core.runtime.IPath;
/** /**
*/ */
public class PEParser implements IBinaryParser { public class PEParser extends AbstractCExtension implements IBinaryParser {
/** /**
* @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IFile) * @see org.eclipse.cdt.core.model.IBinaryParser#getBinary(IFile)

View file

@ -77,19 +77,19 @@
</type> </type>
</extension> </extension>
<extension <!-- Define the list of the Binary Parser provided by the CDT -->
point="org.eclipse.cdt.core.BinaryParser"> <extension id="ELF" name="Elf Parser" point="org.eclipse.cdt.core.BinaryParser">
<parser <cextension>
name="Elf Parser" <run class="org.eclipse.cdt.internal.core.model.parser.ElfParser"/>
class="org.eclipse.cdt.internal.core.model.parser.ElfParser" </cextension>
format="ELF"> </extension>
</parser>
<parser <extension id="PE" name="PE Windows Parser" point="org.eclipse.cdt.core.BinaryParser">
name="PE Windows Parser" <cextension>
class="org.eclipse.cdt.internal.core.model.parser.PEParser" <run class="org.eclipse.cdt.internal.core.model.parser.PEParser"> </run>
format="PE"> </cextension>
</parser> </extension>
</extension>
<extension <extension
id="cbuilder" id="cbuilder"
name="C Builder" name="C Builder"

View file

@ -6,14 +6,12 @@ package org.eclipse.cdt.core;
*/ */
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.eclipse.cdt.core.index.IndexModel; import org.eclipse.cdt.core.index.IndexModel;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.resources.IConsole; import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.BinaryParserConfiguration;
import org.eclipse.cdt.internal.core.CDescriptorManager; import org.eclipse.cdt.internal.core.CDescriptorManager;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
@ -32,16 +30,20 @@ import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor;
public class CCorePlugin extends Plugin { public class CCorePlugin extends Plugin {
public static final int STATUS_CDTPROJECT_EXISTS = 1; public static final int STATUS_CDTPROJECT_EXISTS = 1;
public static final int STATUS_CDTPROJECT_MISMATCH = 2; public static final int STATUS_CDTPROJECT_MISMATCH = 2;
public static final int CDT_PROJECT_NATURE_ID_MISMATCH = 3; public static final int CDT_PROJECT_NATURE_ID_MISMATCH = 3;
public static final String PLUGIN_ID= "org.eclipse.cdt.core"; public static final String PLUGIN_ID = "org.eclipse.cdt.core";
public static final String BUILDER_MODEL_ID= PLUGIN_ID + ".CBuildModel"; public static final String BUILDER_MODEL_ID = PLUGIN_ID + ".CBuildModel";
public static final String BINARY_PARSER_SIMPLE_ID = "BinaryParser";
public final static String BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + BINARY_PARSER_SIMPLE_ID;
public final static String PREF_BINARY_PARSER = "binaryparser";
public final static String DEFAULT_BINARY_PARSER_SIMPLE_ID = "ELF";
public final static String DEFAULT_BINARY_PARSER_UNIQ_ID = PLUGIN_ID + "." + DEFAULT_BINARY_PARSER_SIMPLE_ID;
private static CCorePlugin fgCPlugin; private static CCorePlugin fgCPlugin;
private static ResourceBundle fgResourceBundle; private static ResourceBundle fgResourceBundle;
@ -52,9 +54,11 @@ public class CCorePlugin extends Plugin {
static { static {
try { try {
fgResourceBundle= ResourceBundle.getBundle("org.eclipse.cdt.internal.CCorePluginResources"); fgResourceBundle =
ResourceBundle.getBundle(
"org.eclipse.cdt.internal.CCorePluginResources");
} catch (MissingResourceException x) { } catch (MissingResourceException x) {
fgResourceBundle= null; fgResourceBundle = null;
} }
} }
@ -73,7 +77,9 @@ public class CCorePlugin extends Plugin {
} }
public static String getFormattedString(String key, String arg) { public static String getFormattedString(String key, String arg) {
return MessageFormat.format(getResourceString(key), new String[] { arg }); return MessageFormat.format(
getResourceString(key),
new String[] { arg });
} }
public static String getFormattedString(String key, String[] args) { public static String getFormattedString(String key, String[] args) {
@ -93,14 +99,14 @@ public class CCorePlugin extends Plugin {
} }
public static void log(IStatus status) { public static void log(IStatus status) {
((Plugin)getDefault()).getLog().log(status); ((Plugin) getDefault()).getLog().log(status);
} }
// ------ CPlugin // ------ CPlugin
public CCorePlugin(IPluginDescriptor descriptor) { public CCorePlugin(IPluginDescriptor descriptor) {
super(descriptor); super(descriptor);
fgCPlugin= this; fgCPlugin = this;
} }
/** /**
@ -127,17 +133,23 @@ public class CCorePlugin extends Plugin {
public IConsole getConsole(String id) { public IConsole getConsole(String id) {
try { try {
IExtensionPoint extension = getDescriptor().getExtensionPoint("CBuildConsole"); IExtensionPoint extension =
getDescriptor().getExtensionPoint("CBuildConsole");
if (extension != null) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
for(int i = 0; i < extensions.length; i++){ for (int i = 0; i < extensions.length; i++) {
IConfigurationElement [] configElements = extensions[i].getConfigurationElements(); IConfigurationElement[] configElements =
for( int j = 0; j < configElements.length; j++ ) { extensions[i].getConfigurationElements();
String builderID = configElements[j].getAttribute("builderID"); for (int j = 0; j < configElements.length; j++) {
if ( (id == null && builderID == null) || String builderID =
( id != null && builderID.equals(id))) { configElements[j].getAttribute("builderID");
return (IConsole)configElements[j].createExecutableExtension("class"); if ((id == null && builderID == null)
} || (id != null && builderID.equals(id))) {
return (
IConsole) configElements[j]
.createExecutableExtension(
"class");
}
} }
} }
} }
@ -158,41 +170,36 @@ public class CCorePlugin extends Plugin {
return getConsole(null); return getConsole(null);
} }
public IBinaryParserConfiguration[] getBinaryParserConfigurations() { public IBinaryParser getBinaryParser(IProject project) throws CoreException {
ArrayList list = new ArrayList(); IBinaryParser parser = null;
IExtensionPoint extensionPoint = getDescriptor().getExtensionPoint("BinaryParser");
if (extensionPoint != null) {
IExtension[] extensions = extensionPoint.getExtensions();
for(int i = 0; i < extensions.length; i++){
IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for( int j = 0; j < configElements.length; j++ ) {
String format = configElements[j].getAttribute("format");
String name = configElements[j].getAttribute("name");
list.add(new BinaryParserConfiguration(format, name));
}
}
}
return (IBinaryParserConfiguration[])list.toArray(new IBinaryParserConfiguration[0]);
}
public IBinaryParser getBinaryParser(String format) {
try { try {
IExtensionPoint extensionPoint = getDescriptor().getExtensionPoint("BinaryParser"); ICDescriptor cdesc = (ICDescriptor) getCProjectDescription(project);
if (extensionPoint != null) { ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID);
IExtension[] extensions = extensionPoint.getExtensions(); if (cextensions.length > 0)
for(int i = 0; i < extensions.length; i++){ parser = (IBinaryParser) cextensions[0].createExtension();
IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for( int j = 0; j < configElements.length; j++ ) {
String attr = configElements[j].getAttribute("format");
if (attr != null && attr.equalsIgnoreCase(format)) {
return (IBinaryParser)configElements[j].createExecutableExtension("class");
}
}
}
}
} catch (CoreException e) { } catch (CoreException e) {
} }
return null; if (parser == null) {
String id = getPluginPreferences().getDefaultString(PREF_BINARY_PARSER);
if (id == null || id.length() == 0) {
id = DEFAULT_BINARY_PARSER_UNIQ_ID;
}
IExtensionPoint extensionPoint = getDescriptor().getExtensionPoint(BINARY_PARSER_SIMPLE_ID);
IExtension extension = extensionPoint.getExtension(id);
if (extension != null) {
IConfigurationElement element[] = extension.getConfigurationElements();
for (int i = 0; i < element.length; i++) {
if (element[i].getName().equalsIgnoreCase("cextension")) {
parser = (IBinaryParser) element[i].createExecutableExtension("run");
break;
}
}
} else {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "No Binary Format", null);
throw new CoreException(s);
}
}
return parser;
} }
public CoreModel getCoreModel() { public CoreModel getCoreModel() {
@ -203,195 +210,234 @@ public class CCorePlugin extends Plugin {
return IndexModel.getDefault(); return IndexModel.getDefault();
} }
public ICDescriptor getCProjectDescription(IProject project) throws CoreException { public ICDescriptor getCProjectDescription(IProject project)
throws CoreException {
return fDescriptorManager.getDescriptor(project); return fDescriptorManager.getDescriptor(project);
} }
public void mapCProjectOwner(IProject project, String id, boolean override) throws CoreException { public void mapCProjectOwner(IProject project, String id, boolean override)
if ( !override ) { throws CoreException {
if (!override) {
fDescriptorManager.configure(project, id); fDescriptorManager.configure(project, id);
} else { } else {
fDescriptorManager.convert(project, id); fDescriptorManager.convert(project, id);
} }
} }
/** /**
* Creates a C project resource given the project handle and description. * Creates a C project resource given the project handle and description.
* *
* @param description the project description to create a project resource for * @param description the project description to create a project resource for
* @param projectHandle the project handle to create a project resource for * @param projectHandle the project handle to create a project resource for
* @param monitor the progress monitor to show visual progress with * @param monitor the progress monitor to show visual progress with
* @param projectID required for mapping the project to an owner * @param projectID required for mapping the project to an owner
* *
* @exception CoreException if the operation fails * @exception CoreException if the operation fails
* @exception OperationCanceledException if the operation is canceled * @exception OperationCanceledException if the operation is canceled
*/ */
public IProject createCProject(IProjectDescription description, IProject projectHandle, public IProject createCProject(
IProgressMonitor monitor, String projectID) throws CoreException, OperationCanceledException { IProjectDescription description,
try { IProject projectHandle,
if (monitor == null) { IProgressMonitor monitor,
monitor = new NullProgressMonitor(); String projectID)
} throws CoreException, OperationCanceledException {
monitor.beginTask("Creating C Project", 3);//$NON-NLS-1$ try {
if (!projectHandle.exists()){ if (monitor == null) {
projectHandle.create(description, monitor); monitor = new NullProgressMonitor();
} }
monitor.beginTask("Creating C Project", 3); //$NON-NLS-1$
if (!projectHandle.exists()) {
projectHandle.create(description, monitor);
}
if (monitor.isCanceled()){ if (monitor.isCanceled()) {
throw new OperationCanceledException(); throw new OperationCanceledException();
} }
// Open first. // Open first.
projectHandle.open(monitor); projectHandle.open(monitor);
// Add C Nature ... does not add duplicates // Add C Nature ... does not add duplicates
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1)); CProjectNature.addCNature(
mapCProjectOwner(projectHandle, projectID, false); projectHandle,
} finally { new SubProgressMonitor(monitor, 1));
//monitor.done(); mapCProjectOwner(projectHandle, projectID, false);
} } finally {
return projectHandle; //monitor.done();
} }
return projectHandle;
}
/** /**
* Method convertProjectFromCtoCC converts * Method convertProjectFromCtoCC converts
* a C Project to a C++ Project * a C Project to a C++ Project
* The newProject MUST, not be null, already have a C Nature * The newProject MUST, not be null, already have a C Nature
* && must NOT already have a C++ Nature * && must NOT already have a C++ Nature
* *
* @param projectHandle * @param projectHandle
* @param monitor * @param monitor
* @throws CoreException * @throws CoreException
*/ */
public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor) public void convertProjectFromCtoCC(
throws CoreException{ IProject projectHandle,
if ((projectHandle != null) IProgressMonitor monitor)
&& projectHandle.hasNature(CCProjectNature.C_NATURE_ID) throws CoreException {
&& !projectHandle.hasNature(CCProjectNature.CC_NATURE_ID)) { if ((projectHandle != null)
// Add C++ Nature ... does not add duplicates && projectHandle.hasNature(CCProjectNature.C_NATURE_ID)
CCProjectNature.addCCNature(projectHandle, monitor); && !projectHandle.hasNature(CCProjectNature.CC_NATURE_ID)) {
} // Add C++ Nature ... does not add duplicates
} CCProjectNature.addCCNature(projectHandle, monitor);
}
}
/** /**
* Method addDefaultCBuilder adds the default C make builder * Method addDefaultCBuilder adds the default C make builder
* @param projectHandle * @param projectHandle
* @param monitor * @param monitor
* @exception CoreException * @exception CoreException
*/ */
public void addDefaultCBuilder( IProject projectHandle, IProgressMonitor monitor) public void addDefaultCBuilder(
throws CoreException{ IProject projectHandle,
// Set the Default C Builder. IProgressMonitor monitor)
CProjectNature.addCBuildSpec(projectHandle, monitor); throws CoreException {
} // Set the Default C Builder.
CProjectNature.addCBuildSpec(projectHandle, monitor);
}
/** /**
* Method to convert a project to a C nature * Method to convert a project to a C nature
* & default make builder (Will always add a default builder) * & default make builder (Will always add a default builder)
* All checks should have been done externally * All checks should have been done externally
* (as in the Conversion Wizards). * (as in the Conversion Wizards).
* This method blindly does the conversion. * This method blindly does the conversion.
* *
* @param project * @param project
* @param String targetNature * @param String targetNature
* @param monitor * @param monitor
* @param projectID * @param projectID
* @exception CoreException * @exception CoreException
*/ */
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID) public void convertProjectToC(
throws CoreException{ IProject projectHandle,
this.convertProjectToC(projectHandle, monitor, projectID, true); IProgressMonitor monitor,
String projectID)
throws CoreException {
this.convertProjectToC(projectHandle, monitor, projectID, true);
} }
/** /**
* Method to convert a project to a C nature * Method to convert a project to a C nature
* & default make builder (if indicated) * & default make builder (if indicated)
* All checks should have been done externally * All checks should have been done externally
* (as in the Conversion Wizards). * (as in the Conversion Wizards).
* This method blindly does the conversion. * This method blindly does the conversion.
* *
* @param project * @param project
* @param String targetNature * @param String targetNature
* @param monitor * @param monitor
* @param projectID * @param projectID
* @param addMakeBuilder * @param addMakeBuilder
* @exception CoreException * @exception CoreException
*/ */
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID, boolean addMakeBuilder) public void convertProjectToC(
throws CoreException{ IProject projectHandle,
if ((projectHandle == null) || (monitor == null) || (projectID == null)){ IProgressMonitor monitor,
return; String projectID,
} boolean addMakeBuilder)
IWorkspace workspace = ResourcesPlugin.getWorkspace(); throws CoreException {
IProjectDescription description = workspace.newProjectDescription(projectHandle.getName()); if ((projectHandle == null)
description.setLocation(projectHandle.getFullPath()); || (monitor == null)
createCProject(description, projectHandle, monitor, projectID); || (projectID == null)) {
if (addMakeBuilder) { return;
addDefaultCBuilder(projectHandle, monitor); }
} IWorkspace workspace = ResourcesPlugin.getWorkspace();
} IProjectDescription description =
/** workspace.newProjectDescription(projectHandle.getName());
* Method to convert a project to a C++ nature description.setLocation(projectHandle.getFullPath());
* & default make builder(if indicated), if it does not have one already createCProject(description, projectHandle, monitor, projectID);
* if (addMakeBuilder) {
* @param project addDefaultCBuilder(projectHandle, monitor);
* @param String targetNature }
* @param monitor }
* @param projectID /**
* @param addMakeBuilder * Method to convert a project to a C++ nature
* @exception CoreException * & default make builder(if indicated), if it does not have one already
*/ *
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @param addMakeBuilder
* @exception CoreException
*/
public void convertProjectToCC(IProject projectHandle, IProgressMonitor monitor, String projectID, boolean addMakeBuilder) public void convertProjectToCC(
throws CoreException{ IProject projectHandle,
if ((projectHandle == null) || (monitor == null) || (projectID == null)){ IProgressMonitor monitor,
return; String projectID,
} boolean addMakeBuilder)
createCProject(projectHandle.getDescription(), projectHandle, monitor, projectID); throws CoreException {
// now add C++ nature if ((projectHandle == null)
convertProjectFromCtoCC(projectHandle, monitor); || (monitor == null)
if (addMakeBuilder){ || (projectID == null)) {
addDefaultCBuilder(projectHandle, monitor); return;
} }
} createCProject(
/** projectHandle.getDescription(),
* Method to convert a project to a C++ nature projectHandle,
* & default make builder, monitor,
* Note: Always adds the default Make builder projectID);
* // now add C++ nature
* @param project convertProjectFromCtoCC(projectHandle, monitor);
* @param String targetNature if (addMakeBuilder) {
* @param monitor addDefaultCBuilder(projectHandle, monitor);
* @param projectID }
* @exception CoreException }
*/ /**
* Method to convert a project to a C++ nature
* & default make builder,
* Note: Always adds the default Make builder
*
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @exception CoreException
*/
public void convertProjectToCC(IProject projectHandle, IProgressMonitor monitor, String projectID) public void convertProjectToCC(
throws CoreException{ IProject projectHandle,
this.convertProjectToCC(projectHandle, monitor, projectID, true); IProgressMonitor monitor,
} String projectID)
throws CoreException {
this.convertProjectToCC(projectHandle, monitor, projectID, true);
}
// Extract the builder from the .cdtproject. // Extract the builder from the .cdtproject.
// public ICBuilder[] getBuilders(IProject project) throws CoreException { // public ICBuilder[] getBuilders(IProject project) throws CoreException {
// ICExtension extensions[] = fDescriptorManager.createExtensions(BUILDER_MODEL_ID, project); // ICExtension extensions[] = fDescriptorManager.createExtensions(BUILDER_MODEL_ID, project);
// ICBuilder builders[] = new ICBuilder[extensions.length]; // ICBuilder builders[] = new ICBuilder[extensions.length];
// System.arraycopy(extensions, 0, builders, 0, extensions.length); // System.arraycopy(extensions, 0, builders, 0, extensions.length);
// return builders; // return builders;
// } // }
public IProcessList getProcessList() { public IProcessList getProcessList() {
IExtensionPoint extension = getDescriptor().getExtensionPoint("ProcessList"); IExtensionPoint extension =
getDescriptor().getExtensionPoint("ProcessList");
if (extension != null) { if (extension != null) {
IExtension[] extensions = extension.getExtensions(); IExtension[] extensions = extension.getExtensions();
IConfigurationElement [] configElements = extensions[0].getConfigurationElements(); IConfigurationElement[] configElements =
if ( configElements.length != 0 ) { extensions[0].getConfigurationElements();
if (configElements.length != 0) {
try { try {
return (IProcessList) configElements[0].createExecutableExtension("class"); return (
} IProcessList) configElements[0]
catch (CoreException e) { .createExecutableExtension(
"class");
} catch (CoreException e) {
} }
} }
} }

View file

@ -1,12 +0,0 @@
package org.eclipse.cdt.core;
/**
*/
public interface IBinaryParserConfiguration {
String getFormat();
String getName();
IBinaryParser getParser();
}

View file

@ -1,40 +0,0 @@
package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParserConfiguration;
/**
*/
public class BinaryParserConfiguration implements IBinaryParserConfiguration {
String format;
String name;
public BinaryParserConfiguration(String format, String name) {
this.format = format;
this.name = name;
}
/**
* @see org.eclipse.cdt.core.IBinaryParserConfiguration#getFormat()
*/
public String getFormat() {
return format;
}
/**
* @see org.eclipse.cdt.core.IBinaryParserConfiguration#getName()
*/
public String getName() {
return name;
}
/**
* @see org.eclipse.cdt.core.IBinaryParserConfiguration#getParser()
*/
public IBinaryParser getParser() {
return CCorePlugin.getDefault().getBinaryParser(format);
}
}

View file

@ -46,8 +46,6 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
public class CDescriptor implements ICDescriptor { public class CDescriptor implements ICDescriptor {
/* constants */
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private COwner fOwner; private COwner fOwner;
private IProject fProject; private IProject fProject;
private HashMap extMap = new HashMap(4); private HashMap extMap = new HashMap(4);
@ -177,12 +175,15 @@ public class CDescriptor implements ICDescriptor {
} }
public ICExtensionReference[] get(String extensionID) { public ICExtensionReference[] get(String extensionID) {
return (CExtensionReference[]) extMap.get(extensionID); CExtensionReference[] refs = (CExtensionReference[]) extMap.get(extensionID);
if (refs == null)
return new ICExtensionReference[0];
return refs;
} }
public ICExtensionReference[] get(String extensionID, boolean update) { public ICExtensionReference[] get(String extensionID, boolean update) {
ICExtensionReference[] ext = get(extensionID); ICExtensionReference[] ext = get(extensionID);
if ((ext == null || ext.length == 0) && update) { if (ext.length == 0 && update) {
try { try {
fOwner.update(fProject, this, extensionID); fOwner.update(fProject, this, extensionID);
saveInfo(); saveInfo();
@ -204,8 +205,8 @@ public class CDescriptor implements ICDescriptor {
extensions = newExtensions; extensions = newExtensions;
extMap.put(extensionPoint, extensions); extMap.put(extensionPoint, extensions);
} }
setDirty();
extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extensionID); extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extensionID);
setDirty();
return extensions[extensions.length - 1]; return extensions[extensions.length - 1];
} }
@ -230,7 +231,7 @@ public class CDescriptor implements ICDescriptor {
public void remove(String extensionPoint) throws CoreException { public void remove(String extensionPoint) throws CoreException {
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint); CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
if (extensions != null) { if (extensions != null) {
extMap.put(extensionPoint, null); extMap.remove(extensionPoint);
setDirty(); setDirty();
} }
} }

View file

@ -88,6 +88,7 @@ public class CDescriptorManager implements IResourceChangeListener {
cproject = (CDescriptor)fDescriptorMap.get(project) ; cproject = (CDescriptor)fDescriptorMap.get(project) ;
if ( cproject == null ) { if ( cproject == null ) {
cproject = new CDescriptor(project); cproject = new CDescriptor(project);
cproject.setAutoSave(true);
fDescriptorMap.put(project, cproject); fDescriptorMap.put(project, cproject);
} }
return cproject; return cproject;

View file

@ -6,29 +6,31 @@ package org.eclipse.cdt.ui.wizards;
*/ */
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParserConfiguration; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.utils.ui.controls.ControlFactory; import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.cdt.utils.ui.controls.RadioButtonsArea; import org.eclipse.cdt.utils.ui.controls.RadioButtonsArea;
import org.eclipse.cdt.utils.ui.swt.IValidation; import org.eclipse.cdt.utils.ui.swt.IValidation;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
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.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
public class BinaryParserBlock implements IWizardTab { public class BinaryParserBlock implements IWizardTab {
private static final String PREFIX = "BinaryParserBlock"; //$NON-NLS-1$ //private static final String PREFIX = "BinaryParserBlock"; //$NON-NLS-1$
private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$ //private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
private static String[][] radios; private static String[][] radios;
private IProject project; private IProject project;
protected RadioButtonsArea radioButtons; protected RadioButtonsArea radioButtons;
private String defaultFormat; private String id;
// protected Button defButton; // protected Button defButton;
IValidation page; IValidation page;
@ -39,16 +41,28 @@ public class BinaryParserBlock implements IWizardTab {
public BinaryParserBlock(IValidation valid, IProject p) { public BinaryParserBlock(IValidation valid, IProject p) {
page = valid; page = valid;
project = p; project = p;
IBinaryParserConfiguration[] configs = CCorePlugin.getDefault().getBinaryParserConfigurations(); IExtensionPoint point = CCorePlugin.getDefault().getDescriptor().getExtensionPoint(CCorePlugin.BINARY_PARSER_SIMPLE_ID);
radios = new String[configs.length][2]; if (point != null) {
for (int i = 0; i < configs.length; i++) { IExtension[] exts = point.getExtensions();
radios[i] = new String[] {configs[i].getName(), configs[i].getFormat()}; radios = new String[exts.length][2];
for (int i = 0; i < exts.length; i++) {
radios[i] = new String[] { exts[i].getLabel(), exts[i].getUniqueIdentifier()};
}
} }
CoreModel model = CCorePlugin.getDefault().getCoreModel(); try {
if (project == null) { ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(p);
defaultFormat = model.getDefaultBinaryParserFormat(); ICExtensionReference[] ref = desc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID);
} else { if (ref.length > 0)
defaultFormat = model.getBinaryParserFormat(project); id = ref[0].getID();
} catch (CoreException e) {
//e.printStackTrace();
}
if (id == null) {
id = CCorePlugin.getDefault().getPluginPreferences().getDefaultString(CCorePlugin.PREF_BINARY_PARSER);
if (id == null || id.length() == 0) {
id = CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID;
}
} }
} }
@ -66,8 +80,8 @@ public class BinaryParserBlock implements IWizardTab {
radioButtons = new RadioButtonsArea(composite, "Parsers", 1, radios); radioButtons = new RadioButtonsArea(composite, "Parsers", 1, radios);
radioButtons.setEnabled(true); radioButtons.setEnabled(true);
if (defaultFormat != null) { if (id != null) {
radioButtons.setSelectValue(defaultFormat); radioButtons.setSelectValue(id);
} }
return composite; return composite;
} }
@ -84,13 +98,18 @@ public class BinaryParserBlock implements IWizardTab {
monitor = new NullProgressMonitor(); monitor = new NullProgressMonitor();
} }
monitor.beginTask("Parsers", 1); monitor.beginTask("Parsers", 1);
CoreModel model = CCorePlugin.getDefault().getCoreModel(); try {
String format = radioButtons.getSelectedValue(); ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project);
if (format != null) { String identity = radioButtons.getSelectedValue();
if (defaultFormat == null || !format.equals(defaultFormat)) { if (identity != null) {
model.setBinaryParserFormat(project, format, monitor); if (id == null || !identity.equals(id)) {
defaultFormat = format; desc.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
desc.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, identity);
CCorePlugin.getDefault().getCoreModel().resetBinaryParser(project);
id = identity;
}
} }
} catch (CoreException e) {
} }
} }