Skip to content

Commit 3157986

Browse files
brunoborgesCopilot
andauthored
Support multi-field Java versions like 18.0.1.1 (#1092)
Java's version scheme (JEP 322) can contain more than the three numeric fields SemVer allows, e.g. 18.0.1.1 or 11.0.9.1. normalizeVersion() rejected these inputs. Convert exact multi-field versions to SemVer build notation (18.0.1.1 -> 18.0.1+1) before validation, reusing the existing convertVersionToSemver() helper. Ranges, EA tags, and inputs that already carry build metadata are left untouched. Fixes: #326 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 548a822 commit 3157986

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ steps:
104104
The `java-version` input supports an exact version or a version range using [SemVer](https://semver.org/) notation. The values below are examples, not an exhaustive list:
105105
- major versions, such as: `8`, `11`, `16`, `17`, `21`, `25`
106106
- more specific versions: `8.0.282+8`, `8.0.232`, `11.0`, `11.0.4`, `17.0`
107+
- multi-field Java versions (JEP 322), such as: `11.0.9.1`, `18.0.1.1`
107108
- early access (EA) versions: `15-ea`, `15.0.0-ea`
108109

109110
#### Supported distributions

‎__tests__/distributors/base-installer.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,11 @@ describe('normalizeVersion', () => {
748748
['11.0', {version: '11.0', stable: true}],
749749
['11.0.10', {version: '11.0.10', stable: true}],
750750
['11-ea', {version: '11', stable: false}],
751-
['11.0.2-ea', {version: '11.0.2', stable: false}]
751+
['11.0.2-ea', {version: '11.0.2', stable: false}],
752+
['18.0.1.1', {version: '18.0.1+1', stable: true}],
753+
['11.0.9.1', {version: '11.0.9+1', stable: true}],
754+
['12.0.2.1.0', {version: '12.0.2+1.0', stable: true}],
755+
['18.0.1.1-ea', {version: '18.0.1+1', stable: false}]
752756
])('normalizeVersion from %s to %s', (input, expected) => {
753757
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(
754758
expected

‎dist/setup/index.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131258,6 +131258,14 @@ class JavaBase {
131258131258
version = version.replace('-ea.', '+');
131259131259
stable = false;
131260131260
}
131261+
// Java uses a versioning scheme (JEP 322) that can contain more numeric
131262+
// fields than SemVer allows, e.g. '18.0.1.1' or '11.0.9.1'. Convert such
131263+
// exact versions to SemVer build notation ('18.0.1+1') so they are
131264+
// accepted. Ranges and versions that already carry build metadata are
131265+
// left untouched.
131266+
if (/^\d+(\.\d+){3,}$/.test(version)) {
131267+
version = convertVersionToSemver(version);
131268+
}
131261131269
if (!semver_default().validRange(version)) {
131262131270
throw new Error(`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`);
131263131271
}

‎src/distributions/base-installer.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as fs from 'fs';
44
import semver from 'semver';
55
import path from 'path';
66
import * as httpm from '@actions/http-client';
7-
import {getToolcachePath, isVersionSatisfies} from '../util.js';
7+
import {
8+
convertVersionToSemver,
9+
getToolcachePath,
10+
isVersionSatisfies
11+
} from '../util.js';
812
import {
913
JavaDownloadRelease,
1014
JavaInstallerOptions,
@@ -273,6 +277,15 @@ export abstract class JavaBase {
273277
stable = false;
274278
}
275279

280+
// Java uses a versioning scheme (JEP 322) that can contain more numeric
281+
// fields than SemVer allows, e.g. '18.0.1.1' or '11.0.9.1'. Convert such
282+
// exact versions to SemVer build notation ('18.0.1+1') so they are
283+
// accepted. Ranges and versions that already carry build metadata are
284+
// left untouched.
285+
if (/^\d+(\.\d+){3,}$/.test(version)) {
286+
version = convertVersionToSemver(version);
287+
}
288+
276289
if (!semver.validRange(version)) {
277290
throw new Error(
278291
`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`

0 commit comments

Comments
 (0)