mirror of
https://github.com/actions/setup-java.git
synced 2025-06-29 04:24:14 +00:00
Add inputs 'update-toolchains-only', 'update-env-javahome', 'add-to-env-path'
Changes in detail: ------------------ - action.yml: - add inputs: - update-toolchains-only - update-env-javahome - add-to-env-path - update description for input "overwrite-settings" - remove default value of input "overwrite-settings", since the default is now propagated from input 'update-toolchains-only' - base-models.ts: - extend interface JavaInstallerOptions: - add fields: - updateEnvJavaHome: boolean; - addToEnvPath: boolean; - constants.ts: - add constant INPUT_UPDATE_TOOLCHAINS_ONLY = 'update-toolchains-only' - auth.ts: - function configureAuthentication(): - add parameter: - overwriteSettings: boolean - remove the now obsolete const overwriteSettings - toolchains.ts: - function configureToolchains(...): - add parameter updateToolchains: boolean - remove the now obsolete const overwriteSettings - improve variable naming: - rename any occurrence of 'overwriteSettings' by 'updateToolchains' - add field updateToolchains: boolean to the parameter object - function writeToolchainsFileToDisk(...): - improve variable naming: - rename variable 'settingsExists' by 'toolchainsExists' - update wording of info logs to be more applicable - setup-java.ts: - interface installerInputsOptions: - rename to IInstallerInputsOption to meet common coding convention - add fields: - updateToolchainsOnly: boolean; - overwriteSettings: boolean; - updateEnvJavaHome: boolean; - addToEnvPath: boolean; - function run(): - add const: - const updateToolchainsOnly: - get as boolean from input 'update-toolchains-only', default: false - const overwriteSettings: - get as boolean from input 'overwrite-settings', default: !updateToolchainsOnly - const updateEnvJavaHome: - get as boolean input 'update-env-javahome', default: !updateToolchainsOnly - const addToEnvPath: - get as boolean input 'add-to-env-path', default: !updateToolchainsOnly - extend const installerInputsOptions to match with IInstallerInputsOption: - add field updateToolchainsOnly - add field overwriteSettings - add field updateEnvJavaHome - add field addToEnvPath - update call of auth.configureAuthentication() to auth.configureAuthentication(overwriteSettings) - function installVersion(...): - add const and init from parameter options: - updateToolchainsOnly, overwriteSettings, updateEnvJavaHome, addToEnvPath - init the additional fields of installerInputsOptions accordingly - call toolchains.configureToolchains(...): - with parameter updateToolchains= overwriteSettings || updateToolchainsOnly - base-installer.ts: - add constants to import from constants: - INPUT_UPDATE_JAVA_HOME - INPUT_ADD_TO_PATH - add fields: - protected updateEnvJavaHome: boolean; - protected addToEnvPath: boolean; - ctor: - init these fields from JavaInstallerOptions accoprdingly - function setJavaDefault(...): - if updateEnvJavaHome is false: - SKIP updating env.JAVA_HOME - log info: `Skip updating env.JAVA_HOME according to ${INPUT_UPDATE_JAVA_HOME}` - if addToEnvPath is false: - SKIP adding toolchain path to env.PATH - log info: `Skip adding to env.PATH according to ${INPUT_ADD_TO_PATH}`
This commit is contained in:
parent
c5195efecf
commit
b75dfa6f66
7 changed files with 89 additions and 41 deletions
|
@ -19,6 +19,7 @@ export async function configureToolchains(
|
|||
version: string,
|
||||
distributionName: string,
|
||||
jdkHome: string,
|
||||
updateToolchains: boolean,
|
||||
toolchainId?: string
|
||||
) {
|
||||
const vendor =
|
||||
|
@ -27,10 +28,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,21 +37,21 @@ export async function configureToolchains(
|
|||
jdkHome
|
||||
},
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
updateToolchains
|
||||
});
|
||||
}
|
||||
|
||||
export async function createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory,
|
||||
overwriteSettings
|
||||
updateToolchains
|
||||
}: {
|
||||
jdkInfo: JdkInfo;
|
||||
settingsDirectory: string;
|
||||
overwriteSettings: boolean;
|
||||
updateToolchains: boolean;
|
||||
}) {
|
||||
core.info(
|
||||
`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
`Adding a toolchain entry in ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`
|
||||
);
|
||||
// when an alternate m2 location is specified use only that location (no .m2 directory)
|
||||
// otherwise use the home/.m2/ path
|
||||
|
@ -72,7 +69,7 @@ export async function createToolchainsSettings({
|
|||
await writeToolchainsFileToDisk(
|
||||
settingsDirectory,
|
||||
updatedToolchains,
|
||||
overwriteSettings
|
||||
updateToolchains
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -147,17 +144,17 @@ async function readExistingToolchainsFile(directory: string) {
|
|||
async function writeToolchainsFileToDisk(
|
||||
directory: string,
|
||||
settings: string,
|
||||
overwriteSettings: boolean
|
||||
updateToolchains: boolean
|
||||
) {
|
||||
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
|
||||
const settingsExists = fs.existsSync(location);
|
||||
if (settingsExists && overwriteSettings) {
|
||||
core.info(`Overwriting existing file ${location}`);
|
||||
} else if (!settingsExists) {
|
||||
core.info(`Writing to ${location}`);
|
||||
const toolchainsExists = fs.existsSync(location);
|
||||
if (toolchainsExists && updateToolchains) {
|
||||
core.info(`Updating existing file ${location}`);
|
||||
} else if (!toolchainsExists) {
|
||||
core.info(`Creating file ${location}`);
|
||||
} else {
|
||||
core.info(
|
||||
`Skipping generation of ${location} because file already exists and overwriting is not enabled`
|
||||
`Skipping update of ${location} since file already exists and updating is not enabled`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue