mirror of https://github.com/sbt/sbt.git
Merge pull request #2951 from retronym/topic/java9
Preliminary compatibility with JDK 9
This commit is contained in:
commit
756151f555
|
|
@ -0,0 +1,61 @@
|
||||||
|
package sbt
|
||||||
|
package inc
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException
|
||||||
|
import javax.xml.bind.DatatypeConverter
|
||||||
|
|
||||||
|
private[sbt] trait Base64 {
|
||||||
|
def encode(bytes: Array[Byte]): String
|
||||||
|
|
||||||
|
def decode(string: String): Array[Byte]
|
||||||
|
}
|
||||||
|
|
||||||
|
private[sbt] object Base64 {
|
||||||
|
lazy val factory: () => Base64 = {
|
||||||
|
try {
|
||||||
|
new Java678Encoder().encode(Array[Byte]())
|
||||||
|
() => new Java678Encoder()
|
||||||
|
} catch {
|
||||||
|
case _: LinkageError =>
|
||||||
|
() => new Java89Encoder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private[sbt] class Java678Encoder extends Base64 {
|
||||||
|
def encode(bytes: Array[Byte]): String = DatatypeConverter.printBase64Binary(bytes)
|
||||||
|
|
||||||
|
def decode(string: String): Array[Byte] = DatatypeConverter.parseBase64Binary(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
private[sbt] object Java89Encoder {
|
||||||
|
|
||||||
|
import scala.runtime.ScalaRunTime.ensureAccessible
|
||||||
|
|
||||||
|
private val Base64_class = Class.forName("java.util.Base64")
|
||||||
|
private val Base64_getEncoder = ensureAccessible(Base64_class.getMethod("getEncoder"))
|
||||||
|
private val Base64_getDecoder = ensureAccessible(Base64_class.getMethod("getEncoder"))
|
||||||
|
private val Base64_Encoder_class = Class.forName("java.util.Base64$Encoder")
|
||||||
|
private val Base64_Decoder_class = Class.forName("java.util.Base64$Decoder")
|
||||||
|
private val Base64_Encoder_encodeToString = ensureAccessible(Base64_Encoder_class.getMethod("encodeToString", classOf[Array[Byte]]))
|
||||||
|
private val Base64_Decoder_decode = ensureAccessible(Base64_Decoder_class.getMethod("decode", classOf[String]))
|
||||||
|
}
|
||||||
|
|
||||||
|
private[sbt] class Java89Encoder extends Base64 {
|
||||||
|
|
||||||
|
import Java89Encoder._
|
||||||
|
|
||||||
|
def encode(bytes: Array[Byte]): String = try {
|
||||||
|
val encoder = Base64_getEncoder.invoke(null)
|
||||||
|
Base64_Encoder_encodeToString.invoke(encoder, bytes).asInstanceOf[String]
|
||||||
|
} catch {
|
||||||
|
case ex: InvocationTargetException => throw ex.getCause
|
||||||
|
}
|
||||||
|
|
||||||
|
def decode(string: String): Array[Byte] = try {
|
||||||
|
val decoder = Base64_getDecoder.invoke(null)
|
||||||
|
Base64_Decoder_decode.invoke(decoder, string).asInstanceOf[Array[Byte]]
|
||||||
|
} catch {
|
||||||
|
case ex: InvocationTargetException => throw ex.getCause
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ import java.io._
|
||||||
import sbt.{ CompileSetup, Relation }
|
import sbt.{ CompileSetup, Relation }
|
||||||
import xsbti.api.{ Compilation, Source }
|
import xsbti.api.{ Compilation, Source }
|
||||||
import xsbti.compile.{ MultipleOutput, SingleOutput }
|
import xsbti.compile.{ MultipleOutput, SingleOutput }
|
||||||
import javax.xml.bind.DatatypeConverter
|
|
||||||
|
|
||||||
// Very simple timer for timing repeated code sections.
|
// Very simple timer for timing repeated code sections.
|
||||||
// TODO: Temporary. Remove once we've milked all available performance gains.
|
// TODO: Temporary. Remove once we've milked all available performance gains.
|
||||||
|
|
@ -328,11 +327,11 @@ object TextAnalysisFormat {
|
||||||
val out = new sbinary.JavaOutput(baos)
|
val out = new sbinary.JavaOutput(baos)
|
||||||
FormatTimer.aggregate("sbinary write") { try { fmt.writes(out, o) } finally { baos.close() } }
|
FormatTimer.aggregate("sbinary write") { try { fmt.writes(out, o) } finally { baos.close() } }
|
||||||
val bytes = FormatTimer.aggregate("byte copy") { baos.toByteArray }
|
val bytes = FormatTimer.aggregate("byte copy") { baos.toByteArray }
|
||||||
FormatTimer.aggregate("bytes -> base64") { DatatypeConverter.printBase64Binary(bytes) }
|
FormatTimer.aggregate("bytes -> base64") { Base64.factory().encode(bytes) }
|
||||||
}
|
}
|
||||||
|
|
||||||
def stringToObj[T](s: String)(implicit fmt: sbinary.Format[T]) = {
|
def stringToObj[T](s: String)(implicit fmt: sbinary.Format[T]) = {
|
||||||
val bytes = FormatTimer.aggregate("base64 -> bytes") { DatatypeConverter.parseBase64Binary(s) }
|
val bytes = FormatTimer.aggregate("base64 -> bytes") { Base64.factory().decode(s) }
|
||||||
val in = new sbinary.JavaInput(new ByteArrayInputStream(bytes))
|
val in = new sbinary.JavaInput(new ByteArrayInputStream(bytes))
|
||||||
FormatTimer.aggregate("sbinary read") { fmt.reads(in) }
|
FormatTimer.aggregate("sbinary read") { fmt.reads(in) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ final class CompilerArguments(scalaInstance: xsbti.compile.ScalaInstance, cp: xs
|
||||||
def bootClasspathFor(classpath: Seq[File]) = bootClasspath(hasLibrary(classpath))
|
def bootClasspathFor(classpath: Seq[File]) = bootClasspath(hasLibrary(classpath))
|
||||||
|
|
||||||
import Path._
|
import Path._
|
||||||
def extClasspath: Seq[File] = (IO.parseClasspath(System.getProperty("java.ext.dirs")) * "*.jar").get
|
def extClasspath: Seq[File] = (IO.parseClasspath(System.getProperty("java.ext.dirs", "")) * "*.jar").get
|
||||||
}
|
}
|
||||||
object CompilerArguments {
|
object CompilerArguments {
|
||||||
val BootClasspathOption = "-bootclasspath"
|
val BootClasspathOption = "-bootclasspath"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue