2019-07-10 14:54:25 +00:00
|
|
|
import * as core from '@actions/core';
|
2019-11-16 00:01:13 +00:00
|
|
|
import * as auth from './auth';
|
2022-03-31 19:09:57 +00:00
|
|
|
import { getBooleanInput, isCacheFeatureAvailable } from './util';
|
2022-01-16 16:33:29 +00:00
|
|
|
import * as toolchains from './toolchains';
|
2020-07-16 01:53:39 +00:00
|
|
|
import * as constants from './constants';
|
2021-08-19 17:19:35 +00:00
|
|
|
import { restore } from './cache';
|
2019-07-12 02:57:54 +00:00
|
|
|
import * as path from 'path';
|
2021-04-05 10:02:27 +00:00
|
|
|
import { getJavaDistribution } from './distributions/distribution-factory';
|
|
|
|
import { JavaInstallerOptions } from './distributions/base-models';
|
2019-07-10 14:54:25 +00:00
|
|
|
|
|
|
|
async function run() {
|
2019-07-11 03:11:48 +00:00
|
|
|
try {
|
2022-09-08 13:26:54 +00:00
|
|
|
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION, { required: true });
|
2021-04-05 10:02:27 +00:00
|
|
|
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
|
|
|
|
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
|
|
|
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
|
|
|
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
2021-08-19 17:19:35 +00:00
|
|
|
const cache = core.getInput(constants.INPUT_CACHE);
|
2021-04-05 10:02:27 +00:00
|
|
|
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
2022-01-16 16:33:29 +00:00
|
|
|
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
|
|
|
|
|
|
|
if (versions.length !== toolchainIds.length) {
|
|
|
|
toolchainIds = [];
|
|
|
|
}
|
2021-04-05 10:02:27 +00:00
|
|
|
|
2022-09-08 13:26:54 +00:00
|
|
|
core.startGroup('Installed distributions');
|
2022-01-16 16:33:29 +00:00
|
|
|
for (const [index, version] of versions.entries()) {
|
2022-09-08 13:26:54 +00:00
|
|
|
const installerOptions: JavaInstallerOptions = {
|
|
|
|
architecture,
|
|
|
|
packageType,
|
|
|
|
version,
|
|
|
|
checkLatest
|
|
|
|
};
|
|
|
|
|
|
|
|
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
|
|
|
if (!distribution) {
|
|
|
|
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = await distribution.setupJava();
|
2022-01-16 16:33:29 +00:00
|
|
|
await toolchains.configureToolchains(
|
|
|
|
version,
|
|
|
|
distributionName,
|
|
|
|
result.path,
|
|
|
|
toolchainIds[index]
|
|
|
|
);
|
2022-09-08 13:26:54 +00:00
|
|
|
|
|
|
|
core.info('');
|
|
|
|
core.info('Java configuration:');
|
|
|
|
core.info(` Distribution: ${distributionName}`);
|
|
|
|
core.info(` Version: ${result.version}`);
|
|
|
|
core.info(` Path: ${result.path}`);
|
|
|
|
core.info('');
|
2019-08-13 20:24:39 +00:00
|
|
|
}
|
2022-09-08 13:26:54 +00:00
|
|
|
core.endGroup();
|
2020-05-02 11:33:15 +00:00
|
|
|
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
2020-07-16 01:53:39 +00:00
|
|
|
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
|
|
|
|
2021-04-05 10:02:27 +00:00
|
|
|
await auth.configureAuthentication();
|
2022-03-31 19:09:57 +00:00
|
|
|
if (cache && isCacheFeatureAvailable()) {
|
2021-08-19 17:19:35 +00:00
|
|
|
await restore(cache);
|
|
|
|
}
|
2019-07-11 03:11:48 +00:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
2019-07-10 14:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run();
|