mirror of
https://github.com/actions/setup-java.git
synced 2025-04-19 17:36:45 +00:00
added support for tool version file
This commit is contained in:
parent
c3eb4ca47a
commit
7abdf1c01e
4 changed files with 31 additions and 8 deletions
10
dist/cleanup/index.js
vendored
10
dist/cleanup/index.js
vendored
|
@ -87887,9 +87887,15 @@ function isCacheFeatureAvailable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFileContent(content, distributionName) {
|
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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
|
||||||
: '';
|
: '';
|
||||||
|
|
12
dist/setup/index.js
vendored
12
dist/setup/index.js
vendored
|
@ -124907,7 +124907,7 @@ function run() {
|
||||||
if (!versions.length) {
|
if (!versions.length) {
|
||||||
core.debug('java-version input is empty, looking for java-version-file input');
|
core.debug('java-version input is empty, looking for java-version-file input');
|
||||||
const content = fs_1.default.readFileSync(versionFile).toString().trim();
|
const content = fs_1.default.readFileSync(versionFile).toString().trim();
|
||||||
const version = (0, util_1.getVersionFromFileContent)(content, distributionName);
|
const version = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||||
|
@ -125261,9 +125261,15 @@ function isCacheFeatureAvailable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFileContent(content, distributionName) {
|
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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
|
||||||
: '';
|
: '';
|
||||||
|
|
|
@ -55,7 +55,11 @@ async function run() {
|
||||||
);
|
);
|
||||||
const content = fs.readFileSync(versionFile).toString().trim();
|
const content = fs.readFileSync(versionFile).toString().trim();
|
||||||
|
|
||||||
const version = getVersionFromFileContent(content, distributionName);
|
const version = getVersionFromFileContent(
|
||||||
|
content,
|
||||||
|
distributionName,
|
||||||
|
versionFile
|
||||||
|
);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
|
|
11
src/util.ts
11
src/util.ts
|
@ -115,9 +115,16 @@ export function isCacheFeatureAvailable(): boolean {
|
||||||
|
|
||||||
export function getVersionFromFileContent(
|
export function getVersionFromFileContent(
|
||||||
content: string,
|
content: string,
|
||||||
distributionName: string
|
distributionName: string,
|
||||||
|
versionFile: string
|
||||||
): string | null {
|
): string | null {
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp: RegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp = /^java\s+(?:\S+-)?v?(?<version>[^\s]+)$/m;
|
||||||
|
} else {
|
||||||
|
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||||
|
}
|
||||||
|
|
||||||
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
||||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||||
: '';
|
: '';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue