Bug 241598 - [API] Constant needed for .classpath
Summary: [API] Constant needed for .classpath
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-21 19:19 EDT by Konstantin Komissarchik CLA
Modified: 2011-03-08 12:19 EST (History)
3 users (show)

See Also:


Attachments
Proposed Patch (1.94 KB, patch)
2008-07-21 19:19 EDT, Konstantin Komissarchik CLA
no flags Details | Diff
Proposed fix (3.15 KB, patch)
2011-02-04 10:32 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix (2.87 KB, patch)
2011-02-23 22:11 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix (2.77 KB, patch)
2011-02-24 11:51 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Komissarchik CLA 2008-07-21 19:19:30 EDT
Created attachment 108009 [details]
Proposed Patch

It would be nice to expose public constants for the .classpath and .settings/org.eclipse.jdt.core.prefs files. Such constants exist in the internal JavaProject class, so downstream plugins have to choose between referencing internal api or duplicating constants. I have seen numerous situations where these paths/names get duplicated in downstream plugins. This happens primarily in cases where a batched IWorkspace.validateEdit() request needs to be made prior to starting an operation.

Something similar to what platform has done with IProjectDescription.DESCRIPTION_FILE_NAME...

Attaching a proposed patch.
Comment 1 Markus Keller CLA 2011-02-04 09:43:27 EST
I agree about ".classpath" (but the Javadoc has to tell explicitly that the format of the file is not specified and that the file is not to be modified).

