Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Usage Of Deprecated
lines
Method
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
Showing
4 changed files
with
384 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
) | ||
} |
Oops, something went wrong.