Skip to content
Prev Previous commit
Next Next commit
resolving comments
  • Loading branch information
dmitry-shibanov committed Mar 18, 2021
commit 9887b5cf979ae339ab0caaa4e21dcc834b99514e
11 changes: 5 additions & 6 deletions __tests__/distributors/base-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 10 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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* () {
Expand All @@ -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`);
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/distributions/base-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need the ?? false since getBooleanInput defaults to it if there is no value

}

protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
Expand All @@ -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`);
Expand Down
6 changes: 3 additions & 3 deletions src/setup-java.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down