Skip to content

Commit

Permalink
Merge pull request #911 from olafurpg/jdk11
Browse files Browse the repository at this point in the history
Add support for Java 11
  • Loading branch information
olafurpg authored Nov 28, 2018
2 parents 18eac3f + 3146e3e commit 6ef1520
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 29 deletions.
1 change: 0 additions & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
-XX:+TieredCompilation
-XX:-UseGCOverheadLimit
-XX:+CMSClassUnloadingEnabled
-XX:+UseConcMarkSweepGC
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
script: sbt ci-211
- env: TEST="2.12"
script: sbt ci-212
- jdk: openjdk11
env: TEST="2.12"
script: sbt ci-212

# Disabled until stable v0.6
# - env: TEST="mima"
Expand Down
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ noPublish

// force javac to fork by setting javaHome to get error messages during compilation,
// see https://github.com/sbt/zinc/issues/520
def inferJavaHome() =
Some(file(System.getProperty("java.home")).getParentFile)
def inferJavaHome() = {
val home = file(sys.props("java.home"))
val actualHome =
if (System.getProperty("java.version").startsWith("1.8")) home.getParentFile
else home
Some(actualHome)
}

lazy val interfaces = project
.in(file("scalafix-interfaces"))
Expand Down
10 changes: 5 additions & 5 deletions scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ object MainOps {
DiffUtils.unifiedDiff(
input.syntax + "-ondisk",
input.syntax + "-semanticdb",
input.text.lines.toList,
doc.text.lines.toList,
input.text.linesIterator.toList,
doc.text.linesIterator.toList,
3
)
}
Expand Down Expand Up @@ -213,8 +213,8 @@ object MainOps {
val diff = DiffUtils.unifiedDiff(
file.toString(),
"<expected fix>",
input.text.lines.toList,
fixed.lines.toList,
input.text.linesIterator.toList,
fixed.linesIterator.toList,
3
)
args.args.out.println(diff)
Expand Down Expand Up @@ -304,7 +304,7 @@ object MainOps {
}
buf.clear()
}
text.lines.foreach { line =>
text.linesIterator.foreach { line =>
if (line.startsWith("```")) {
flush()
insideCodeFence = !insideCodeFence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ object PatchInternals {
add1.tok,
add1.addLeft + add2.addLeft,
add1.addRight + add2.addRight,
add1.keepTok && add2.keepTok)
add1.keepTok && add2.keepTok
)
case (_: Remove, add: Add) => add.copy(keepTok = false)
case (add: Add, _: Remove) => add.copy(keepTok = false)
case (rem: Remove, rem2: Remove) => rem
Expand Down Expand Up @@ -70,18 +71,21 @@ object PatchInternals {
patchesByName,
new LegacyRuleCtx(doc.internal.doc),
Some(new LegacySemanticdbIndex(doc)),
suppress)
suppress
)
}

def treePatchApply(patch: Patch)(
implicit
ctx: v0.RuleCtx,
index: v0.SemanticdbIndex): Iterable[TokenPatch] = {
index: v0.SemanticdbIndex
): Iterable[TokenPatch] = {
val base = underlying(patch)
val moveSymbol = underlying(
ReplaceSymbolOps.naiveMoveSymbolPatch(base.collect {
case m: ReplaceSymbol => m
})(ctx, index))
})(ctx, index)
)
val patches = base.filterNot(_.isInstanceOf[ReplaceSymbol]) ++ moveSymbol
val tokenPatches = patches.collect { case e: TokenPatch => e }
val importPatches = patches.collect { case e: ImportPatch => e }
Expand All @@ -97,15 +101,17 @@ object PatchInternals {
case x: TokenPatch => x
case els =>
throw Failure.InvariantFailedException(
s"Expected TokenPatch, got $els")
s"Expected TokenPatch, got $els"
)
}
}
importTokenPatches ++ tokenPatches
}

