Bug 277533 - All references to ManagedBuildManager.SETTINGS_FILE_NAME should be updated
Summary: All references to ManagedBuildManager.SETTINGS_FILE_NAME should be updated
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 6.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-22 16:06 EDT by Navid Mehregani CLA
Modified: 2020-09-04 15:26 EDT (History)
1 user (show)

See Also:


Attachments
Simple patch (898 bytes, patch)
2009-06-02 16:30 EDT, James Blackburn CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Navid Mehregani CLA 2009-05-22 16:06:46 EDT
As far as I understand, the .cproject file has taken over the position of .cdtbuild.  However, ManagedBuildManager.SETTINGS_FILE_NAME is still pointing to .cdtbuild.  This is causing a number of NPEs.

For example, ManagedBuildManager.canLoadBuildInfo throws a null pointer exception, because "file.getLocation()" is null in the following:

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();
}

Either the ManagedBuildManager.SETTINGS_FILE_NAME constant has to be changed or all the code that references this constant should be updated.
Comment 1 Chris Recoskie CLA 2009-05-25 12:02:02 EDT
The constant is used by the project conversion mechanism to update build settings from old projects, so we can't remove it.  The method you mention does need to change though.
Comment 2 Chris Recoskie CLA 2009-05-25 12:02:29 EDT
Er, I meant change, not remove.
Comment 3 Chris Recoskie CLA 2009-05-25 14:46:26 EDT
Ok I'm confused...

From what I can tell, canLoadBuildInfo() is only called in one place, by ManagedBuildManager.canFindBuildInfo(), and even then if it's an older project that has been converted.  So as far as I know, this is doing what it's supposed to.

Were you using an old project at the time?  If so, did the .cdtbuild file get deleted?  Or is this a new project created with CDT 6.0?
Comment 4 Navid Mehregani CLA 2009-05-28 12:02:41 EDT
Does this mean public APIs that make a reference to this constant are deprecated?  (Example: ManagedBuildManager.canGetBuildInfo(IResource)).  'canGetBuildInfo' doesn't seem to be deprecated in its javadoc.

We make references to these APIs in our code and when I upgraded my CDT plug-ins, I started getting NPEs.

Is there another method that should be used in place of this method?

Thanks!
Comment 5 Chris Recoskie CLA 2009-05-28 12:32:52 EDT
(In reply to comment #4)
> Does this mean public APIs that make a reference to this constant are
> deprecated?  (Example: ManagedBuildManager.canGetBuildInfo(IResource)). 
> 'canGetBuildInfo' doesn't seem to be deprecated in its javadoc.
> We make references to these APIs in our code and when I upgraded my CDT
> plug-ins, I started getting NPEs.
> Is there another method that should be used in place of this method?
> Thanks!

"Deprecated" is not quite the right word.  They are there for backwards compatibility.  So they're not deprecated in the sense of "don't reference them at all", but they don't reflect current functionality.

Unfortunately I don't see a way to get at this from public API, but ICProjectDescriptionStorageType.STORAGE_FILE_NAME is what you want I think.
Comment 6 Chris Recoskie CLA 2009-06-02 12:23:34 EDT
James (and others), do you think it's valid to want a public way to get at ICProjectDescriptionStorageType.STORAGE_FILE_NAME?  Or should we continue to intentionally hide this as internal?  I would think in general that it ought to be hidden, as reads and writes to the storage should happen via API calls.  However, maybe for project conversion we might need to check if the file exists?  Even then I would think we should be doing all that in the internals.
Comment 7 James Blackburn CLA 2009-06-02 16:30:54 EDT
Created attachment 138053 [details]
Simple patch

(In reply to comment #4)
> Does this mean public APIs that make a reference to this constant are
> deprecated?  (Example: ManagedBuildManager.canGetBuildInfo(IResource)). 
> 'canGetBuildInfo' doesn't seem to be deprecated in its javadoc.

canGetBuildInfo resorts to this only if the build information isn't loaded, and you're right, it's the wrong thing to do.

> We make references to these APIs in our code and when I upgraded my CDT
> plug-ins, I started getting NPEs.

Which other APIs? That seems to be the only method (having had a quick look at the call-hierarchy for SETTINGS_FILE_NAME).

I guess there are a couple of issues. AFAICS the API doesn't contain a way to get at this information. The project description is loaded and the build system is called back to load it's data.  The build system's data is opaque to the project description. There's no way for cdt.core / the build-system to know if there's data to load without actually trying to load it.
See #getBuildInfo(IProject):
This (effectively) does:
getLoadedBuildInfo() == null ?
   getProjectDescription(...)
   return getLoadedBuildInfo()

So by my reckoning you can replace canGetBuildInfo(IProject) with
getBuildInfo(IProject, true) != null

(In reply to comment #6)
> James (and others), do you think it's valid to want a public way to get at
> ICProjectDescriptionStorageType.STORAGE_FILE_NAME?  Or should we continue to
> intentionally hide this as internal?  I would think in general that it ought to
> be hidden, as reads and writes to the storage should happen via API calls. 
> However, maybe for project conversion we might need to check if the file
> exists?  Even then I would think we should be doing all that in the internals.

I agree. I think the storage should be considered and these variables should be internal / deprecated / marked don't use... The project's storage should be considered opaque as it might live anywhere.  

That said there may be a need to discover if a project has managed build enabled on it.  Note that testing for the existence of a file isn't sufficient to prove this... Perhaps this flag could be cached in the IResource metadata.  However given that we load and hang onto build configuration as soon as the project is loaded, the whole area of loading / storing seems to be in need of a revamp :)