Add option add-toolchain-only
This commit is contained in:
parent
eb6157cd13
commit
fa4b328aab
@ -87,7 +87,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: altHome,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(false);
|
||||
@ -136,7 +136,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -218,7 +218,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -304,7 +304,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -382,7 +382,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -453,7 +453,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -546,7 +546,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -606,7 +606,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -665,7 +665,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -749,7 +749,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -829,7 +829,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
addToolchain: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -884,7 +884,7 @@ describe('toolchains tests', () => {
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: false
|
||||
addToolchain: false
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
@ -944,6 +944,7 @@ describe('toolchains tests', () => {
|
||||
version,
|
||||
distributionName,
|
||||
jdkHome,
|
||||
true,
|
||||
undefined
|
||||
);
|
||||
|
||||
|
||||
12
action.yml
12
action.yml
@ -31,9 +31,9 @@ inputs:
|
||||
required: false
|
||||
default: false
|
||||
set-default:
|
||||
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
|
||||
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set. Default is "!add-toolchain-only". If explcitly set "true", it will update JAVA_HOME and PATH regardless of "add-toolchain-only".'
|
||||
required: false
|
||||
default: true
|
||||
# DO NOT set a default here! If not explicitly set, the default will be propagated from input 'add-toolchain-only'!
|
||||
verify-signature:
|
||||
description: 'Verify downloaded Java package signatures when supported by the selected distribution'
|
||||
required: false
|
||||
@ -60,9 +60,13 @@ inputs:
|
||||
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
|
||||
required: false
|
||||
overwrite-settings:
|
||||
description: 'Overwrite the settings.xml file if it exists. Default is "true".'
|
||||
description: 'Overwrite the settings.xml file if it exists. Default is "!add-toolchain-only". If explcitly set "true", it will update settings.xml regardless of "add-toolchain-only".'
|
||||
required: false
|
||||
default: true
|
||||
# DO NOT set a default here! If not explicitly set, the default will be propagated from input 'add-toolchain-only'!
|
||||
add-toolchain-only:
|
||||
description: 'Update toolchains.xml only. Default is "false". No update of settings.xml, no update of JAVA_HOME and PATH unless "overwrite-settings" or "set-default" are explicitly set "true".'
|
||||
required: false
|
||||
default: false
|
||||
gpg-private-key:
|
||||
description: 'GPG private key to import. Default is empty string.'
|
||||
required: false
|
||||
|
||||
@ -8,19 +8,14 @@ import * as os from 'os';
|
||||
import {create as xmlCreate} from 'xmlbuilder2';
|
||||
import * as constants from './constants.js';
|
||||
import * as gpg from './gpg.js';
|
||||
import {getBooleanInput} from './util.js';
|
||||
|
||||
export async function configureAuthentication() {
|
||||
export async function configureAuthentication(overwriteSettings: boolean) {
|
||||
const id = core.getInput(constants.INPUT_SERVER_ID);
|
||||
const username = core.getInput(constants.INPUT_SERVER_USERNAME);
|
||||
const password = core.getInput(constants.INPUT_SERVER_PASSWORD);
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
const gpgPrivateKey =
|
||||
core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
|
||||
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
|
||||
|
||||
@ -15,6 +15,7 @@ export const INPUT_SERVER_USERNAME = 'server-username';
|
||||
export const INPUT_SERVER_PASSWORD = 'server-password';
|
||||
export const INPUT_SETTINGS_PATH = 'settings-path';
|
||||
export const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
|
||||
export const INPUT_ADD_TOOLCHAIN_ONLY = 'add-toolchain-only';
|
||||
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
|
||||
export const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
|
||||
|
||||
|
||||
@ -15,6 +15,20 @@ import {getJavaDistribution} from './distributions/distribution-factory.js';
|
||||
import {JavaInstallerOptions} from './distributions/base-models.js';
|
||||
import {configureMavenArgs} from './maven-args.js';
|
||||
|
||||
interface IInstallerInputsOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
setDefault: boolean;
|
||||
overwriteSettings: boolean;
|
||||
addToolchainOnly: boolean;
|
||||
verifySignature: boolean;
|
||||
verifySignaturePublicKey: string | undefined;
|
||||
distributionName: string;
|
||||
jdkFile: string;
|
||||
toolchainIds: Array<string>;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
@ -28,7 +42,18 @@ async function run() {
|
||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||
);
|
||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
|
||||
const addToolchainOnly = getBooleanInput(
|
||||
constants.INPUT_ADD_TOOLCHAIN_ONLY,
|
||||
false
|
||||
);
|
||||
const setDefault = getBooleanInput(
|
||||
constants.INPUT_SET_DEFAULT,
|
||||
!addToolchainOnly
|
||||
);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
!addToolchainOnly
|
||||
);
|
||||
const verifySignature = getBooleanInput(
|
||||
constants.INPUT_VERIFY_SIGNATURE,
|
||||
false
|
||||
@ -78,16 +103,18 @@ async function run() {
|
||||
);
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
const installerInputsOptions: IInstallerInputsOptions = {
|
||||
architecture: architecture,
|
||||
packageType: packageType,
|
||||
checkLatest: checkLatest,
|
||||
setDefault: setDefault,
|
||||
overwriteSettings: overwriteSettings,
|
||||
addToolchainOnly: addToolchainOnly,
|
||||
verifySignature: verifySignature,
|
||||
verifySignaturePublicKey: verifySignaturePublicKey,
|
||||
distributionName: distributionName,
|
||||
jdkFile: jdkFile,
|
||||
toolchainIds: toolchainIds
|
||||
};
|
||||
|
||||
await installVersion(versionInfo.version, installerInputsOptions);
|
||||
@ -97,16 +124,18 @@ async function run() {
|
||||
throw new Error('distribution input is required');
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
const installerInputsOptions: IInstallerInputsOptions = {
|
||||
architecture: architecture,
|
||||
packageType: packageType,
|
||||
checkLatest: checkLatest,
|
||||
setDefault: setDefault,
|
||||
overwriteSettings: overwriteSettings,
|
||||
addToolchainOnly: addToolchainOnly,
|
||||
verifySignature: verifySignature,
|
||||
verifySignaturePublicKey: verifySignaturePublicKey,
|
||||
distributionName: distributionName,
|
||||
jdkFile: jdkFile,
|
||||
toolchainIds: toolchainIds
|
||||
};
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
@ -122,7 +151,7 @@ async function run() {
|
||||
);
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
|
||||
await auth.configureAuthentication();
|
||||
await auth.configureAuthentication(overwriteSettings);
|
||||
configureMavenArgs();
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
await restore(cache, cacheDependencyPath);
|
||||
@ -149,39 +178,27 @@ function getJdkFileInput(): string {
|
||||
|
||||
async function installVersion(
|
||||
version: string,
|
||||
options: installerInputsOptions,
|
||||
options: IInstallerInputsOptions,
|
||||
toolchainId = 0
|
||||
) {
|
||||
const {
|
||||
distributionName,
|
||||
jdkFile,
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
toolchainIds
|
||||
} = options;
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
architecture: options.architecture,
|
||||
packageType: options.packageType,
|
||||
checkLatest: options.checkLatest,
|
||||
setDefault: options.setDefault,
|
||||
verifySignature: options.verifySignature,
|
||||
verifySignaturePublicKey: options.verifySignaturePublicKey,
|
||||
version
|
||||
};
|
||||
|
||||
const distribution = getJavaDistribution(
|
||||
distributionName,
|
||||
options.distributionName,
|
||||
installerOptions,
|
||||
jdkFile
|
||||
options.jdkFile
|
||||
);
|
||||
if (!distribution) {
|
||||
throw new Error(
|
||||
`No supported distribution was found for input ${distributionName}`
|
||||
`No supported distribution was found for input ${options.distributionName}`
|
||||
);
|
||||
}
|
||||
|
||||
@ -194,27 +211,16 @@ async function installVersion(
|
||||
|
||||
await toolchains.configureToolchains(
|
||||
toolchainVersion,
|
||||
distributionName,
|
||||
options.distributionName,
|
||||
result.path,
|
||||
toolchainIds[toolchainId]
|
||||
options.overwriteSettings || options.addToolchainOnly,
|
||||
options.toolchainIds[toolchainId]
|
||||
);
|
||||
|
||||
core.info('');
|
||||
core.info('Java configuration:');
|
||||
core.info(` Distribution: ${distributionName}`);
|
||||
core.info(` Distribution: ${options.distributionName}`);
|
||||
core.info(` Version: ${result.version}`);
|
||||
core.info(` Path: ${result.path}`);
|
||||
core.info('');
|
||||
}
|
||||
|
||||
interface installerInputsOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
setDefault: boolean;
|
||||
verifySignature: boolean;
|
||||
verifySignaturePublicKey: string | undefined;
|
||||
distributionName: string;
|
||||
jdkFile: string;
|
||||
toolchainIds: Array<string>;
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as constants from './constants.js';
|
||||
|
||||
import {getBooleanInput} from './util.js';
|
||||
import {create as xmlCreate} from 'xmlbuilder2';
|
||||
|
||||
interface JdkInfo {
|
||||
@ -19,6 +18,7 @@ export async function configureToolchains(
|
||||
version: string,
|
||||
distributionName: string,
|
||||
jdkHome: string,
|
||||
addToolchain: boolean,
|
||||
toolchainId?: string
|
||||
) {
|
||||
const vendor =
|
||||
@ -27,10 +27,6 @@ export async function configureToolchains(
|
||||
const settingsDirectory =
|
||||
core.getInput(constants.INPUT_SETTINGS_PATH) ||
|
||||
path.join(os.homedir(), constants.M2_DIR);
|
||||
const overwriteSettings = getBooleanInput(
|
||||
constants.INPUT_OVERWRITE_SETTINGS,
|
||||
true
|
||||
);
|
||||
|
||||
await createToolchainsSettings({
|
||||
jdkInfo: {
|
||||
@ -40,18 +36,18 @@ export async function configureToolchains(
|
||||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
addToolchain
|
||||
});
|
||||
}
|
||||
|
||||
export async function createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
addToolchain
|
||||
}: {
|
||||
jdkInfo: JdkInfo;
|
||||
settingsDirectory: string;
|
||||
overwriteSettings: boolean;
|
||||
addToolchain: boolean;
|
||||
}) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
@ -71,7 +67,7 @@ export async function createToolchainsSettings({
|
||||
await writeToolchainsFileToDisk(
|
||||
settingsDirectory,
|
||||
updatedToolchains,
|
||||
overwriteSettings
|
||||
addToolchain
|
||||
);
|
||||
}
|
||||
|
||||
@ -175,11 +171,11 @@ async function readExistingToolchainsFile(directory: string) {
|
||||
async function writeToolchainsFileToDisk(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
addToolchain: boolean
|
||||
) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
if (settingsExists && addToolchain) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
} else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user