I wouldn't make the .prefs file API, since this is an implementation detail of the org.eclipse.equinox.preferences bundle, so any such API should go there (see org.eclipse.core.internal.preferences.EclipsePreferences#computeLocation(..)).
Comment 2 Olivier Thomann CLA 2011-02-04 09:49:12 EST
(In reply to comment #1)
> I wouldn't make the .prefs file API, since this is an implementation detail of
> the org.eclipse.equinox.preferences bundle, so any such API should go there
> (see
> org.eclipse.core.internal.preferences.EclipsePreferences#computeLocation(..)).
Thanks Markus. I agree. JDT/Core should not expose an API constant that is related to the preference bundle.
Comment 3 Olivier Thomann CLA 2011-02-04 09:56:42 EST
I would propose:
/**
 * Name of the file containing the project's classpath.
 * 
 * <p>The format of this file is unspecified and it is not meant to be modified.
 * Its contents is modified by using the <code>setRawClasspath</code> methods.</p>
 * 
 * @see #setRawClasspath(IClasspathEntry[], IProgressMonitor)
 * @see #setRawClasspath(IClasspathEntry[], boolean, IProgressMonitor)
 * @see #setRawClasspath(IClasspathEntry[], IPath, IProgressMonitor)
 * @see #setRawClasspath(IClasspathEntry[], IClasspathEntry[], IPath, IProgressMonitor)
 * @see #setRawClasspath(IClasspathEntry[], IPath, boolean, IProgressMonitor)
 * @since 3.7
 */
String CLASSPATH_FILE_PATH = ".classpath"; //$NON-NLS-1$
Comment 4 Markus Keller CLA 2011-02-04 10:18:46 EST
If you just say "Name of the file", then it's not clear where the file is located. "Path to the file" would at least suggest that it's a project-relative path.

But I would call the constant CLASSPATH_FILE_NAME and add "The file is a child of the project folder." as second sentence of the Javadoc.
Comment 5 Olivier Thomann CLA 2011-02-04 10:27:19 EST
(In reply to comment #4)
> But I would call the constant CLASSPATH_FILE_NAME and add "The file is a child
> of the project folder." as second sentence of the Javadoc.
Ok, sounds good. I'll adjust the patch.
Comment 6 Olivier Thomann CLA 2011-02-04 10:32:00 EST
Created attachment 188329 [details]
Proposed fix
Comment 7 Konstantin Komissarchik CLA 2011-02-04 13:16:06 EST
The attached patch addresses half the stated requirement. Perhaps instead of committing to API for specific files, we can have the following method:

IJavaProject.getMetadataFiles() -> List<IFile>

I think this would address Markus's concerns regarding not creating API around implementation details of preferences API while also allowing JDT API users to reliably validateEdit() _all_ classes that might need to be written when using JDT API.
Comment 8 Markus Keller CLA 2011-02-07 10:23:37 EST
(In reply to comment #7)
> IJavaProject.getMetadataFiles() -> List<IFile>

That would just be a guess, which can quite as well be implemented in client code. And it's too coarse-grained to be useful, since you still don't know which API modifies which files. E.g. when you copy a compilation unit that uses a non-default encoding, then this will modify org.eclipse.core.resources.prefs as well (or maybe the *.derived.* variant).

The best guess you can make is to include the whole .settings folder.
Comment 9 Konstantin Komissarchik CLA 2011-02-07 12:02:17 EST
Don't you think that this guess would be better implemented and maintained by JDT rather than by multitude of clients? Having clients "guess" the entire .settings directory is both not sufficient to cover all JDT metadata files and too broad, so users aren't going to stand for that.

The case of file encoding metadata can be handled separately as if you go to modify a compilation unit you will also be modifying the source file in question. You would need something like ICompilationUnit.getFiles(). Note that I am not requesting that API. The cases that I've seen center primarily around programmatic changes to classpath and compiler level settings.
Comment 10 Olivier Thomann CLA 2011-02-09 09:10:05 EST
Let be clear about what we can do here.
It makes sense to me to expose the path to the .classpath file. I don't like the idea of exposing the preferences files for a java project. This doesn't belong to the java project. This is handled by the preference bundles, not JDT.
Comment 11 Olivier Thomann CLA 2011-02-15 14:01:12 EST
(In reply to comment #9)
> Don't you think that this guess would be better implemented and maintained by
> JDT rather than by multitude of clients? Having clients "guess" the entire
> .settings directory is both not sufficient to cover all JDT metadata files and
> too broad, so users aren't going to stand for that.
JDT metadata is the .classpath file.
Files under .settings should be seen as metadata files from the preference bundle.

I plan to expose the .classpath constant. Maybe we should state that the value of the constant is unspecified. It is only a path relative to the project. So it can be used to retrieve the .classpath file and give us the freedom to change the layout in the future.
Comment 12 Olivier Thomann CLA 2011-02-23 22:03:25 EST
Markus, what do you think about releasing the current patch with the modification described in comment 11?
I found many usages of ".classpath" inside JDT code and this relies on an unspecified behavior. So it is worth specifying this once for all.
Comment 13 Olivier Thomann CLA 2011-02-23 22:11:53 EST
Created attachment 189670 [details]
Proposed fix

It could be something like this.
Comment 14 Markus Keller CLA 2011-02-24 08:27:56 EST
> +	 * <p>The value of the path is unspecified.

That doesn't work, since this is a compile-time constant that will be inlined in referencing class files. But since you won't be able to change this path anyway (for compatibility with old projects that are stored in source code repositories), I think you should just leave out this sentence.

If the path ever changes in the future, you'd have to deprecate this constant and add a new one for the new file.

The rest of the patch looks good.
Comment 15 Olivier Thomann CLA 2011-02-24 11:51:02 EST
Ok, I'll add back the previous sentence:
<p>The file is a child of the project folder.</p>

Will be released shortly.
Comment 16 Olivier Thomann CLA 2011-02-24 11:51:29 EST
Created attachment 189717 [details]
Proposed fix

Patch to be released.
Comment 17 Olivier Thomann CLA 2011-02-24 15:23:27 EST
Released for 3.7M6.
Comment 18 Jay Arthanareeswaran CLA 2011-03-08 12:19:20 EST
Verified for 3.7M6 by code inspection.