From 99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:42:58 +0530 Subject: [PATCH] Patch for java version file (#610) * patch to extract file from other location * patch to extract filename from other directories * removed code failing checks * changed the validation for .java-version type --- dist/cleanup/index.js | 11 ++++++----- dist/setup/index.js | 11 ++++++----- src/util.ts | 12 ++++++++---- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index fc0b1d1..c90128b 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -88355,15 +88355,16 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; let javaVersionRegExp; - if (versionFile == '.tool-versions') { + function getFileName(versionFile) { + return path_1.default.basename(versionFile); + } + const versionFileName = getFileName(versionFile); + if (versionFileName == '.tool-versions') { javaVersionRegExp = /^(java\s+)(?:\S*-)?v?(?(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; } - else if (versionFile == '.java-version') { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - } else { - throw new Error('Invalid version file'); + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version diff --git a/dist/setup/index.js b/dist/setup/index.js index 55a0964..1302348 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -125729,15 +125729,16 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName, versionFile) { var _a, _b, _c, _d, _e; let javaVersionRegExp; - if (versionFile == '.tool-versions') { + function getFileName(versionFile) { + return path_1.default.basename(versionFile); + } + const versionFileName = getFileName(versionFile); + if (versionFileName == '.tool-versions') { javaVersionRegExp = /^(java\s+)(?:\S*-)?v?(?(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; } - else if (versionFile == '.java-version') { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; - } else { - throw new Error('Invalid version file'); + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version diff --git a/src/util.ts b/src/util.ts index e02cea6..034fc83 100644 --- a/src/util.ts +++ b/src/util.ts @@ -119,13 +119,17 @@ export function getVersionFromFileContent( versionFile: string ): string | null { let javaVersionRegExp: RegExp; - if (versionFile == '.tool-versions') { + + function getFileName(versionFile: string) { + return path.basename(versionFile); + } + + const versionFileName = getFileName(versionFile); + if (versionFileName == '.tool-versions') { javaVersionRegExp = /^(java\s+)(?:\S*-)?v?(?(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; - } else if (versionFile == '.java-version') { - javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } else { - throw new Error('Invalid version file'); + javaVersionRegExp = /(?(?<=(^|\s|-))(\d+\S*))(\s|$)/; } const fileContent = content.match(javaVersionRegExp)?.groups?.version