From 9887b5cf979ae339ab0caaa4e21dcc834b99514e Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 18 Mar 2021 15:47:15 +0300 Subject: [PATCH] resolving comments --- __tests__/distributors/base-installer.test.ts | 11 +++++------ dist/setup/index.js | 14 ++++++++++---- src/distributions/base-installer.ts | 7 +++++-- src/setup-java.ts | 6 +++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 3fd28f53..ab963cd6 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -225,24 +225,23 @@ describe('setupJava', () => { mockJavaBase = new EmptyJavaBase(input); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); expect(spyGetToolcachePath).toHaveBeenCalled(); - expect(spyCoreInfo).toHaveBeenCalledWith( - `Java ${input.version} was not found in tool-cache. Trying to download...` - ); + expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve latest version remotely'); + expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...'); expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${installedJavaVersion} was downloaded`); }); it.each([ [ { version: '11', architecture: 'x86', packageType: 'jre' }, - { path: `toolcache/Java_Empty_jre/11.0.9/x86`, version: '11.0.9' } + { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' } ], [ { version: '11', architecture: 'x64', packageType: 'jdk' }, - { path: `toolcache/Java_Empty_jdk/11.0.9/x64`, version: '11.0.9' } + { path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'), version: '11.0.9' } ], [ { version: '11', architecture: 'x64', packageType: 'jre' }, - { path: `toolcache/Java_Empty_jre/11.0.9/x64`, version: '11.0.9' } + { path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' } ] ])('download java with configuration %s', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); diff --git a/dist/setup/index.js b/dist/setup/index.js index 9c36741f..e676f8e8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3957,6 +3957,7 @@ const httpm = __importStar(__webpack_require__(539)); const util_1 = __webpack_require__(322); class JavaBase { constructor(distribution, installerOptions) { + var _a; this.distribution = distribution; this.http = new httpm.HttpClient('actions/setup-java', undefined, { allowRetries: true, @@ -3965,7 +3966,7 @@ class JavaBase { ({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version)); this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; - this.checkLatest = !!installerOptions.checkLatest; + this.checkLatest = (_a = installerOptions.checkLatest) !== null && _a !== void 0 ? _a : false; } setupJava() { return __awaiter(this, void 0, void 0, function* () { @@ -3974,12 +3975,16 @@ class JavaBase { core.info(`Resolved Java ${foundJava.version} from tool-cache`); } else { - core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`); + core.info('Trying to resolve latest version remotely'); const javaRelease = yield this.findPackageForDownload(this.version); + core.info('Trying to download...'); if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) != javaRelease.version) { foundJava = yield this.downloadTool(javaRelease); core.info(`Java ${foundJava.version} was downloaded`); } + else { + core.info('latest version was resolved locally'); + } core.info(`Java ${foundJava.version} was resolved`); } core.info(`Setting Java ${foundJava.version} as the default`); @@ -35648,6 +35653,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(__webpack_require__(470)); const auth = __importStar(__webpack_require__(331)); +const util_1 = __webpack_require__(322); const constants = __importStar(__webpack_require__(211)); const path = __importStar(__webpack_require__(622)); const distribution_factory_1 = __webpack_require__(24); @@ -35659,12 +35665,12 @@ function run() { const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); - const checkLatest = core.getInput(constants.INPUT_CHECK_LATEST); + const checkLatest = util_1.getBooleanInput(constants.INPUT_CHECK_LATEST, false); const installerOptions = { architecture, packageType, version, - checkLatest: checkLatest ? false : checkLatest.toLowerCase() === 'true' + checkLatest }; const distribution = distribution_factory_1.getJavaDistribution(distributionName, installerOptions, jdkFile); if (!distribution) { diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 36634b9a..47441567 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -25,7 +25,7 @@ export abstract class JavaBase { )); this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; - this.checkLatest = !!installerOptions.checkLatest; + this.checkLatest = installerOptions.checkLatest ?? false; } protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise; @@ -36,11 +36,14 @@ export abstract class JavaBase { if (foundJava && !this.checkLatest) { core.info(`Resolved Java ${foundJava.version} from tool-cache`); } else { - core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`); + core.info('Trying to resolve latest version remotely'); const javaRelease = await this.findPackageForDownload(this.version); + core.info('Trying to download...'); if (foundJava?.version != javaRelease.version) { foundJava = await this.downloadTool(javaRelease); core.info(`Java ${foundJava.version} was downloaded`); + } else { + core.info('latest version was resolved locally'); } core.info(`Java ${foundJava.version} was resolved`); diff --git a/src/setup-java.ts b/src/setup-java.ts index f7e6b980..92a86197 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core'; import * as auth from './auth'; - +import { getBooleanInput } from './util'; import * as constants from './constants'; import * as path from 'path'; import { getJavaDistribution } from './distributions/distribution-factory'; @@ -13,13 +13,13 @@ async function run() { const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); - const checkLatest = core.getInput(constants.INPUT_CHECK_LATEST); + const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false); const installerOptions: JavaInstallerOptions = { architecture, packageType, version, - checkLatest: checkLatest ? false : checkLatest.toLowerCase() === 'true' + checkLatest }; const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);