diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index c27d2405b20..9d71cc0a9e0 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -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. * diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java index b61a154b890..7bfd97df0a6 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/InputType.java @@ -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(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java index 797d5d1f36c..e16b3c3e0db 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedMakeProject.java @@ -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) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java index d64e09b70ef..68d3ea0be99 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Option.java @@ -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) { diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java index 082a3856363..809bdc25f00 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/OutputType.java @@ -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(); } diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties index af6b240fcb1..6c8ffdae2fb 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties @@ -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: diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java index 1be5cc97fbf..1cb791f8126 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ResourceChangeHandler.java @@ -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; diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java index d8f9df51020..a191d116f48 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java @@ -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