Skip to content

Commit

Permalink
Use correct Java version for Maven build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Aug 16, 2022
1 parent c3b8f4b commit fad0baa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,14 +35,15 @@ 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,
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.
Properties.isJavaAtLeast(11)
GradleJavaToolchains.isJavaAtLeast(SystemJavaVersion.detect(), "11")
)
buildCommand ++=
List(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit fad0baa

Please sign in to comment.