This commit is contained in:
Lukasz 2026-03-24 19:50:12 +01:00 committed by GitHub
commit b21a2e0596
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 296 additions and 78 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,59 @@ 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'],
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc'); ['java=17.0.13-albba', '17.0.13', 'dragonwell'],
expect(actual).toBe(expected); ['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', 'semeru'],
['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'
);
expect(actual?.version).toBe(expectedVersion);
expect(actual?.distribution).toBe(expectedDist);
}
);
it('should warn and return undefined distribution for unknown identifier', () => {
const warnSpy = jest.spyOn(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 +159,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

52
dist/cleanup/index.js vendored
View File

@ -77227,8 +77227,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);
} }
@ -77238,14 +77239,23 @@ 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;
@ -77259,13 +77269,41 @@ 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: 'semeru',
albba: 'dragonwell',
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;

106
dist/setup/index.js vendored
View File

@ -114983,9 +114983,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);
@ -115001,26 +114999,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');
@ -115371,8 +115391,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);
} }
@ -115382,14 +115403,23 @@ 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;
@ -115403,13 +115433,41 @@ 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: 'semeru',
albba: 'dragonwell',
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;

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,65 @@ 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,27 @@ 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 +182,48 @@ 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: 'semeru',
albba: 'dragonwell',
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`