Skip to content

Commit

Permalink
fix(cli): handle unrecognized java --version (#6577)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored May 8, 2023
1 parent 2661700 commit 56b0037
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions cli/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,26 +536,30 @@ export function resolvePlatform(
}

export async function checkJDKMajorVersion(): Promise<number> {
const string = await runCommand('java', ['--version']);
const versionRegex = RegExp(/([0-9]+)\.?([0-9]*)\.?([0-9]*)/);
const versionMatch = versionRegex.exec(string);

if (versionMatch === null) {
return -1;
}
try {
const string = await runCommand('java', ['--version']);
const versionRegex = RegExp(/([0-9]+)\.?([0-9]*)\.?([0-9]*)/);
const versionMatch = versionRegex.exec(string);

const firstVersionNumber = parseInt(versionMatch[1]);
const secondVersionNumber = parseInt(versionMatch[2]);
if (versionMatch === null) {
return -1;
}

if (typeof firstVersionNumber === 'number' && firstVersionNumber != 1) {
return firstVersionNumber;
} else if (
typeof secondVersionNumber === 'number' &&
firstVersionNumber == 1 &&
secondVersionNumber < 9
) {
return secondVersionNumber;
} else {
const firstVersionNumber = parseInt(versionMatch[1]);
const secondVersionNumber = parseInt(versionMatch[2]);

if (typeof firstVersionNumber === 'number' && firstVersionNumber != 1) {
return firstVersionNumber;
} else if (
typeof secondVersionNumber === 'number' &&
firstVersionNumber == 1 &&
secondVersionNumber < 9
) {
return secondVersionNumber;
} else {
return -1;
}
} catch (e) {
return -1;
}
}

0 comments on commit 56b0037

Please sign in to comment.