diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 281f73e5e..c4512ea90 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -1758,6 +1758,9 @@ describe('normalizeVersion', () => { ['11.0.9.1', {version: '11.0.9+1', stable: true, latest: false}], ['12.0.2.1.0', {version: '12.0.2+1.0', stable: true, latest: false}], ['18.0.1.1-ea', {version: '18.0.1+1', stable: false, latest: false}], + ['26.0.2.1+1', {version: '26.0.2+1.1', stable: true, latest: false}], + ['25.0.4.1+1', {version: '25.0.4+1.1', stable: true, latest: false}], + ['26.0.2+10', {version: '26.0.2+10', stable: true, latest: false}], ['latest', {version: 'x', stable: true, latest: true}], ['LATEST', {version: 'x', stable: true, latest: true}], [' Latest ', {version: 'x', stable: true, latest: true}] diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 97f932fbb..c4bf99afd 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -181,7 +181,10 @@ describe('convertVersionToSemver', () => { ['12.0', '12.0'], ['12.0.2', '12.0.2'], ['12.0.2.1', '12.0.2+1'], - ['12.0.2.1.0', '12.0.2+1.0'] + ['12.0.2.1.0', '12.0.2+1.0'], + ['26.0.2.1+1', '26.0.2+1.1'], + ['25.0.4.1+1', '25.0.4+1.1'], + ['26.0.2+10', '26.0.2+10'] ])('%s -> %s', (input: string, expected: string) => { const actual = convertVersionToSemver(input); expect(actual).toBe(expected); diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 00ad7724f..5c1988213 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -31239,13 +31239,28 @@ function avoidOldNotation(content) { return content.startsWith('1.') ? content.substring(2) : content; } function convertVersionToSemver(version) { - // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1) - const versionArray = Array.isArray(version) ? version : version.split('.'); + // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1). + // Temurin also publishes four-field versions that already carry build + // metadata (26.0.2.1+1). Preserve that +build by folding the extra numeric + // fields into SemVer build metadata alongside it. + if (Array.isArray(version)) { + const mainVersion = version.slice(0, 3).join('.'); + if (version.length > 3) { + return `${mainVersion}+${version.slice(3).join('.')}`; + } + return mainVersion; + } + const plusIndex = version.indexOf('+'); + const core = plusIndex >= 0 ? version.slice(0, plusIndex) : version; + const existingBuild = plusIndex >= 0 ? version.slice(plusIndex + 1) : ''; + const versionArray = core.split('.'); const mainVersion = versionArray.slice(0, 3).join('.'); if (versionArray.length > 3) { - return `${mainVersion}+${versionArray.slice(3).join('.')}`; + const fromFields = versionArray.slice(3).join('.'); + const mergedBuild = [fromFields, existingBuild].filter(Boolean).join('.'); + return `${mainVersion}+${mergedBuild}`; } - return mainVersion; + return existingBuild ? `${mainVersion}+${existingBuild}` : mainVersion; } /** * Builds a validator for the bytes currently served by a URL from the response diff --git a/dist/setup/242.index.js b/dist/setup/242.index.js index 12e3d457d..0fc815fb6 100644 --- a/dist/setup/242.index.js +++ b/dist/setup/242.index.js @@ -731,9 +731,10 @@ class JavaBase { // 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)) { + // accepted. Also cover four-field versions that already include +build + // metadata (Temurin: '26.0.2.1+1' -> '26.0.2+1.1'). Ranges with fewer + // than four numeric fields are left untouched. + if (/^\d+(\.\d+){3,}(\+.*)?$/.test(version)) { version = (0,util/* convertVersionToSemver */.ZY)(version); } if (!semver_default().validRange(version)) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 8e019a02a..d4413fe30 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -31696,13 +31696,28 @@ function avoidOldNotation(content) { return content.startsWith('1.') ? content.substring(2) : content; } function convertVersionToSemver(version) { - // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1) - const versionArray = Array.isArray(version) ? version : version.split('.'); + // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1). + // Temurin also publishes four-field versions that already carry build + // metadata (26.0.2.1+1). Preserve that +build by folding the extra numeric + // fields into SemVer build metadata alongside it. + if (Array.isArray(version)) { + const mainVersion = version.slice(0, 3).join('.'); + if (version.length > 3) { + return `${mainVersion}+${version.slice(3).join('.')}`; + } + return mainVersion; + } + const plusIndex = version.indexOf('+'); + const core = plusIndex >= 0 ? version.slice(0, plusIndex) : version; + const existingBuild = plusIndex >= 0 ? version.slice(plusIndex + 1) : ''; + const versionArray = core.split('.'); const mainVersion = versionArray.slice(0, 3).join('.'); if (versionArray.length > 3) { - return `${mainVersion}+${versionArray.slice(3).join('.')}`; + const fromFields = versionArray.slice(3).join('.'); + const mergedBuild = [fromFields, existingBuild].filter(Boolean).join('.'); + return `${mainVersion}+${mergedBuild}`; } - return mainVersion; + return existingBuild ? `${mainVersion}+${existingBuild}` : mainVersion; } /** * Builds a validator for the bytes currently served by a URL from the response diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index f2d0c1414..65f5b9964 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -676,9 +676,10 @@ export abstract class JavaBase { // 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)) { + // accepted. Also cover four-field versions that already include +build + // metadata (Temurin: '26.0.2.1+1' -> '26.0.2+1.1'). Ranges with fewer + // than four numeric fields are left untouched. + if (/^\d+(\.\d+){3,}(\+.*)?$/.test(version)) { version = convertVersionToSemver(version); } diff --git a/src/util.ts b/src/util.ts index e2583849d..776694da6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -501,13 +501,29 @@ function avoidOldNotation(content: string): string { } export function convertVersionToSemver(version: number[] | string) { - // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1) - const versionArray = Array.isArray(version) ? version : version.split('.'); + // Some distributions may use semver-like notation (12.10.2.1, 12.10.2.1.1). + // Temurin also publishes four-field versions that already carry build + // metadata (26.0.2.1+1). Preserve that +build by folding the extra numeric + // fields into SemVer build metadata alongside it. + if (Array.isArray(version)) { + const mainVersion = version.slice(0, 3).join('.'); + if (version.length > 3) { + return `${mainVersion}+${version.slice(3).join('.')}`; + } + return mainVersion; + } + + const plusIndex = version.indexOf('+'); + const core = plusIndex >= 0 ? version.slice(0, plusIndex) : version; + const existingBuild = plusIndex >= 0 ? version.slice(plusIndex + 1) : ''; + const versionArray = core.split('.'); const mainVersion = versionArray.slice(0, 3).join('.'); if (versionArray.length > 3) { - return `${mainVersion}+${versionArray.slice(3).join('.')}`; + const fromFields = versionArray.slice(3).join('.'); + const mergedBuild = [fromFields, existingBuild].filter(Boolean).join('.'); + return `${mainVersion}+${mergedBuild}`; } - return mainVersion; + return existingBuild ? `${mainVersion}+${existingBuild}` : mainVersion; } /**