From 7813a7efce292e9ea221b6bff7e08301cfa5347f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 1 Jul 2022 11:22:07 +0000 Subject: [PATCH 1/5] Update dependency bazel to v5.2.0 --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index ac14c3df..91ff5727 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.1.1 +5.2.0 From 452884df1d8a3e4d32350702cb530010d86fb54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Fri, 24 Jun 2022 15:08:02 +0200 Subject: [PATCH 2/5] Include missing `--add-exports` flags for Java 9+ Gradle builds Previously, we didn't include the necessary `--add-exports` flags when indexing Java 17 builds with Gradle that don't use toolchains. This commit fixes that bug so we can correctly index repos like airbytehq/airbyte. --- .../scip_java/buildtools/GradleBuildTool.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala index 0477b391..ae08d427 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala @@ -144,6 +144,17 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { val dependenciesPath = targetroot.resolve("dependencies.txt") val kotlinSemanticdbVersion = BuildInfo.semanticdbKotlincVersion Files.deleteIfExists(dependenciesPath) + val javaModuleOptions = + if (Properties.isJavaAtLeast(9)) { + // Include --add-exports flags for Java 9+ + BuildInfo + .javacModuleOptions + .map(option => s""""$option"""") + .mkString(",") + } else { + // No --add-exports flags for Java 8 + "" + } val script = s"""|allprojects { | gradle.projectsEvaluated { @@ -160,6 +171,7 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { | tasks.withType(JavaCompile) { | options.fork = true | options.incremental = false + | options.forkOptions.jvmArgs.addAll([$javaModuleOptions]) | $executable | } | } From c3b8f4bba4f0fa13d9a9d1a88f8437e3a2ae5aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Tue, 16 Aug 2022 12:48:47 +0200 Subject: [PATCH 3/5] Make `buildTools/test` work on Java 17 Previously, we only tested `sbt test` on Java 8 and we had a lot of failing tests if sbt was started with Java 17. This commit makes the tests in the `buildTools` project pass on Java 17. --- .github/workflows/ci.yml | 5 +- .../com/sourcegraph/scip_java/Embedded.scala | 17 +++- .../buildtools/GradleBuildTool.scala | 16 +--- .../buildtools/GradleJavaCompiler.scala | 7 +- .../buildtools/GradleJavaToolchains.scala | 96 ++++++++++++++++++- .../scip_java/buildtools/MavenBuildTool.scala | 6 +- .../test/scala/tests/BaseBuildToolSuite.scala | 10 ++ .../scala/tests/GradleBuildToolSuite.scala | 15 +-- 8 files changed, 145 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e73e7c7..dde01059 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,17 +6,18 @@ on: pull_request: jobs: test: - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: matrix: # NOTE(olafurpg) Windows is not enabled because it times out due to reasons I don't understand. # os: [windows-latest, ubuntu-latest] os: [ubuntu-latest] + java: [8, 17] steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: - java-version: 8 + java-version: ${{ matrix.java }} - uses: actions/setup-go@v2 with: go-version: "^1.13.1" diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/Embedded.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/Embedded.scala index 3aa44d93..674941a9 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/Embedded.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/Embedded.scala @@ -5,6 +5,7 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption +import com.sourcegraph.scip_java.BuildInfo import moped.reporters.Reporter import os.CommandResult @@ -22,7 +23,12 @@ object Embedded { private def javacErrorpath(tmp: Path) = tmp.resolve("errorpath.txt") - def customJavac(sourceroot: Path, targetroot: Path, tmp: Path): Path = { + def customJavac( + sourceroot: Path, + targetroot: Path, + tmp: Path, + javaAtLeast17: Boolean + ): Path = { val bin = tmp.resolve("bin") val javac = bin.resolve("javac") val java = bin.resolve("java") @@ -38,6 +44,11 @@ object Embedded { |""".stripMargin.getBytes(StandardCharsets.UTF_8) ) val newJavacopts = tmp.resolve("javac_newarguments") + val javacModuleOptions = + if (javaAtLeast17) + BuildInfo.javacModuleOptions.mkString(" ") + else + "" val injectSemanticdbArguments = List[String]( "java", s"-Dsemanticdb.errorpath=$errorpath", @@ -62,9 +73,9 @@ object Embedded { |done |$injectSemanticdbArguments |if [ $${#LAUNCHER_ARGS[@]} -eq 0 ]; then - | javac "@$$NEW_JAVAC_OPTS" + | javac $javacModuleOptions "@$$NEW_JAVAC_OPTS" |else - | javac "@$$NEW_JAVAC_OPTS" "$${LAUNCHER_ARGS[@]}" + | javac $javacModuleOptions "@$$NEW_JAVAC_OPTS" "$${LAUNCHER_ARGS[@]}" |fi |""".stripMargin Files.write(javac, script.getBytes(StandardCharsets.UTF_8)) diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala index ae08d427..97820692 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala @@ -126,8 +126,9 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { } private def initScript(toolchains: GradleJavaToolchains, tmp: Path): Path = { + val executableJavacPath = toolchains.executableJavacPath() val executable = - toolchains.executableJavacPath() match { + executableJavacPath match { case Some(path) => s"options.forkOptions.executable = '$path'" case None => @@ -144,17 +145,6 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { val dependenciesPath = targetroot.resolve("dependencies.txt") val kotlinSemanticdbVersion = BuildInfo.semanticdbKotlincVersion Files.deleteIfExists(dependenciesPath) - val javaModuleOptions = - if (Properties.isJavaAtLeast(9)) { - // Include --add-exports flags for Java 9+ - BuildInfo - .javacModuleOptions - .map(option => s""""$option"""") - .mkString(",") - } else { - // No --add-exports flags for Java 8 - "" - } val script = s"""|allprojects { | gradle.projectsEvaluated { @@ -171,7 +161,7 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { | tasks.withType(JavaCompile) { | options.fork = true | options.incremental = false - | options.forkOptions.jvmArgs.addAll([$javaModuleOptions]) + | System.out.println("JAVA VERSION " + System.getProperty("java.version")) | $executable | } | } diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaCompiler.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaCompiler.scala index 3e34097c..7e6eeeaf 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaCompiler.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaCompiler.scala @@ -27,7 +27,12 @@ case class GradleJavaCompiler(languageVersion: String, javacPath: Path) { pluginPath: Path ): Path = { val home = tmp.resolve(s"1.$languageVersion") - val javac = Embedded.customJavac(index.workingDirectory, targetroot, tmp) + val javac = Embedded.customJavac( + index.workingDirectory, + targetroot, + tmp, + GradleJavaToolchains.isJavaAtLeast(languageVersion, "17") + ) val agent = Embedded.agentJar(tmp) val debugPath = GradleJavaCompiler.debugPath(tmp) val javacopts = targetroot.resolve("javacopts.txt") diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaToolchains.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaToolchains.scala index 3cf1ce09..b66963b3 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaToolchains.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleJavaToolchains.scala @@ -4,6 +4,7 @@ import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path +import scala.annotation.tailrec import scala.jdk.CollectionConverters._ import com.sourcegraph.scip_java.Embedded @@ -14,6 +15,7 @@ case class GradleJavaToolchains( tool: GradleBuildTool, index: IndexCommand, gradleVersion: Option[String], + javaVersion: Option[String], isJavaEnabled: Boolean, isScalaEnabled: Boolean, isKotlinEnabled: Boolean, @@ -24,9 +26,22 @@ case class GradleJavaToolchains( def isEmpty: Boolean = toolchains.isEmpty + def isJavaAtLeast(version: Int): Boolean = { + val actualVersion = javaVersion.getOrElse(sys.props("java.version")) + GradleJavaToolchains + .isJavaAtLeast(actualVersion, math.max(version, 0).toString()) + } + def executableJavacPath(): Option[Path] = { if (toolchains.isEmpty) { - Some(Embedded.customJavac(index.workingDirectory, tool.targetroot, tmp)) + Some( + Embedded.customJavac( + index.workingDirectory, + tool.targetroot, + tmp, + isJavaAtLeast(17) + ) + ) } else { None } @@ -62,6 +77,7 @@ object GradleJavaToolchains { val javaEnabledPath = tmp.resolve("java-enabled.txt") val scalaEnabledPath = tmp.resolve("scala-enabled.txt") val kotlinEnabledPath = tmp.resolve("kotlin-enabled.txt") + val javaVersionPath = tmp.resolve("java-version.txt") val kotlinMultiplatformEnabledPath = tmp .resolve("kotlin-multiplatform-enabled.txt") val gradleVersionPath = tmp.resolve("gradle-version.txt") @@ -75,6 +91,12 @@ object GradleJavaToolchains { | [gradle.gradleVersion], | java.nio.file.StandardOpenOption.TRUNCATE_EXISTING, | java.nio.file.StandardOpenOption.CREATE) + | java.nio.file.Files.write( + | java.nio.file.Paths.get( + | java.net.URI.create('${javaVersionPath.toUri}')), + | [System.getProperty("java.version")], + | java.nio.file.StandardOpenOption.TRUNCATE_EXISTING, + | java.nio.file.StandardOpenOption.CREATE) |} catch (Exception e) { | // Ignore errors. |} @@ -146,11 +168,19 @@ object GradleJavaToolchains { None } + val javaVersion = + if (Files.isRegularFile(javaVersionPath)) { + Some(new String(Files.readAllBytes(javaVersionPath)).trim) + } else { + None + } + GradleJavaToolchains( toolchains, tool, index, gradleVersion = gradleVersion, + javaVersion = javaVersion, isJavaEnabled = Files.isRegularFile(javaEnabledPath), isScalaEnabled = Files.isRegularFile(scalaEnabledPath), isKotlinEnabled = Files.isRegularFile(kotlinEnabledPath), @@ -160,4 +190,68 @@ object GradleJavaToolchains { tmp = tmp ) } + + // Copy-pasted from scala.util.Properties.isJavaAtLeast but makes the actual + // version a parameterizeable instead of being hard-coded to + // `Properties.javaVersionSpec`. + def isJavaAtLeast( + actualVersion: String, + comparisonVersion: String + ): Boolean = { + def versionOf(s: String, depth: Int): (Int, String) = + s.indexOf('.') match { + case 0 => + (-2, s.substring(1)) + case 1 if depth == 0 && s.charAt(0) == '1' => + val r0 = s.substring(2) + val (v, r) = versionOf(r0, 1) + val n = + if (v > 8 || r0.isEmpty) + -2 + else + v // accept 1.8, not 1.9 or 1. + (n, r) + case -1 => + val n = + if (!s.isEmpty) + s.toInt + else if (depth == 0) + -2 + else + 0 + (n, "") + case i => + val r = s.substring(i + 1) + val n = + if (depth < 2 && r.isEmpty) + -2 + else + s.substring(0, i).toInt + (n, r) + } + @tailrec + def compareVersions(s: String, v: String, depth: Int): Int = { + if (depth >= 3) + 0 + else { + val (sn, srest) = versionOf(s, depth) + val (vn, vrest) = versionOf(v, depth) + if (vn < 0) + -2 + else if (sn < vn) + -1 + else if (sn > vn) + 1 + else + compareVersions(srest, vrest, depth + 1) + } + } + + compareVersions(actualVersion, comparisonVersion, 0) match { + case -2 => + throw new NumberFormatException(s"Not a version: $comparisonVersion") + case i => + i >= 0 + } + } } diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala index be3a5b06..f76184e8 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala @@ -5,6 +5,7 @@ import java.nio.file.Path import java.nio.file.Paths import scala.collection.mutable.ListBuffer +import scala.util.Properties import com.sourcegraph.scip_java.Embedded import com.sourcegraph.scip_java.commands.IndexCommand @@ -39,7 +40,10 @@ class MavenBuildTool(index: IndexCommand) extends BuildTool("Maven", index) { val executable = Embedded.customJavac( index.workingDirectory, index.finalTargetroot(defaultTargetroot), - tmp + tmp, + // TODO: infer Java version from `java -version` because it may not + // match the Java version that's used by the current process. + Properties.isJavaAtLeast(11) ) buildCommand ++= List( diff --git a/tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala b/tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala index 490f1bcd..ca526930 100644 --- a/tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala +++ b/tests/buildTools/src/test/scala/tests/BaseBuildToolSuite.scala @@ -18,6 +18,8 @@ import munit.Tag import munit.TestOptions import os.Shellable +object Java8Only extends munit.Tag("Java8Only") + abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) { override def environmentVariables: Map[String, String] = sys.env @@ -26,6 +28,14 @@ abstract class BaseBuildToolSuite extends MopedSuite(ScipJava.app) { override def munitTestTransforms: List[TestTransform] = super.munitTestTransforms ++ List( + new TestTransform( + "Java8Only", + t => + if (Properties.isJavaAtLeast(9) && t.tags(Java8Only)) + t.tag(munit.Ignore) + else + t + ), new TestTransform( "SkipWindows", t => diff --git a/tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala b/tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala index 9c936592..3c45bfd5 100644 --- a/tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala +++ b/tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala @@ -27,7 +27,10 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { List("latest" -> "implementation", "4.0" -> "compile").foreach { case (version, config) => checkBuild( - s"basic-$version", + if (version == "latest") + "basic-latest" + else + s"basic-$version".tag(Java8Only), s"""|/build.gradle |apply plugin: 'java' |repositories { @@ -55,7 +58,7 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { List("3.3", "2.2.1").foreach { version => checkBuild( - s"legacy-$version", + s"legacy-$version".tag(Java8Only), s"""|/build.gradle |apply plugin: 'java' |/src/main/java/Example.java @@ -90,7 +93,7 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { ) checkBuild( - "toolchains-6.7", + "toolchains-6.7".tag(Java8Only), """|/build.gradle |apply plugin: 'java' |java { @@ -114,7 +117,7 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { ) checkBuild( - "toolchains-6.8", + "toolchains-6.8".tag(Java8Only), """|/build.gradle |apply plugin: 'java' |java { @@ -158,7 +161,7 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { ) checkBuild( - "playframework", + "playframework".tag(Java8Only), """|/build.gradle |plugins { | id 'org.gradle.playframework' version '0.11' @@ -209,7 +212,7 @@ class GradleBuildToolSuite extends BaseBuildToolSuite { ) checkBuild( - "checkerframework", + "checkerframework".tag(Java8Only), """|/build.gradle |plugins { | id 'java' From fad0baa1547789e909586c06685b92474051fe23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Tue, 16 Aug 2022 17:09:41 +0200 Subject: [PATCH 4/5] Use correct Java version for Maven build tools --- .github/workflows/ci.yml | 1 + .../scip_java/buildtools/MavenBuildTool.scala | 4 +-- .../buildtools/SystemJavaVersion.scala | 26 +++++++++++++++++++ .../semanticdb_javac/PrintJavaVersion.java | 7 +++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala create mode 100644 semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/PrintJavaVersion.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dde01059..c63b249a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ jobs: test: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: # NOTE(olafurpg) Windows is not enabled because it times out due to reasons I don't understand. # os: [windows-latest, ubuntu-latest] diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala index f76184e8..3dd4008b 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala @@ -5,7 +5,6 @@ import java.nio.file.Path import java.nio.file.Paths import scala.collection.mutable.ListBuffer -import scala.util.Properties import com.sourcegraph.scip_java.Embedded import com.sourcegraph.scip_java.commands.IndexCommand @@ -36,6 +35,7 @@ class MavenBuildTool(index: IndexCommand) extends BuildTool("Maven", index) { else { "mvn" } + val start = System.nanoTime() val buildCommand = ListBuffer.empty[String] val executable = Embedded.customJavac( index.workingDirectory, @@ -43,7 +43,7 @@ class MavenBuildTool(index: IndexCommand) extends BuildTool("Maven", index) { tmp, // TODO: infer Java version from `java -version` because it may not // match the Java version that's used by the current process. - Properties.isJavaAtLeast(11) + GradleJavaToolchains.isJavaAtLeast(SystemJavaVersion.detect(), "11") ) buildCommand ++= List( diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala new file mode 100644 index 00000000..6c81ed78 --- /dev/null +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala @@ -0,0 +1,26 @@ +package com.sourcegraph.scip_java.buildtools + +import java.nio.file.Files + +import com.sourcegraph.scip_java.Embedded + +object SystemJavaVersion { + def detect(): String = { + val tmp = Files.createTempDirectory("java-version") + val jar = Embedded.semanticdbJar(tmp) + try { + os.proc( + "java", + "-cp", + jar.toString(), + "com.sourcegraph.semanticdb_javac.PrintJavaVersion" + ) + .call() + .out + .text() + .trim() + } finally { + Files.deleteIfExists(jar) + } + } +} diff --git a/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/PrintJavaVersion.java b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/PrintJavaVersion.java new file mode 100644 index 00000000..07826402 --- /dev/null +++ b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/PrintJavaVersion.java @@ -0,0 +1,7 @@ +package com.sourcegraph.semanticdb_javac; + +public class PrintJavaVersion { + public static void main(String[] args) { + System.out.print(System.getProperty("java.version")); + } +} From 3078f4d5acfb5a829f455520b166c6b1e8530f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Tue, 16 Aug 2022 17:13:51 +0200 Subject: [PATCH 5/5] Clean up Java 17 fixes --- .../sourcegraph/scip_java/buildtools/GradleBuildTool.scala | 4 +--- .../com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala | 2 -- .../sourcegraph/scip_java/buildtools/SystemJavaVersion.scala | 4 ++++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala index 97820692..0477b391 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/GradleBuildTool.scala @@ -126,9 +126,8 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { } private def initScript(toolchains: GradleJavaToolchains, tmp: Path): Path = { - val executableJavacPath = toolchains.executableJavacPath() val executable = - executableJavacPath match { + toolchains.executableJavacPath() match { case Some(path) => s"options.forkOptions.executable = '$path'" case None => @@ -161,7 +160,6 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) { | tasks.withType(JavaCompile) { | options.fork = true | options.incremental = false - | System.out.println("JAVA VERSION " + System.getProperty("java.version")) | $executable | } | } diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala index 3dd4008b..ff202327 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/MavenBuildTool.scala @@ -41,8 +41,6 @@ class MavenBuildTool(index: IndexCommand) extends BuildTool("Maven", index) { index.workingDirectory, index.finalTargetroot(defaultTargetroot), tmp, - // TODO: infer Java version from `java -version` because it may not - // match the Java version that's used by the current process. GradleJavaToolchains.isJavaAtLeast(SystemJavaVersion.detect(), "11") ) buildCommand ++= diff --git a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala index 6c81ed78..e3a62dbb 100644 --- a/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala +++ b/scip-java/src/main/scala/com/sourcegraph/scip_java/buildtools/SystemJavaVersion.scala @@ -5,6 +5,10 @@ import java.nio.file.Files import com.sourcegraph.scip_java.Embedded object SystemJavaVersion { + // Returns the output of `System.getProperty("java.version")` from a fresh JVM + // instance using the system JVM installation. We can't use this process since + // it may be running on a separate JVM process (that's the case when we run + // `sbt test` in this build at least). def detect(): String = { val tmp = Files.createTempDirectory("java-version") val jar = Embedded.semanticdbJar(tmp)