Skip to content

Commit

Permalink
javac doesn't configure output folders of dependent projects correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Dec 12, 2024
1 parent dc4db81 commit 8df3562
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private static void configurePaths(JavaProject javaProject, Context context, Jav
})
.collect(Collectors.toSet());

Collection<File> classpathFiles = classpathEntriesToFiles(javaProject, entry -> entry.getEntryKind() != IClasspathEntry.CPE_SOURCE && (isTest || !entry.isTest()));
Collection<File> classpathFiles = classpathEntriesToFiles(javaProject, entry -> isTest || !entry.isTest());
Collection<File> filteredFiles = classpathFiles.stream().filter(x -> x.length() != 0).toList();
fileManager.setLocation(StandardLocation.CLASS_PATH, filteredFiles);
classpathFiles.addAll(outDirectories(javaProject, entry -> isTest || !entry.isTest()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="out" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>proj1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package proj1;

public class Foo {
public void test() {
System.out.println("Hello, world!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry combineaccessrules="false" kind="src" path="/proj1"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>proj2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package proj2;

import proj1.Foo;

public class Main {
public void test() {
Foo foo = new Foo();
foo.test();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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<IMarker> 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());
Expand All @@ -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<IMarker> findMarkers(IResource resource, Integer... severities) throws CoreException {
if (resource == null) {
return null;
}
Set<Integer> targetSeverities = severities == null ? Collections.emptySet()
: new HashSet<>(Arrays.asList(severities));
IMarker[] allmarkers = resource.findMarkers(null /* all markers */, true /* subtypes */,
IResource.DEPTH_INFINITE);
List<IMarker> markers = Stream.of(allmarkers).filter(
m -> targetSeverities.isEmpty() || targetSeverities.contains(m.getAttribute(IMarker.SEVERITY, 0)))
.collect(Collectors.toList());
return markers;
}
}

0 comments on commit 8df3562

Please sign in to comment.