mirror of
https://github.com/enso-org/enso.git
synced 2024-11-27 04:52:45 +03:00
VSCode JUnit classpath fix (#8795)
Recently a classpath misconfiguration appeared in `engine/runtime` project: ![org.junit not found](https://github.com/enso-org/enso/assets/26887752/215a074b-1fad-4d4d-a5a8-a573b0d53e76) The problem was caused by the `XyzTest.java` files being incorrectly assigned to `engine/runtime/src/main/java` source root and its classpath (which obviously doesn't contain JUnit). This PR restricts the `srcCp` to `inputDir`, when it is known. That properly assignes the `XyzTest.java` files to `engine/runtime/src/test/java` source root. The IGV as well as VSCode support seems to recognize unit test classpath properly now.
This commit is contained in:
parent
32d0459534
commit
457eb2279f
11
.github/workflows/enso4igv.yml
vendored
11
.github/workflows/enso4igv.yml
vendored
@ -24,10 +24,19 @@ jobs:
|
|||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
cache: maven
|
cache: maven
|
||||||
|
|
||||||
|
- name: Find out pom & micro versions
|
||||||
|
working-directory: tools/enso4igv
|
||||||
|
run: |
|
||||||
|
# Why do we subtract a number? Read versioning policy!
|
||||||
|
# https://github.com/enso-org/enso/pull/7861#discussion_r1333133490
|
||||||
|
echo "POM_VERSION=`mvn -q -DforceStdout help:evaluate -Dexpression=project.version | cut -f1 -d -`" >> "$GITHUB_ENV"
|
||||||
|
echo "MICRO_VERSION=`expr $GITHUB_RUN_NUMBER - 2100`" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Update project version
|
- name: Update project version
|
||||||
working-directory: tools/enso4igv
|
working-directory: tools/enso4igv
|
||||||
run: |
|
run: |
|
||||||
mvn versions:set -DnewVersion=`mvn -q -DforceStdout help:evaluate -Dexpression=project.version | cut -f1 -d -`.`expr $GITHUB_RUN_NUMBER - 1666`
|
echo "Setting version to $POM_VERSION.$MICRO_VERSION"
|
||||||
|
mvn versions:set -DnewVersion="$POM_VERSION.$MICRO_VERSION"
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: mvn -B -Pvsix package --file tools/enso4igv/pom.xml
|
run: mvn -B -Pvsix package --file tools/enso4igv/pom.xml
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<artifactId>enso4igv</artifactId>
|
<artifactId>enso4igv</artifactId>
|
||||||
<packaging>nbm</packaging>
|
<packaging>nbm</packaging>
|
||||||
<name>Enso Language Support for NetBeans & Ideal Graph Visualizer</name>
|
<name>Enso Language Support for NetBeans & Ideal Graph Visualizer</name>
|
||||||
<version>1.15-SNAPSHOT</version>
|
<version>1.21-SNAPSHOT</version>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -63,16 +63,15 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.frgaal</groupId>
|
<groupId>org.frgaal</groupId>
|
||||||
<artifactId>compiler-maven-plugin</artifactId>
|
<artifactId>compiler-maven-plugin</artifactId>
|
||||||
<version>19.0.0</version>
|
<version>21.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerId>frgaal</compilerId>
|
<compilerId>frgaal</compilerId>
|
||||||
<source>19</source>
|
<source>21</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
<arg>-Xlint:deprecation</arg>
|
<arg>-Xlint:deprecation</arg>
|
||||||
<arg>--enable-preview</arg>
|
|
||||||
</compilerArgs>
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -53,12 +54,13 @@ Sources, BinaryForSourceQueryImplementation2<EnsoSbtClassPathProvider.EnsoSource
|
|||||||
public ClassPath findClassPath(FileObject file, String type) {
|
public ClassPath findClassPath(FileObject file, String type) {
|
||||||
for (var g : sources) {
|
for (var g : sources) {
|
||||||
if (g instanceof EnsoSources i && i.controlsSource(file)) {
|
if (g instanceof EnsoSources i && i.controlsSource(file)) {
|
||||||
return switch (type) {
|
var cp = switch (type) {
|
||||||
case SOURCE -> i.srcCp;
|
case SOURCE -> i.srcCp;
|
||||||
case COMPILE -> i.cp;
|
case COMPILE -> i.cp;
|
||||||
case BOOT -> i.platform.getBootstrapLibraries();
|
case BOOT -> i.platform.getBootstrapLibraries();
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
return cp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -88,10 +90,10 @@ Sources, BinaryForSourceQueryImplementation2<EnsoSbtClassPathProvider.EnsoSource
|
|||||||
var sources = new ArrayList<SourceGroup>();
|
var sources = new ArrayList<SourceGroup>();
|
||||||
var platform = JavaPlatform.getDefault();
|
var platform = JavaPlatform.getDefault();
|
||||||
var roots = new LinkedHashSet<>();
|
var roots = new LinkedHashSet<>();
|
||||||
var generatedSources = new LinkedHashSet<>();
|
var generatedSources = new LinkedHashSet<FileObject>();
|
||||||
var source = "19";
|
var source = "21";
|
||||||
var options = new ArrayList<String>();
|
var options = new ArrayList<String>();
|
||||||
for (FileObject ch : prj.getProjectDirectory().getChildren()) {
|
for (var ch : prj.getProjectDirectory().getChildren()) {
|
||||||
if (ch.getNameExt().startsWith(".enso-sources-")) {
|
if (ch.getNameExt().startsWith(".enso-sources-")) {
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
try (InputStream is = ch.getInputStream()) {
|
try (InputStream is = ch.getInputStream()) {
|
||||||
@ -142,29 +144,38 @@ Sources, BinaryForSourceQueryImplementation2<EnsoSbtClassPathProvider.EnsoSource
|
|||||||
}
|
}
|
||||||
options.add(prop);
|
options.add(prop);
|
||||||
}
|
}
|
||||||
var srcRoots = new LinkedHashSet<>();
|
var srcRoots = new LinkedHashSet<FileObject>();
|
||||||
|
|
||||||
var inputSrc = p.getProperty("input");
|
var inputSrc = p.getProperty("input");
|
||||||
FileObject inputDir = findProjectFileObject(prj, inputSrc);
|
var inputDir = findProjectFileObject(prj, inputSrc);
|
||||||
if (inputDir != null) {
|
if (inputDir != null) {
|
||||||
|
var addSibblings = true;
|
||||||
if (inputDir.getNameExt().equals("org")) {
|
if (inputDir.getNameExt().equals("org")) {
|
||||||
// lib/rust/parser doesn't follow typical project conventions
|
// lib/rust/parser doesn't follow typical project conventions
|
||||||
inputDir = inputDir.getParent();
|
inputDir = inputDir.getParent();
|
||||||
|
addSibblings = false;
|
||||||
}
|
}
|
||||||
srcRoots.add(inputDir);
|
srcRoots.add(inputDir);
|
||||||
}
|
if (addSibblings) {
|
||||||
|
for (var sibbling : inputDir.getParent().getChildren()) {
|
||||||
var srcDir = prj.getProjectDirectory().getFileObject("src");
|
if (sibbling.isFolder() && sibbling != inputDir) {
|
||||||
if (srcDir != null) {
|
srcRoots.add(sibbling);
|
||||||
for (var group : srcDir.getChildren()) {
|
}
|
||||||
if (group.isFolder()) {
|
|
||||||
for (var child : group.getChildren()) {
|
|
||||||
if (child.isFolder()) {
|
|
||||||
srcRoots.add(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var srcDir = prj.getProjectDirectory().getFileObject("src");
|
||||||
|
if (srcDir != null) {
|
||||||
|
for (var group : srcDir.getChildren()) {
|
||||||
|
if (group.isFolder()) {
|
||||||
|
for (var child : group.getChildren()) {
|
||||||
|
if (child.isFolder()) {
|
||||||
|
srcRoots.add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
srcRoots.addAll(generatedSources);
|
srcRoots.addAll(generatedSources);
|
||||||
|
|
||||||
@ -177,6 +188,9 @@ Sources, BinaryForSourceQueryImplementation2<EnsoSbtClassPathProvider.EnsoSource
|
|||||||
srcRoots.add(generatedDir);
|
srcRoots.add(generatedDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var r : srcRoots) {
|
||||||
|
assert r.isFolder() : "Expecting folders in " + srcRoots;
|
||||||
|
}
|
||||||
|
|
||||||
var cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[0]));
|
var cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[0]));
|
||||||
var srcCp = ClassPathSupport.createClassPath(srcRoots.toArray(new FileObject[0]));
|
var srcCp = ClassPathSupport.createClassPath(srcRoots.toArray(new FileObject[0]));
|
||||||
|
@ -25,7 +25,7 @@ import org.openide.windows.TopComponent;
|
|||||||
displayName = "#LBL_Scala_LOADER",
|
displayName = "#LBL_Scala_LOADER",
|
||||||
mimeType = "text/x-scala",
|
mimeType = "text/x-scala",
|
||||||
extension = {"scala", "sbt"},
|
extension = {"scala", "sbt"},
|
||||||
position = 330
|
position = 333
|
||||||
)
|
)
|
||||||
@DataObject.Registration(
|
@DataObject.Registration(
|
||||||
mimeType = "text/x-scala",
|
mimeType = "text/x-scala",
|
||||||
|
@ -3,6 +3,7 @@ package org.enso.tools.enso4igv;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import org.netbeans.api.java.classpath.ClassPath;
|
||||||
import org.netbeans.api.project.ProjectManager;
|
import org.netbeans.api.project.ProjectManager;
|
||||||
import org.netbeans.api.project.Sources;
|
import org.netbeans.api.project.Sources;
|
||||||
import org.netbeans.junit.NbTestCase;
|
import org.netbeans.junit.NbTestCase;
|
||||||
@ -36,6 +37,23 @@ public class EnsoSbtProjectTest extends NbTestCase {
|
|||||||
|
|
||||||
var javaGroups = s.getSourceGroups("java");
|
var javaGroups = s.getSourceGroups("java");
|
||||||
assertEquals("1 bench, 2 tests, 4 main: " + Arrays.toString(javaGroups), 7, javaGroups.length);
|
assertEquals("1 bench, 2 tests, 4 main: " + Arrays.toString(javaGroups), 7, javaGroups.length);
|
||||||
|
|
||||||
|
var javaFile = root.getFileObject("src/main/java/MainJava.java");
|
||||||
|
assertNotNull("Main java found", javaFile);
|
||||||
|
var javaCp = ClassPath.getClassPath(javaFile, ClassPath.SOURCE);
|
||||||
|
assertNotNull("java classpath found", javaCp);
|
||||||
|
|
||||||
|
assertNotNull("Main java is on source path", javaCp.findResource("MainJava.java"));
|
||||||
|
assertNotNull("Main scala is on source path", javaCp.findResource("MainScala.scala"));
|
||||||
|
assertNull("Test scala is not on source path", javaCp.findResource("TestScala.scala"));
|
||||||
|
|
||||||
|
var scalaTestFile = root.getFileObject("src/test/scala/TestScala.scala");
|
||||||
|
assertNotNull("Test scala found", scalaTestFile);
|
||||||
|
for (var g : javaGroups) {
|
||||||
|
if (g.contains(scalaTestFile)) {
|
||||||
|
assertEquals("test/scala", g.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FileObject setLanguageServerProjectUp() throws IOException {
|
private static FileObject setLanguageServerProjectUp() throws IOException {
|
||||||
@ -46,11 +64,14 @@ public class EnsoSbtProjectTest extends NbTestCase {
|
|||||||
var srcBenchScala = srcBench.createFolder("scala");
|
var srcBenchScala = srcBench.createFolder("scala");
|
||||||
var srcTest = src.createFolder("test");
|
var srcTest = src.createFolder("test");
|
||||||
var srcTestScala = srcTest.createFolder("scala");
|
var srcTestScala = srcTest.createFolder("scala");
|
||||||
|
var srcTestScalaFile = srcTestScala.createData("TestScala.scala");
|
||||||
var srcTestResources = srcTest.createFolder("resources");
|
var srcTestResources = srcTest.createFolder("resources");
|
||||||
var srcMain = src.createFolder("main");
|
var srcMain = src.createFolder("main");
|
||||||
var srcMainJava = srcMain.createFolder("java");
|
var srcMainJava = srcMain.createFolder("java");
|
||||||
|
var srcMainJavaFile = srcMainJava.createData("MainJava.java");
|
||||||
var srcMainResources = srcMain.createFolder("resources");
|
var srcMainResources = srcMain.createFolder("resources");
|
||||||
var srcMainScala = srcMain.createFolder("scala");
|
var srcMainScala = srcMain.createFolder("scala");
|
||||||
|
var srcMainScalaFile = srcMainScala.createData("MainScala.scala");
|
||||||
var srcMainSchema = srcMain.createFolder("schema");
|
var srcMainSchema = srcMain.createFolder("schema");
|
||||||
var ensoSources = root.createData(".enso-sources");
|
var ensoSources = root.createData(".enso-sources");
|
||||||
try (var os = root.createAndOpen(".enso-sources-classes")) {
|
try (var os = root.createAndOpen(".enso-sources-classes")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user