From 9df8e3ee054ff1a8c23c8517e0abab362951fe92 Mon Sep 17 00:00:00 2001 From: Michael Haubenwallner Date: Tue, 7 Mar 2023 16:33:58 +0100 Subject: [PATCH] Update classpath settings: avoid duplicate build path for libs 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. --- .../eclipse/pde/internal/core/ClasspathComputer.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java index eaf677cb09..f2b994d7be 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathComputer.java @@ -20,6 +20,7 @@ import java.util.Iterator; 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; @@ -124,7 +125,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); } } } @@ -236,7 +237,9 @@ 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 result) throws JavaModelException { + private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, + IClasspathAttribute[] attrs, Set paths, ArrayList result) + throws JavaModelException { String name = ClasspathUtilCore.expandLibraryName(library.getName()); IResource jarFile = project.findMember(name); if (jarFile == null) { @@ -248,7 +251,7 @@ 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; } @@ -256,7 +259,7 @@ private static void addLibraryEntry(IProject project, IPluginLibrary library, IP } IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); - if (!result.contains(entry)) { + if (paths.add(entry.getPath())) { result.add(entry); } }