From ef0b92225551f5dea37b94738e0faca5c4cb1d50 Mon Sep 17 00:00:00 2001 From: Bruno Borges Date: Wed, 4 Nov 2026 16:26:15 -0500 Subject: [PATCH] Fix Liberica Java 25 release resolution (#1313) * Fix Liberica multi-component patch resolution Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Fix Liberica patch version ordering Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../distributors/liberica-installer.test.ts | 97 +++++++++++++++++++ dist/setup/63.index.js | 34 +++++-- src/distributions/liberica/installer.ts | 48 ++++++--- 3 files changed, 158 insertions(+), 21 deletions(-) diff --git a/__tests__/distributors/liberica-installer.test.ts b/__tests__/distributors/liberica-installer.test.ts index 2ce57c2c..105a555c 100644 --- a/__tests__/distributors/liberica-installer.test.ts +++ b/__tests__/distributors/liberica-installer.test.ts @@ -320,6 +320,60 @@ describe('findPackageForDownload', () => { }); }); + it('selects the latest multi-component patch release for Java 25', async () => { + const releases: LibericaVersion[] = [ + '25.0.5+11', + '25.0.5.0.2+5', + '25.0.5.0.3+5' + ].map(version => { + const [versionWithoutBuild, buildVersion] = version.split('+'); + const [featureVersion, interimVersion, updateVersion] = + versionWithoutBuild.split('.').map(Number); + return { + version, + featureVersion, + interimVersion, + updateVersion, + buildVersion: Number(buildVersion), + downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz` + }; + }); + distribution['getAvailableVersions'] = async () => releases; + + await expect(distribution['findPackageForDownload']('25')).resolves.toEqual( + { + version: '25.0.5+0.3.5', + url: 'https://download.bell-sw.com/java/25.0.5.0.3+5/jdk.tar.gz' + } + ); + }); + + it('compares patch components before build numbers when patch lengths differ', async () => { + const releases: LibericaVersion[] = ['25.0.5.1+10', '25.0.5.1.1+1'].map( + version => { + const [versionWithoutBuild, buildVersion] = version.split('+'); + const [featureVersion, interimVersion, updateVersion] = + versionWithoutBuild.split('.').map(Number); + return { + version, + featureVersion, + interimVersion, + updateVersion, + buildVersion: Number(buildVersion), + downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz` + }; + } + ); + distribution['getAvailableVersions'] = async () => releases; + + await expect( + distribution['findPackageForDownload']('25.0.5') + ).resolves.toEqual({ + version: '25.0.5+1.1.1', + url: 'https://download.bell-sw.com/java/25.0.5.1.1+1/jdk.tar.gz' + }); + }); + it('should throw an error', async () => { await expect(distribution['findPackageForDownload']('17')).rejects.toThrow( /No matching version found for SemVer/ @@ -431,6 +485,39 @@ describe('patch request resolution from the constructor', () => { expect(distribution['version']).toBe('17.0.20.1'); }); + it('normalizes multi-component patch-only requests for exact matching', async () => { + const releases: LibericaVersion[] = ['25.0.5.0.2+5', '25.0.5.0.3+5'].map( + version => { + const [versionWithoutBuild, buildVersion] = version.split('+'); + const [featureVersion, interimVersion, updateVersion] = + versionWithoutBuild.split('.').map(Number); + return { + version, + featureVersion, + interimVersion, + updateVersion, + buildVersion: Number(buildVersion), + downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz` + }; + } + ); + const distribution = new LibericaDistributions({ + version: '25.0.5.0.3', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }); + distribution['getAvailableVersions'] = async () => releases; + + expect(distribution['version']).toBe('25.0.5.0.3'); + await expect( + distribution['findPackageForDownload'](distribution['version']) + ).resolves.toEqual({ + version: '25.0.5+0.3.5', + url: 'https://download.bell-sw.com/java/25.0.5.0.3+5/jdk.tar.gz' + }); + }); + it('orders main versions, patches, and builds consistently in cache', async () => { for (const version of ['17.0.20-1.2', '17.0.20-1.10', '17.0.21-1']) { const javaPath = path.join( @@ -577,6 +664,16 @@ describe('convertVersionToSemver', () => { }, '25.0.4+1.1' ], + [ + { + version: '25.0.5.0.3+5', + featureVersion: 25, + interimVersion: 0, + updateVersion: 5, + buildVersion: 5 + }, + '25.0.5+0.3.5' + ], [ { version: '17.0.20.1+2', diff --git a/dist/setup/63.index.js b/dist/setup/63.index.js index 44eb30a1..4342736e 100644 --- a/dist/setup/63.index.js +++ b/dist/setup/63.index.js @@ -62,21 +62,23 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_ } normalizeVersion(version) { const normalized = super.normalizeVersion(version); - if (/^\d+\.\d+\.\d+\.\d+(?:-ea)?$/.test(version)) { + if (/^\d+\.\d+\.\d+(?:\.\d+)+(?:-ea)?$/.test(version)) { // Keep patch-only requests distinct from exact SDKMAN build requests. normalized.version = version.replace(/-ea$/, ''); } return normalized; } isVersionSatisfied(range, version) { - const patchRequest = range.match(/^(\d+\.\d+\.\d+)\.(\d+)$/); + const patchRequest = range.match(/^(\d+\.\d+\.\d+)((?:\.\d+)+)$/); if (patchRequest) { const candidate = semver__WEBPACK_IMPORTED_MODULE_1___default().parse(version); if (!candidate || !semver__WEBPACK_IMPORTED_MODULE_1___default().eq(patchRequest[1], candidate)) { return false; } - const patch = candidate.build.length > 1 ? candidate.build[0] : '0'; - return patch === patchRequest[2]; + const patch = candidate.build.length > 1 + ? candidate.build.slice(0, -1).join('.') + : '0'; + return patch === patchRequest[2].slice(1); } return super.isVersionSatisfied(range, version); } @@ -85,12 +87,22 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_ if (mainComparison !== 0) { return mainComparison; } - // SDKMAN encodes patch.build, but unpatched releases contain only build. - const patchAndBuild = (version) => { + const getPatchAndBuild = (version) => { const build = new (semver__WEBPACK_IMPORTED_MODULE_1___default().SemVer)(version).build; - return (build.length > 1 ? build : ['0', ...build]).join('.'); + return build.length > 1 + ? { patch: build.slice(0, -1), build: build[build.length - 1] } + : { patch: [], build: build[0] ?? '0' }; }; - return semver__WEBPACK_IMPORTED_MODULE_1___default().compareBuild(`0.0.0+${patchAndBuild(a)}`, `0.0.0+${patchAndBuild(b)}`); + const first = getPatchAndBuild(a); + const second = getPatchAndBuild(b); + const compareNumericIdentifiers = (left, right) => semver__WEBPACK_IMPORTED_MODULE_1___default().compareBuild(`0.0.0+${left}`, `0.0.0+${right}`); + for (let index = 0; index < Math.max(first.patch.length, second.patch.length); index++) { + const patchComparison = compareNumericIdentifiers(first.patch[index] ?? '0', second.patch[index] ?? '0'); + if (patchComparison !== 0) { + return patchComparison; + } + } + return compareNumericIdentifiers(first.build, second.build); } async getAvailableVersions() { if (_actions_core__WEBPACK_IMPORTED_MODULE_3__/* .isDebug */ ._o()) { @@ -163,7 +175,11 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_ const { featureVersion, interimVersion, updateVersion } = version; const buildVersion = version.version.split('+')[1] || version.buildVersion; const mainVersion = [featureVersion, interimVersion, updateVersion].join('.'); - const patchVersion = version.version.split('+')[0].split('.')[3]; + const patchVersion = version.version + .split('+')[0] + .split('.') + .slice(3) + .join('.'); if (patchVersion) { return `${mainVersion}+${patchVersion}.${buildVersion}`; } diff --git a/src/distributions/liberica/installer.ts b/src/distributions/liberica/installer.ts index 41737cea..46185002 100644 --- a/src/distributions/liberica/installer.ts +++ b/src/distributions/liberica/installer.ts @@ -80,7 +80,7 @@ export class LibericaDistributions extends JavaBase { protected normalizeVersion(version: string) { const normalized = super.normalizeVersion(version); - if (/^\d+\.\d+\.\d+\.\d+(?:-ea)?$/.test(version)) { + if (/^\d+\.\d+\.\d+(?:\.\d+)+(?:-ea)?$/.test(version)) { // Keep patch-only requests distinct from exact SDKMAN build requests. normalized.version = version.replace(/-ea$/, ''); } @@ -88,14 +88,17 @@ export class LibericaDistributions extends JavaBase { } protected isVersionSatisfied(range: string, version: string): boolean { - const patchRequest = range.match(/^(\d+\.\d+\.\d+)\.(\d+)$/); + const patchRequest = range.match(/^(\d+\.\d+\.\d+)((?:\.\d+)+)$/); if (patchRequest) { const candidate = semver.parse(version); if (!candidate || !semver.eq(patchRequest[1], candidate)) { return false; } - const patch = candidate.build.length > 1 ? candidate.build[0] : '0'; - return patch === patchRequest[2]; + const patch = + candidate.build.length > 1 + ? candidate.build.slice(0, -1).join('.') + : '0'; + return patch === patchRequest[2].slice(1); } return super.isVersionSatisfied(range, version); } @@ -106,15 +109,32 @@ export class LibericaDistributions extends JavaBase { return mainComparison; } - // SDKMAN encodes patch.build, but unpatched releases contain only build. - const patchAndBuild = (version: string): string => { + const getPatchAndBuild = (version: string) => { const build = new semver.SemVer(version).build; - return (build.length > 1 ? build : ['0', ...build]).join('.'); + return build.length > 1 + ? {patch: build.slice(0, -1), build: build[build.length - 1]} + : {patch: [], build: build[0] ?? '0'}; }; - return semver.compareBuild( - `0.0.0+${patchAndBuild(a)}`, - `0.0.0+${patchAndBuild(b)}` - ); + const first = getPatchAndBuild(a); + const second = getPatchAndBuild(b); + const compareNumericIdentifiers = (left: string, right: string) => + semver.compareBuild(`0.0.0+${left}`, `0.0.0+${right}`); + + for ( + let index = 0; + index < Math.max(first.patch.length, second.patch.length); + index++ + ) { + const patchComparison = compareNumericIdentifiers( + first.patch[index] ?? '0', + second.patch[index] ?? '0' + ); + if (patchComparison !== 0) { + return patchComparison; + } + } + + return compareNumericIdentifiers(first.build, second.build); } private async getAvailableVersions(): Promise { @@ -209,7 +229,11 @@ export class LibericaDistributions extends JavaBase { const mainVersion = [featureVersion, interimVersion, updateVersion].join( '.' ); - const patchVersion = version.version.split('+')[0].split('.')[3]; + const patchVersion = version.version + .split('+')[0] + .split('.') + .slice(3) + .join('.'); if (patchVersion) { return `${mainVersion}+${patchVersion}.${buildVersion}`; }