diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 4b4a3c0d..9e2825e8 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -27,19 +27,19 @@ describe('getAvailableVersions', () => { it.each([ [ - { version: '11', architecture: 'x64', packageType: 'jdk' }, + { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'os=mac&architecture=x64&image_type=jdk&release_type=ga&page_size=20&page=0' ], [ - { version: '11', architecture: 'x86', packageType: 'jdk' }, + { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, 'os=mac&architecture=x86&image_type=jdk&release_type=ga&page_size=20&page=0' ], [ - { version: '11', architecture: 'x64', packageType: 'jre' }, + { version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'os=mac&architecture=x64&image_type=jre&release_type=ga&page_size=20&page=0' ], [ - { version: '11-ea', architecture: 'x64', packageType: 'jdk' }, + { version: '11-ea', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'os=mac&architecture=x64&image_type=jdk&release_type=ea&page_size=20&page=0' ] ])( @@ -79,7 +79,8 @@ describe('getAvailableVersions', () => { const distribution = new AdoptDistribution({ version: '11', architecture: 'x64', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); const availableVersions = await distribution['getAvailableVersions'](); expect(availableVersions).not.toBeNull(); @@ -104,7 +105,8 @@ describe('findPackageForDownload', () => { const distribution = new AdoptDistribution({ version: '11', architecture: 'x64', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => manifestData; const resolvedVersion = await distribution['findPackageForDownload'](input); @@ -115,7 +117,8 @@ describe('findPackageForDownload', () => { const distribution = new AdoptDistribution({ version: '11', architecture: 'x64', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => manifestData; await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError( @@ -127,7 +130,8 @@ describe('findPackageForDownload', () => { const distribution = new AdoptDistribution({ version: '11', architecture: 'x64', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => manifestData; await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError( @@ -139,7 +143,8 @@ describe('findPackageForDownload', () => { const distribution = new AdoptDistribution({ version: '11', architecture: 'x64', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => []; await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError( diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index e57a5fe4..a36393a8 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -58,15 +58,15 @@ describe('findInToolcache', () => { it.each([ [ - { version: '11', architecture: 'x64', packageType: 'jdk' }, + { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false }, { version: actualJavaVersion, path: javaPath } ], [ - { version: '11.0', architecture: 'x64', packageType: 'jdk' }, + { version: '11.0', architecture: 'x64', packageType: 'jdk', checkLatest: false }, { version: actualJavaVersion, path: javaPath } ], [ - { version: '11.0.8', architecture: 'x64', packageType: 'jdk' }, + { version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: false }, { version: actualJavaVersion, path: javaPath } ], [ @@ -81,10 +81,10 @@ describe('findInToolcache', () => { { version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: true }, { version: actualJavaVersion, path: javaPath } ], - [{ version: '11', architecture: 'x64', packageType: 'jre' }, null], - [{ version: '8', architecture: 'x64', packageType: 'jdk' }, null], - [{ version: '11', architecture: 'x86', packageType: 'jdk' }, null], - [{ version: '11', architecture: 'x86', packageType: 'jre' }, null] + [{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, null], + [{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false }, null], + [{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, null], + [{ version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false }, null] ])(`should find java for path %s -> %s`, (input, expected) => { spyTcFindAllVersions.mockReturnValue([actualJavaVersion]); spyGetToolcachePath.mockImplementation( @@ -127,7 +127,12 @@ describe('findInToolcache', () => { (toolname: string, javaVersion: string, architecture: string) => `/hostedtoolcache/${toolname}/${javaVersion}/${architecture}` ); - mockJavaBase = new EmptyJavaBase({ version: input, architecture: 'x64', packageType: 'jdk' }); + mockJavaBase = new EmptyJavaBase({ + version: input, + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }); const foundVersion = mockJavaBase['findInToolcache'](); expect(foundVersion?.version).toEqual(expected); }); @@ -191,15 +196,15 @@ describe('setupJava', () => { it.each([ [ - { version: '11', architecture: 'x86', packageType: 'jdk' }, + { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, { version: installedJavaVersion, path: javaPath } ], [ - { version: '11.0', architecture: 'x86', packageType: 'jdk' }, + { version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: false }, { version: installedJavaVersion, path: javaPath } ], [ - { version: '11.0.8', architecture: 'x86', packageType: 'jdk' }, + { version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false }, { version: installedJavaVersion, path: javaPath } ] ])('should find java locally for %s', (input, expected) => { @@ -216,15 +221,15 @@ describe('setupJava', () => { it.each([ [ - { version: '11', architecture: 'x86', packageType: 'jre' }, + { version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false }, { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' } ], [ - { version: '11', architecture: 'x64', packageType: 'jdk' }, + { version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false }, { path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'), version: '11.0.9' } ], [ - { version: '11', architecture: 'x64', packageType: 'jre' }, + { version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' } ] ])('download java with configuration %s', async (input, expected) => { @@ -281,8 +286,8 @@ describe('setupJava', () => { }); it.each([ - [{ version: '15', architecture: 'x86', packageType: 'jre' }], - [{ version: '11.0.7', architecture: 'x64', packageType: 'jre' }] + [{ version: '15', architecture: 'x86', packageType: 'jre', checkLatest: false }], + [{ version: '11.0.7', architecture: 'x64', packageType: 'jre', checkLatest: false }] ])('should throw an error for Available version not found for %s', async input => { mockJavaBase = new EmptyJavaBase(input); await expect(mockJavaBase.setupJava()).rejects.toThrowError('Available version not found'); diff --git a/__tests__/distributors/local-installer.test.ts b/__tests__/distributors/local-installer.test.ts index c3b085bf..c1618971 100644 --- a/__tests__/distributors/local-installer.test.ts +++ b/__tests__/distributors/local-installer.test.ts @@ -93,7 +93,12 @@ describe('setupJava', () => { }); it('java is resolved from toolcache, jdkfile is untouched', async () => { - const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk' }; + const inputs = { + version: actualJavaVersion, + architecture: 'x86', + packageType: 'jdk', + checkLatest: false + }; const jdkFile = 'not_existing_one'; const expected = { version: actualJavaVersion, @@ -110,7 +115,12 @@ describe('setupJava', () => { }); it("java is resolved from toolcache, jdkfile doesn't exist", async () => { - const inputs = { version: actualJavaVersion, architecture: 'x86', packageType: 'jdk' }; + const inputs = { + version: actualJavaVersion, + architecture: 'x86', + packageType: 'jdk', + checkLatest: false + }; const jdkFile = undefined; const expected = { version: actualJavaVersion, @@ -127,7 +137,12 @@ describe('setupJava', () => { }); it('java is unpacked from jdkfile', async () => { - const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk' }; + const inputs = { + version: '11.0.289', + architecture: 'x86', + packageType: 'jdk', + checkLatest: false + }; const jdkFile = expectedJdkFile; const expected = { version: '11.0.289', @@ -147,7 +162,12 @@ describe('setupJava', () => { }); it('jdk file is not found', async () => { - const inputs = { version: '11.0.289', architecture: 'x86', packageType: 'jdk' }; + const inputs = { + version: '11.0.289', + architecture: 'x86', + packageType: 'jdk', + checkLatest: false + }; const jdkFile = 'not_existing_one'; const expected = { javaVersion: '11.0.289', @@ -170,10 +190,22 @@ describe('setupJava', () => { }); it.each([ - [{ version: '8.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], - [{ version: '11.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], - [{ version: '12.0.289', architecture: 'x64', packageType: 'jdk' }, 'otherJdkFile'], - [{ version: '11.1.11', architecture: 'x64', packageType: 'jdk' }, 'not_existing_one'] + [ + { version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + 'otherJdkFile' + ], + [ + { version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + 'otherJdkFile' + ], + [ + { version: '12.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + 'otherJdkFile' + ], + [ + { version: '11.1.11', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + 'not_existing_one' + ] ])( `Throw an error if jdkfile has wrong path, inputs %s, jdkfile %s, real name ${expectedJdkFile}`, async (inputs, jdkFile) => { @@ -186,9 +218,15 @@ describe('setupJava', () => { ); it.each([ - [{ version: '8.0.289', architecture: 'x64', packageType: 'jdk' }, ''], - [{ version: '7.0.289', architecture: 'x64', packageType: 'jdk' }, undefined], - [{ version: '11.0.289', architecture: 'x64', packageType: 'jdk' }, undefined] + [{ version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, ''], + [ + { version: '7.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + undefined + ], + [ + { version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, + undefined + ] ])('Throw an error if jdkfile is not specified, inputs %s', async (inputs, jdkFile) => { mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).rejects.toThrowError("'jdkFile' is not specified"); diff --git a/__tests__/distributors/zulu-installer.test.ts b/__tests__/distributors/zulu-installer.test.ts index fe5958a9..666cd90d 100644 --- a/__tests__/distributors/zulu-installer.test.ts +++ b/__tests__/distributors/zulu-installer.test.ts @@ -30,27 +30,27 @@ describe('getAvailableVersions', () => { it.each([ [ - { version: '11', architecture: 'x86', packageType: 'jdk' }, + { version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ga' ], [ - { version: '11-ea', architecture: 'x86', packageType: 'jdk' }, + { version: '11-ea', architecture: 'x86', packageType: 'jdk', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ea' ], [ - { version: '8', architecture: 'x64', packageType: 'jdk' }, + { version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=64&release_status=ga' ], [ - { version: '8', architecture: 'x64', packageType: 'jre' }, + { version: '8', architecture: 'x64', packageType: 'jre', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jre&javafx=false&arch=x86&hw_bitness=64&release_status=ga' ], [ - { version: '8', architecture: 'x64', packageType: 'jdk+fx' }, + { version: '8', architecture: 'x64', packageType: 'jdk+fx', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jdk&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx' ], [ - { version: '8', architecture: 'x64', packageType: 'jre+fx' }, + { version: '8', architecture: 'x64', packageType: 'jre+fx', checkLatest: false }, '?os=macos&ext=tar.gz&bundle_type=jre&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx' ] ])('build correct url for %s -> %s', async (input, parsedUrl) => { @@ -68,7 +68,8 @@ describe('getAvailableVersions', () => { const distribution = new ZuluDistribution({ version: '11', architecture: 'x86', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); const availableVersions = await distribution['getAvailableVersions'](); expect(availableVersions).toHaveLength(manifestData.length); @@ -85,7 +86,8 @@ describe('getArchitectureOptions', () => { const distribution = new ZuluDistribution({ version: '11', architecture: input.architecture, - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); expect(distribution['getArchitectureOptions']()).toEqual(expected); }); @@ -108,7 +110,8 @@ describe('findPackageForDownload', () => { const distribution = new ZuluDistribution({ version: input, architecture: 'x86', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => manifestData; const result = await distribution['findPackageForDownload'](distribution['version']); @@ -119,7 +122,8 @@ describe('findPackageForDownload', () => { const distribution = new ZuluDistribution({ version: '', architecture: 'x86', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); distribution['getAvailableVersions'] = async () => manifestData; const result = await distribution['findPackageForDownload']('11.0.5'); @@ -132,7 +136,8 @@ describe('findPackageForDownload', () => { const distribution = new ZuluDistribution({ version: '18', architecture: 'x86', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); await expect( distribution['findPackageForDownload'](distribution['version']) @@ -151,7 +156,8 @@ describe('convertVersionToSemver', () => { const distribution = new ZuluDistribution({ version: '18', architecture: 'x86', - packageType: 'jdk' + packageType: 'jdk', + checkLatest: false }); const actual = distribution['convertVersionToSemver'](input); expect(actual).toBe(expected); diff --git a/dist/setup/index.js b/dist/setup/index.js index fc2e9c52..f329f2d5 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3959,7 +3959,6 @@ const util_1 = __webpack_require__(322); const constants_1 = __webpack_require__(211); class JavaBase { constructor(distribution, installerOptions) { - var _a; this.distribution = distribution; this.http = new httpm.HttpClient('actions/setup-java', undefined, { allowRetries: true, @@ -3968,7 +3967,7 @@ class JavaBase { ({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version)); this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; - this.checkLatest = (_a = installerOptions.checkLatest) !== null && _a !== void 0 ? _a : false; + this.checkLatest = installerOptions.checkLatest; } setupJava() { var _a, _b; diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index c15b4875..9c9ea3a3 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -27,7 +27,7 @@ export abstract class JavaBase { )); this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; - this.checkLatest = installerOptions.checkLatest ?? false; + this.checkLatest = installerOptions.checkLatest; } protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise; diff --git a/src/distributions/base-models.ts b/src/distributions/base-models.ts index d667377a..82344d58 100644 --- a/src/distributions/base-models.ts +++ b/src/distributions/base-models.ts @@ -2,7 +2,7 @@ export interface JavaInstallerOptions { version: string; architecture: string; packageType: string; - checkLatest?: boolean; + checkLatest: boolean; } export interface JavaInstallerResults {