Visitar URL original
feat: Add distribution detection support to .sdkmanrc file (#975) · actions/setup-java@0f481fc · GitHub
Skip to content

Commit 0f481fc

Browse files
lukaszgygbrunoborgesCopilot
authored
feat: Add distribution detection support to .sdkmanrc file (#975)
* feat: Add distribution detection support to .sdkmanrc file Extends .sdkmanrc support to automatically detect Java distribution from SDKMAN identifiers (e.g., java=21.0.5-tem maps to temurin distribution). Makes distribution input optional when using .sdkmanrc with distribution suffix. * fix: align SDKMAN sem identifier mapping * fix: support SDKMAN albba identifier * docs: clarify sdkmanrc distribution inference scope Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add Tencent Kona SDKMAN mapping and format sdkmanrc docs as a table - Map SDKMAN 'kona' identifier to the 'kona' distribution (added in #672) - Add a .sdkmanrc test case for the kona suffix - Convert the inline SDKMAN suffix mapping in advanced-usage.md to a table - Rebuild dist bundles Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Bruno Borges <brborges@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Bruno Borges <bruno.borges@gmail.com>
1 parent c4922bf commit 0f481fc

9 files changed

Lines changed: 333 additions & 89 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ For more details, see the full release notes on the [releases page](https://git
2929

3030
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
3131

32-
- `java-version-file`: The path to a file containing java version. Supported file types are `.java-version` and `.tool-versions`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).
32+
- `java-version-file`: The path to a file containing java version. Supported file types are `.java-version`, `.tool-versions`, and `.sdkmanrc`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).
3333

34-
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
34+
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).
3535

3636
- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`.
3737

‎__tests__/data/sdkman-java-versions.csv‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
7.0.352-zulu, 7.0.352
33
8.0.282-trava, 8.0.282
44
8.0.432-albba, 8.0.432
5-
8.0.432-amzn, 8.0.432
5+
8.0.432-amzn, 8
66
8.0.432-kona, 8.0.432
77
8.0.432-librca, 8.0.432
88
8.0.432-sem, 8.0.432
99
8.0.432-tem, 8.0.432
1010
8.0.432-zulu, 8.0.432
1111
8.0.432.fx-librca, 8.0.432
1212
8.0.432.fx-zulu, 8.0.432
13-
8.0.442-amzn, 8.0.442
13+
8.0.442-amzn, 8
1414
8.0.442-librca, 8.0.442
1515
8.0.442-tem, 8.0.442
1616
8.0.442-zulu, 8.0.442
@@ -19,7 +19,7 @@
1919
11.0.14.1-jbr, 11.0.14
2020
11.0.15-trava, 11.0.15
2121
11.0.25-albba, 11.0.25
22-
11.0.25-amzn, 11.0.25
22+
11.0.25-amzn, 11
2323
11.0.25-kona, 11.0.25
2424
11.0.25-librca, 11.0.25
2525
11.0.25-ms, 11.0.25
@@ -29,7 +29,7 @@
2929
11.0.25-zulu, 11.0.25
3030
11.0.25.fx-librca, 11.0.25
3131
11.0.25.fx-zulu, 11.0.25
32-
11.0.26-amzn, 11.0.26
32+
11.0.26-amzn, 11
3333
11.0.26-librca, 11.0.26
3434
11.0.26-ms, 11.0.26
3535
11.0.26-sapmchn, 11.0.26
@@ -40,7 +40,7 @@
4040
17.0.12-jbr, 17.0.12
4141
17.0.12-oracle, 17.0.12
4242
17.0.13-albba, 17.0.13
43-
17.0.13-amzn, 17.0.13
43+
17.0.13-amzn, 17
4444
17.0.13-kona, 17.0.13
4545
17.0.13-librca, 17.0.13
4646
17.0.13-ms, 17.0.13
@@ -52,7 +52,7 @@
5252
17.0.13.crac-zulu, 17.0.13
5353
17.0.13.fx-librca, 17.0.13
5454
17.0.13.fx-zulu, 17.0.13
55-
17.0.14-amzn, 17.0.14
55+
17.0.14-amzn, 17
5656
17.0.14-librca, 17.0.14
5757
17.0.14-ms, 17.0.14
5858
17.0.14-sapmchn, 17.0.14
@@ -62,7 +62,7 @@
6262
17.0.9-graalce, 17.0.9
6363
21.0.2-graalce, 21.0.2
6464
21.0.2-open, 21.0.2
65-
21.0.5-amzn, 21.0.5
65+
21.0.5-amzn, 21
6666
21.0.5-graal, 21.0.5
6767
21.0.5-jbr, 21.0.5
6868
21.0.5-kona, 21.0.5
@@ -77,7 +77,7 @@
7777
21.0.5.crac-zulu, 21.0.5
7878
21.0.5.fx-librca, 21.0.5
7979
21.0.5.fx-zulu, 21.0.5
80-
21.0.6-amzn, 21.0.6
80+
21.0.6-amzn, 21
8181
21.0.6-graal, 21.0.6
8282
21.0.6-librca, 21.0.6
8383
21.0.6-ms, 21.0.6
@@ -94,7 +94,7 @@
9494
22.3.5.r17-mandrel, 22.3.5
9595
22.3.5.r17-nik, 22.3.5
9696
23-open, 23
97-
23.0.1-amzn, 23.0.1
97+
23.0.1-amzn, 23
9898
23.0.1-graal, 23.0.1
9999
23.0.1-graalce, 23.0.1
100100
23.0.1-librca, 23.0.1
@@ -106,7 +106,7 @@
106106
23.0.1.crac-zulu, 23.0.1
107107
23.0.1.fx-librca, 23.0.1
108108
23.0.1.fx-zulu, 23.0.1
109-
23.0.2-amzn, 23.0.2
109+
23.0.2-amzn, 23
110110
23.0.2-graal, 23.0.2
111111
23.0.2-graalce, 23.0.2
112112
23.0.2-librca, 23.0.2

‎__tests__/util.test.ts‎

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,60 @@ describe('validatePaginationUrl', () => {
166166
describe('getVersionFromFileContent', () => {
167167
describe('.sdkmanrc', () => {
168168
it.each([
169-
['java=11.0.20.1-tem', '11.0.20'],
170-
['java = 11.0.20.1-tem', '11.0.20'],
171-
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
172-
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
173-
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
174-
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
175-
])('parsing %s should return %s', (content: string, expected: string) => {
176-
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
177-
expect(actual).toBe(expected);
169+
['java=11.0.20.1-tem', '11.0.20', 'temurin'],
170+
['java = 11.0.20.1-tem', '11.0.20', 'temurin'],
171+
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20', 'temurin'],
172+
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
173+
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
174+
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20', 'temurin'], // first one is 'commented' in .sdkmanrc
175+
['java=21.0.5-zulu', '21.0.5', 'zulu'],
176+
['java=17.0.13-albba', '17.0.13', 'dragonwell'],
177+
['java=17.0.13-amzn', '17', 'corretto'],
178+
['java=21.0.5-graal', '21.0.5', 'graalvm'],
179+
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
180+
['java=11.0.25-librca', '11.0.25', 'liberica'],
181+
['java=11.0.25-ms', '11.0.25', 'microsoft'],
182+
['java=21.0.5-oracle', '21.0.5', 'oracle'],
183+
['java=11.0.25-sapmchn', '11.0.25', 'sapmachine'],
184+
['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
185+
['java=11.0.25-sem', '11.0.25', 'semeru'],
186+
['java=17.0.13-dragonwell', '17.0.13', 'dragonwell'],
187+
['java=21.0.5-kona', '21.0.5', 'kona']
188+
])(
189+
'parsing %s should return version %s and distribution %s',
190+
(content: string, expectedVersion: string, expectedDist: string) => {
191+
const actual = getVersionFromFileContent(
192+
content,
193+
'openjdk',
194+
'.sdkmanrc'
195+
);
196+
expect(actual?.version).toBe(expectedVersion);
197+
expect(actual?.distribution).toBe(expectedDist);
198+
}
199+
);
200+
201+
it('should warn and return undefined distribution for unknown identifier', () => {
202+
const warnSpy = jest.spyOn(core, 'warning');
203+
const actual = getVersionFromFileContent(
204+
'java=21.0.5-unknown',
205+
'temurin',
206+
'.sdkmanrc'
207+
);
208+
expect(actual?.version).toBe('21.0.5');
209+
expect(actual?.distribution).toBeUndefined();
210+
expect(warnSpy).toHaveBeenCalledWith(
211+
expect.stringContaining('Unknown SDKMAN distribution identifier')
212+
);
213+
});
214+
215+
it('should return version without distribution when no suffix provided', () => {
216+
const actual = getVersionFromFileContent(
217+
'java=11.0.20',
218+
'temurin',
219+
'.sdkmanrc'
220+
);
221+
expect(actual?.version).toBe('11.0.20');
222+
expect(actual?.distribution).toBeUndefined();
178223
});
179224

180225
describe('known versions', () => {
@@ -193,7 +238,7 @@ describe('getVersionFromFileContent', () => {
193238
'openjdk',
194239
'.sdkmanrc'
195240
);
196-
expect(actual).toBe(expected);
241+
expect(actual?.version).toBe(expected);
197242
}
198243
);
199244
});

‎action.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ inputs:
1010
description: 'The path to a file containing the Java version to set up (.java-version, .tool-versions, .sdkmanrc). Used when java-version is not set. See examples of supported syntax in README file'
1111
required: false
1212
distribution:
13-
description: 'Java distribution. See the list of supported distributions in README file'
14-
required: true
13+
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
14+
required: false
1515
java-package:
1616
description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
1717
required: false

‎dist/cleanup/index.js‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52572,8 +52572,9 @@ function isCacheFeatureAvailable() {
5257252572
}
5257352573
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
5257452574
function getVersionFromFileContent(content, distributionName, versionFile) {
52575-
var _a, _b, _c, _d, _e;
52575+
var _a, _b, _c;
5257652576
let javaVersionRegExp;
52577+
let extractedDistribution;
5257752578
function getFileName(versionFile) {
5257852579
return path_1.default.basename(versionFile);
5257952580
}
@@ -52583,14 +52584,23 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
5258352584
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
5258452585
}
5258552586
else if (versionFileName == '.sdkmanrc') {
52586-
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
52587+
// Match both version and optional distribution identifier
52588+
javaVersionRegExp =
52589+
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
5258752590
}
5258852591
else {
5258952592
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
5259052593
}
52591-
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
52592-
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
52594+
const match = content.match(javaVersionRegExp);
52595+
const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
52596+
? match.groups.version
5259352597
: '';
52598+
// Extract distribution from .sdkmanrc file
52599+
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
52600+
const sdkmanDist = match.groups.distribution;
52601+
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
52602+
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
52603+
}
5259452604
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
5259552605
if (!capturedVersion) {
5259652606
return null;
@@ -52604,13 +52614,42 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
5260452614
if (!version) {
5260552615
return null;
5260652616
}
52607-
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
52608-
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
52617+
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
52618+
// (either explicitly provided or extracted from the version file) is in the list.
52619+
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
52620+
const coerceVersion = (_c = semver.coerce(version)) !== null && _c !== void 0 ? _c : version;
5260952621
version = semver.major(coerceVersion).toString();
5261052622
}
52611-
return version.toString();
52623+
return {
52624+
version: version.toString(),
52625+
distribution: extractedDistribution
52626+
};
5261252627
}
5261352628
exports.getVersionFromFileContent = getVersionFromFileContent;
52629+
// Map SDKMAN distribution identifiers to setup-java distribution names
52630+
function mapSdkmanDistribution(sdkmanDist) {
52631+
const distributionMap = {
52632+
tem: 'temurin',
52633+
sem: 'semeru',
52634+
albba: 'dragonwell',
52635+
zulu: 'zulu',
52636+
amzn: 'corretto',
52637+
graal: 'graalvm',
52638+
graalce: 'graalvm',
52639+
librca: 'liberica',
52640+
ms: 'microsoft',
52641+
oracle: 'oracle',
52642+
sapmchn: 'sapmachine',
52643+
jbr: 'jetbrains',
52644+
dragonwell: 'dragonwell',
52645+
kona: 'kona'
52646+
};
52647+
const mapped = distributionMap[sdkmanDist.toLowerCase()];
52648+
if (!mapped) {
52649+
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
52650+
}
52651+
return mapped;
52652+
}
5261452653
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
5261552654
function avoidOldNotation(content) {
5261652655
return content.startsWith('1.') ? content.substring(2) : content;

0 commit comments

Comments
 (0)