From 4826c07bc151bffdae770986d54dee7dfd5dadc0 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:13:25 +0000 Subject: [PATCH] Fixes from review --- .../distributors/adopt-installer.test.ts | 61 +++++++++++++++---- dist/setup/index.js | 7 ++- src/distributions/adopt/installer.ts | 5 +- src/distributions/base-installer.ts | 4 +- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 9accc266..05be8d53 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -4,6 +4,7 @@ import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer'; +import {TemurinDistribution} from '../../src/distributions/temurin/installer'; import {JavaInstallerOptions} from '../../src/distributions/base-models'; import os from 'os'; @@ -256,6 +257,38 @@ describe('getAvailableVersions', () => { }); describe('findPackageForDownload', () => { + it('returns Temurin result and does not query Adopt API when Temurin succeeds', async () => { + const temurinRelease = { + version: '11.0.31+11', + url: 'https://example.test/temurin-11.tar.gz' + }; + const temurinFindPackageForDownload = jest + .fn() + .mockResolvedValue(temurinRelease); + const temurinDistribution = { + findPackageForDownload: temurinFindPackageForDownload + } as unknown as TemurinDistribution; + + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); + const adoptLookupSpy = jest.fn(); + distribution['getAvailableVersions'] = adoptLookupSpy; + + const resolvedVersion = await distribution['findPackageForDownload']('11'); + + expect(resolvedVersion).toEqual(temurinRelease); + expect(temurinFindPackageForDownload).toHaveBeenCalledWith('11'); + expect(adoptLookupSpy).not.toHaveBeenCalled(); + }); + it.each([ ['9', '9.0.7+10'], ['15', '15.0.2+7'], @@ -279,9 +312,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; const resolvedVersion = await distribution['findPackageForDownload'](input); expect(resolvedVersion.version).toBe(expected); @@ -298,9 +332,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect( distribution['findPackageForDownload']('9.0.8') @@ -318,9 +353,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow( /No matching version found for SemVer */ @@ -338,9 +374,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => []; await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( /No matching version found for SemVer */ diff --git a/dist/setup/index.js b/dist/setup/index.js index 1ec38992..2273faf2 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77848,7 +77848,8 @@ class AdoptDistribution extends base_installer_1.JavaBase { catch (error) { // Log the failure but always fall back to legacy AdoptOpenJDK for resilience const errorMessage = error instanceof Error ? error.message : String(error); - if (errorMessage.includes('No matching version found')) { + if (error instanceof Error && + error.name === 'VersionNotFoundError') { core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'); } @@ -78260,7 +78261,9 @@ class JavaBase { parts.push(`(showing first ${maxVersionsToShow} of ${availableVersions.length} versions, enable debug mode to see all)`); } } - return new Error(parts.join('\n')); + const error = new Error(parts.join('\n')); + error.name = 'VersionNotFoundError'; + return error; } setJavaDefault(version, toolPath) { const majorVersion = version.split('.')[0]; diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 00a1a6b3..78798bfc 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -73,8 +73,9 @@ export class AdoptDistribution extends JavaBase { return await this.temurinDistribution.findPackageForDownload(version); } catch (error) { // Log the failure but always fall back to legacy AdoptOpenJDK for resilience - const errorMessage = error instanceof Error ? error.message : String(error); - if (errorMessage.includes('No matching version found')) { + const errorMessage = + error instanceof Error ? error.message : String(error); + if (error instanceof Error && error.name === 'VersionNotFoundError') { core.notice( 'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.' diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 10e37d99..5d9f3c82 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -292,7 +292,9 @@ export abstract class JavaBase { } } - return new Error(parts.join('\n')); + const error = new Error(parts.join('\n')); + error.name = 'VersionNotFoundError'; + return error; } protected setJavaDefault(version: string, toolPath: string) {