Skip to content

Commit 100a91d

Browse files
committed
Test on Java 8, Java 11 and Java 15.
Previously, the build used the Java version that `sbt` was launched with. Now, the build automatically downloads appropriate Java versions for each project. * Build by default with Java 11. * Build compiler plugin with Java 8. * Cross-build the "minimized" project for Java 8/11/15.
1 parent 0227872 commit 100a91d

File tree

6 files changed

+129
-91
lines changed

6 files changed

+129
-91
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v2
1212
- uses: olafurpg/setup-scala@v10
13-
with:
14-
java-version: [email protected]
1513
- uses: actions/setup-go@v2
1614
with:
1715
go-version: '^1.13.1'
@@ -22,6 +20,4 @@ jobs:
2220
steps:
2321
- uses: actions/checkout@v2
2422
- uses: olafurpg/setup-scala@v10
25-
with:
26-
java-version: [email protected]
2723
- run: sbt checkAll

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ Currently, only Java 8 with the build tool sbt is supported. We hope to increase
1313
compatibility with more Java language versions and build tools as the project
1414
evolves.
1515

16-
| Language version | Support |
17-
| ---------------- | ------------------ |
18-
| Java 7 ||
19-
| Java 8 ||
20-
| Java 11 ||
21-
| Java 12 | Untested, may work |
22-
| Java 13 | Untested, may work |
23-
| Java 14 | Untested, may work |
24-
| Java 15 | Untested, may work |
25-
| Java 16 | Untested, may work |
26-
| Java 17 | Untested, may work |
16+
| Language version | Support |
17+
| ---------------- | --------------------------------- |
18+
| Java 7 | |
19+
| Java 8 | |
20+
| Java 11 | |
21+
| Java 12 | Not tested in CI, but should work |
22+
| Java 13 | Not tested in CI, but should work |
23+
| Java 14 | Not tested in CI, but should work |
24+
| Java 15 | |
25+
| Java 16 | Not tested in CI, but should work |
26+
| Java 17 | Not tested in CI, but should work |
2727

2828
| Build tool | Support |
2929
| ---------- | ------- |