private def tokenPatchApply(
ctx: v0.RuleCtx,
patches: Iterable[TokenPatch]): String = {
patches: Iterable[TokenPatch]
): String = {
val patchMap = patches
.groupBy(x => TokenOps.hash(x.tok))
.mapValues(_.reduce(merge).newTok)
Expand Down Expand Up @@ -159,9 +165,10 @@ object PatchInternals {
DiffUtils.unifiedDiff(
original.label,
revised.label,
new String(original.chars).lines.toList,
new String(revised.chars).lines.toList,
context)
new String(original.chars).linesIterator.toList,
new String(revised.chars).linesIterator.toList,
context
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scalafix.internal.v1
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import javax.xml.bind.DatatypeConverter

object FingerprintOps {

Expand All @@ -14,7 +13,20 @@ object FingerprintOps {
def md5(buffer: ByteBuffer): String = {
val md = MessageDigest.getInstance("MD5")
md.update(buffer)
DatatypeConverter.printHexBinary(md.digest())
bytesToHex(md.digest())
}

private val hexArray = "0123456789ABCDEF".toCharArray
def bytesToHex(bytes: Array[Byte]): String = {
val hexChars = new Array[Char](bytes.length * 2)
var j = 0
while (j < bytes.length) {
val v: Int = bytes(j) & 0xFF
hexChars(j * 2) = hexArray(v >>> 4)
hexChars(j * 2 + 1) = hexArray(v & 0x0F)
j += 1
}
new String(hexChars)
}

}
5 changes: 3 additions & 2 deletions scalafix-docs/src/main/scala/docs/FileModifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class FileModifier extends StringModifier {
override def process(
info: String,
code: Input,
reporter: Reporter): String = {
reporter: Reporter
): String = {
val filename = info
val path = Paths.get(filename)
val text = new String(Files.readAllBytes(path), StandardCharsets.UTF_8)
val input = Input.VirtualFile(filename, text)
code.text.lines.toList match {
code.text.linesIterator.toList match {
case List(startMarker, endMarker) =>
val start = text.indexOf(startMarker.stripSuffix("..."))
val end = text.indexOf(endMarker.stripPrefix("..."))
Expand Down
2 changes: 1 addition & 1 deletion scalafix-docs/src/main/scala/scalafix/docs/PatchDocs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object PatchDocs {
}
}
def printDiff(diff: String): Unit = {
val trimmed = diff.lines.drop(3).mkString("\n")
val trimmed = diff.linesIterator.drop(3).mkString("\n")
val message =
if (trimmed.isEmpty) "<no diff>"
else trimmed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object RuleDecoderOps {
} else {
val ctor = cls.getDeclaredConstructor()
ctor.setAccessible(true)
cls.newInstance().asInstanceOf[v1.Rule]
cls.getConstructor().newInstance().asInstanceOf[v1.Rule]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ trait DiffAssertions extends FunSuiteLike {
): Boolean = {
val result = compareContents(obtained, expected)
if (result.isEmpty) true
else if (obtained.lines.toList == expected.lines.toList) {
else if (obtained.linesIterator.toList == expected.linesIterator.toList) {
// Ignore \r\n and \n differences
true
} else {
if (printObtained) {
println("\"\"\"|")
obtained.lines.foreach { line =>
obtained.linesIterator.foreach { line =>
print(" |")
println(line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions {
}
semanticdbscalac.getOrElse {
throw new IllegalStateException(
"unable to auto-detect semanticdb-scalac compiler plugin")
"unable to auto-detect semanticdb-scalac compiler plugin"
)
}
}
def scalaLibrary: AbsolutePath =
Expand Down Expand Up @@ -132,7 +133,8 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions {
// This rule is published to Maven Central to simplify testing --tool-classpath.
val toolClasspathJars = CoursierSmall.fetch(settings)
val toolClasspath = ClasspathOps.toClassLoader(
Classpath(toolClasspathJars.map(jar => AbsolutePath(jar))))
Classpath(toolClasspathJars.map(jar => AbsolutePath(jar)))
)
val scalacOptions = Array[String](
"-Yrangepos",
s"-Xplugin:${semanticdbPluginPath()}",
Expand All @@ -158,7 +160,8 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions {
val args = api
.newArguments()
.withParsedArguments(
List("--settings.DisableSyntax.noSemicolons", "true").asJava)
List("--settings.DisableSyntax.noSemicolons", "true").asJava
)
.withCharset(charset)
.withClasspath(List(d, scalaLibrary.toNIO).asJava)
.withSourceroot(src)
Expand Down Expand Up @@ -204,7 +207,7 @@ class ScalafixImplSuite extends FunSuite with DiffAssertions {
.plainText
.replaceAllLiterally(semicolon.toString, relativePath.toString)
.replace('\\', '/') // for windows
.lines
.linesIterator
.filterNot(_.trim.isEmpty)
.mkString("\n")
assert(errors == List("LinterError", "TestError"), stdout)
Expand Down

0 comments on commit 6ef1520

Please sign in to comment.