mirror of
https://gitea.com/actions/setup-java.git
synced 2026-07-10 19:31:55 +08:00
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>
This commit is contained in:
@@ -104,6 +104,7 @@ steps:
|
|||||||
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:
|
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:
|
||||||
- major versions, such as: `8`, `11`, `16`, `17`, `21`, `25`
|
- major versions, such as: `8`, `11`, `16`, `17`, `21`, `25`
|
||||||
- more specific versions: `8.0.282+8`, `8.0.232`, `11.0`, `11.0.4`, `17.0`
|
- more specific versions: `8.0.282+8`, `8.0.232`, `11.0`, `11.0.4`, `17.0`
|
||||||
|
- multi-field Java versions (JEP 322), such as: `11.0.9.1`, `18.0.1.1`
|
||||||
- early access (EA) versions: `15-ea`, `15.0.0-ea`
|
- early access (EA) versions: `15-ea`, `15.0.0-ea`
|
||||||
|
|
||||||
#### Supported distributions
|
#### Supported distributions
|
||||||
|
|||||||
@@ -748,7 +748,11 @@ describe('normalizeVersion', () => {
|
|||||||
['11.0', {version: '11.0', stable: true}],
|
['11.0', {version: '11.0', stable: true}],
|
||||||
['11.0.10', {version: '11.0.10', stable: true}],
|
['11.0.10', {version: '11.0.10', stable: true}],
|
||||||
['11-ea', {version: '11', stable: false}],
|
['11-ea', {version: '11', stable: false}],
|
||||||
['11.0.2-ea', {version: '11.0.2', stable: false}]
|
['11.0.2-ea', {version: '11.0.2', stable: false}],
|
||||||
|
['18.0.1.1', {version: '18.0.1+1', stable: true}],
|
||||||
|
['11.0.9.1', {version: '11.0.9+1', stable: true}],
|
||||||
|
['12.0.2.1.0', {version: '12.0.2+1.0', stable: true}],
|
||||||
|
['18.0.1.1-ea', {version: '18.0.1+1', stable: false}]
|
||||||
])('normalizeVersion from %s to %s', (input, expected) => {
|
])('normalizeVersion from %s to %s', (input, expected) => {
|
||||||
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(
|
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(
|
||||||
expected
|
expected
|
||||||
|
|||||||
8
dist/setup/index.js
vendored
8
dist/setup/index.js
vendored
@@ -131258,6 +131258,14 @@ class JavaBase {
|
|||||||
version = version.replace('-ea.', '+');
|
version = version.replace('-ea.', '+');
|
||||||
stable = false;
|
stable = false;
|
||||||
}
|
}
|
||||||
|
// Java uses a versioning scheme (JEP 322) that can contain more numeric
|
||||||
|
// fields than SemVer allows, e.g. '18.0.1.1' or '11.0.9.1'. Convert such
|
||||||
|
// exact versions to SemVer build notation ('18.0.1+1') so they are
|
||||||
|
// accepted. Ranges and versions that already carry build metadata are
|
||||||
|
// left untouched.
|
||||||
|
if (/^\d+(\.\d+){3,}$/.test(version)) {
|
||||||
|
version = convertVersionToSemver(version);
|
||||||
|
}
|
||||||
if (!semver_default().validRange(version)) {
|
if (!semver_default().validRange(version)) {
|
||||||
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`);
|
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`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import * as fs from 'fs';
|
|||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import {getToolcachePath, isVersionSatisfies} from '../util.js';
|
import {
|
||||||
|
convertVersionToSemver,
|
||||||
|
getToolcachePath,
|
||||||
|
isVersionSatisfies
|
||||||
|
} from '../util.js';
|
||||||
import {
|
import {
|
||||||
JavaDownloadRelease,
|
JavaDownloadRelease,
|
||||||
JavaInstallerOptions,
|
JavaInstallerOptions,
|
||||||
@@ -273,6 +277,15 @@ export abstract class JavaBase {
|
|||||||
stable = false;
|
stable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Java uses a versioning scheme (JEP 322) that can contain more numeric
|
||||||
|
// fields than SemVer allows, e.g. '18.0.1.1' or '11.0.9.1'. Convert such
|
||||||
|
// exact versions to SemVer build notation ('18.0.1+1') so they are
|
||||||
|
// accepted. Ranges and versions that already carry build metadata are
|
||||||
|
// left untouched.
|
||||||
|
if (/^\d+(\.\d+){3,}$/.test(version)) {
|
||||||
|
version = convertVersionToSemver(version);
|
||||||
|
}
|
||||||
|
|
||||||
if (!semver.validRange(version)) {
|
if (!semver.validRange(version)) {
|
||||||
throw new Error(
|
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`
|
`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`
|
||||||
|
|||||||
Reference in New Issue
Block a user