1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

Fix problem with trying to access managedBuildInfo before the .cdtbuild file is created

Update how .c extension is added to a converted project
Update how the project specific file extensions are obtained
Fix problem with resolving options
This commit is contained in:
Leo Treggiari 2005-07-10 03:25:24 +00:00
parent 610f6d0dac
commit 07d3cbbf01
9 changed files with 196 additions and 128 deletions

View file

@ -116,6 +116,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
private static final String VERSION_ELEMENT_NAME = "fileVersion"; //$NON-NLS-1$
private static final String MANIFEST_VERSION_ERROR ="ManagedBuildManager.error.manifest.version.error"; //$NON-NLS-1$
private static final String PROJECT_VERSION_ERROR ="ManagedBuildManager.error.project.version.error"; //$NON-NLS-1$
private static final String PROJECT_FILE_ERROR = "ManagedBuildManager.error.project.file.missing"; //$NON-NLS-1$
private static final String MANIFEST_ERROR_HEADER = "ManagedBuildManager.error.manifest.header"; //$NON-NLS-1$
public static final String MANIFEST_ERROR_RESOLVING = "ManagedBuildManager.error.manifest.resolving"; //$NON-NLS-1$
public static final String MANIFEST_ERROR_DUPLICATE = "ManagedBuildManager.error.manifest.duplicate"; //$NON-NLS-1$
@ -1463,6 +1464,18 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return(buildInfoVersion.isGreaterOrEqualTo(version));
}
/* (non-Javadoc)
* Determine if the .cdtbuild file is present, which will determine if build information
* can be loaded externally or not. Return true if present, false otherwise.
*/
private static boolean canLoadBuildInfo(final IProject project) {
IFile file = project.getFile(SETTINGS_FILE_NAME);
if (file == null) return false;
File cdtbuild = file.getLocation().toFile();
if (cdtbuild == null) return false;
return cdtbuild.exists();
}
/* (non-Javadoc)
* Load the build information for the specified resource from its project
* file. Pay attention to the version number too.
@ -1471,9 +1484,11 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
ManagedBuildInfo buildInfo = null;
IFile file = project.getFile(SETTINGS_FILE_NAME);
File cdtbuild = file.getLocation().toFile();
if (!cdtbuild.exists())
return null;
if (!cdtbuild.exists()) {
// If we cannot find the .cdtbuild project file, throw an exception and let the user know
throw new BuildException(ManagedMakeMessages.getFormattedString(PROJECT_FILE_ERROR, project.getName()));
}
// So there is a project file, load the information there
InputStream stream = new FileInputStream(cdtbuild);
try {
@ -1931,10 +1946,10 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
}
/**
/*
* Creates a new build information object and associates it with the
* resource in the argument. Note that the information contains no
* build target or configuation information. It is the respoinsibility
* build target or configuation information. It is the responsibility
* of the caller to populate it. It is also important to note that the
* caller is responsible for associating an IPathEntryContainer with the
* build information after it has been populated.
@ -2011,7 +2026,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
* @return
*/
private static ManagedBuildInfo findBuildInfo(IResource resource/*, boolean create*/) {
// I am sick of NPEs
if (resource == null) return null;
// Make sure the extension information is loaded first
@ -2035,7 +2050,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return null;
}
if(buildInfo == null && resource instanceof IProject)
if (buildInfo == null && resource instanceof IProject)
buildInfo = findBuildInfoSynchronized((IProject)resource);
/*
// Nothing in session store, so see if we can load it from cdtbuild
@ -2057,6 +2072,47 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return buildInfo;
}
/* (non-Javadoc)
* Determine if build information can be found. Various attempts are made
* to find the information, and if successful, true is returned; false otherwise.
* Typically, this routine would be called prior to findBuildInfo, to deterimine
* if findBuildInfo should be called to actually do the loading of build
* information, if possible
* @param resource
* @return
*/
private static boolean canFindBuildInfo(IResource resource) {
if (resource == null) return false;
// Make sure the extension information is loaded first
try {
loadExtensions();
} catch (BuildException e) {
e.printStackTrace();
return false;
}
ManagedBuildInfo buildInfo = null;
// Check if there is any build info associated with this project for this session
try {
buildInfo = (ManagedBuildInfo)resource.getSessionProperty(buildInfoProperty);
} catch (CoreException e) {
// Continue, to see if any of the upcoming checks are successful
}
if (buildInfo == null && resource instanceof IProject) {
// Check weather getBuildInfo is called from converter
buildInfo = UpdateManagedProjectManager.getConvertedManagedBuildInfo((IProject)resource);
if (buildInfo != null) return true;
// Check if the build information can be loaded from the .cdtbuild file
return canLoadBuildInfo(((IProject)resource));
}
return (buildInfo != null);
}
/* (non-Javadoc)
* this method is called if managed build info session property
* was not set. The caller will use the project rule
@ -2094,7 +2150,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
// Check weather getBuildInfo is called from converter
if(buildInfo == null) {
if (buildInfo == null) {
buildInfo = UpdateManagedProjectManager.getConvertedManagedBuildInfo(project);
if (buildInfo != null) return buildInfo;
}
@ -2160,6 +2216,18 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
return findBuildInfo(resource.getProject());
}
/**
* Determines if the managed build information for the
* argument can be found.
*
* @see ManagedBuildManager#initBuildInfo(IResource)
* @param resource The resource to search for managed build information on.
* @return boolean True if the build info can be found; false otherwise.
*/
public static boolean canGetBuildInfo(IResource resource) {
return canFindBuildInfo(resource.getProject());
}
/**
* Answers the current version of the managed builder plugin.
*

View file

@ -683,23 +683,6 @@ public class InputType extends BuildObject implements IInputType {
}
return (IPath[])ins.toArray(new IPath[ins.size()]);
}
/* (non-Javadoc)
* Returns the project that uses this IInputType
*/
public IProject getProject(ITool tool) {
IBuildObject toolParent = tool.getParent();
if (toolParent != null) {
if (toolParent instanceof IToolChain) {
IConfiguration config = ((IToolChain)toolParent).getParent();
if (config == null) return null;
return (IProject)config.getOwner();
} else if (toolParent instanceof IResourceConfiguration) {
return (IProject)((IResourceConfiguration)toolParent).getOwner();
}
}
return null;
}
/* (non-Javadoc)
* Memory-safe way to access the list of input orders
@ -833,23 +816,7 @@ public class InputType extends BuildObject implements IInputType {
// Use content type if specified and registered with Eclipse
IContentType type = getDependencyContentType();
if (type != null) {
IContentTypeSettings settings = null;
IProject project = getProject(tool);
if (project != null) {
IScopeContext projectScope = new ProjectScope(project);
try {
settings = type.getSettings(projectScope);
} catch (Exception e) {}
if (settings != null) {
String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
// TODO: There doesn't seem to be any way to distinguish between these 2 cases:
// 1. No project specific entries have been set so getFileSpecs returns an empty list
// 2. There are project specific entries and all of the "default" entries have been removed
// For now, we have to assume the first case.
if (specs.length > 0) return specs;
}
}
return type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
return ((Tool)tool).getContentTypeFileSpecs(type);
}
return getDependencyExtensionsAttribute();
}
@ -1049,23 +1016,7 @@ public class InputType extends BuildObject implements IInputType {
// Use content type if specified and registered with Eclipse
IContentType type = getSourceContentType();
if (type != null) {
IContentTypeSettings settings = null;
IProject project = getProject(tool);
if (project != null) {
IScopeContext projectScope = new ProjectScope(project);
try {
settings = type.getSettings(projectScope);
} catch (Exception e) {}
if (settings != null) {
String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
// TODO: There doesn't seem to be any way to distinguish between these 2 cases:
// 1. No project specific entries have been set so getFileSpecs returns an empty list
// 2. There are project specific entries and all of the "default" entries have been removed
// For now, we have to assume the first case.
if (specs.length > 0) return specs;
}
}
return type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
return ((Tool)tool).getContentTypeFileSpecs(type);
}
return getSourceExtensionsAttribute();
}

View file

@ -66,28 +66,33 @@ public class ManagedMakeProject implements ICOwner {
private void updateBinaryParsers(ICDescriptor cDescriptor) throws CoreException {
IManagedBuildInfo buildInfo = null;
String[] ids = null;
try {
IProject project = cDescriptor.getProject();
buildInfo = ManagedBuildManager.getBuildInfo(project);
if (buildInfo != null) {
IConfiguration config = buildInfo.getDefaultConfiguration();
if (config == null && buildInfo.getManagedProject() != null) {
IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations();
if (configs != null && configs.length > 0)
config = configs[0];
}
if (config != null) {
// Get the values from the current configuration
IToolChain toolChain = config.getToolChain();
if (toolChain != null) {
ITargetPlatform targPlatform = toolChain.getTargetPlatform();
if (targPlatform != null) {
ids = targPlatform.getBinaryParserList();
}
IProject project = cDescriptor.getProject();
// If we cannot get the build information, it may be due to the fact that the
// build information is yet to be created, due to a synchronization issue
// Don't do anything now to the binary parsers because there is nothing meaningful to do.
// This routine should be invoked later, when the required build information is available
if (!ManagedBuildManager.canGetBuildInfo(project)) return;
buildInfo = ManagedBuildManager.getBuildInfo(project);
if (buildInfo != null) {
IConfiguration config = buildInfo.getDefaultConfiguration();
if (config == null && buildInfo.getManagedProject() != null) {
IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations();
if (configs != null && configs.length > 0)
config = configs[0];
}
if (config != null) {
// Get the values from the current configuration
IToolChain toolChain = config.getToolChain();
if (toolChain != null) {
ITargetPlatform targPlatform = toolChain.getTargetPlatform();
if (targPlatform != null) {
ids = targPlatform.getBinaryParserList();
}
}
}
} catch (Exception e) {return;}
}
cDescriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
if (ids != null) {

View file

@ -1527,6 +1527,10 @@ public class Option extends BuildObject implements IOption {
superClassId,
"option", //$NON-NLS-1$
getId());
} else {
// All of our superclasses must be resolved in order to call
// getValueType below.
((Option)superClass).resolveReferences();
}
}
if (categoryId != null) {

View file

@ -419,22 +419,6 @@ public class OutputType extends BuildObject implements IOutputType {
return parent;
}
/* (non-Javadoc)
* Returns the project that uses this IOutputType
*/
public IProject getProject(ITool tool) {
IProject project = null;
IBuildObject toolParent = tool.getParent();
if (toolParent != null) {
if (toolParent instanceof IToolChain) {
return (IProject)((IToolChain)toolParent).getParent().getOwner();
} else if (toolParent instanceof IResourceConfiguration) {
return (IProject)((IResourceConfiguration)toolParent).getOwner();
}
}
return project;
}
/*
* M O D E L A T T R I B U T E A C C E S S O R S
*/
@ -662,23 +646,7 @@ public class OutputType extends BuildObject implements IOutputType {
// Use content type if specified and registered with Eclipse
IContentType type = getOutputContentType();
if (type != null) {
IContentTypeSettings settings = null;
IProject project = getProject(tool);
if (project != null) {
IScopeContext projectScope = new ProjectScope(project);
try {
settings = type.getSettings(projectScope);
} catch (Exception e) {}
if (settings != null) {
String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
// TODO: There doesn't seem to be any way to distinguish between these 2 cases:
// 1. No project specific entries have been set so getFileSpecs returns an empty list
// 2. There are project specific entries and all of the "default" entries have been removed
// For now, we have to assume the first case.
if (specs.length > 0) return specs;
}
}
return type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
return ((Tool)tool).getContentTypeFileSpecs(type);
}
return getOutputExtensionsAttribute();
}

