Community
Participate
Working Groups
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.
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.
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).
Ok to close?
I just saw that IJavaProject.findPackageFragmentRoot is the method that implements the heuristic. Ok to close.
Great. Thanks guys!
Closing