@@ -2,12 +2,12 @@ package com.tschuchort.compiletesting
22
33import okio.Buffer
44import java.io.*
5- import java.lang.IllegalArgumentException
65import java.net.URI
76import java.nio.charset.Charset
87import javax.tools.JavaCompiler
98import javax.tools.JavaFileObject
109import javax.tools.SimpleJavaFileObject
10+ import kotlin.IllegalArgumentException
1111
1212/* *
1313 * A [JavaFileObject] created from a source [File].
@@ -81,12 +81,22 @@ internal fun getJavacVersionString(javacCommand: String): String {
8181}
8282
8383internal fun isJavac9OrLater (javacVersionString : String ): Boolean {
84- val (majorv, minorv, patchv, otherv) = Regex (" ([0-9]*)\\ .([0-9]*)\\ .([0-9]*)(.*)" )
85- .matchEntire(javacVersionString)?.destructured
86- ? : throw IllegalArgumentException (" Could not parse javac version string: '$javacVersionString '" )
84+ try {
85+ val (majorv, minorv, patchv, otherv) = Regex (" ([0-9]*)(?:\\ .([0-9]*))?(?:\\ .([0-9]*))?(.*)" )
86+ .matchEntire(javacVersionString)?.destructured
87+ ? : throw IllegalArgumentException (" Could not match version regex" )
8788
88- return (majorv.toInt() == 1 && minorv.toInt() >= 9 ) // old versioning scheme: 1.8.x
89- || (majorv.toInt() >= 9 ) // new versioning scheme: 10.x.x
89+ check(majorv.isNotBlank()) { " Major version can not be blank" }
90+
91+ if (majorv.toInt() == 1 )
92+ check(minorv.isNotBlank()) { " Minor version can not be blank if major version is 1" }
93+
94+ return (majorv.toInt() == 1 && minorv.toInt() >= 9 ) // old versioning scheme: 1.8.x
95+ || (majorv.toInt() >= 9 ) // new versioning scheme: 10.x.x
96+ }
97+ catch (t: Throwable ) {
98+ throw IllegalArgumentException (" Could not parse javac version string: '$javacVersionString '" , t)
99+ }
90100}
91101
92102/* * Finds the tools.jar given a path to a JDK 8 or earlier */
0 commit comments