1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 10:25:32 +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.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class CoreModel {
@ -145,36 +144,20 @@ public class CoreModel {
return manager.hasCNature(project);
}
/**
* Return true if project has C++ nature.
*/
public boolean hasCCNature(IProject 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) {
return manager.getBinaryParserFormat(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);
public void resetBinaryParser(IProject project) {
manager.resetBinaryParser(project);
}
/**

View file

@ -20,7 +20,6 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
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.IArchive;
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.ICRoot;
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.IFolder;
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.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
public class CModelManager implements IResourceChangeListener {
private Map fParsedResources = Collections.synchronizedMap(new HashMap());
final static String BINARY_PARSER= "binaryparser";
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();
//private static HashMap fParsers = new HashMap();
/**
* Used to convert <code>IResourceDelta</code>s into <code>IJavaElementDelta</code>s.
@ -377,84 +368,126 @@ public class CModelManager implements IResourceChangeListener {
}
return null;
}
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 {
if (project != null) {
format = project.getPersistentProperty(binaryParserKey);
}
return CCorePlugin.getDefault().getBinaryParser(project);
} catch (CoreException e) {
}
return format;
return new NullBinaryParser();
}
public void setDefaultBinaryParserFormat(String format) {
CCorePlugin.getDefault().getPluginPreferences().setDefault(BINARY_PARSER, format);
}
// 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 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);
}
// 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 {
// if (project != null) {
// format = project.getPersistentProperty(binaryParserKey);
// }
// } 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
CElementDelta delta = new CElementDelta(getCRoot());
delta.binaryParserChanged(create(project));
registerCModelDelta(delta);
fire();
for (int i = 0; i < list.size(); i++) {
ICElement ce = (ICElement)list.get(i);
releaseCElement(ce);
}
}
} 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());
return (bin.getType() == IBinaryFile.SHARED);
} catch (IOException e) {
//e.printStackTrace();
}
return false;
}
@ -475,7 +507,6 @@ public class CModelManager implements IResourceChangeListener {
IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.OBJECT);
} catch (IOException e) {
//e.printStackTrace();
}
return false;
}
@ -500,7 +531,6 @@ public class CModelManager implements IResourceChangeListener {
|| bin.getType() == IBinaryFile.SHARED
|| bin.getType() == IBinaryFile.CORE);
} catch (IOException e) {
//e.printStackTrace();
}
return false;
}
@ -511,7 +541,6 @@ public class CModelManager implements IResourceChangeListener {
IBinaryFile bin = parser.getBinary(file.getLocation());
return (bin.getType() == IBinaryFile.ARCHIVE);
} catch (IOException e) {
//e.printStackTrace();
}
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 org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.elf.AR;
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)

View file

@ -7,6 +7,7 @@ package org.eclipse.cdt.internal.core.model.parser;
import java.io.IOException;
import org.eclipse.cdt.core.AbstractCExtension;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.utils.coff.PE;
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)

View file

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

View file

@ -6,14 +6,12 @@ package org.eclipse.cdt.core;
*/
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.cdt.core.index.IndexModel;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.core.BinaryParserConfiguration;
import org.eclipse.cdt.internal.core.CDescriptorManager;
import org.eclipse.core.resources.IProject;
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.SubProgressMonitor;
public class CCorePlugin extends Plugin {
public static final int STATUS_CDTPROJECT_EXISTS = 1;
public static final int STATUS_CDTPROJECT_MISMATCH = 2;
public static final int CDT_PROJECT_NATURE_ID_MISMATCH = 3;
public static final String PLUGIN_ID= "org.eclipse.cdt.core";
public static final String BUILDER_MODEL_ID= PLUGIN_ID + ".CBuildModel";
public static final String PLUGIN_ID = "org.eclipse.cdt.core";
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 ResourceBundle fgResourceBundle;
@ -49,12 +51,14 @@ public class CCorePlugin extends Plugin {
private CDescriptorManager fDescriptorManager;
// -------- static methods --------
static {
try {
fgResourceBundle= ResourceBundle.getBundle("org.eclipse.cdt.internal.CCorePluginResources");
fgResourceBundle =
ResourceBundle.getBundle(
"org.eclipse.cdt.internal.CCorePluginResources");
} catch (MissingResourceException x) {
fgResourceBundle= null;
fgResourceBundle = null;
}
}
@ -67,50 +71,52 @@ public class CCorePlugin extends Plugin {
return "#" + key + "#";
}
}
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
public static String getFormattedString(String key, String arg) {
return MessageFormat.format(getResourceString(key), new String[] { arg });
}
public static String getFormattedString(String key, String arg) {
return MessageFormat.format(
getResourceString(key),
new String[] { arg });
}
public static String getFormattedString(String key, String[] args) {
return MessageFormat.format(getResourceString(key), args);
}
public static ResourceBundle getResourceBundle() {
return fgResourceBundle;
}
public static CCorePlugin getDefault() {
return fgCPlugin;
}
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Error", e));
}
public static void log(IStatus status) {
((Plugin)getDefault()).getLog().log(status);
}
((Plugin) getDefault()).getLog().log(status);
}
// ------ CPlugin
public CCorePlugin(IPluginDescriptor descriptor) {
super(descriptor);
fgCPlugin= this;
fgCPlugin = this;
}
/**
* @see Plugin#shutdown
*/
public void shutdown() throws CoreException {
super.shutdown();
fDescriptorManager.shutdown();
}
}
/**
* @see Plugin#startup
*/
@ -127,22 +133,28 @@ public class CCorePlugin extends Plugin {
public IConsole getConsole(String id) {
try {
IExtensionPoint extension = getDescriptor().getExtensionPoint("CBuildConsole");
IExtensionPoint extension =
getDescriptor().getExtensionPoint("CBuildConsole");
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
for(int i = 0; i < extensions.length; i++){
IConfigurationElement [] configElements = extensions[i].getConfigurationElements();
for( int j = 0; j < configElements.length; j++ ) {
String builderID = configElements[j].getAttribute("builderID");
if ( (id == null && builderID == null) ||
( id != null && builderID.equals(id))) {
return (IConsole)configElements[j].createExecutableExtension("class");
}
IExtension[] extensions = extension.getExtensions();
for (int i = 0; i < extensions.length; i++) {
IConfigurationElement[] configElements =
extensions[i].getConfigurationElements();
for (int j = 0; j < configElements.length; j++) {
String builderID =
configElements[j].getAttribute("builderID");
if ((id == null && builderID == null)
|| (id != null && builderID.equals(id))) {
return (
IConsole) configElements[j]
.createExecutableExtension(
"class");
}
}
}
}
}
} catch (CoreException e) {
}
}
return new IConsole() {
public void clear() {
}
@ -158,41 +170,36 @@ public class CCorePlugin extends Plugin {
return getConsole(null);
}
public IBinaryParserConfiguration[] getBinaryParserConfigurations() {
ArrayList list = new ArrayList();
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) {
public IBinaryParser getBinaryParser(IProject project) throws CoreException {
IBinaryParser parser = null;
try {
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 attr = configElements[j].getAttribute("format");
if (attr != null && attr.equalsIgnoreCase(format)) {
return (IBinaryParser)configElements[j].createExecutableExtension("class");
}
ICDescriptor cdesc = (ICDescriptor) getCProjectDescription(project);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID);
if (cextensions.length > 0)
parser = (IBinaryParser) cextensions[0].createExtension();
} catch (CoreException e) {
}
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;
}
}
}
} catch (CoreException e) {
}
return null;
} else {
IStatus s = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, "No Binary Format", null);
throw new CoreException(s);
}
}
return parser;
}
public CoreModel getCoreModel() {
@ -201,197 +208,236 @@ public class CCorePlugin extends Plugin {
public IndexModel getIndexModel() {
return IndexModel.getDefault();
}
public ICDescriptor getCProjectDescription(IProject project) throws CoreException {
}
public ICDescriptor getCProjectDescription(IProject project)
throws CoreException {
return fDescriptorManager.getDescriptor(project);
}
public void mapCProjectOwner(IProject project, String id, boolean override) throws CoreException {
if ( !override ) {
public void mapCProjectOwner(IProject project, String id, boolean override)
throws CoreException {
if (!override) {
fDescriptorManager.configure(project, id);
} else {
fDescriptorManager.convert(project, id);
}
}
/**
* Creates a C project resource given the project handle and description.
*
* @param description the project description 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 projectID required for mapping the project to an owner
*
* @exception CoreException if the operation fails
* @exception OperationCanceledException if the operation is canceled
*/
public IProject createCProject(IProjectDescription description, IProject projectHandle,
IProgressMonitor monitor, String projectID) throws CoreException, OperationCanceledException {
try {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Creating C Project", 3);//$NON-NLS-1$
if (!projectHandle.exists()){
projectHandle.create(description, monitor);
}
if (monitor.isCanceled()){
throw new OperationCanceledException();
}
// Open first.
projectHandle.open(monitor);
// Add C Nature ... does not add duplicates
CProjectNature.addCNature(projectHandle, new SubProgressMonitor(monitor, 1));
mapCProjectOwner(projectHandle, projectID, false);
} finally {
//monitor.done();
}
return projectHandle;
}
/**
* Creates a C project resource given the project handle and description.
*
* @param description the project description 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 projectID required for mapping the project to an owner
*
* @exception CoreException if the operation fails
* @exception OperationCanceledException if the operation is canceled
*/
public IProject createCProject(
IProjectDescription description,
IProject projectHandle,
IProgressMonitor monitor,
String projectID)
throws CoreException, OperationCanceledException {
try {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Creating C Project", 3); //$NON-NLS-1$
if (!projectHandle.exists()) {
projectHandle.create(description, monitor);
}
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
// Open first.
projectHandle.open(monitor);
// Add C Nature ... does not add duplicates
CProjectNature.addCNature(
projectHandle,
new SubProgressMonitor(monitor, 1));
mapCProjectOwner(projectHandle, projectID, false);
} finally {
//monitor.done();
}
return projectHandle;
}
/**
* Method convertProjectFromCtoCC converts
* a C Project to a C++ Project
* The newProject MUST, not be null, already have a C Nature
* && must NOT already have a C++ Nature
*
* @param projectHandle
* @param monitor
* @throws CoreException
*/
public void convertProjectFromCtoCC(
IProject projectHandle,
IProgressMonitor monitor)
throws CoreException {
if ((projectHandle != null)
&& projectHandle.hasNature(CCProjectNature.C_NATURE_ID)
&& !projectHandle.hasNature(CCProjectNature.CC_NATURE_ID)) {
// Add C++ Nature ... does not add duplicates
CCProjectNature.addCCNature(projectHandle, monitor);
}
}
/**
* Method convertProjectFromCtoCC converts
* a C Project to a C++ Project
* The newProject MUST, not be null, already have a C Nature
* && must NOT already have a C++ Nature
*
* @param projectHandle
* @param monitor
* @throws CoreException
*/
public void convertProjectFromCtoCC(IProject projectHandle, IProgressMonitor monitor)
throws CoreException{
if ((projectHandle != null)
&& projectHandle.hasNature(CCProjectNature.C_NATURE_ID)
&& !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
* @param projectHandle
* @param monitor
* @exception CoreException
* @exception CoreException
*/
public void addDefaultCBuilder( IProject projectHandle, IProgressMonitor monitor)
throws CoreException{
// Set the Default C Builder.
CProjectNature.addCBuildSpec(projectHandle, monitor);
}
public void addDefaultCBuilder(
IProject projectHandle,
IProgressMonitor monitor)
throws CoreException {
// Set the Default C Builder.
CProjectNature.addCBuildSpec(projectHandle, monitor);
}
/**
* Method to convert a project to a C nature
* & default make builder (Will always add a default builder)
* All checks should have been done externally
* (as in the Conversion Wizards).
* This method blindly does the conversion.
*
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @exception CoreException
*/
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID)
throws CoreException{
this.convertProjectToC(projectHandle, monitor, projectID, true);
/**
* Method to convert a project to a C nature
* & default make builder (Will always add a default builder)
* All checks should have been done externally
* (as in the Conversion Wizards).
* This method blindly does the conversion.
*
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @exception CoreException
*/
public void convertProjectToC(
IProject projectHandle,
IProgressMonitor monitor,
String projectID)
throws CoreException {
this.convertProjectToC(projectHandle, monitor, projectID, true);
}
/**
* Method to convert a project to a C nature
* & default make builder (if indicated)
* All checks should have been done externally
* (as in the Conversion Wizards).
* This method blindly does the conversion.
*
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @param addMakeBuilder
* @exception CoreException
*/
public void convertProjectToC(
IProject projectHandle,
IProgressMonitor monitor,
String projectID,
boolean addMakeBuilder)
throws CoreException {
if ((projectHandle == null)
|| (monitor == null)
|| (projectID == null)) {
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description =
workspace.newProjectDescription(projectHandle.getName());
description.setLocation(projectHandle.getFullPath());
createCProject(description, projectHandle, monitor, projectID);
if (addMakeBuilder) {
addDefaultCBuilder(projectHandle, monitor);
}
}
/**
* Method to convert a project to a C++ nature
* & 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)
throws CoreException {
if ((projectHandle == null)
|| (monitor == null)
|| (projectID == null)) {
return;
}
createCProject(
projectHandle.getDescription(),
projectHandle,
monitor,
projectID);
// now add C++ nature
convertProjectFromCtoCC(projectHandle, monitor);
if (addMakeBuilder) {
addDefaultCBuilder(projectHandle, monitor);
}
}
/**
* 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)
throws CoreException {
this.convertProjectToCC(projectHandle, monitor, projectID, true);
}
// Extract the builder from the .cdtproject.
// public ICBuilder[] getBuilders(IProject project) throws CoreException {
// ICExtension extensions[] = fDescriptorManager.createExtensions(BUILDER_MODEL_ID, project);
// ICBuilder builders[] = new ICBuilder[extensions.length];
// System.arraycopy(extensions, 0, builders, 0, extensions.length);
// return builders;
// }
}
/**
* Method to convert a project to a C nature
* & default make builder (if indicated)
* All checks should have been done externally
* (as in the Conversion Wizards).
* This method blindly does the conversion.
*
* @param project
* @param String targetNature
* @param monitor
* @param projectID
* @param addMakeBuilder
* @exception CoreException
*/
public void convertProjectToC(IProject projectHandle, IProgressMonitor monitor, String projectID, boolean addMakeBuilder)
throws CoreException{
if ((projectHandle == null) || (monitor == null) || (projectID == null)){
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.newProjectDescription(projectHandle.getName());
description.setLocation(projectHandle.getFullPath());
createCProject(description, projectHandle, monitor, projectID);
if (addMakeBuilder) {
addDefaultCBuilder(projectHandle, monitor);
}
}
/**
* Method to convert a project to a C++ nature
* & 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)
throws CoreException{
if ((projectHandle == null) || (monitor == null) || (projectID == null)){
return;
}
createCProject(projectHandle.getDescription(), projectHandle, monitor, projectID);
// now add C++ nature
convertProjectFromCtoCC(projectHandle, monitor);
if (addMakeBuilder){
addDefaultCBuilder(projectHandle, monitor);
}
}
/**
* 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)
throws CoreException{
this.convertProjectToCC(projectHandle, monitor, projectID, true);
}
// Extract the builder from the .cdtproject.
// public ICBuilder[] getBuilders(IProject project) throws CoreException {
// ICExtension extensions[] = fDescriptorManager.createExtensions(BUILDER_MODEL_ID, project);
// ICBuilder builders[] = new ICBuilder[extensions.length];
// System.arraycopy(extensions, 0, builders, 0, extensions.length);
// return builders;
// }
public IProcessList getProcessList() {
IExtensionPoint extension = getDescriptor().getExtensionPoint("ProcessList");
IExtensionPoint extension =
getDescriptor().getExtensionPoint("ProcessList");
if (extension != null) {
IExtension[] extensions = extension.getExtensions();
IConfigurationElement [] configElements = extensions[0].getConfigurationElements();
if ( configElements.length != 0 ) {
IExtension[] extensions = extension.getExtensions();
IConfigurationElement[] configElements =
extensions[0].getConfigurationElements();
if (configElements.length != 0) {
try {
return (IProcessList) configElements[0].createExecutableExtension("class");
}
catch (CoreException e) {
return (
IProcessList) configElements[0]
.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;
public class CDescriptor implements ICDescriptor {
/* constants */
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private COwner fOwner;
private IProject fProject;
private HashMap extMap = new HashMap(4);
@ -177,12 +175,15 @@ public class CDescriptor implements ICDescriptor {
}
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) {
ICExtensionReference[] ext = get(extensionID);
if ((ext == null || ext.length == 0) && update) {
if (ext.length == 0 && update) {
try {
fOwner.update(fProject, this, extensionID);
saveInfo();
@ -204,8 +205,8 @@ public class CDescriptor implements ICDescriptor {
extensions = newExtensions;
extMap.put(extensionPoint, extensions);
}
setDirty();
extensions[extensions.length - 1] = new CExtensionReference(this, extensionPoint, extensionID);
setDirty();
return extensions[extensions.length - 1];
}
@ -230,7 +231,7 @@ public class CDescriptor implements ICDescriptor {
public void remove(String extensionPoint) throws CoreException {
CExtensionReference extensions[] = (CExtensionReference[]) extMap.get(extensionPoint);
if (extensions != null) {
extMap.put(extensionPoint, null);
extMap.remove(extensionPoint);
setDirty();
}
}

View file

@ -88,6 +88,7 @@ public class CDescriptorManager implements IResourceChangeListener {
cproject = (CDescriptor)fDescriptorMap.get(project) ;
if ( cproject == null ) {
cproject = new CDescriptor(project);
cproject.setAutoSave(true);
fDescriptorMap.put(project, 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.IBinaryParserConfiguration;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.cdt.utils.ui.controls.RadioButtonsArea;
import org.eclipse.cdt.utils.ui.swt.IValidation;
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.NullProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
public class BinaryParserBlock implements IWizardTab {
private static final String PREFIX = "BinaryParserBlock"; //$NON-NLS-1$
private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
//private static final String PREFIX = "BinaryParserBlock"; //$NON-NLS-1$
//private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
private static String[][] radios;
private IProject project;
protected RadioButtonsArea radioButtons;
private String defaultFormat;
// protected Button defButton;
private String id;
// protected Button defButton;
IValidation page;
@ -39,16 +41,28 @@ public class BinaryParserBlock implements IWizardTab {
public BinaryParserBlock(IValidation valid, IProject p) {
page = valid;
project = p;
IBinaryParserConfiguration[] configs = CCorePlugin.getDefault().getBinaryParserConfigurations();
radios = new String[configs.length][2];
for (int i = 0; i < configs.length; i++) {
radios[i] = new String[] {configs[i].getName(), configs[i].getFormat()};
IExtensionPoint point = CCorePlugin.getDefault().getDescriptor().getExtensionPoint(CCorePlugin.BINARY_PARSER_SIMPLE_ID);
if (point != null) {
IExtension[] exts = point.getExtensions();
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();
if (project == null) {
defaultFormat = model.getDefaultBinaryParserFormat();
} else {
defaultFormat = model.getBinaryParserFormat(project);
try {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(p);
ICExtensionReference[] ref = desc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID);
if (ref.length > 0)
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.setEnabled(true);
if (defaultFormat != null) {
radioButtons.setSelectValue(defaultFormat);
if (id != null) {
radioButtons.setSelectValue(id);
}
return composite;
}
@ -75,7 +89,7 @@ public class BinaryParserBlock implements IWizardTab {
public boolean isValid() {
return true;
}
public void setVisible(boolean visible) {
}
@ -84,13 +98,18 @@ public class BinaryParserBlock implements IWizardTab {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Parsers", 1);
CoreModel model = CCorePlugin.getDefault().getCoreModel();
String format = radioButtons.getSelectedValue();
if (format != null) {
if (defaultFormat == null || !format.equals(defaultFormat)) {
model.setBinaryParserFormat(project, format, monitor);
defaultFormat = format;
try {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(project);
String identity = radioButtons.getSelectedValue();
if (identity != null) {
if (id == null || !identity.equals(id)) {
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) {
}
}