Visitar URL original
Fix Liberica Java 25 release resolution (#1313) · actions/setup-java@ef0b922 · GitHub
Skip to content

Commit ef0b922

Browse files
brunoborgesCopilot
andauthored
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>
1 parent e144521 commit ef0b922

3 files changed

Lines changed: 158 additions & 21 deletions

File tree

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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,60 @@ describe('findPackageForDownload', () => {
320320
});
321321
});
322322

323+
it('selects the latest multi-component patch release for Java 25', async () => {
324+
const releases: LibericaVersion[] = [
325+
'25.0.5+11',
326+
'25.0.5.0.2+5',
327+
'25.0.5.0.3+5'
328+
].map(version => {
329+
const [versionWithoutBuild, buildVersion] = version.split('+');
330+
const [featureVersion, interimVersion, updateVersion] =
331+
versionWithoutBuild.split('.').map(Number);
332+
return {
333+
version,
334+
featureVersion,
335+
interimVersion,
336+
updateVersion,
337+
buildVersion: Number(buildVersion),
338+
downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz`
339+
};
340+
});
341+
distribution['getAvailableVersions'] = async () => releases;
342+
343+
await expect(distribution['findPackageForDownload']('25')).resolves.toEqual(
344+
{
345+
version: '25.0.5+0.3.5',
346+
url: 'https://download.bell-sw.com/java/25.0.5.0.3+5/jdk.tar.gz'
347+
}
348+
);
349+
});
350+
351+
it('compares patch components before build numbers when patch lengths differ', async () => {
352+
const releases: LibericaVersion[] = ['25.0.5.1+10', '25.0.5.1.1+1'].map(
353+
version => {
354+
const [versionWithoutBuild, buildVersion] = version.split('+');
355+
const [featureVersion, interimVersion, updateVersion] =
356+
versionWithoutBuild.split('.').map(Number);
357+
return {
358+
version,
359+
featureVersion,
360+
interimVersion,
361+
updateVersion,
362+
buildVersion: Number(buildVersion),
363+
downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz`
364+
};
365+
}
366+
);
367+
distribution['getAvailableVersions'] = async () => releases;
368+
369+
await expect(
370+
distribution['findPackageForDownload']('25.0.5')
371+
).resolves.toEqual({
372+
version: '25.0.5+1.1.1',
373+
url: 'https://download.bell-sw.com/java/25.0.5.1.1+1/jdk.tar.gz'
374+
});
375+
});
376+
323377
it('should throw an error', async () => {
324378
await expect(distribution['findPackageForDownload']('17')).rejects.toThrow(
325379
/No matching version found for SemVer/
@@ -431,6 +485,39 @@ describe('patch request resolution from the constructor', () => {
431485
expect(distribution['version']).toBe('17.0.20.1');
432486
});
433487

488+
it('normalizes multi-component patch-only requests for exact matching', async () => {
489+
const releases: LibericaVersion[] = ['25.0.5.0.2+5', '25.0.5.0.3+5'].map(
490+
version => {
491+
const [versionWithoutBuild, buildVersion] = version.split('+');
492+
const [featureVersion, interimVersion, updateVersion] =
493+
versionWithoutBuild.split('.').map(Number);
494+
return {
495+
version,
496+
featureVersion,
497+
interimVersion,
498+
updateVersion,
499+
buildVersion: Number(buildVersion),
500+
downloadUrl: `https://download.bell-sw.com/java/${version}/jdk.tar.gz`
501+
};
502+
}
503+
);
504+
const distribution = new LibericaDistributions({
505+
version: '25.0.5.0.3',
506+
architecture: 'x64',
507+
packageType: 'jdk',
508+
checkLatest: false
509+
});
510+
distribution['getAvailableVersions'] = async () => releases;
511+
512+
expect(distribution['version']).toBe('25.0.5.0.3');
513+
await expect(
514+
distribution['findPackageForDownload'](distribution['version'])
515+
).resolves.toEqual({
516+
version: '25.0.5+0.3.5',
517+
url: 'https://download.bell-sw.com/java/25.0.5.0.3+5/jdk.tar.gz'
518+
});
519+
});
520+
434521
it('orders main versions, patches, and builds consistently in cache', async () => {
435522
for (const version of ['17.0.20-1.2', '17.0.20-1.10', '17.0.21-1']) {
436523
const javaPath = path.join(
@@ -577,6 +664,16 @@ describe('convertVersionToSemver', () => {
577664
},
578665
'25.0.4+1.1'
579666
],
667+
[
668+
{
669+
version: '25.0.5.0.3+5',
670+
featureVersion: 25,
671+
interimVersion: 0,
672+
updateVersion: 5,
673+
buildVersion: 5
674+
},
675+
'25.0.5+0.3.5'
676+
],
580677
[
581678
{
582679
version: '17.0.20.1+2',

‎dist/setup/63.index.js‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_
6262
}
6363
normalizeVersion(version) {
6464
const normalized = super.normalizeVersion(version);
65-
if (/^\d+\.\d+\.\d+\.\d+(?:-ea)?$/.test(version)) {
65+
if (/^\d+\.\d+\.\d+(?:\.\d+)+(?:-ea)?$/.test(version)) {
6666
// Keep patch-only requests distinct from exact SDKMAN build requests.
6767
normalized.version = version.replace(/-ea$/, '');
6868
}
6969
return normalized;
7070
}
7171
isVersionSatisfied(range, version) {
72-
const patchRequest = range.match(/^(\d+\.\d+\.\d+)\.(\d+)$/);
72+
const patchRequest = range.match(/^(\d+\.\d+\.\d+)((?:\.\d+)+)$/);
7373
if (patchRequest) {
7474
const candidate = semver__WEBPACK_IMPORTED_MODULE_1___default().parse(version);
7575
if (!candidate || !semver__WEBPACK_IMPORTED_MODULE_1___default().eq(patchRequest[1], candidate)) {
7676
return false;
7777
}
78-
const patch = candidate.build.length > 1 ? candidate.build[0] : '0';
79-
return patch === patchRequest[2];
78+
const patch = candidate.build.length > 1
79+
? candidate.build.slice(0, -1).join('.')
80+
: '0';
81+
return patch === patchRequest[2].slice(1);
8082
}
8183
return super.isVersionSatisfied(range, version);
8284
}
@@ -85,12 +87,22 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_
8587
if (mainComparison !== 0) {
8688
return mainComparison;
8789
}
88-
// SDKMAN encodes patch.build, but unpatched releases contain only build.
89-
const patchAndBuild = (version) => {
90+
const getPatchAndBuild = (version) => {
9091
const build = new (semver__WEBPACK_IMPORTED_MODULE_1___default().SemVer)(version).build;
91-
return (build.length > 1 ? build : ['0', ...build]).join('.');
92+
return build.length > 1
93+
? { patch: build.slice(0, -1), build: build[build.length - 1] }
94+
: { patch: [], build: build[0] ?? '0' };
9295
};
93-
return semver__WEBPACK_IMPORTED_MODULE_1___default().compareBuild(`0.0.0+${patchAndBuild(a)}`, `0.0.0+${patchAndBuild(b)}`);
96+
const first = getPatchAndBuild(a);
97+
const second = getPatchAndBuild(b);
98+
const compareNumericIdentifiers = (left, right) => semver__WEBPACK_IMPORTED_MODULE_1___default().compareBuild(`0.0.0+${left}`, `0.0.0+${right}`);
99+
for (let index = 0; index < Math.max(first.patch.length, second.patch.length); index++) {
100+
const patchComparison = compareNumericIdentifiers(first.patch[index] ?? '0', second.patch[index] ?? '0');
101+
if (patchComparison !== 0) {
102+
return patchComparison;
103+
}
104+
}
105+
return compareNumericIdentifiers(first.build, second.build);
94106
}
95107
async getAvailableVersions() {
96108
if (_actions_core__WEBPACK_IMPORTED_MODULE_3__/* .isDebug */ ._o()) {
@@ -163,7 +175,11 @@ class LibericaDistributions extends _base_installer_js__WEBPACK_IMPORTED_MODULE_
163175
const { featureVersion, interimVersion, updateVersion } = version;
164176
const buildVersion = version.version.split('+')[1] || version.buildVersion;
165177
const mainVersion = [featureVersion, interimVersion, updateVersion].join('.');
166-
const patchVersion = version.version.split('+')[0].split('.')[3];
178+
const patchVersion = version.version
179+
.split('+')[0]
180+
.split('.')
181+
.slice(3)
182+
.join('.');
167183
if (patchVersion) {
168184
return `${mainVersion}+${patchVersion}.${buildVersion}`;
169185
}

‎src/distributions/liberica/installer.ts‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,25 @@ export class LibericaDistributions extends JavaBase {
8080

8181
protected normalizeVersion(version: string) {
8282
const normalized = super.normalizeVersion(version);
83-
if (/^\d+\.\d+\.\d+\.\d+(?:-ea)?$/.test(version)) {
83+
if (/^\d+\.\d+\.\d+(?:\.\d+)+(?:-ea)?$/.test(version)) {
8484
// Keep patch-only requests distinct from exact SDKMAN build requests.
8585
normalized.version = version.replace(/-ea$/, '');
8686
}
8787
return normalized;
8888
}
8989

9090
protected isVersionSatisfied(range: string, version: string): boolean {
91-
const patchRequest = range.match(/^(\d+\.\d+\.\d+)\.(\d+)$/);
91+
const patchRequest = range.match(/^(\d+\.\d+\.\d+)((?:\.\d+)+)$/);
9292
if (patchRequest) {
9393
const candidate = semver.parse(version);
9494
if (!candidate || !semver.eq(patchRequest[1], candidate)) {
9595
return false;
9696
}
97-
const patch = candidate.build.length > 1 ? candidate.build[0] : '0';
98-
return patch === patchRequest[2];
97+
const patch =
98+
candidate.build.length > 1
99+
? candidate.build.slice(0, -1).join('.')
100+
: '0';
101+
return patch === patchRequest[2].slice(1);
99102
}
100103
return super.isVersionSatisfied(range, version);
101104
}
@@ -106,15 +109,32 @@ export class LibericaDistributions extends JavaBase {
106109
return mainComparison;
107110
}
108111

109-
// SDKMAN encodes patch.build, but unpatched releases contain only build.
110-
const patchAndBuild = (version: string): string => {
112+
const getPatchAndBuild = (version: string) => {
111113
const build = new semver.SemVer(version).build;
112-
return (build.length > 1 ? build : ['0', ...build]).join('.');
114+
return build.length > 1
115+
? {patch: build.slice(0, -1), build: build[build.length - 1]}
116+
: {patch: [], build: build[0] ?? '0'};
113117
};
114-
return semver.compareBuild(
115-
`0.0.0+${patchAndBuild(a)}`,
116-
`0.0.0+${patchAndBuild(b)}`
117-
);
118+
const first = getPatchAndBuild(a);
119+
const second = getPatchAndBuild(b);
120+
const compareNumericIdentifiers = (left: string, right: string) =>
121+
semver.compareBuild(`0.0.0+${left}`, `0.0.0+${right}`);
122+
123+
for (
124+
let index = 0;
125+
index < Math.max(first.patch.length, second.patch.length);
126+
index++
127+
) {
128+
const patchComparison = compareNumericIdentifiers(
129+
first.patch[index] ?? '0',
130+
second.patch[index] ?? '0'
131+
);
132+
if (patchComparison !== 0) {
133+
return patchComparison;
134+
}
135+
}
136+
137+
return compareNumericIdentifiers(first.build, second.build);
118138
}
119139

120140
private async getAvailableVersions(): Promise<LibericaVersion[]> {
@@ -209,7 +229,11 @@ export class LibericaDistributions extends JavaBase {
209229
const mainVersion = [featureVersion, interimVersion, updateVersion].join(
210230
'.'
211231
);
212-
const patchVersion = version.version.split('+')[0].split('.')[3];
232+
const patchVersion = version.version
233+
.split('+')[0]
234+
.split('.')
235+
.slice(3)
236+
.join('.');
213237
if (patchVersion) {
214238
return `${mainVersion}+${patchVersion}.${buildVersion}`;
215239
}

0 commit comments

Comments
 (0)