diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index fc0b1d19..c90128bb 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 55a09649..13023489 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 e02cea6d..034fc83d 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