Skip to content

Commit edeaf83

Browse files
committed
Better separate source and bin in sourcepath/classpath
Fixes #1347
1 parent 00f8889 commit edeaf83

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacUtils.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav
280280
sourcePathEnabled = true;
281281
}
282282
if (!sourcePathEnabled) {
283-
fileManager.setLocation(StandardLocation.SOURCE_PATH, classpathEntriesToFiles(javaProject, entry -> entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && (isTest || !entry.isTest())));
283+
fileManager.setLocation(StandardLocation.SOURCE_PATH, classpathEntriesToFiles(javaProject, true, entry -> (isTest || !entry.isTest())));
284284
}
285285

286286
boolean classpathEnabled = false;
@@ -315,7 +315,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav
315315
})
316316
.collect(Collectors.toSet());
317317

318-
Collection<File> classpathFiles = classpathEntriesToFiles(javaProject, entry -> isTest || !entry.isTest());
318+
Collection<File> classpathFiles = classpathEntriesToFiles(javaProject, false, entry -> isTest || !entry.isTest());
319319
Collection<File> filteredFiles = classpathFiles.stream().filter(x -> x.length() != 0).toList();
320320
fileManager.setLocation(StandardLocation.CLASS_PATH, filteredFiles);
321321
classpathFiles.addAll(outDirectories(javaProject, entry -> isTest || !entry.isTest()));
@@ -368,7 +368,7 @@ public static <T> boolean isEmpty(List<T> list) {
368368
return list == null || list.isEmpty();
369369
}
370370

371-
private static Collection<File> classpathEntriesToFiles(JavaProject project, Predicate<IClasspathEntry> select) {
371+
private static Collection<File> classpathEntriesToFiles(JavaProject project, boolean source, Predicate<IClasspathEntry> select) {
372372
try {
373373
LinkedHashSet<File> res = new LinkedHashSet<>();
374374
ArrayList<IClasspathEntry> seen = new ArrayList<>();
@@ -395,13 +395,25 @@ private static Collection<File> classpathEntriesToFiles(JavaProject project, Pre
395395
}
396396
if (moduleDescription == null) {
397397
IPath path = referencedJavaProject.getOutputLocation();
398-
addPath(referencedJavaProject, path, res);
398+
if (!source) {
399+
addPath(referencedJavaProject, path, res);
400+
}
399401
IClasspathEntry[] resolved = referencedJavaProject.resolveClasspath(referencedJavaProject.getExpandedClasspath());
400402
for (IClasspathEntry transitiveEntry : resolved ) {
401403
if (transitiveEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
402-
IPath outputLocation = transitiveEntry.getOutputLocation();
403-
if (outputLocation != null && select.test(transitiveEntry)) {
404-
addPath(referencedJavaProject, outputLocation, res);
404+
if (select.test(transitiveEntry)) {
405+
if (!source) {
406+
IPath outputLocation = transitiveEntry.getOutputLocation();
407+
if (outputLocation != null) {
408+
addPath(referencedJavaProject, outputLocation, res);
409+
}
410+
}
411+
if (source) {
412+
IPath sourceLocation = transitiveEntry.getPath();
413+
if (sourceLocation != null) {
414+
addPath(referencedJavaProject, sourceLocation, res);
415+
}
416+
}
405417
}
406418
} else if (transitiveEntry.isExported() && !seen.contains(transitiveEntry)) {
407419
toProcess.add(transitiveEntry);
@@ -411,7 +423,8 @@ private static Collection<File> classpathEntriesToFiles(JavaProject project, Pre
411423
}
412424
}
413425
}
414-
} else if (select.test(current)) {
426+
} else if (select.test(current) &&
427+
((source && current.getEntryKind() == IClasspathEntry.CPE_SOURCE) || (!source && current.getEntryKind() != IClasspathEntry.CPE_SOURCE))) {
415428
IPath path = current.getPath();
416429
addPath(project, path, res);
417430
}

org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public void testBuildReferenceOtherProjectSource() throws Exception {
106106
IWorkspaceDescription wsDesc = ResourcesPlugin.getWorkspace().getDescription();
107107
wsDesc.setAutoBuilding(false);
108108
ResourcesPlugin.getWorkspace().setDescription(wsDesc);
109-
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
110109
IProject dependent = importProject("projects/dependent");
111110
// at this stage, no .class file exists, so we test that resolution through sourcePath/referenced projects work
112111
ICompilationUnit unit = (ICompilationUnit)JavaCore.create(dependent).findElement(Path.fromOSString("D.java"));

0 commit comments

Comments
 (0)