This commit is contained in:
Lukasz 2026-01-24 11:53:07 +01:00 committed by GitHub
commit e475f1a1e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 265 additions and 84 deletions

View File

@ -2,7 +2,7 @@
7.0.352-zulu, 7.0.352 7.0.352-zulu, 7.0.352
8.0.282-trava, 8.0.282 8.0.282-trava, 8.0.282
8.0.432-albba, 8.0.432 8.0.432-albba, 8.0.432
8.0.432-amzn, 8.0.432 8.0.432-amzn, 8
8.0.432-kona, 8.0.432 8.0.432-kona, 8.0.432
8.0.432-librca, 8.0.432 8.0.432-librca, 8.0.432
8.0.432-sem, 8.0.432 8.0.432-sem, 8.0.432
@ -10,7 +10,7 @@
8.0.432-zulu, 8.0.432 8.0.432-zulu, 8.0.432
8.0.432.fx-librca, 8.0.432 8.0.432.fx-librca, 8.0.432
8.0.432.fx-zulu, 8.0.432 8.0.432.fx-zulu, 8.0.432
8.0.442-amzn, 8.0.442 8.0.442-amzn, 8
8.0.442-librca, 8.0.442 8.0.442-librca, 8.0.442
8.0.442-tem, 8.0.442 8.0.442-tem, 8.0.442
8.0.442-zulu, 8.0.442 8.0.442-zulu, 8.0.442
@ -19,7 +19,7 @@
11.0.14.1-jbr, 11.0.14 11.0.14.1-jbr, 11.0.14
11.0.15-trava, 11.0.15 11.0.15-trava, 11.0.15
11.0.25-albba, 11.0.25 11.0.25-albba, 11.0.25
11.0.25-amzn, 11.0.25 11.0.25-amzn, 11
11.0.25-kona, 11.0.25 11.0.25-kona, 11.0.25
11.0.25-librca, 11.0.25 11.0.25-librca, 11.0.25
11.0.25-ms, 11.0.25 11.0.25-ms, 11.0.25
@ -29,7 +29,7 @@
11.0.25-zulu, 11.0.25 11.0.25-zulu, 11.0.25
11.0.25.fx-librca, 11.0.25 11.0.25.fx-librca, 11.0.25
11.0.25.fx-zulu, 11.0.25 11.0.25.fx-zulu, 11.0.25
11.0.26-amzn, 11.0.26 11.0.26-amzn, 11
11.0.26-librca, 11.0.26 11.0.26-librca, 11.0.26
11.0.26-ms, 11.0.26 11.0.26-ms, 11.0.26
11.0.26-sapmchn, 11.0.26 11.0.26-sapmchn, 11.0.26
@ -40,7 +40,7 @@
17.0.12-jbr, 17.0.12 17.0.12-jbr, 17.0.12
17.0.12-oracle, 17.0.12 17.0.12-oracle, 17.0.12
17.0.13-albba, 17.0.13 17.0.13-albba, 17.0.13
17.0.13-amzn, 17.0.13 17.0.13-amzn, 17
17.0.13-kona, 17.0.13 17.0.13-kona, 17.0.13
17.0.13-librca, 17.0.13 17.0.13-librca, 17.0.13
17.0.13-ms, 17.0.13 17.0.13-ms, 17.0.13
@ -52,7 +52,7 @@
17.0.13.crac-zulu, 17.0.13 17.0.13.crac-zulu, 17.0.13
17.0.13.fx-librca, 17.0.13 17.0.13.fx-librca, 17.0.13
17.0.13.fx-zulu, 17.0.13 17.0.13.fx-zulu, 17.0.13
17.0.14-amzn, 17.0.14 17.0.14-amzn, 17
17.0.14-librca, 17.0.14 17.0.14-librca, 17.0.14
17.0.14-ms, 17.0.14 17.0.14-ms, 17.0.14
17.0.14-sapmchn, 17.0.14 17.0.14-sapmchn, 17.0.14
@ -62,7 +62,7 @@
17.0.9-graalce, 17.0.9 17.0.9-graalce, 17.0.9
21.0.2-graalce, 21.0.2 21.0.2-graalce, 21.0.2
21.0.2-open, 21.0.2 21.0.2-open, 21.0.2
21.0.5-amzn, 21.0.5 21.0.5-amzn, 21
21.0.5-graal, 21.0.5 21.0.5-graal, 21.0.5
21.0.5-jbr, 21.0.5 21.0.5-jbr, 21.0.5
21.0.5-kona, 21.0.5 21.0.5-kona, 21.0.5
@ -77,7 +77,7 @@
21.0.5.crac-zulu, 21.0.5 21.0.5.crac-zulu, 21.0.5
21.0.5.fx-librca, 21.0.5 21.0.5.fx-librca, 21.0.5
21.0.5.fx-zulu, 21.0.5 21.0.5.fx-zulu, 21.0.5
21.0.6-amzn, 21.0.6 21.0.6-amzn, 21
21.0.6-graal, 21.0.6 21.0.6-graal, 21.0.6
21.0.6-librca, 21.0.6 21.0.6-librca, 21.0.6
21.0.6-ms, 21.0.6 21.0.6-ms, 21.0.6
@ -94,7 +94,7 @@
22.3.5.r17-mandrel, 22.3.5 22.3.5.r17-mandrel, 22.3.5
22.3.5.r17-nik, 22.3.5 22.3.5.r17-nik, 22.3.5
23-open, 23 23-open, 23
23.0.1-amzn, 23.0.1 23.0.1-amzn, 23
23.0.1-graal, 23.0.1 23.0.1-graal, 23.0.1
23.0.1-graalce, 23.0.1 23.0.1-graalce, 23.0.1
23.0.1-librca, 23.0.1 23.0.1-librca, 23.0.1
@ -106,7 +106,7 @@
23.0.1.crac-zulu, 23.0.1 23.0.1.crac-zulu, 23.0.1
23.0.1.fx-librca, 23.0.1 23.0.1.fx-librca, 23.0.1
23.0.1.fx-zulu, 23.0.1 23.0.1.fx-zulu, 23.0.1
23.0.2-amzn, 23.0.2 23.0.2-amzn, 23
23.0.2-graal, 23.0.2 23.0.2-graal, 23.0.2
23.0.2-graalce, 23.0.2 23.0.2-graalce, 23.0.2
23.0.2-librca, 23.0.2 23.0.2-librca, 23.0.2