build.sbt

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ lazy val plugin = project
9191
.in(file("semanticdb-javac"))
9292
.settings(
9393
moduleName := "semanticdb-javac",
94+
javaToolchainVersion := "1.8",
9495
autoScalaLibrary := false,
9596
incOptions ~= { old =>
9697
old.withEnabled(false)
@@ -152,24 +153,39 @@ lazy val cli = project
152153
)
153154
.enablePlugins(NativeImagePlugin, BuildInfoPlugin)
154155

156+
def minimizedSourceDirectory =
157+
file("tests/minimized/src/main/java").getAbsoluteFile
158+
lazy val minimizedSettings = List[Def.Setting[_]](
159+
autoScalaLibrary := false,
160+
skip.in(publish) := true,
161+
fork.in(run) := true,
162+
unmanagedSourceDirectories.in(Compile) += minimizedSourceDirectory,
163+
javacOptions.in(Compile) ++=
164+
List[String](
165+
s"-Arandomtimestamp=${System.nanoTime()}",
166+
List(
167+
s"-Xplugin:semanticdb",
168+
s"-text:on",
169+
s"-verbose",
170+
s"-sourceroot:${baseDirectory.in(ThisBuild).value}",
171+
s"-targetroot:${semanticdbTargetRoot.in(Compile).value}"
172+
).mkString(" ")
173+
)
174+
)
175+
155176
lazy val minimized = project
156-
.in(file("tests/minimized"))
157-
.settings(
158-
autoScalaLibrary := false,
159-
skip.in(publish) := true,
160-
fork.in(run) := true,
161-
javacOptions.in(Compile) ++=
162-
List[String](
163-
s"-Arandomtimestamp=${System.nanoTime()}",
164-
List(
165-
s"-Xplugin:semanticdb",
166-
s"-text:on",
167-
s"-verbose",
168-
s"-sourceroot:${baseDirectory.in(ThisBuild).value}",
169-
s"-targetroot:${semanticdbTargetRoot.in(Compile).value}"
170-
).mkString(" ")
171-
)
172-
)
177+
.in(file("tests/minimized/.j11"))
178+
.settings(minimizedSettings)
179+
.dependsOn(agent, plugin)
180+
181+
lazy val minimized8 = project
182+
.in(file("tests/minimized/.j8"))
183+
.settings(minimizedSettings, javaToolchainVersion := "8")
184+
.dependsOn(agent, plugin)
185+
186+
lazy val minimized15 = project
187+
.in(file("tests/minimized/.j15"))
188+
.settings(minimizedSettings, javaToolchainVersion := "15")
173189
.dependsOn(agent, plugin)
174190

175191
lazy val minimizedScala = project
@@ -190,8 +206,7 @@ lazy val unit = project
190206
scalaVersion,
191207
"temporaryDirectory" -> target.value / "tmpdir",
192208
"sourceroot" -> baseDirectory.in(ThisBuild).value,
193-
"minimizedJavaSourceDirectory" ->
194-
sourceDirectory.in(minimized, Compile).value / "java",
209+
"minimizedJavaSourceDirectory" -> minimizedSourceDirectory,
195210
"minimizedJavaTargetroot" ->
196211
semanticdbTargetRoot.in(minimized, Compile).value,
197212
"minimizedScalaSourceDirectory" ->

project/JavaToolchainPlugin.scala

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import sbt.{Compile, Def, File, _}
2+
import sbt.Keys._
3+
import sbt.plugins.JvmPlugin
4+
5+
import java.nio.file.Paths
6+
import java.util
7+
import java.util.Collections
8+
import scala.util.Properties
9+
import scala.sys.process.Process
10+
11+
/**
12+
* An sbt plugin that automatically adds the Java compiler to the boot classpath
13+
* when necessary.
14+
*/
15+
object JavaToolchainPlugin extends AutoPlugin {
16+
override def trigger = allRequirements
17+
override def requires = JvmPlugin
18+
19+
object autoImport {
20+
lazy val javaToolchainVersion = settingKey[String](
21+
"The version of the Java"
22+
)
23+
}
24+
import autoImport._
25+
26+
lazy val configSettings = List(
27+
javacOptions ++=
28+
List(
29+
"-target",
30+
"1.8",
31+
"-source",
32+
"1.8",
33+
"-bootclasspath",
34+
java8Bootclasspath()
35+
),
36+
javacOptions.in(doc) --= List("-target", "1.8"),
37+
javacOptions.in(doc) --= bootclasspathSettings(javaToolchainVersion.value),
38+
javaHome := Some(getJavaHome(javaToolchainVersion.value)),
39+
javacOptions ++= bootclasspathSettings(javaToolchainVersion.value),
40+
javaOptions ++= bootclasspathSettings(javaToolchainVersion.value)
41+
)
42+
43+
override lazy val projectSettings: Seq[Def.Setting[_]] =
44+
List(Compile, Test).flatMap(c => inConfig(c)(configSettings)) ++
45+
List(fork := true, javaToolchainVersion := "11")
46+
47+
/**
48+
* For Java 8, we need to manually add the Java compiler to the boot
49+
* classpath.
50+
*
51+
* Newer Java versions include the compiler by default.
52+
*/
53+
private def bootclasspathSettings(version: String): List[String] = {
54+
val home = getJavaHome(version)
55+
val toolsJar: File = home / "lib" / "tools.jar"
56+
// The tools.jar file includes the bytecode for the Java compiler in the com.sun.source package.
57+
// The Java compiler is available by default in Java 9+, so we only need to add tools.jar to the
58+
// bootclasspath for Java 8.
59+
if (home.toString.contains("1.8") && toolsJar.isFile) {
60+
List(s"-Xbootclasspath/p:$toolsJar")
61+
} else {
62+
List()
63+
}
64+
}
65+
66+
private def java8Bootclasspath(): String = {
67+
(getJavaHome("8") / "jre" / "lib" / "rt.jar").toString
68+
}
69+
70+
private val javaHomeCache: util.Map[String, File] = Collections
71+
.synchronizedMap(new util.HashMap[String, File]())
72+
private def getJavaHome(version: String): File = {
73+
javaHomeCache.computeIfAbsent(
74+
version,
75+
(v: String) => {
76+
val coursier = Paths.get("bin", "coursier")
77+
new File(
78+
Process(List(coursier.toString, "java-home", "--jvm", v)).!!.trim
79+
)
80+
}
81+
)
82+
}
83+
}

project/JavacBootClasspathPlugin.scala

Lines changed: 0 additions & 55 deletions
This file was deleted.

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/GlobalSymbolsCache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ private String uncachedSemanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
4444
}
4545
SemanticdbSymbols.Descriptor desc = semanticdbDescriptor(sym);
4646
if (options.verboseEnabled && desc.kind == SemanticdbSymbols.Descriptor.Kind.None) {
47-
pprint(sym.name.toString());
48-
pprint(sym.kind);
47+
pprint(sym.getQualifiedName().toString());
4948
pprint(
5049
String.format(
5150
"sym: %s (%s - superclass %s)", sym, sym.getClass(), sym.getClass().getSuperclass()));

0 commit comments

Comments
 (0)