From 385a3d986a416f07867094d184b1da7785be15b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 23 Jun 2025 08:48:38 +0200 Subject: [PATCH] Sort entries by test attribute Currently all entries are given in the insertion order, but for test entries they should come last as they are only accessible in the test code while other entries are accessible by both. To prevent test entries from overriding regular ones, we sort them to be placed later in the classpath. --- .../core/RequiredPluginsClasspathContainer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java index daa34b028fd..68b0c2c4e7f 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -41,6 +42,7 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.JavaCore; @@ -137,10 +139,25 @@ public IClasspathEntry[] getClasspathEntries() { System.out.println("\t" + entry); //$NON-NLS-1$ } } + // see for example + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4133 + // we need to make sure that regular entries are before test + // entries, this is also the "natural" order of items in regular + // classpath + Arrays.sort(fEntries, Comparator.comparingInt(cpe -> isTestEntry(cpe) ? 1 : 0)); } return fEntries; } + private boolean isTestEntry(IClasspathEntry cpe) { + for (IClasspathAttribute attr : cpe.getExtraAttributes()) { + if (IClasspathAttribute.TEST.equals(attr.getName())) { + return Boolean.parseBoolean(attr.getValue()); + } + } + return false; + } + private IClasspathEntry[] computePluginEntriesByProject() { try { Optional bndProject = BndProjectManager.getBndProject(project);