1 6.0.119-zulu 6.0.119
2 7.0.352-zulu 7.0.352
3 8.0.282-trava 8.0.282
4 8.0.432-albba 8.0.432
5 8.0.432-amzn 8.0.432 8
6 8.0.432-kona 8.0.432
7 8.0.432-librca 8.0.432
8 8.0.432-sem 8.0.432
10 8.0.432-zulu 8.0.432
11 8.0.432.fx-librca 8.0.432
12 8.0.432.fx-zulu 8.0.432
13 8.0.442-amzn 8.0.442 8
14 8.0.442-librca 8.0.442
15 8.0.442-tem 8.0.442
16 8.0.442-zulu 8.0.442
19 11.0.14.1-jbr 11.0.14
20 11.0.15-trava 11.0.15
21 11.0.25-albba 11.0.25
22 11.0.25-amzn 11.0.25 11
23 11.0.25-kona 11.0.25
24 11.0.25-librca 11.0.25
25 11.0.25-ms 11.0.25
29 11.0.25-zulu 11.0.25
30 11.0.25.fx-librca 11.0.25
31 11.0.25.fx-zulu 11.0.25
32 11.0.26-amzn 11.0.26 11
33 11.0.26-librca 11.0.26
34 11.0.26-ms 11.0.26
35 11.0.26-sapmchn 11.0.26
40 17.0.12-jbr 17.0.12
41 17.0.12-oracle 17.0.12
42 17.0.13-albba 17.0.13
43 17.0.13-amzn 17.0.13 17
44 17.0.13-kona 17.0.13
45 17.0.13-librca 17.0.13
46 17.0.13-ms 17.0.13
52 17.0.13.crac-zulu 17.0.13
53 17.0.13.fx-librca 17.0.13
54 17.0.13.fx-zulu 17.0.13
55 17.0.14-amzn 17.0.14 17
56 17.0.14-librca 17.0.14
57 17.0.14-ms 17.0.14
58 17.0.14-sapmchn 17.0.14
62 17.0.9-graalce 17.0.9
63 21.0.2-graalce 21.0.2
64 21.0.2-open 21.0.2
65 21.0.5-amzn 21.0.5 21
66 21.0.5-graal 21.0.5
67 21.0.5-jbr 21.0.5
68 21.0.5-kona 21.0.5
77 21.0.5.crac-zulu 21.0.5
78 21.0.5.fx-librca 21.0.5
79 21.0.5.fx-zulu 21.0.5
80 21.0.6-amzn 21.0.6 21
81 21.0.6-graal 21.0.6
82 21.0.6-librca 21.0.6
83 21.0.6-ms 21.0.6
94 22.3.5.r17-mandrel 22.3.5
95 22.3.5.r17-nik 22.3.5
96 23-open 23
97 23.0.1-amzn 23.0.1 23
98 23.0.1-graal 23.0.1
99 23.0.1-graalce 23.0.1
100 23.0.1-librca 23.0.1
106 23.0.1.crac-zulu 23.0.1
107 23.0.1.fx-librca 23.0.1
108 23.0.1.fx-zulu 23.0.1
109 23.0.2-amzn 23.0.2 23
110 23.0.2-graal 23.0.2
111 23.0.2-graalce 23.0.2
112 23.0.2-librca 23.0.2

View File

@ -88,15 +88,41 @@ describe('convertVersionToSemver', () => {
describe('getVersionFromFileContent', () => { describe('getVersionFromFileContent', () => {
describe('.sdkmanrc', () => { describe('.sdkmanrc', () => {
it.each([ it.each([
['java=11.0.20.1-tem', '11.0.20'], ['java=11.0.20.1-tem', '11.0.20', 'temurin'],
['java = 11.0.20.1-tem', '11.0.20'], ['java = 11.0.20.1-tem', '11.0.20', 'temurin'],
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'], ['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20', 'temurin'],
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match ['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match ['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc ['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20', 'temurin'], // first one is 'commented' in .sdkmanrc
])('parsing %s should return %s', (content: string, expected: string) => { ['java=21.0.5-zulu', '21.0.5', 'zulu'],
['java=17.0.13-amzn', '17', 'corretto'],
['java=21.0.5-graal', '21.0.5', 'graalvm'],
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
['java=11.0.25-librca', '11.0.25', 'liberica'],
['java=11.0.25-ms', '11.0.25', 'microsoft'],
['java=21.0.5-oracle', '21.0.5', 'oracle'],
['java=11.0.25-sapmchn', '11.0.25', 'sapmachine'],
['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
['java=11.0.25-sem', '11.0.25', 'temurin'],
['java=17.0.13-dragonwell', '17.0.13', 'dragonwell']
])('parsing %s should return version %s and distribution %s', (content: string, expectedVersion: string, expectedDist: string) => {
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc'); const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
expect(actual).toBe(expected); expect(actual?.version).toBe(expectedVersion);
expect(actual?.distribution).toBe(expectedDist);
});
it('should warn and return undefined distribution for unknown identifier', () => {
const warnSpy = jest.spyOn(require('@actions/core'), 'warning');
const actual = getVersionFromFileContent('java=21.0.5-unknown', 'temurin', '.sdkmanrc');
expect(actual?.version).toBe('21.0.5');
expect(actual?.distribution).toBeUndefined();
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Unknown SDKMAN distribution identifier'));
});
it('should return version without distribution when no suffix provided', () => {
const actual = getVersionFromFileContent('java=11.0.20', 'temurin', '.sdkmanrc');
expect(actual?.version).toBe('11.0.20');
expect(actual?.distribution).toBeUndefined();
}); });
describe('known versions', () => { describe('known versions', () => {
@ -115,7 +141,7 @@ describe('getVersionFromFileContent', () => {
'openjdk', 'openjdk',
'.sdkmanrc' '.sdkmanrc'
); );
expect(actual).toBe(expected); expect(actual?.version).toBe(expected);
} }
); );
}); });

View File

@ -8,8 +8,8 @@ inputs:
java-version-file: java-version-file:
description: 'The path to the `.java-version` file. See examples of supported syntax in README file' description: 'The path to the `.java-version` file. See examples of supported syntax in README file'
distribution: distribution:
description: 'Java distribution. See the list of supported distributions in README file' description: 'Java distribution. See the list of supported distributions in README file. When using .sdkmanrc with a distribution suffix (e.g., java=21.0.5-tem), this input is optional.'
required: true required: false
java-package: java-package:
description: 'The package type (jdk, jre, jdk+fx, jre+fx)' description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
required: false required: false

50
dist/cleanup/index.js vendored
View File

@ -49755,8 +49755,9 @@ function isCacheFeatureAvailable() {
} }
exports.isCacheFeatureAvailable = isCacheFeatureAvailable; exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) { function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e; var _a, _b, _c;
let javaVersionRegExp; let javaVersionRegExp;
let extractedDistribution;
function getFileName(versionFile) { function getFileName(versionFile) {
return path_1.default.basename(versionFile); return path_1.default.basename(versionFile);
} }
@ -49766,14 +49767,22 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im; /^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} }
else if (versionFileName == '.sdkmanrc') { else if (versionFileName == '.sdkmanrc') {
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m; // Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
} }
else { else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/; javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} }
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) const match = content.match(javaVersionRegExp);
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
? match.groups.version
: ''; : '';
// Extract distribution from .sdkmanrc file
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
const sdkmanDist = match.groups.distribution;
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
}
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`); core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
if (!capturedVersion) { if (!capturedVersion) {
return null; return null;
@ -49787,13 +49796,40 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
if (!version) { if (!version) {
return null; return null;
} }
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) { // Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version; // (either explicitly provided or extracted from the version file) is in the list.
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
const coerceVersion = (_c = semver.coerce(version)) !== null && _c !== void 0 ? _c : version;
version = semver.major(coerceVersion).toString(); version = semver.major(coerceVersion).toString();
} }
return version.toString(); return {
version: version.toString(),
distribution: extractedDistribution
};
} }
exports.getVersionFromFileContent = getVersionFromFileContent; exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
const distributionMap = {
'tem': 'temurin',
'sem': 'temurin',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
}
return mapped;
}
// By convention, action expects version 8 in the format `8.*` instead of `1.8` // By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) { function avoidOldNotation(content) {
return content.startsWith('1.') ? content.substring(2) : content; return content.startsWith('1.') ? content.substring(2) : content;

104
dist/setup/index.js vendored
View File

@ -87511,9 +87511,7 @@ function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION); const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
required: true
});
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE); const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
@ -87529,26 +87527,48 @@ function run() {
if (!versions.length && !versionFile) { if (!versions.length && !versionFile) {
throw new Error('java-version or java-version-file input expected'); throw new Error('java-version or java-version-file input expected');
} }
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
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, versionFile); const versionInfo = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
core.debug(`Parsed version from file '${version}'`); core.debug(`Parsed version from file '${versionInfo === null || versionInfo === void 0 ? void 0 : versionInfo.version}'`);
if (!version) { if (!versionInfo) {
throw new Error(`No supported version was found in file ${versionFile}`); throw new Error(`No supported version was found in file ${versionFile}`);
} }
yield installVersion(version, installerInputsOptions); // Use distribution from file if available, otherwise use the input
if (versionInfo.distribution) {
core.info(`Using distribution '${versionInfo.distribution}' from ${versionFile}`);
distributionName = versionInfo.distribution;
}
else if (!distributionName) {
throw new Error('distribution input is required when not specified in the version file');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
yield installVersion(versionInfo.version, installerInputsOptions);
} }
for (const [index, version] of versions.entries()) { else {
yield installVersion(version, installerInputsOptions, index); // When using java-version input, distribution is still required
if (!distributionName) {
throw new Error('distribution input is required');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
for (const [index, version] of versions.entries()) {
yield installVersion(version, installerInputsOptions, index);
}
} }
core.endGroup(); core.endGroup();
const matchersPath = path.join(__dirname, '..', '..', '.github'); const matchersPath = path.join(__dirname, '..', '..', '.github');
@ -87899,8 +87919,9 @@ function isCacheFeatureAvailable() {
} }
exports.isCacheFeatureAvailable = isCacheFeatureAvailable; exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) { function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e; var _a, _b, _c;
let javaVersionRegExp; let javaVersionRegExp;
let extractedDistribution;
function getFileName(versionFile) { function getFileName(versionFile) {
return path_1.default.basename(versionFile); return path_1.default.basename(versionFile);
} }
@ -87910,14 +87931,22 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im; /^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} }
else if (versionFileName == '.sdkmanrc') { else if (versionFileName == '.sdkmanrc') {
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m; // Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
} }
else { else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/; javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} }
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version) const match = content.match(javaVersionRegExp);
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
? match.groups.version
: ''; : '';
// Extract distribution from .sdkmanrc file
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
const sdkmanDist = match.groups.distribution;
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
}
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`); core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
if (!capturedVersion) { if (!capturedVersion) {
return null; return null;
@ -87931,13 +87960,40 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
if (!version) { if (!version) {
return null; return null;
} }
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) { // Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version; // (either explicitly provided or extracted from the version file) is in the list.
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
const coerceVersion = (_c = semver.coerce(version)) !== null && _c !== void 0 ? _c : version;
version = semver.major(coerceVersion).toString(); version = semver.major(coerceVersion).toString();
} }
return version.toString(); return {
version: version.toString(),
distribution: extractedDistribution
};
} }
exports.getVersionFromFileContent = getVersionFromFileContent; exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
const distributionMap = {
'tem': 'temurin',
'sem': 'temurin',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
}
return mapped;
}
// By convention, action expects version 8 in the format `8.*` instead of `1.8` // By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) { function avoidOldNotation(content) {
return content.startsWith('1.') ? content.substring(2) : content; return content.startsWith('1.') ? content.substring(2) : content;

7
package-lock.json generated
View File

@ -496,7 +496,6 @@
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz",
"integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==", "integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@ampproject/remapping": "^2.2.0", "@ampproject/remapping": "^2.2.0",
"@babel/code-frame": "^7.22.13", "@babel/code-frame": "^7.22.13",
@ -1788,7 +1787,6 @@
"integrity": "sha512-B7RIQiTsCBBmY+yW4+ILd6mF5h1FUwJsVvpqkrgpszYifetQ2Ke+Z4u6aZh0CblkUGIdR59iYVyXqqZGkZ3aBw==", "integrity": "sha512-B7RIQiTsCBBmY+yW4+ILd6mF5h1FUwJsVvpqkrgpszYifetQ2Ke+Z4u6aZh0CblkUGIdR59iYVyXqqZGkZ3aBw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"peer": true,
"dependencies": { "dependencies": {
"@typescript-eslint/scope-manager": "8.43.0", "@typescript-eslint/scope-manager": "8.43.0",
"@typescript-eslint/types": "8.43.0", "@typescript-eslint/types": "8.43.0",
@ -2037,7 +2035,6 @@
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
"dev": true, "dev": true,
"peer": true,
"bin": { "bin": {
"acorn": "bin/acorn" "acorn": "bin/acorn"
}, },
@ -2317,7 +2314,6 @@
"url": "https://github.com/sponsors/ai" "url": "https://github.com/sponsors/ai"
} }
], ],
"peer": true,
"dependencies": { "dependencies": {
"caniuse-lite": "^1.0.30001541", "caniuse-lite": "^1.0.30001541",
"electron-to-chromium": "^1.4.535", "electron-to-chromium": "^1.4.535",
@ -2687,7 +2683,6 @@
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz",
"integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1", "@eslint-community/regexpp": "^4.6.1",
@ -3634,7 +3629,6 @@
"resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz",
"integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@jest/core": "^29.7.0", "@jest/core": "^29.7.0",
"@jest/types": "^29.6.3", "@jest/types": "^29.6.3",
@ -5299,7 +5293,6 @@
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
"dev": true, "dev": true,
"peer": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
"tsserver": "bin/tsserver" "tsserver": "bin/tsserver"

View File

@ -16,9 +16,7 @@ import {JavaInstallerOptions} from './distributions/base-models';
async function run() { async function run() {
try { try {
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION); const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
required: true
});
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE); const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
@ -40,39 +38,63 @@ async function run() {
throw new Error('java-version or java-version-file input expected'); throw new Error('java-version or java-version-file input expected');
} }
const installerInputsOptions: installerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
if (!versions.length) { if (!versions.length) {
core.debug( core.debug(
'java-version input is empty, looking for java-version-file input' 'java-version input is empty, looking for java-version-file input'
); );
const content = fs.readFileSync(versionFile).toString().trim(); const content = fs.readFileSync(versionFile).toString().trim();
const version = getVersionFromFileContent( const versionInfo = getVersionFromFileContent(
content, content,
distributionName, distributionName,
versionFile versionFile
); );
core.debug(`Parsed version from file '${version}'`); core.debug(`Parsed version from file '${versionInfo?.version}'`);
if (!version) { if (!versionInfo) {
throw new Error( throw new Error(
`No supported version was found in file ${versionFile}` `No supported version was found in file ${versionFile}`
); );
} }
await installVersion(version, installerInputsOptions); // Use distribution from file if available, otherwise use the input
} if (versionInfo.distribution) {
core.info(`Using distribution '${versionInfo.distribution}' from ${versionFile}`);
distributionName = versionInfo.distribution;
} else if (!distributionName) {
throw new Error(
'distribution input is required when not specified in the version file'
);
}
for (const [index, version] of versions.entries()) { const installerInputsOptions: installerInputsOptions = {
await installVersion(version, installerInputsOptions, index); architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
await installVersion(versionInfo.version, installerInputsOptions);
} else {
// When using java-version input, distribution is still required
if (!distributionName) {
throw new Error('distribution input is required');
}
const installerInputsOptions: installerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
};
for (const [index, version] of versions.entries()) {
await installVersion(version, installerInputsOptions, index);
}
} }
core.endGroup(); core.endGroup();
const matchersPath = path.join(__dirname, '..', '..', '.github'); const matchersPath = path.join(__dirname, '..', '..', '.github');

View File

@ -119,12 +119,18 @@ export function isCacheFeatureAvailable(): boolean {
return false; return false;
} }
export interface VersionInfo {
version: string;
distribution?: string;
}
export function getVersionFromFileContent( export function getVersionFromFileContent(
content: string, content: string,
distributionName: string, distributionName: string,
versionFile: string versionFile: string
): string | null { ): VersionInfo | null {
let javaVersionRegExp: RegExp; let javaVersionRegExp: RegExp;
let extractedDistribution: string | undefined;
function getFileName(versionFile: string) { function getFileName(versionFile: string) {
return path.basename(versionFile); return path.basename(versionFile);
@ -135,15 +141,26 @@ export function getVersionFromFileContent(
javaVersionRegExp = javaVersionRegExp =
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im; /^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} else if (versionFileName == '.sdkmanrc') { } else if (versionFileName == '.sdkmanrc') {
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m; // Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
} else { } else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/; javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} }
const capturedVersion = content.match(javaVersionRegExp)?.groups?.version const match = content.match(javaVersionRegExp);
? (content.match(javaVersionRegExp)?.groups?.version as string) const capturedVersion = match?.groups?.version
? (match.groups.version as string)
: ''; : '';
// Extract distribution from .sdkmanrc file
if (versionFileName == '.sdkmanrc' && match?.groups?.distribution) {
const sdkmanDist = match.groups.distribution;
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
core.debug(
`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`
);
}
core.debug( core.debug(
`Parsed version '${capturedVersion}' from file '${versionFileName}'` `Parsed version '${capturedVersion}' from file '${versionFileName}'`
); );
@ -164,12 +181,43 @@ export function getVersionFromFileContent(
return null; return null;
} }
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) { // Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
// (either explicitly provided or extracted from the version file) is in the list.
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
const coerceVersion = semver.coerce(version) ?? version; const coerceVersion = semver.coerce(version) ?? version;
version = semver.major(coerceVersion).toString(); version = semver.major(coerceVersion).toString();
} }
return version.toString(); return {
version: version.toString(),
distribution: extractedDistribution
};
}
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist: string): string | undefined {
const distributionMap: Record<string, string> = {
'tem': 'temurin',
'sem': 'temurin',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {
core.warning(
`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`
);
}
return mapped;
} }
// By convention, action expects version 8 in the format `8.*` instead of `1.8` // By convention, action expects version 8 in the format `8.*` instead of `1.8`