2022-12-13 11:45:14 +00:00
|
|
|
import fs from 'fs';
|
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';
|
2023-03-09 12:49:35 +00:00
|
|
|
import {
|
|
|
|
getBooleanInput,
|
|
|
|
isCacheFeatureAvailable,
|
|
|
|
getVersionFromFileContent
|
|
|
|
} 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';
|
2023-03-09 12:49:35 +00:00
|
|
|
import {restore} from './cache';
|
2019-07-12 02:57:54 +00:00
|
|
|
import * as path from 'path';
|
2023-03-09 12:49:35 +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-12-13 11:45:14 +00:00
|
|
|
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
2023-03-09 12:49:35 +00:00
|
|
|
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, {
|
|
|
|
required: true
|
|
|
|
});
|
2022-12-13 11:45:14 +00:00
|
|
|
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
2021-04-05 10:02:27 +00:00
|
|
|
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);
|
|
|
|
|
2022-12-13 11:45:14 +00:00
|
|
|
core.startGroup('Installed distributions');
|
|
|
|
|
2022-01-16 16:33:29 +00:00
|
|
|
if (versions.length !== toolchainIds.length) {
|
|
|
|
toolchainIds = [];
|
|
|
|
}
|
2021-04-05 10:02:27 +00:00
|
|
|
|
2022-12-13 11:45:14 +00:00
|
|
|
if (!versions.length && !versionFile) {
|
|
|
|
throw new Error('java-version or java-version-file input expected');
|
|
|
|
}
|
|
|
|
|
|
|
|
const installerInputsOptions: installerInputsOptions = {
|
|
|
|
architecture,
|
|
|
|
packageType,
|
|
|
|
checkLatest,
|
|
|
|
distributionName,
|
|
|
|
jdkFile,
|
|
|
|
toolchainIds
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!versions.length) {
|
2023-03-09 12:49:35 +00:00
|
|
|
core.debug(
|
|
|
|
'java-version input is empty, looking for java-version-file input'
|
|
|
|
);
|
|
|
|
const content = fs.readFileSync(versionFile).toString().trim();
|
2022-12-13 11:45:14 +00:00
|
|
|
|
|
|
|
const version = getVersionFromFileContent(content, distributionName);
|
|
|
|
core.debug(`Parsed version from file '${version}'`);
|
|
|
|
|
|
|
|
if (!version) {
|
2023-03-09 12:49:35 +00:00
|
|
|
throw new Error(
|
|
|
|
`No supported version was found in file ${versionFile}`
|
|
|
|
);
|
2022-09-08 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 11:45:14 +00:00
|
|
|
await installVersion(version, installerInputsOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const [index, version] of versions.entries()) {
|
|
|
|
await installVersion(version, installerInputsOptions, index);
|
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();
|
2022-12-13 11:45:14 +00:00
|
|
|
|
2023-03-09 12:49:35 +00:00
|
|
|
async function installVersion(
|
|
|
|
version: string,
|
|
|
|
options: installerInputsOptions,
|
|
|
|
toolchainId = 0
|
|
|
|
) {
|
2022-12-13 11:45:14 +00:00
|
|
|
const {
|
|
|
|
distributionName,
|
|
|
|
jdkFile,
|
|
|
|
architecture,
|
|
|
|
packageType,
|
|
|
|
checkLatest,
|
|
|
|
toolchainIds
|
|
|
|
} = options;
|
|
|
|
|
|
|
|
const installerOptions: JavaInstallerOptions = {
|
|
|
|
architecture,
|
|
|
|
packageType,
|
|
|
|
checkLatest,
|
|
|
|
version
|
|
|
|
};
|
|
|
|
|
2023-03-09 12:49:35 +00:00
|
|
|
const distribution = getJavaDistribution(
|
|
|
|
distributionName,
|
|
|
|
installerOptions,
|
|
|
|
jdkFile
|
|
|
|
);
|
2022-12-13 11:45:14 +00:00
|
|
|
if (!distribution) {
|
2023-03-09 12:49:35 +00:00
|
|
|
throw new Error(
|
|
|
|
`No supported distribution was found for input ${distributionName}`
|
|
|
|
);
|
2022-12-13 11:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const result = await distribution.setupJava();
|
|
|
|
await toolchains.configureToolchains(
|
|
|
|
version,
|
|
|
|
distributionName,
|
|
|
|
result.path,
|
|
|
|
toolchainIds[toolchainId]
|
|
|
|
);
|
|
|
|
|
|
|
|
core.info('');
|
|
|
|
core.info('Java configuration:');
|
|
|
|
core.info(` Distribution: ${distributionName}`);
|
|
|
|
core.info(` Version: ${result.version}`);
|
|
|
|
core.info(` Path: ${result.path}`);
|
|
|
|
core.info('');
|
|
|
|
}
|
|
|
|
|
|
|
|
interface installerInputsOptions {
|
|
|
|
architecture: string;
|
|
|
|
packageType: string;
|
|
|
|
checkLatest: boolean;
|
|
|
|
distributionName: string;
|
|
|
|
jdkFile: string;
|
|
|
|
toolchainIds: Array<string>;
|
|
|
|
}
|