Skip to content

Commit

Permalink
Merge pull request #153 from SlowBrainDude/bugfix-ea-jdk-version-parsing
Browse files Browse the repository at this point in the history
Fix JDK version parsing for EA builds
  • Loading branch information
tgodzik committed Sep 22, 2023
2 parents ebe09e1 + 903c1eb commit ef4ea5a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bloop-rifle/src/bloop/rifle/BloopVersion.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package bloop.rifle
case class BloopVersion(raw: String) {
def isOlderThan(other: BloopVersion) = {
val bloopVRegex = "([0-9]+).([0-9]+)[.]([0-9]+)[-]?([0-9]+)?".r
val bloopVRegex = "([0-9]+).([0-9]+)[.]([0-9]+)[-]?[a-z]*[-]?([0-9]+)?".r
// https://regex101.com/r/YOZsOH/1
def unwrapVersionString(v: String) =
List(1, 2, 3, 4).map(bloopVRegex.findAllIn(v).group(_)).map(x =>
if (x != null) x.toInt else 0
Expand Down
3 changes: 2 additions & 1 deletion bloop-rifle/src/bloop/rifle/VersionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object VersionUtil {
def parseBloopAbout(stdoutFromBloopAbout: String): Option[BloopRifle.BloopServerRuntimeInfo] = {

val bloopVersionRegex = "bloop v(.*)\\s".r
val bloopJvmRegex = "Running on Java ... v([0-9._A-Za-z]+) [(](.*)[)]".r
val bloopJvmRegex = "Running on Java ... v([0-9._A-Za-z\\-]+) [(](.*)[)]".r
// https://regex101.com/r/lT624X/1

for {
bloopVersion <- bloopVersionRegex.findFirstMatchIn(stdoutFromBloopAbout).map(_.group(1))
Expand Down
21 changes: 21 additions & 0 deletions bloop-rifle/test/src/bloop/rifle/ParsingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ParsingTests extends munit.FunSuite {
expect(!("1.4.9".v isOlderThan "1.4.9".v))
expect("1.4.10-2".v isOlderThan "1.4.10-4".v)
expect("1.4.10-2-abc".v isOlderThan "1.4.10-4-def".v)
expect("1.5.6-sc-2".v isOlderThan "1.5.6-sc-4".v)
}

test("jvm release parsing test") {
Expand All @@ -29,13 +30,17 @@ class ParsingTests extends munit.FunSuite {
expect("9".j == Some(9))
expect("14".j == Some(14))
expect("17".j == Some(17))
expect("17.0.9-ea".j == Some(17))
expect("21-ea".j == Some(21))
}

test("parse jvm version") {
expect("""openjdk version "1.8.0_292" """.jv == Some(8))
expect("""openjdk version "9" """.jv == Some(9))
expect("""openjdk version "11.0.11" 2021-04-20 """.jv == Some(11))
expect("""openjdk version "16" 2021-03-16 """.jv == Some(16))
expect("""openjdk version "17.0.9-ea" 2023-10-17 """.jv == Some(17))
expect("""openjdk version "21-ea" 2023-09-19 """.jv == Some(21))
}

val jreBloopOutput =
Expand All @@ -55,6 +60,14 @@ class ParsingTests extends munit.FunSuite {
| -> Supports debugging user code, Java Debug Interface (JDI) is available.
|Maintained by the Scala Center and the community.""".stripMargin

val jdkBloopOutputEA =
"""|bloop v1.5.6-sc-4
|
|Using Scala v2.12.17 and Zinc v1.8.0
|Running on Java JDK v17.0.9-ea (/usr/lib/jvm/java-17-openjdk-amd64)
| -> Supports debugging user code, Java Debug Interface (JDI) is available.
|Maintained by the Scala Center and the community.""".stripMargin

test("parse jre bloop about") {
expect(jreBloopOutput.p == Some(BloopRifle.BloopServerRuntimeInfo(
BloopVersion("1.4.11"),
Expand All @@ -71,4 +84,12 @@ class ParsingTests extends munit.FunSuite {
)))
}

test("parse jdk bloop about (EA JDK)") {
expect(jdkBloopOutputEA.p == Some(BloopRifle.BloopServerRuntimeInfo(
BloopVersion("1.5.6-sc-4"),
17,
"/usr/lib/jvm/java-17-openjdk-amd64"
)))
}

}

0 comments on commit ef4ea5a

Please sign in to comment.