Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-Xss2m
-Xms1G
-Xmx4G
-Dfile.encoding=UTF-8
-Dfile.encoding=UTF-8
Binary file modified bin/coursier
Binary file not shown.
77 changes: 67 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io.File
import java.nio.file.Files
import java.util.Properties
import scala.collection.mutable.ListBuffer
import scala.util.control.NoStackTrace

lazy val V =
new {
Expand Down Expand Up @@ -271,12 +272,9 @@ commands +=

def minimizedSourceDirectory =
file("tests/minimized/src/main/java").getAbsoluteFile
lazy val minimizedSettings = List[Def.Setting[_]](
autoScalaLibrary := false,
(publish / skip) := true,
(run / fork) := true,
(Compile / unmanagedSourceDirectories) += minimizedSourceDirectory,
(Compile / javacOptions) ++=

def semanticdbCompileOptions =
Def.setting {
List[String](
s"-Arandomtimestamp=${System.nanoTime()}",
List(
Expand All @@ -288,6 +286,13 @@ lazy val minimizedSettings = List[Def.Setting[_]](
s"-targetroot:${(Compile / semanticdbTargetRoot).value}"
).mkString(" ")
)
}
lazy val minimizedSettings = List[Def.Setting[_]](
autoScalaLibrary := false,
(publish / skip) := true,
(run / fork) := true,
(Compile / unmanagedSourceDirectories) += minimizedSourceDirectory,
(Compile / javacOptions) ++= semanticdbCompileOptions.value
)

lazy val minimized = project
Expand All @@ -302,13 +307,65 @@ lazy val minimized8 = project
.dependsOn(agent, plugin)
.disablePlugins(JavaFormatterPlugin)

def javaModuleExports =
List(
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
)

def compileWithJava17 =
Def.task {
val args = ListBuffer.empty[String]
val javaSources = (minimized8 / Compile / sources)
.value
.map(_.getAbsolutePath)
val javac = (Compile / javaHome)
.value
.get
.toPath
.resolve("bin")
.resolve("javac")
.toString
val compileClasspath = List(
"-classpath",
(Compile / dependencyClasspath)
.value
.map(_.data.getAbsolutePath)
.mkString(java.io.File.pathSeparator)
)
val outputDirectory = (Compile / classDirectory).value
IO.delete(outputDirectory)

args += javac
args ++= javaModuleExports
args ++= List("-d", outputDirectory.getAbsolutePath)
args ++= semanticdbCompileOptions.value
args ++= compileClasspath
args ++= javaSources
val exit = scala.sys.process.Process(args.toList).!
if (exit != 0) {
throw new RuntimeException("javac compilation failed") with NoStackTrace
}
}

lazy val minimized17 = project
.in(file("tests/minimized/.j15"))
.in(file("tests/minimized/.j17"))
.settings(
minimizedSettings,
// Non-zulu release is blocked by https://github.com/coursier/jvm-index/pull/53
javaToolchainVersion := "zulu:17",
Compile / javaHome := None
Compile / sources := Nil,
javaToolchainJvmIndex :=
Some("https://github.com/coursier/jvm-index/blob/master/index.json"),
javaToolchainVersion := "temurin:17",
Compile / compile :=
(Compile / compile).dependsOn(compileWithJava17).value
)
.dependsOn(agent, plugin)
.disablePlugins(JavaFormatterPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
public class JavaVersion {
public final boolean isJava8;
public final JdkPackage pkg;
private static PathMatcher CLASS_PATTERN =
private static final PathMatcher CLASS_PATTERN =
FileSystems.getDefault().getPathMatcher("glob:**.class");
private static PathMatcher JAR_PATTERN = FileSystems.getDefault().getPathMatcher("glob:**.jar");
private static final PathMatcher JAR_PATTERN =
FileSystems.getDefault().getPathMatcher("glob:**.jar");

public static int JAVA8_VERSION = 8;
public static int JAVA11_VERSION = 11;
public static int DEFAULT_JAVA_VERSION = JAVA8_VERSION;
private static int JAVA0_MAJOR_VERSION = 44;
public static final int JAVA8_VERSION = 8;
public static final int JAVA11_VERSION = 11;
public static final int JAVA17_VERSION = 17;
public static final int DEFAULT_JAVA_VERSION = JAVA8_VERSION;

@SuppressWarnings("FieldCanBeLocal")
private static final int JAVA0_MAJOR_VERSION = 44;

public JavaVersion() {
this(System.getProperty("java.version"));
Expand All @@ -40,9 +44,11 @@ private String javaVersion(String version) {
else return version;
}

@SuppressWarnings("ManualMinMaxCalculation")
public static int roundToNearestStableRelease(int version) {
if (version <= JAVA8_VERSION) return JAVA8_VERSION;
if (version <= JAVA11_VERSION) return JAVA11_VERSION;
if (version <= JAVA17_VERSION) return JAVA17_VERSION;
return version;
}

Expand Down
28 changes: 22 additions & 6 deletions project/JavaToolchainPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ object JavaToolchainPlugin extends AutoPlugin {
lazy val javaToolchainVersion = settingKey[String](
"The version of the Java"
)
lazy val javaToolchainJvmIndex = settingKey[Option[String]](
"The JVM index to use"
)
}
import autoImport._

Expand All @@ -36,14 +39,21 @@ object JavaToolchainPlugin extends AutoPlugin {
(doc / javacOptions) --= List("-target", "1.8"),
(doc / javacOptions) --= bootclasspathSettings(javaToolchainVersion.value),
(doc / javacOptions) --= List("-g"),
javaHome := Some(getJavaHome(javaToolchainVersion.value)),
javaHome :=
Some(
getJavaHome(javaToolchainVersion.value, javaToolchainJvmIndex.value)
),
javacOptions ++= bootclasspathSettings(javaToolchainVersion.value),
javaOptions ++= bootclasspathSettings(javaToolchainVersion.value)
)

override lazy val projectSettings: Seq[Def.Setting[_]] =
List(Compile, Test).flatMap(c => inConfig(c)(configSettings)) ++
List(fork := true, javaToolchainVersion := "11")
List(
fork := true,
javaToolchainVersion := "11",
javaToolchainJvmIndex := None
)

/**
* For Java 8, we need to manually add the Java compiler to the boot
Expand All @@ -70,14 +80,20 @@ object JavaToolchainPlugin extends AutoPlugin {

private val javaHomeCache: util.Map[String, File] = Collections
.synchronizedMap(new util.HashMap[String, File]())
private def getJavaHome(version: String): File = {
private def getJavaHome(
version: String,
jvmIndex: Option[String] = None
): File = {
javaHomeCache.computeIfAbsent(
version,
(v: String) => {
val coursier = Paths.get("bin", "coursier")
new File(
Process(List(coursier.toString, "java-home", "--jvm", v)).!!.trim
)
val index = jvmIndex
.toList
.flatMap(index => "--jvm-index" :: index :: Nil)
val arguments =
List(coursier.toString, "java-home", "--jvm", v) ++ index
new File(Process(arguments).!!.trim)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sun.tools.javac.code.Symbol;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import java.util.*;

Expand Down Expand Up @@ -57,7 +58,14 @@ private String uncachedSemanticdbSymbol(Symbol sym, LocalSymbolsCache locals) {
}

private boolean isLocalVariable(Symbol sym) {
return sym instanceof Symbol.VarSymbol && sym.isLocal();
switch (sym.getKind()) {
case PARAMETER:
case EXCEPTION_PARAMETER:
case LOCAL_VARIABLE:
return true;
default:
return false;
}
}

private boolean isAnonymousClass(Symbol sym) {
Expand Down