Bug 24243

Summary: Heuristic to differ between internal JAR and external JAR.
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: renaud+eclipse
Version: 2.0   
Target Milestone: 2.1 M2   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Martin Aeschlimann CLA 2002-10-01 03:32:45 EDT
20020924

Having a path from a IClasspathEntry / library entry, the path can either point 
to an external JAR or internal JAR. A heuristic is used to detemine which it is:
First check if the path is a valid external location, if nothing found, search 
in workspace.
JCore should offer API to offer the used heuristic.
Comment 1 Renaud Waldura CLA 2002-10-01 12:08:19 EDT
I've implemented the aforementioned heuristic with the following code, but I'm 
not positive it is truly the best solution:

// entry path is relative to workspace dir
if (!entry.getPath().toFile().isAbsolute())
{
    entry = makeAbsolute(entry, project);
}

private static IClasspathEntry makeAbsolute(IClasspathEntry entry, IJavaProject 
project)
{
    IPath projectDir = project.getProject().getLocation();
    IPath entryFullPath = projectDir.append(entry.getPath().removeFirstSegments
(1));
    
    return new ClasspathEntry(
        entry.getContentKind(),
        entry.getEntryKind(),
        entryFullPath,
        entry.getSourceAttachmentPath(),
        entry.getSourceAttachmentRootPath(),
        entry.isExported());
}

As Martin said, we'd much rather leverage something in JCore that returns the 
true absolute path.

Comment 2 Philipe Mulet CLA 2002-10-02 06:41:17 EDT
JDT/Core always gives precedence to resource over external file. 
The heuristic is implemented in: JavaModel.getTarget(IContainer container,IPath 
path, boolean checkResourceExistence)

We may indeed surface it on IJavaModel... however don't you already have the 
corresponding root in your hand ? If so, you should simply ask it whether it is 
external or not (IPackageFragmentRoot#isExternal).
Comment 3 Philipe Mulet CLA 2002-10-04 04:58:01 EDT
Ok to close?
Comment 4 Martin Aeschlimann CLA 2002-10-04 05:43:46 EDT
I just saw that IJavaProject.findPackageFragmentRoot is the method that 
implements the heuristic.

Ok to close.
Comment 5 Renaud Waldura CLA 2002-10-04 12:23:09 EDT
Great. Thanks guys!
Comment 6 Philipe Mulet CLA 2002-10-08 07:22:37 EDT
Closing
Comment 7 Philipe Mulet CLA 2002-10-08 07:22:55 EDT
Closing