Skip to content

Commit e66ed9e

Browse files
author
skad
committed
Fixing version check for Openjdk
- using multiline regex for parsing verion number - validate if java or openjdk
1 parent 038b5a6 commit e66ed9e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

source/PlayServicesResolver/src/JavaUtilities.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace GooglePlayServices {
1919
using System.Collections.Generic;
2020
using System.Globalization;
2121
using System.IO;
22+
using System.Text.RegularExpressions;
2223
using UnityEditor;
2324

2425
using Google;
@@ -185,19 +186,12 @@ internal static void CheckJdkForApiLevel() {
185186
float majorMinorVersion = 0;
186187
// The version string is can be reported via stderr or stdout so scrape the
187188
// concatenated message string.
188-
foreach (var line in CommandLine.SplitLines(result.message)) {
189-
if (line.StartsWith("java version ")) {
190-
var tokens = line.Split();
191-
var versionString = tokens[tokens.Length - 1].Trim(new [] { '"' });
192-
var components = versionString.Split(new [] { '.' });
193-
if (components.Length < 2) {
194-
continue;
195-
}
196-
if (!float.TryParse(components[0] + "." + components[1], NumberStyles.Any,
197-
CultureInfo.InvariantCulture, out majorMinorVersion)) {
198-
continue;
199-
}
200-
}
189+
string pattern = "^(?<model>java||openjdk) version \"(?<major>\\d).(?<minor>\\d).(?<patch>\\d).*$";
190+
191+
Match match = Regex.Match(result.message,pattern,RegexOptions.Multiline);
192+
if (match.Success) {
193+
float.TryParse(match.Groups["major"].Value + "." + match.Groups["minor"].Value, NumberStyles.Any,
194+
CultureInfo.InvariantCulture, out majorMinorVersion);
201195
}
202196
if (majorMinorVersion == 0) {
203197
LogJdkVersionFailedWarning(javaPath, result.message);

0 commit comments

Comments
 (0)