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
This commit is contained in:
mahabaleshwars 2024-03-14 19:42:58 +05:30 committed by GitHub
parent 5896cecc08
commit 99b8673ff6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 14 deletions

11
dist/cleanup/index.js vendored
View File

@ -88355,15 +88355,16 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) { function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e; var _a, _b, _c, _d, _e;
let javaVersionRegExp; let javaVersionRegExp;
if (versionFile == '.tool-versions') { function getFileName(versionFile) {
return path_1.default.basename(versionFile);
}
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp = javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; /^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
} }
else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
else { else {
throw new Error('Invalid version file'); javaVersionRegExp = /(?<version>(?<=(^|\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) 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 ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version

11
dist/setup/index.js vendored
View File

@ -125729,15 +125729,16 @@ exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) { function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e; var _a, _b, _c, _d, _e;
let javaVersionRegExp; let javaVersionRegExp;
if (versionFile == '.tool-versions') { function getFileName(versionFile) {
return path_1.default.basename(versionFile);
}
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp = javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; /^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
} }
else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
else { else {
throw new Error('Invalid version file'); javaVersionRegExp = /(?<version>(?<=(^|\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) 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 ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version

View File

@ -119,13 +119,17 @@ export function getVersionFromFileContent(
versionFile: string versionFile: string
): string | null { ): string | null {
let javaVersionRegExp: RegExp; let javaVersionRegExp: RegExp;
if (versionFile == '.tool-versions') {
function getFileName(versionFile: string) {
return path.basename(versionFile);
}
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp = javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m; /^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
} else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} else { } else {
throw new Error('Invalid version file'); javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} }
const fileContent = content.match(javaVersionRegExp)?.groups?.version const fileContent = content.match(javaVersionRegExp)?.groups?.version