View file

@ -48,9 +48,10 @@ ManagedBuildManager.error.manifest.option.category=Option {0} uses a null catego
ManagedBuildManager.error.manifest.option.filter=Option {0} uses an unsupported resourceFilter attribute value. The option was ignored.
ManagedBuildManager.error.manifest.option.valuehandler=Could not load value handler {0} in option {1}.
ManagedBuildManager.error.open_failed_title=Managed Make Project File Error
ManagedBuildManager.error.open_failed=The Managed Make project file could not be read because of the following error.\n\n{0}\n\nManaged Make functionality will not be available for this project.
ManagedBuildManager.error.open_failed=The Managed Make project file could not be read because of the following error:\n\n{0}\n\nManaged Make functionality will not be available for this project.
ManagedBuildManager.error.project.version.error=The version number of the project {0} is greater than the Managed Build System version number.
ManagedBuildManager.error.id.nomatch=Error loading Managed Make project information for project {0}. The tool definitions used to create the project are not available.
ManagedBuildManager.error.project.file.missing=The Managed Make project file for project {0} is missing.
# Makefile Generator Messages
MakefileGenerator.message.start.file=Building file:
MakefileGenerator.message.finish.file=Finished building:

View file

@ -253,13 +253,17 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
private IManagedBuilderMakefileGenerator getInitializedGenerator(IProject project){
IManagedBuilderMakefileGenerator makeGen = (IManagedBuilderMakefileGenerator)fBuildFileGeneratorMap.get(project);
if(makeGen == null){
try{
if(project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)){
if (makeGen == null) {
try {
if (project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
// Determine if we can access the build info before actually trying
// If not, don't try, to avoid putting up a dialog box warning the user
if (!ManagedBuildManager.canGetBuildInfo(project)) return null;
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
if(buildInfo != null){
if (buildInfo != null){
IConfiguration defaultCfg = buildInfo.getDefaultConfiguration();
if(defaultCfg != null){
if (defaultCfg != null) {
makeGen = ManagedBuildManager.getBuildfileGenerator(defaultCfg);
makeGen.initialize(project,buildInfo,new NullProgressMonitor());
fBuildFileGeneratorMap.put(project,makeGen);
@ -267,6 +271,7 @@ public class ResourceChangeHandler implements IResourceChangeListener, ISavePart
}
}
} catch (CoreException e){
return null;
}
}
return makeGen;

View file

@ -46,6 +46,8 @@ import org.eclipse.cdt.managedbuilder.internal.macros.MacroResolver;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtension;
@ -54,6 +56,9 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PluginVersionIdentifier;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@ -2639,4 +2644,49 @@ public class Tool extends HoldsOptions implements ITool, IOptionCategory {
public IConfigurationElement getCurrentMbsVersionConversionElement() {
return currentMbsVersionConversionElement;
}
public IProject getProject() {
IBuildObject toolParent = getParent();
if (toolParent != null) {
if (toolParent instanceof IToolChain) {
IConfiguration config = ((IToolChain)toolParent).getParent();
if (config == null) return null;
return (IProject)config.getOwner();
} else if (toolParent instanceof IResourceConfiguration) {
return (IProject)((IResourceConfiguration)toolParent).getOwner();
}
}
return null;
}
public String[] getContentTypeFileSpecs (IContentType type) {
String[] globalSpecs = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
IContentTypeSettings settings = null;
IProject project = getProject();
if (project != null) {
IScopeContext projectScope = new ProjectScope(project);
try {
settings = type.getSettings(projectScope);
} catch (Exception e) {}
if (settings != null) {
String[] specs = settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
if (specs.length > 0) {
int total = globalSpecs.length + specs.length;
String[] projSpecs = new String[total];
int i=0;
for (int j=0; j<specs.length; j++) {
projSpecs[i] = specs[j];
i++;
}
for (int j=0; j<globalSpecs.length; j++) {
projSpecs[i] = globalSpecs[j];
i++;
}
return projSpecs;
}
}
}
return globalSpecs;
}
}

View file

@ -27,6 +27,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
@ -37,8 +38,14 @@ import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;
class UpdateManagedProject21 {
private static final String CONTENT_TYPE_PREF_NODE = "content-types"; //$NON-NLS-1$
private static final String FULLPATH_CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + CONTENT_TYPE_PREF_NODE;
private static final String PREF_LOCAL_CONTENT_TYPE_SETTINGS = "enabled"; //$NON-NLS-1$
/**
* @param monitor the monitor to allow users to cancel the long-running operation
@ -138,20 +145,29 @@ class UpdateManagedProject21 {
IResource.NONE);
if(found[0]){
IScopeContext projectScope = new ProjectScope(project);
// First, we need to enable user settings on the project __explicitely__
// Unfortunately there is no clear API in Eclipse-3.1 to do this.
// We should revisit this code when Eclipse-3.1.x and above is out
// with more complete API.
Preferences contentTypePrefs = projectScope.getNode(FULLPATH_CONTENT_TYPE_PREF_NODE);
// enable project-specific settings for this project
contentTypePrefs.putBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, true);
try {
contentTypePrefs.flush();
} catch (BackingStoreException e) {
// ignore ??
}
// Now the project setting is on/enable.
// Add the new association in the project user setting.
// the conflict resolution of the ContentTypeManager framework
// will give preference to the project settings.
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType("org.eclipse.cdt.core.cxxSource"); //$NON-NLS-1$
IScopeContext projectScope = new ProjectScope(project);
IContentTypeSettings settings = contentType.getSettings(projectScope);
// First, copy the extensions from the "global" content type
String[] specs = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
for (int j = 0; j < specs.length; j++) {
settings.addFileSpec(specs[j], IContentType.FILE_EXTENSION_SPEC);
}
specs = contentType.getFileSpecs(IContentType.FILE_NAME_SPEC);
for (int j = 0; j < specs.length; j++) {
settings.addFileSpec(specs[j], IContentType.FILE_NAME_SPEC);
}
// Add the .c extension
// Add the .c extension on the C++ content type.
settings.addFileSpec("c", IContentType.FILE_EXTENSION_SPEC); //$NON-NLS-1$
}
} catch (CoreException e) {