mirror of
https://github.com/actions/setup-java.git
synced 2025-04-19 17:36:45 +00:00
Add support for java.version file (#426)
This commit is contained in:
parent
c3ac5dd0ed
commit
1df8dbefe2
10 changed files with 358 additions and 56 deletions
|
@ -1,6 +1,7 @@
|
|||
import fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as auth from './auth';
|
||||
import { getBooleanInput, isCacheFeatureAvailable } from './util';
|
||||
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFileContent } from './util';
|
||||
import * as toolchains from './toolchains';
|
||||
import * as constants from './constants';
|
||||
import { restore } from './cache';
|
||||
|
@ -10,8 +11,9 @@ import { JavaInstallerOptions } from './distributions/base-models';
|
|||
|
||||
async function run() {
|
||||
try {
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION, { required: true });
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true });
|
||||
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||
|
@ -19,38 +21,44 @@ async function run() {
|
|||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||
|
||||
core.startGroup('Installed distributions');
|
||||
|
||||
if (versions.length !== toolchainIds.length) {
|
||||
toolchainIds = [];
|
||||
}
|
||||
|
||||
core.startGroup('Installed distributions');
|
||||
for (const [index, version] of versions.entries()) {
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
version,
|
||||
checkLatest
|
||||
};
|
||||
if (!versions.length && !versionFile) {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
if (!versions.length) {
|
||||
core.debug('java-version input is empty, looking for java-version-file input');
|
||||
const content = fs
|
||||
.readFileSync(versionFile)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
const version = getVersionFromFileContent(content, distributionName);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||
}
|
||||
|
||||
const result = await distribution.setupJava();
|
||||
await toolchains.configureToolchains(
|
||||
version,
|
||||
distributionName,
|
||||
result.path,
|
||||
toolchainIds[index]
|
||||
);
|
||||
await installVersion(version, installerInputsOptions);
|
||||
}
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
|
@ -66,3 +74,50 @@ async function run() {
|
|||
}
|
||||
|
||||
run();
|
||||
|
||||
async function installVersion(version: string, options: installerInputsOptions, toolchainId = 0) {
|
||||
const {
|
||||
distributionName,
|
||||
jdkFile,
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
toolchainIds
|
||||
} = options;
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
version
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile);
|
||||
if (!distribution) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
}
|
||||
|
||||
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>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue