Skip to content

Commit

Permalink
Update classpath settings: avoid duplicate build path for libs
Browse files Browse the repository at this point in the history
When computing the classpath entry for a library found in the PDE
plugin, the result has export=true and no source attachment.
If the already existing classpath entry differs in whatever irrelevant
parameter, the computed classpath entry is added as well, so Update
classpath settings fails with "Build path contains duplicate entry".

Instead, use the library path only to check for the already existing
classpath entry.
  • Loading branch information
haubi committed Mar 7, 2023
1 parent fc645e8 commit a5193da
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static void addSourceAndLibraries(IProject project, IPluginModelBase mod
if (library.getName().equals(".")) { //$NON-NLS-1$
addJARdPlugin(project, ClasspathUtilCore.getFilename(model), sourceAttachment, attrs, result);
} else {
addLibraryEntry(project, library, sourceAttachment, attrs, result);
addLibraryEntry(project, library, sourceAttachment, attrs, paths, result);
}
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ protected static IBuild getBuild(IProject project) throws CoreException {
return (buildModel != null) ? buildModel.getBuild() : null;
}

private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList<IClasspathEntry> result) throws JavaModelException {
private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, HashSet<IPath> paths, ArrayList<IClasspathEntry> result) throws JavaModelException {
String name = ClasspathUtilCore.expandLibraryName(library.getName());
IResource jarFile = project.findMember(name);
if (jarFile == null) {
Expand All @@ -248,15 +248,15 @@ private static void addLibraryEntry(IProject project, IPluginLibrary library, IP
IClasspathEntry oldEntry = root.getRawClasspathEntry();
// If we have the same binary root but new or different source, we should recreate the entry
if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null) || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) {
if (!result.contains(oldEntry)) {
if (paths.add(oldEntry.getPath())) {
result.add(oldEntry);
return;
}
}
}

IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported());
if (!result.contains(entry)) {
if (paths.add(entry.getPath())) {
result.add(entry);
}
}
Expand Down

0 comments on commit a5193da

Please sign in to comment.