From 7f1cc05ecfb0a7169a61a09e9a98345432412f6a Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 8 Aug 2023 13:02:14 +0100 Subject: [PATCH 1/3] Make the Adoptopenjdk package type look at the Temurin repo first for latest assets --- .../distributors/adopt-installer.test.ts | 86 +++++++++++++++++-- src/distributions/adopt/installer.ts | 39 ++++++++- src/distributions/temurin/installer.ts | 2 +- 3 files changed, 119 insertions(+), 8 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 8a112243..02b74d49 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -1,14 +1,11 @@ import {HttpClient} from '@actions/http-client'; -import {IAdoptAvailableVersions} from '../../src/distributions/adopt/models'; -import { - AdoptDistribution, - AdoptImplementation -} from '../../src/distributions/adopt/installer'; +import {AdoptDistribution, AdoptImplementation} from '../../src/distributions/adopt/installer'; import {JavaInstallerOptions} from '../../src/distributions/base-models'; import os from 'os'; import manifestData from '../data/adopt.json'; +import {TemurinDistribution, TemurinImplementation} from "../../src/distributions/temurin/installer"; describe('getAvailableVersions', () => { let spyHttpClient: jest.SpyInstance; @@ -247,6 +244,85 @@ describe('findPackageForDownload', () => { expect(resolvedVersion.version).toBe(expected); }); + describe('delegates to Temurin', () => { + it.each([ + ['9', '9.0.7+10'], + ['15', '15.0.2+7'], + ['15.0', '15.0.2+7'], + ['15.0.2', '15.0.2+7'], + ['15.0.1', '15.0.1+9.1'], + ['11.x', '11.0.10+9'], + ['x', '15.0.2+7'], + ['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly + ['12.0.2+10.1', '12.0.2+10.1'], + ['15.0.1+9', '15.0.1+9'], + ['15.0.1+9.1', '15.0.1+9.1'] + ])('version is resolved correctly %s -> %s', async (input, expected) => { + + const temurinDistribution = new TemurinDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + TemurinImplementation.Hotspot + ); + + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); + + temurinDistribution['getAvailableVersions'] = async () => manifestData as any; + const resolvedVersion = await distribution['findPackageForDownload'](input); + expect(resolvedVersion.version).toBe(expected); + }); + }); + + + describe('Falls back if Temurin fails', () => { + it.each([ + ['9', '9.0.7+10'] + ])('version is resolved correctly %s -> %s', async (input, expected) => { + + const temurinDistribution = new TemurinDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + TemurinImplementation.Hotspot + ); + + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); + + temurinDistribution['findPackageForDownload'] = async () => new Promise(function () { + throw new Error("Could not find satisfied version for SemVer") + }); + distribution['getAvailableVersions'] = async () => manifestData as any; + + const resolvedVersion = await distribution['findPackageForDownload'](input); + expect(resolvedVersion.version).toBe(expected); + }); + }); + it('version is found but binaries list is empty', async () => { const distribution = new AdoptDistribution( { diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 9887b789..9104b96f 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -17,6 +17,7 @@ import { getDownloadArchiveExtension, isVersionSatisfies } from '../../util'; +import {TemurinDistribution, TemurinImplementation} from "../temurin/installer"; export enum AdoptImplementation { Hotspot = 'Hotspot', @@ -26,13 +27,47 @@ export enum AdoptImplementation { export class AdoptDistribution extends JavaBase { constructor( installerOptions: JavaInstallerOptions, - private readonly jvmImpl: AdoptImplementation + private readonly jvmImpl: AdoptImplementation, + private readonly temurinDistribution: TemurinDistribution | null = null ) { super(`Adopt-${jvmImpl}`, installerOptions); + + if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) { + throw new Error("Only Hotspot JVM is supported by Temurin.") + } + + // Only use the temurin repo for Hotspot JVMs + if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) { + this.temurinDistribution = new TemurinDistribution( + installerOptions, + TemurinImplementation.Hotspot); + } } protected async findPackageForDownload( - version: string + version: string + ): Promise { + if (this.jvmImpl == AdoptImplementation.Hotspot && this.temurinDistribution != null) { + try { + let result = await this.temurinDistribution.findPackageForDownload(version) + + if (result != undefined) { + return result + } + } catch (error) { + if (error.message.includes('Could not find satisfied version')) { + console.warn("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.") + } + } + } + + // failed to find a Temurin version, so fall back to AdoptOpenJDK + return this.findPackageForDownloadOldAdoptOpenJdk(version); + } + + private async findPackageForDownloadOldAdoptOpenJdk( + version: string ): Promise { const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsWithBinaries = availableVersionsRaw diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index 4a1989bc..870ff73f 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -30,7 +30,7 @@ export class TemurinDistribution extends JavaBase { super(`Temurin-${jvmImpl}`, installerOptions); } - protected async findPackageForDownload( + public async findPackageForDownload( version: string ): Promise { const availableVersionsRaw = await this.getAvailableVersions(); From 5256614f4c9e604a68dffbe32ceebb6036ba21e3 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Wed, 9 Aug 2023 15:58:28 +0100 Subject: [PATCH 2/3] add warning --- src/distributions/adopt/installer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 9104b96f..33ccfb7f 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -47,6 +47,11 @@ export class AdoptDistribution extends JavaBase { protected async findPackageForDownload( version: string ): Promise { + + if (this.jvmImpl == AdoptImplementation.Hotspot) { + core.notice("AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration.") + } + if (this.jvmImpl == AdoptImplementation.Hotspot && this.temurinDistribution != null) { try { let result = await this.temurinDistribution.findPackageForDownload(version) @@ -56,7 +61,7 @@ export class AdoptDistribution extends JavaBase { } } catch (error) { if (error.message.includes('Could not find satisfied version')) { - console.warn("The JVM you are looking for could not be found in the Temurin repository, this likely indicates " + + 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.") } } From 2df4cee1ae0b4464388b01ca8a62d2f56dafb473 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:43:18 +0100 Subject: [PATCH 3/3] Format adopt --- .../distributors/adopt-installer.test.ts | 154 ++++++++++-------- src/distributions/adopt/installer.ts | 35 ++-- 2 files changed, 104 insertions(+), 85 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 02b74d49..b1d7f6d0 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -1,11 +1,17 @@ import {HttpClient} from '@actions/http-client'; -import {AdoptDistribution, AdoptImplementation} from '../../src/distributions/adopt/installer'; +import { + AdoptDistribution, + AdoptImplementation +} from '../../src/distributions/adopt/installer'; import {JavaInstallerOptions} from '../../src/distributions/base-models'; import os from 'os'; import manifestData from '../data/adopt.json'; -import {TemurinDistribution, TemurinImplementation} from "../../src/distributions/temurin/installer"; +import { + TemurinDistribution, + TemurinImplementation +} from '../../src/distributions/temurin/installer'; describe('getAvailableVersions', () => { let spyHttpClient: jest.SpyInstance; @@ -245,83 +251,87 @@ describe('findPackageForDownload', () => { }); describe('delegates to Temurin', () => { - it.each([ - ['9', '9.0.7+10'], - ['15', '15.0.2+7'], - ['15.0', '15.0.2+7'], - ['15.0.2', '15.0.2+7'], - ['15.0.1', '15.0.1+9.1'], - ['11.x', '11.0.10+9'], - ['x', '15.0.2+7'], - ['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly - ['12.0.2+10.1', '12.0.2+10.1'], - ['15.0.1+9', '15.0.1+9'], - ['15.0.1+9.1', '15.0.1+9.1'] - ])('version is resolved correctly %s -> %s', async (input, expected) => { + it.each([ + ['9', '9.0.7+10'], + ['15', '15.0.2+7'], + ['15.0', '15.0.2+7'], + ['15.0.2', '15.0.2+7'], + ['15.0.1', '15.0.1+9.1'], + ['11.x', '11.0.10+9'], + ['x', '15.0.2+7'], + ['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly + ['12.0.2+10.1', '12.0.2+10.1'], + ['15.0.1+9', '15.0.1+9'], + ['15.0.1+9.1', '15.0.1+9.1'] + ])('version is resolved correctly %s -> %s', async (input, expected) => { + const temurinDistribution = new TemurinDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + TemurinImplementation.Hotspot + ); - const temurinDistribution = new TemurinDistribution( - { - version: '11', - architecture: 'x64', - packageType: 'jdk', - checkLatest: false - }, - TemurinImplementation.Hotspot - ); + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); - const distribution = new AdoptDistribution( - { - version: '11', - architecture: 'x64', - packageType: 'jdk', - checkLatest: false - }, - AdoptImplementation.Hotspot, - temurinDistribution - ); - - temurinDistribution['getAvailableVersions'] = async () => manifestData as any; - const resolvedVersion = await distribution['findPackageForDownload'](input); - expect(resolvedVersion.version).toBe(expected); - }); + temurinDistribution['getAvailableVersions'] = async () => + manifestData as any; + const resolvedVersion = await distribution['findPackageForDownload']( + input + ); + expect(resolvedVersion.version).toBe(expected); + }); }); + describe('Falls back if Temurin fails', () => { + it.each([['9', '9.0.7+10']])( + 'version is resolved correctly %s -> %s', + async (input, expected) => { + const temurinDistribution = new TemurinDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + TemurinImplementation.Hotspot + ); - describe('Falls back if Temurin fails', () => { - it.each([ - ['9', '9.0.7+10'] - ])('version is resolved correctly %s -> %s', async (input, expected) => { + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); - const temurinDistribution = new TemurinDistribution( - { - version: '11', - architecture: 'x64', - packageType: 'jdk', - checkLatest: false - }, - TemurinImplementation.Hotspot - ); + temurinDistribution['findPackageForDownload'] = async () => + new Promise(function () { + throw new Error('Could not find satisfied version for SemVer'); + }); + distribution['getAvailableVersions'] = async () => manifestData as any; - const distribution = new AdoptDistribution( - { - version: '11', - architecture: 'x64', - packageType: 'jdk', - checkLatest: false - }, - AdoptImplementation.Hotspot, - temurinDistribution - ); - - temurinDistribution['findPackageForDownload'] = async () => new Promise(function () { - throw new Error("Could not find satisfied version for SemVer") - }); - distribution['getAvailableVersions'] = async () => manifestData as any; - - const resolvedVersion = await distribution['findPackageForDownload'](input); - expect(resolvedVersion.version).toBe(expected); - }); - }); + const resolvedVersion = await distribution['findPackageForDownload']( + input + ); + expect(resolvedVersion.version).toBe(expected); + } + ); + }); it('version is found but binaries list is empty', async () => { const distribution = new AdoptDistribution( diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 33ccfb7f..57997981 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -17,7 +17,7 @@ import { getDownloadArchiveExtension, isVersionSatisfies } from '../../util'; -import {TemurinDistribution, TemurinImplementation} from "../temurin/installer"; +import {TemurinDistribution, TemurinImplementation} from '../temurin/installer'; export enum AdoptImplementation { Hotspot = 'Hotspot', @@ -33,36 +33,45 @@ export class AdoptDistribution extends JavaBase { super(`Adopt-${jvmImpl}`, installerOptions); if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) { - throw new Error("Only Hotspot JVM is supported by Temurin.") + throw new Error('Only Hotspot JVM is supported by Temurin.'); } // Only use the temurin repo for Hotspot JVMs if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) { this.temurinDistribution = new TemurinDistribution( - installerOptions, - TemurinImplementation.Hotspot); + installerOptions, + TemurinImplementation.Hotspot + ); } } protected async findPackageForDownload( - version: string + version: string ): Promise { - if (this.jvmImpl == AdoptImplementation.Hotspot) { - core.notice("AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration.") + core.notice( + "AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration." + ); } - if (this.jvmImpl == AdoptImplementation.Hotspot && this.temurinDistribution != null) { + if ( + this.jvmImpl == AdoptImplementation.Hotspot && + this.temurinDistribution != null + ) { try { - let result = await this.temurinDistribution.findPackageForDownload(version) + let result = await this.temurinDistribution.findPackageForDownload( + version + ); if (result != undefined) { - return result + return result; } } catch (error) { if (error.message.includes('Could not find satisfied version')) { - 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.") + 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.' + ); } } } @@ -72,7 +81,7 @@ export class AdoptDistribution extends JavaBase { } private async findPackageForDownloadOldAdoptOpenJdk( - version: string + version: string ): Promise { const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsWithBinaries = availableVersionsRaw