Skip to content

Commit

Permalink
Pick different FileConverters depending on the Java version, close #615
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Jun 17, 2022
1 parent d6b75f6 commit 4eafa8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/sbt_inc/SbtIncrementalCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import scala.Tuple2;
import scala_maven.MavenArtifactResolver;
import util.FileUtils;
import util.JavaVersion;
import xsbti.FileConverter;
import xsbti.PathBasedFile;
import xsbti.T2;
import xsbti.VirtualFile;
Expand Down Expand Up @@ -156,6 +158,11 @@ public void compile(
fullClasspath.add(classesDirectory);
fullClasspath.addAll(classpathElements);

Optional<FileConverter> fileConverter =
JavaVersion.JAVA_MAJOR_VERSION >= 9
? Optional.empty()
: Optional.of(PlainVirtualFileConverter.converter());

CompileOptions options =
CompileOptions.of(
fullClasspath.stream()
Expand All @@ -169,7 +176,7 @@ public void compile(
pos -> pos, // sourcePositionMappers
compileOrder, // order
Optional.empty(), // temporaryClassesDirectory
Optional.empty(), // _converter
fileConverter, // _converter
Optional.empty(), // _stamper
Optional.empty() // _earlyOutput
);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/util/JavaVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* This is free and unencumbered software released into the public domain.
* See UNLICENSE.
*/
package util;

public final class JavaVersion {

private JavaVersion() {}

public static final int JAVA_MAJOR_VERSION;

static {
String javaSpecVersion = System.getProperty("java.specification.version");
String[] components = javaSpecVersion.split("\\.");
int component0 = Integer.parseInt(components[0]);
JAVA_MAJOR_VERSION = component0 == 1 ? Integer.parseInt(components[1]) : component0;
}
}

0 comments on commit 4eafa8b

Please sign in to comment.