Skip to content

Commit 6ef1520

Browse files
authored
Merge pull request #911 from olafurpg/jdk11
Add support for Java 11
2 parents 18eac3f + 3146e3e commit 6ef1520

File tree

11 files changed

+59
-29
lines changed

11 files changed

+59
-29
lines changed

.jvmopts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
-XX:+TieredCompilation
77
-XX:-UseGCOverheadLimit
88
-XX:+CMSClassUnloadingEnabled
9-
-XX:+UseConcMarkSweepGC

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
script: sbt ci-211
1919
- env: TEST="2.12"
2020
script: sbt ci-212
21+
- jdk: openjdk11
22+
env: TEST="2.12"
23+
script: sbt ci-212
2124

2225
# Disabled until stable v0.6
2326
# - env: TEST="mima"

build.sbt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ noPublish
1111

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

1722
lazy val interfaces = project
1823
.in(file("scalafix-interfaces"))

scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ object MainOps {
167167
DiffUtils.unifiedDiff(
168168
input.syntax + "-ondisk",
169169
input.syntax + "-semanticdb",
170-
input.text.lines.toList,
171-
doc.text.lines.toList,
170+
input.text.linesIterator.toList,
171+
doc.text.linesIterator.toList,
172172
3
173173
)
174174
}
@@ -213,8 +213,8 @@ object MainOps {
213213
val diff = DiffUtils.unifiedDiff(
214214
file.toString(),
215215
"<expected fix>",
216-
input.text.lines.toList,
217-
fixed.lines.toList,
216+
input.text.linesIterator.toList,
217+
fixed.linesIterator.toList,
218218
3
219219
)
220220
args.args.out.println(diff)
@@ -304,7 +304,7 @@ object MainOps {
304304
}
305305
buf.clear()
306306
}
307-
text.lines.foreach { line =>
307+
text.linesIterator.foreach { line =>
308308
if (line.startsWith("```")) {
309309
flush()
310310
insideCodeFence = !insideCodeFence

scalafix-core/src/main/scala/scalafix/internal/patch/PatchInternals.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ object PatchInternals {
2121
add1.tok,
2222
add1.addLeft + add2.addLeft,
2323
add1.addRight + add2.addRight,
24-
add1.keepTok && add2.keepTok)
24+
add1.keepTok && add2.keepTok
25+
)
2526
case (_: Remove, add: Add) => add.copy(keepTok = false)
2627
case (add: Add, _: Remove) => add.copy(keepTok = false)
2728
case (rem: Remove, rem2: Remove) => rem
@@ -70,18 +71,21 @@ object PatchInternals {
7071
patchesByName,
7172
new LegacyRuleCtx(doc.internal.doc),
7273
Some(new LegacySemanticdbIndex(doc)),
73-
suppress)
74+
suppress
75+
)
7476
}
7577

7678
def treePatchApply(patch: Patch)(
7779
implicit
7880
ctx: v0.RuleCtx,
79-
index: v0.SemanticdbIndex): Iterable[TokenPatch] = {
81+
index: v0.SemanticdbIndex
82+
): Iterable[TokenPatch] = {
8083
val base = underlying(patch)
8184
val moveSymbol = underlying(
8285
ReplaceSymbolOps.naiveMoveSymbolPatch(base.collect {
8386
case m: ReplaceSymbol => m
84-
})(ctx, index))
87+
})(ctx, index)
88+
)
8589
val patches = base.filterNot(_.isInstanceOf[ReplaceSymbol]) ++ moveSymbol
8690
val tokenPatches = patches.collect { case e: TokenPatch => e }
8791
val importPatches = patches.collect { case e: ImportPatch => e }
@@ -97,15 +101,17 @@ object PatchInternals {
97101
case x: TokenPatch => x
98102
case els =>
99103
throw Failure.InvariantFailedException(
100-
s"Expected TokenPatch, got $els")
104+
s"Expected TokenPatch, got $els"
105+
)
101106
}
102107
}
103108
importTokenPatches ++ tokenPatches
104109
}
105110

