Skip to content

Commit 80aebec

Browse files
committed
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.
1 parent 5247598 commit 80aebec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/RequiredPluginsClasspathContainer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.ArrayList;
2222
import java.util.Arrays;
2323
import java.util.Collection;
24+
import java.util.Comparator;
2425
import java.util.HashMap;
2526
import java.util.HashSet;
2627
import java.util.List;
@@ -41,6 +42,7 @@
4142
import org.eclipse.core.runtime.IExtensionRegistry;
4243
import org.eclipse.core.runtime.IPath;
4344
import org.eclipse.core.runtime.Platform;
45+
import org.eclipse.jdt.core.IClasspathAttribute;
4446
import org.eclipse.jdt.core.IClasspathContainer;
4547
import org.eclipse.jdt.core.IClasspathEntry;
4648
import org.eclipse.jdt.core.JavaCore;
@@ -137,10 +139,25 @@ public IClasspathEntry[] getClasspathEntries() {
137139
System.out.println("\t" + entry); //$NON-NLS-1$
138140
}
139141
}
142+
// see for example
143+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4133
144+
// we need to make sure that regular entries are before test
145+
// entries, this is also the "natural" order of items in regular
146+
// classpath
147+
Arrays.sort(fEntries, Comparator.comparingInt(cpe -> isTestEntry(cpe) ? 1 : 0));
140148
}
141149
return fEntries;
142150
}
143151

152+
private boolean isTestEntry(IClasspathEntry cpe) {
153+
for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
154+
if (IClasspathAttribute.TEST.equals(attr.getName())) {
155+
return Boolean.parseBoolean(attr.getValue());
156+
}
157+
}
158+
return false;
159+
}
160+
144161
private IClasspathEntry[] computePluginEntriesByProject() {
145162
try {
146163
Optional<Project> bndProject = BndProjectManager.getBndProject(project);

0 commit comments

Comments
 (0)