diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacUtils.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacUtils.java index 8b872bba4fc..a76fcfae878 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacUtils.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacUtils.java @@ -300,7 +300,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav }) .collect(Collectors.toSet()); - Collection classpathFiles = classpathEntriesToFiles(javaProject, entry -> entry.getEntryKind() != IClasspathEntry.CPE_SOURCE && (isTest || !entry.isTest())); + Collection classpathFiles = classpathEntriesToFiles(javaProject, entry -> isTest || !entry.isTest()); Collection filteredFiles = classpathFiles.stream().filter(x -> x.length() != 0).toList(); fileManager.setLocation(StandardLocation.CLASS_PATH, filteredFiles); classpathFiles.addAll(outDirectories(javaProject, entry -> isTest || !entry.isTest())); diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.classpath b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.classpath new file mode 100644 index 00000000000..dc76c933473 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.project b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.project new file mode 100644 index 00000000000..bf454369640 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.project @@ -0,0 +1,17 @@ + + + proj1 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..3d1fdb619b3 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/src/proj1/Foo.java b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/src/proj1/Foo.java new file mode 100644 index 00000000000..017eaa2b620 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj1/src/proj1/Foo.java @@ -0,0 +1,8 @@ +package proj1; + +public class Foo { + public void test() { + System.out.println("Hello, world!"); + } + +} diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.classpath b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.classpath new file mode 100644 index 00000000000..4c26a010c8d --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.project b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.project new file mode 100644 index 00000000000..b588f2b1bfe --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.project @@ -0,0 +1,17 @@ + + + proj2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..3d1fdb619b3 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 diff --git a/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/src/proj2/Main.java b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/src/proj2/Main.java new file mode 100644 index 00000000000..546578c2642 --- /dev/null +++ b/org.eclipse.jdt.core.tests.javac/projects/multipleOutputDirectories/proj2/src/proj2/Main.java @@ -0,0 +1,10 @@ +package proj2; + +import proj1.Foo; + +public class Main { + public void test() { + Foo foo = new Foo(); + foo.test(); + } +} \ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java b/org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java index e57d084a874..33f4fae6945 100644 --- a/org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java +++ b/org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/RegressionTests.java @@ -18,11 +18,17 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceDescription; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.resources.ResourcesPlugin; @@ -40,18 +46,27 @@ import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.internal.core.CompilationUnit; -import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Before; import org.junit.Test; public class RegressionTests { private static IProject project; - @BeforeClass - public static void setUpBeforeClass() throws Exception { + @Before + public void setUp() throws Exception { project = importProject("projects/dummy"); } + @After + public void cleanUp() throws Exception { + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + for (IProject p: projects) { + p.delete(false, true, null); + } + } + @Test public void testCheckBuild() throws Exception { project.build(IncrementalProjectBuilder.FULL_BUILD, null); @@ -96,7 +111,22 @@ public void testBuildMultipleOutputDirectories() throws Exception { assertTrue(p.getFolder("bin2").getFile("A.class").exists()); } - + // https://github.com/eclipse-jdtls/eclipse-jdt-core-incubator/issues/1016 + @Test + public void testBuildMultipleOutputDirectories2() throws Exception { + IProject proj1 = importProject("projects/multipleOutputDirectories/proj1"); + IProject proj2 = importProject("projects/multipleOutputDirectories/proj2"); + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null); + ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + List errors = findMarkers(proj1, IMarker.SEVERITY_ERROR); + assertTrue(errors.isEmpty()); + errors = findMarkers(proj2, IMarker.SEVERITY_ERROR); + assertTrue(errors.isEmpty()); + CompilationUnit unit = (CompilationUnit)JavaCore.create(proj2).findElement(Path.fromOSString("proj2/Main.java")); + unit.becomeWorkingCopy(null); + var dom = unit.reconcile(AST.getJLSLatest(), true, unit.getOwner(), null); + assertArrayEquals(new IProblem[0], dom.getProblems()); + } static IProject importProject(String locationInBundle) throws URISyntaxException, IOException, CoreException { File file = new File(FileLocator.toFileURL(RegressionTests.class.getResource("/" + locationInBundle + "/.project")).toURI()); @@ -109,4 +139,19 @@ static IProject importProject(String locationInBundle) throws URISyntaxException project.open(null); return project; } + + // copied from org.eclipse.jdt.ls.core.internal.ResourceUtils.findMarkers(IResource, Integer...) + static List findMarkers(IResource resource, Integer... severities) throws CoreException { + if (resource == null) { + return null; + } + Set targetSeverities = severities == null ? Collections.emptySet() + : new HashSet<>(Arrays.asList(severities)); + IMarker[] allmarkers = resource.findMarkers(null /* all markers */, true /* subtypes */, + IResource.DEPTH_INFINITE); + List markers = Stream.of(allmarkers).filter( + m -> targetSeverities.isEmpty() || targetSeverities.contains(m.getAttribute(IMarker.SEVERITY, 0))) + .collect(Collectors.toList()); + return markers; + } }