Bug 24243 - Heuristic to differ between internal JAR and external JAR.
Summary: Heuristic to differ between internal JAR and external JAR.
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-01 03:32 EDT by Martin Aeschlimann CLA
Modified: 2002-10-08 07:22 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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