test: fix java skipping (#15232)

This commit is contained in:
Michael Kriese 2022-04-21 16:59:49 +02:00 committed by GitHub
parent 8267e77a64
commit d9bbc18155
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,16 +10,11 @@ const gradleJavaVersionSupport = {
const skipJava = process.env.SKIP_JAVA_TESTS === 'true'; const skipJava = process.env.SKIP_JAVA_TESTS === 'true';
const enforceJava = process.env[failIfNoJavaEnv] === 'true' && !skipJava; const enforceJava = process.env[failIfNoJavaEnv] === 'true' && !skipJava;
function parseJavaVersion( function parseJavaVersion(javaVersionOutput: string | undefined): number {
javaVersionOutput: string | undefined
): number | null {
if (!javaVersionOutput) {
return null;
}
const versionMatch = /version "(?:1\.)?(\d+)[\d._-]*"/.exec( const versionMatch = /version "(?:1\.)?(\d+)[\d._-]*"/.exec(
javaVersionOutput javaVersionOutput ?? ''
); );
if (versionMatch !== null && versionMatch.length === 2) { if (versionMatch?.length === 2) {
return parseInt(versionMatch[1], 10); return parseInt(versionMatch[1], 10);
} }
if (enforceJava) { if (enforceJava) {
@ -30,10 +25,10 @@ ${javaVersionOutput}`);
return 0; return 0;
} }
let cachedJavaVersion: number | null | undefined = undefined; let cachedJavaVersion: number | null = null;
function determineJavaVersion(): number | null { function determineJavaVersion(): number {
if (cachedJavaVersion === undefined) { if (cachedJavaVersion === null) {
let javaVersionCommand: SpawnSyncReturns<string> | undefined; let javaVersionCommand: SpawnSyncReturns<string> | undefined;
let error: Error | undefined; let error: Error | undefined;
try { try {
@ -67,9 +62,6 @@ class WithGradle {
constructor(gradleVersion: keyof typeof gradleJavaVersionSupport) { constructor(gradleVersion: keyof typeof gradleJavaVersionSupport) {
const javaVersion = determineJavaVersion(); const javaVersion = determineJavaVersion();
if (!javaVersion) {
throw Error(`Unknown java version!`);
}
if (gradleJavaVersionSupport[gradleVersion] === undefined) { if (gradleJavaVersionSupport[gradleVersion] === undefined) {
throw Error(`Unknown gradle version '${gradleVersion}'!`); throw Error(`Unknown gradle version '${gradleVersion}'!`);
} }