Skip to content

Commit

Permalink
Remove Usage Of Deprecated lines Method
Browse files Browse the repository at this point in the history
Another instance of the deprecated `lines` method was recently added to the code base. This method causes metals to be not build on JDK >= 11.

This commit also updates the CI to build with JDK's 8 and 11 using OpenJDK and AdoptOpenJDK. This should help prevent future additions of this method.

Finally this commit also modifies the `TreeViewLspSuite` test and adds the ADT `JVMVersion` to permit these tests to function correctly on both JDK 8 and JDKs supporting modules, e.g. > 8.

See: ce9c890 and 4d78f9c for more context.
  • Loading branch information
isomarcte committed Dec 9, 2019
1 parent f15d7b4 commit 7035ea5
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 278 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -12,9 +12,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
java-version:
- "adopt@1.11"
- "adopt@1.8"
- "openjdk@1.11"
steps:
- uses: actions/checkout@v1
- uses: olafurpg/setup-scala@v7
with:
java-version: ${{ matrix.java-version }}
- name: Run unit tests
run: |
bin/test.sh unit/test
Expand Down
Expand Up @@ -143,7 +143,7 @@ class WorkspaceEditWorksheetPublisher(buffers: Buffers)
private def updateWithEdits(text: String, edits: List[TextEdit]): String = {
val editsMap = edits.map(e => e.getRange().getStart().getLine() -> e).toMap

text.lines.zipWithIndex
text.linesIterator.zipWithIndex
.map {
case (line, i) =>
editsMap.get(i) match {
Expand Down
87 changes: 87 additions & 0 deletions tests/unit/src/main/scala/tests/JVMVersion.scala
@@ -0,0 +1,87 @@
package tests

import scala.util._
import scala.util.matching._

/** ADT used to model the current version of the runtime JVM.
*
* It is needed to know the current version for several of the test cases as
* there are some changes to the classpath between different JVM versions.
*
* For example, on JDK > 8 several standard jar files are now stored as java
* modules and will now longer show up as standalone jars,
* e.g. `charsets.jar`.
*/
sealed trait JVMVersion extends Product with Serializable {
def value: String
}

object JVMVersion {

/** The value of the System property `java.version` used to determine the
* JVM version. It is an `Option` as system values may be `null`.
*/
val javaVmVersion: Option[String] =
Option(System.getProperty("java.version")) // null check

/** A regular expression used to parse the value of `java.version` into
* components. This makes it easy to discriminate on a particular major
* version number.
*/
val numericJVMVersionRegex: Regex =
raw"""(\d+)\.(\d+)\.(\d+)(.*)""".r

/** ADT constructor for a numeric JVM version.
*
* This is the canonical representation we expect, though strictly
* speaking, it is not a requirement that the JVM version be numeric.
*/
final case class NumericJVMVersion(
major: Long,
override final val value: String
) extends JVMVersion

/** ADT constructor for a non-numeric JVM version.
*
* This is the exceptional case, as we normally expect the JVM version to
* be numeric.
*/
final case class NonNumericJVMVersion(override final val value: String)
extends JVMVersion

/** The currently running JVMVersion value.
*
* @note this value will be `None` if the system property `java.version`
* is `null.`
*
* The expected way to use this is to pattern match on the result to
* execute specific code for some specific JVM version.
*
* {{{
* jvmVersion match {
* case Some(NumericJVMVersion(major, _,)) if major > 8L => // Do something special for JDK > 8
* case _ => // Do something else
* }
* }}}
*/
val jvmVersion: Option[JVMVersion] =
this.javaVmVersion.map((version: String) =>
version match {
case numericJVMVersionRegex(aS, bS, cS, suffix) =>
(
for {
a <- Try(aS.toLong)
b <- Try(bS.toLong)
} yield
if (a == 1L) {
// Then this is an old style version number, e.g. 1.8.0
NumericJVMVersion(b, version)
} else {
NumericJVMVersion(a, version)
}
).getOrElse(NonNumericJVMVersion(version)) // if the regex is properly defined, this branch should never execute.
case otherwise =>
NonNumericJVMVersion(otherwise)
}
)
}

0 comments on commit 7035ea5

Please sign in to comment.