106111
private def tokenPatchApply(
107112
ctx: v0.RuleCtx,
108-
patches: Iterable[TokenPatch]): String = {
113+
patches: Iterable[TokenPatch]
114+
): String = {
109115
val patchMap = patches
110116
.groupBy(x => TokenOps.hash(x.tok))
111117
.mapValues(_.reduce(merge).newTok)
@@ -159,9 +165,10 @@ object PatchInternals {
159165
DiffUtils.unifiedDiff(
160166
original.label,
161167
revised.label,
162-
new String(original.chars).lines.toList,
163-
new String(revised.chars).lines.toList,
164-
context)
168+
new String(original.chars).linesIterator.toList,
169+
new String(revised.chars).linesIterator.toList,
170+
context
171+
)
165172
}
166173

167174
}

scalafix-core/src/main/scala/scalafix/internal/v1/FingerprintOps.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package scalafix.internal.v1
33
import java.nio.ByteBuffer
44
import java.nio.charset.StandardCharsets
55
import java.security.MessageDigest
6-
import javax.xml.bind.DatatypeConverter
76

87
object FingerprintOps {
98

@@ -14,7 +13,20 @@ object FingerprintOps {
1413
def md5(buffer: ByteBuffer): String = {
1514
val md = MessageDigest.getInstance("MD5")
1615
md.update(buffer)
17-
DatatypeConverter.printHexBinary(md.digest())
16+
bytesToHex(md.digest())
17+
}
18+
19+
private val hexArray = "0123456789ABCDEF".toCharArray
20+
def bytesToHex(bytes: Array[Byte]): String = {
21+
val hexChars = new Array[Char](bytes.length * 2)
22+
var j = 0
23+
while (j < bytes.length) {
24+
val v: Int = bytes(j) & 0xFF
25+
hexChars(j * 2) = hexArray(v >>> 4)
26+
hexChars(j * 2 + 1) = hexArray(v & 0x0F)
27+
j += 1
28+
}
29+
new String(hexChars)
1830
}
1931

2032
}

scalafix-docs/src/main/scala/docs/FileModifier.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class FileModifier extends StringModifier {
1313
override def process(
1414
info: String,
1515
code: Input,
16-
reporter: Reporter): String = {
16+
reporter: Reporter
17+
): String = {
1718
val filename = info
1819
val path = Paths.get(filename)
1920
val text = new String(Files.readAllBytes(path), StandardCharsets.UTF_8)
2021
val input = Input.VirtualFile(filename, text)
21-
code.text.lines.toList match {
22+
code.text.linesIterator.toList match {
2223
case List(startMarker, endMarker) =>
2324
val start = text.indexOf(startMarker.stripSuffix("..."))
2425
val end = text.indexOf(endMarker.stripPrefix("..."))

scalafix-docs/src/main/scala/scalafix/docs/PatchDocs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ object PatchDocs {
8383
}
8484
}
8585
def printDiff(diff: String): Unit = {
86-
val trimmed = diff.lines.drop(3).mkString("\n")
86+
val trimmed = diff.linesIterator.drop(3).mkString("\n")
8787
val message =
8888
if (trimmed.isEmpty) "<no diff>"
8989
else trimmed

scalafix-reflect/src/main/scala/scalafix/internal/reflect/RuleDecoderOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object RuleDecoderOps {
4040
} else {
4141
val ctor = cls.getDeclaredConstructor()
4242
ctor.setAccessible(true)
43-
cls.newInstance().asInstanceOf[v1.Rule]
43+
cls.getConstructor().newInstance().asInstanceOf[v1.Rule]
4444
}
4545
}
4646

scalafix-testkit/src/main/scala/scalafix/testkit/DiffAssertions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ trait DiffAssertions extends FunSuiteLike {
8585
): Boolean = {
8686
val result = compareContents(obtained, expected)
8787
if (result.isEmpty) true
88-
else if (obtained.lines.toList == expected.lines.toList) {
88+
else if (obtained.linesIterator.toList == expected.linesIterator.toList) {
8989
// Ignore \r\n and \n differences
9090
true
9191
} else {
9292
if (printObtained) {
9393
println("\"\"\"|")
94-
obtained.lines.foreach { line =>
94+
obtained.linesIterator.foreach { line =>
9595
print(" |")
9696
println(line)
9797
}

0 commit comments

Comments
 (0)