Bug 183995 - Public API to access mapping from resolved to raw classpath entries
Summary: Public API to access mapping from resolved to raw classpath entries
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-25 09:17 EDT by Rob Frost CLA
Modified: 2008-05-07 07:31 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Frost CLA 2007-04-25 09:17:05 EDT
I have a need to determine the mapping from resolved to raw classpath entries and am currently obtaining that information via the internal field JavaModelManager.PerProjectInfo.rootPathToRawEntries.

If an acceptable public API currently exists that I can leverage to access these mappings, that would be ideal, otherwise, I would like to request that this information be exposed via the JDT API.
Comment 1 Philipe Mulet CLA 2007-04-25 09:25:18 EDT
IPackageFragmentRoot#getRawClasspathEntry() provides you with this information, assuming you have root in your hands.

I suspect we could have a more flexible API which would only consider a root path, and thus could be used with path from roots or CP entries.
Comment 2 Philipe Mulet CLA 2007-04-25 09:26:25 EDT
Sthg like:

IJavaProject#getRawClasspathEntry(IPath)
IJavaProject#getResolvedClasspathEntry(IPath)

may need the kind as well.
Comment 3 Rob Frost CLA 2007-04-25 09:32:55 EDT
thanks for the info; that more flexible API would be great - I'll try out the IPackageFragmentRoot#getRawClasspathEntry() route now
Comment 4 Rob Frost CLA 2007-04-25 11:29:44 EDT
I was able to get things working using IPackageFragmentRoot but it was a bit awkward and involved calls that bypass the resolved cp cache: I made calls to IJavaProject.findPackageFragmentRoots() for desired raw IClasspathEntry objects (findPackageFragmentRoots() like it skips the PerProjectInfo cache when resolving entries); since I ultimately need resolved IClasspathEntry objects, I then then had to map the paths contained in the resolved IPackageFragmentRoots back to resolved IClasspathEntry objects.

Let me explain my use case and you can may be able to suggest a better public API approach (that leverages the resolved cp cache):

-I want to retrieve all resolved IClasspathEntry objects whose corresponding raw entries have a specific attribute

I had been doing this as follows:

-get the raw classpath and find all raw entries that have the attribute (return if no raw entries have the attribute)
-call IJavaProject.getResolvedClasspath() (which will use the cache if possible)
-iterate through the resolved entries:
  -use PerProjectInfo.rootPathToRawEntries to find the associated raw entry (looks like this is exactly how IPackageFragmentRoot.getRawClasspathEntry() locates the raw cp entry)
  -if the associated raw cp entry had the attribute, then add the resolved cp entry to the list to return (some other checks are done as well) 
Comment 5 Rob Frost CLA 2007-04-25 17:12:19 EDT
ignore the resolved cp cache issue; still have the issue with mapping back from resolved IPackageFragmentRoots to resolved IClasspathEntries so would be nice to eventually have an API like you suggested:

IJavaProject#getRawClasspathEntry(IPath) 
Comment 6 Jerome Lanneluc CLA 2007-04-26 04:50:04 EDT
Targeting for 3.4
Comment 7 Paul Tomlin CLA 2007-05-21 11:43:49 EDT
Not sure if this is related, or the best place for the comment, but this is the only ticket matching "resolvedPathToRawEntries" I can find, and the comments seem relevant.

Using 3.3RC1 with WST, I'm getting the following error with libraries added to the "J2EE Module Dependency" project properties panel.

!ENTRY org.eclipse.wst.validation 4 0 2007-05-21 17:15:23.825
!MESSAGE 
!STACK 0
java.lang.NoSuchFieldError: resolvedPathToRawEntries
        at org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.getComponentClasspathDependencies(ClasspathDependencyUtil.java:187)
        at org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.getComponentClasspathDependencies(ClasspathDependencyUtil.java:146)
        at org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator.validateInJob(ClasspathDependencyValidator.java:133)
        at org.eclipse.wst.validation.internal.operations.ValidatorJob.run(ValidatorJob.java:65)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

I've determined this is caused when a library is added to the build path, and the checkbox next to the library, in the J2EE panel, is ticked (to export to the server). Unchecking the library stops the error. My testing to determine the behaviour was using JUnit4. 

UI issues created as a result of this include the "Add/Remove Projects" dialog not appearing when the error-ing state is in place.

Adding an external jar to the J2EE dependency panel appears to be OK.

Mac OSX 10.4.9
Eclipse 3.3RC1
Apache Tomcat 6.0.10
Comment 8 Rob Frost CLA 2007-05-21 12:11:21 EDT
Hi Paul, you must have an old WTP build and incompatible platform version (we never had an official build with that break since that set of components won't compile); the bug you were looking for is WTP bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=183894

If you grab any of the official WTP builds (with the corresponding Eclipse platform version), you'll be OK: e.g. WTP RC0: 

http://download.eclipse.org/webtools/downloads/drops/R2.0/S-2.0RC0-200705171455/
Comment 9 Jerome Lanneluc CLA 2008-05-07 07:31:03 EDT
Unfortunately we ran out of time and the API is now frozen for 3.4.
Deferring post 3.4