From 500e39810f4ed3cdde6c0604152631db5e67f9af Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 31 May 2024 14:47:12 +0200 Subject: [PATCH] Support --module-path in VSCode extension (#10146) --- .github/workflows/enso4igv.yml | 2 +- tools/enso4igv/pom.xml | 2 +- .../enso4igv/EnsoSbtClassPathProvider.java | 35 ++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/enso4igv.yml b/.github/workflows/enso4igv.yml index 13cfe6c9b5fe..a9dd87eea4ed 100644 --- a/.github/workflows/enso4igv.yml +++ b/.github/workflows/enso4igv.yml @@ -30,7 +30,7 @@ jobs: # 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 - 2250`" >> "$GITHUB_ENV" + echo "MICRO_VERSION=`expr $GITHUB_RUN_NUMBER - 2930`" >> "$GITHUB_ENV" - name: Update project version working-directory: tools/enso4igv diff --git a/tools/enso4igv/pom.xml b/tools/enso4igv/pom.xml index a81415734430..0081177bda00 100644 --- a/tools/enso4igv/pom.xml +++ b/tools/enso4igv/pom.xml @@ -5,7 +5,7 @@ enso4igv nbm Enso Language Support for NetBeans & Ideal Graph Visualizer - 1.33-SNAPSHOT + 1.35-SNAPSHOT diff --git a/tools/enso4igv/src/main/java/org/enso/tools/enso4igv/EnsoSbtClassPathProvider.java b/tools/enso4igv/src/main/java/org/enso/tools/enso4igv/EnsoSbtClassPathProvider.java index 3623d5f3526a..cbd045aa1668 100644 --- a/tools/enso4igv/src/main/java/org/enso/tools/enso4igv/EnsoSbtClassPathProvider.java +++ b/tools/enso4igv/src/main/java/org/enso/tools/enso4igv/EnsoSbtClassPathProvider.java @@ -6,7 +6,6 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; @@ -42,6 +41,7 @@ final class EnsoSbtClassPathProvider extends ProjectOpenedHook private static final String BOOT = "classpath/boot"; private static final String SOURCE = "classpath/source"; private static final String COMPILE = "classpath/compile"; + private static final String MODULES_COMPILE = "modules/compile"; private final EnsoSbtProject project; private final SourceGroup[] sources; @@ -52,11 +52,18 @@ final class EnsoSbtClassPathProvider extends ProjectOpenedHook @Override public ClassPath findClassPath(FileObject file, String type) { + var res = findClassPathImpl(file, type); + LOG.log(Level.FINE, "findClassPath{0} for {1} yields {2}", new Object[]{type, file, res}); + return res; + } + + private ClassPath findClassPathImpl(FileObject file, String type) { for (var g : sources) { if (g instanceof EnsoSources i && i.controlsSource(file)) { var cp = switch (type) { case SOURCE -> i.srcCp; case COMPILE -> i.cp; + case MODULES_COMPILE -> i.moduleCp; case BOOT -> i.platform.getBootstrapLibraries(); default -> null; }; @@ -89,7 +96,8 @@ public void projectClosed() { private static SourceGroup[] computeSbtClassPath(EnsoSbtProject prj) { var sources = new ArrayList(); var platform = JavaPlatform.getDefault(); - var roots = new LinkedHashSet<>(); + var roots = new LinkedHashSet(); + var modulePath = new LinkedHashSet(); var generatedSources = new LinkedHashSet(); var source = "21"; var options = new ArrayList(); @@ -136,6 +144,22 @@ private static SourceGroup[] computeSbtClassPath(EnsoSbtProject prj) { i++; continue; } + if ("--module-path".equals(prop) && next != null) { + var paths = next.split(File.pathSeparator); + for (var element : paths) { + FileObject fo = findProjectFileObject(prj, element); + if (fo != null) { + if (fo.isFolder()) { + modulePath.add(fo); + } else { + var jarRoot = FileUtil.getArchiveRoot(fo); + modulePath.add(jarRoot); + } + } + } + i++; + continue; + } if ("-s".equals(prop) && next != null) { var fo = FileUtil.toFileObject(new File(next)); if (fo != null) { @@ -193,8 +217,9 @@ private static SourceGroup[] computeSbtClassPath(EnsoSbtProject prj) { } var cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[0])); + var moduleCp = ClassPathSupport.createClassPath(modulePath.toArray(new FileObject[0])); var srcCp = ClassPathSupport.createClassPath(srcRoots.toArray(new FileObject[0])); - var s = new EnsoSources(cp, srcCp, platform, outputDir, source, options); + var s = new EnsoSources(cp, moduleCp, srcCp, platform, outputDir, source, options); if ("main".equals(s.getName())) { sources.add(0, s); } else { @@ -363,7 +388,9 @@ public SourceForBinaryQuery.Result findSourceRoots(URL binaryRoot) { } record EnsoSources( - ClassPath cp, ClassPath srcCp, + ClassPath cp, + ClassPath moduleCp, + ClassPath srcCp, JavaPlatform platform, FileObject output, String source, List options