1
0
Fork 0
mirror of https://github.com/actions/setup-java.git synced 2024-08-16 10:19:51 +02:00

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) {
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?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
}
else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
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)
? (_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) {
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?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
}
else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
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)
? (_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
): 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?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
} else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} else {
throw new Error('Invalid version file');
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
const fileContent = content.match(javaVersionRegExp)?.groups?.version