Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ For more details, see the full release notes on the [releases page](https://git

- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.

- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `!add-toolchain-only`. If explcitly set `true`, it will update JAVA_HOME and PATH regardless of `add-toolchain-only`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.

- `verify-signature`: Verifies downloaded Java package signatures when supported by the selected distribution. Currently supported for `temurin` and `microsoft`. If set to `true` for unsupported distributions, the action fails.

Expand All @@ -58,7 +58,9 @@ For more details, see the full release notes on the [releases page](https://git
#### Maven options
The action has a bunch of inputs to generate maven's [settings.xml](https://maven.apache.org/settings.html) on the fly and pass the values to Apache Maven GPG Plugin as well as Apache Maven Toolchains. See [advanced usage](docs/advanced-usage.md) for more.

- `overwrite-settings`: By default action overwrites the settings.xml. In order to skip generation of file if it exists, set this to `false`.
- `overwrite-settings`: 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`.

- `add-toolchain-only`: 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`.

- `server-id`: ID of the distributionManagement repository in the pom.xml file. Default is `github`.

Expand Down
25 changes: 13 additions & 12 deletions __tests__/toolchains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: altHome,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(false);
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -382,7 +382,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -453,7 +453,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -606,7 +606,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -665,7 +665,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -749,7 +749,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -829,7 +829,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: true
addToolchain: true
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -884,7 +884,7 @@ describe('toolchains tests', () => {
await toolchains.createToolchainsSettings({
jdkInfo,
settingsDirectory: m2Dir,
overwriteSettings: false
addToolchain: false
});

expect(fs.existsSync(m2Dir)).toBe(true);
Expand Down Expand Up @@ -944,6 +944,7 @@ describe('toolchains tests', () => {
version,
distributionName,
jdkHome,
true,
undefined
);

Expand Down
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95845,6 +95845,7 @@ const INPUT_SERVER_USERNAME = 'server-username';
const INPUT_SERVER_PASSWORD = 'server-password';
const INPUT_SETTINGS_PATH = 'settings-path';
const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
const INPUT_ADD_TOOLCHAIN_ONLY = 'add-toolchain-only';
const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
const INPUT_DEFAULT_GPG_PRIVATE_KEY = (/* unused pure expression or super */ null && (undefined));
Expand Down
86 changes: 44 additions & 42 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73290,6 +73290,7 @@ const INPUT_SERVER_USERNAME = 'server-username';
const INPUT_SERVER_PASSWORD = 'server-password';
const INPUT_SETTINGS_PATH = 'settings-path';
const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
const INPUT_ADD_TOOLCHAIN_ONLY = 'add-toolchain-only';
const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
const INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
Expand Down Expand Up @@ -127263,14 +127264,12 @@ async function verifyPackageSignature(archivePath, signatureUrl, publicKeyConten




async function configureAuthentication() {
async function configureAuthentication(overwriteSettings) {
const id = getInput(INPUT_SERVER_ID);
const username = getInput(INPUT_SERVER_USERNAME);
const password = getInput(INPUT_SERVER_PASSWORD);
const settingsDirectory = getInput(INPUT_SETTINGS_PATH) ||
external_path_.join(external_os_.homedir(), M2_DIR);
const overwriteSettings = util_getBooleanInput(INPUT_OVERWRITE_SETTINGS, true);
const gpgPrivateKey = getInput(INPUT_GPG_PRIVATE_KEY) ||
INPUT_DEFAULT_GPG_PRIVATE_KEY;
const gpgPassphrase = getInput(INPUT_GPG_PASSPHRASE) ||
Expand Down Expand Up @@ -127351,13 +127350,11 @@ async function write(directory, settings, overwriteSettings) {




async function configureToolchains(version, distributionName, jdkHome, toolchainId) {
async function configureToolchains(version, distributionName, jdkHome, addToolchain, toolchainId) {
const vendor = getInput(INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
const id = toolchainId || `${vendor}_${version}`;
const settingsDirectory = getInput(INPUT_SETTINGS_PATH) ||
external_path_.join(external_os_.homedir(), M2_DIR);
const overwriteSettings = util_getBooleanInput(INPUT_OVERWRITE_SETTINGS, true);
await createToolchainsSettings({
jdkInfo: {
version,
Expand All @@ -127366,17 +127363,17 @@ async function configureToolchains(version, distributionName, jdkHome, toolchain
jdkHome
},
settingsDirectory,
overwriteSettings
addToolchain
});
}
async function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSettings }) {
async function createToolchainsSettings({ jdkInfo, settingsDirectory, addToolchain }) {
info(`Creating ${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
await mkdirP(settingsDirectory);
const originalToolchains = await readExistingToolchainsFile(settingsDirectory);
const updatedToolchains = generateToolchainDefinition(originalToolchains, jdkInfo.version, jdkInfo.vendor, jdkInfo.id, jdkInfo.jdkHome);
await writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, overwriteSettings);
await writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, addToolchain);
}
// only exported for testing purposes
function generateToolchainDefinition(original, version, vendor, id, jdkHome) {
Expand Down Expand Up @@ -127458,10 +127455,10 @@ async function readExistingToolchainsFile(directory) {
}
return '';
}
async function writeToolchainsFileToDisk(directory, settings, overwriteSettings) {
async function writeToolchainsFileToDisk(directory, settings, addToolchain) {
const location = external_path_.join(directory, MVN_TOOLCHAINS_FILE);
const settingsExists = external_fs_namespaceObject.existsSync(location);
if (settingsExists && overwriteSettings) {
if (settingsExists && addToolchain) {
info(`Overwriting existing file ${location}`);
}
else if (!settingsExists) {
Expand Down Expand Up @@ -133669,7 +133666,9 @@ async function run() {
const cache = getInput(INPUT_CACHE);
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
const addToolchainOnly = util_getBooleanInput(INPUT_ADD_TOOLCHAIN_ONLY, false);
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, !addToolchainOnly);
const overwriteSettings = util_getBooleanInput(INPUT_OVERWRITE_SETTINGS, !addToolchainOnly);
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
let toolchainIds = getMultilineInput(INPUT_MVN_TOOLCHAIN_ID);
Expand Down Expand Up @@ -133697,15 +133696,17 @@ async function run() {
throw new Error('distribution input is required when not specified in the version file');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
setDefault,
verifySignature,
verifySignaturePublicKey,
distributionName,
jdkFile,
toolchainIds
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);
}
Expand All @@ -133715,15 +133716,17 @@ async function run() {
throw new Error('distribution input is required');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
setDefault,
verifySignature,
verifySignaturePublicKey,
distributionName,
jdkFile,
toolchainIds
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()) {
await installVersion(version, installerInputsOptions, index);
Expand All @@ -133732,7 +133735,7 @@ async function run() {
endGroup();
const matchersPath = external_path_.join(external_path_.dirname((0,external_url_.fileURLToPath)(import.meta.url)), '..', '..', '.github');
info(`##[add-matcher]${external_path_.join(matchersPath, 'java.json')}`);
await configureAuthentication();
await configureAuthentication(overwriteSettings);
configureMavenArgs();
if (cache && isCacheFeatureAvailable()) {
await restore(cache, cacheDependencyPath);
Expand All @@ -133752,29 +133755,28 @@ function getJdkFileInput() {
return jdkFile || deprecatedJdkFile;
}
async function installVersion(version, options, toolchainId = 0) {
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
const installerOptions = {
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, installerOptions, jdkFile);
const distribution = getJavaDistribution(options.distributionName, installerOptions, options.jdkFile);
if (!distribution) {
throw new Error(`No supported distribution was found for input ${distributionName}`);
throw new Error(`No supported distribution was found for input ${options.distributionName}`);
}
const result = await distribution.setupJava();
// When the `latest` alias is used, the literal input isn't a real version, so
// pass the resolved version to the toolchains configuration instead.
const isLatest = version.trim().toLowerCase() === 'latest';
const toolchainVersion = isLatest ? result.version : version;
await configureToolchains(toolchainVersion, distributionName, result.path, toolchainIds[toolchainId]);
await configureToolchains(toolchainVersion, options.distributionName, result.path, options.overwriteSettings || options.addToolchainOnly, options.toolchainIds[toolchainId]);
info('');
info('Java configuration:');
info(` Distribution: ${distributionName}`);
info(` Distribution: ${options.distributionName}`);
info(` Version: ${result.version}`);
info(` Path: ${result.path}`);
info('');
Expand Down
Loading