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 such a
parameter, the computed classpath entry is added as well, and 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 10, 2023
1 parent f45e79d commit 2f699ce
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -124,7 +126,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 +238,8 @@ 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, Set<IPath> paths, List<IClasspathEntry> result) throws JavaModelException {
String name = ClasspathUtilCore.expandLibraryName(library.getName());
IResource jarFile = project.findMember(name);
if (jarFile == null) {
Expand All @@ -248,15 +251,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 2f699ce

Please sign in to comment.