Compare commits

...

8 Commits

Author SHA1 Message Date
Markus Hoffrogge
6571f1177a
Merge 4473697408 into ead9eaa3cf 2025-09-25 01:07:47 +00:00
Markus Hoffrogge
4473697408
Merge branch 'main' into mhoffrog/552_allow_to_add_a_toolchain_only 2025-09-25 03:07:43 +02:00
aparnajyothi-y
ead9eaa3cf
Update Regex to Support All ASDF Versions for the supported distributions in tool-versions File (#767)
* Regex update to fix #719

* Check failures fix

* npm run format, npm run format-check & npm run build

* Regex update

* regex update

* fixed check failures

* updated regex

* regex update for all the versions

* regex and docmentation update

* Regex update

* format and doc update

* doc format update

* npm audit fix

* resolve conflicts

* resolve conflicts

* resolve conflicts

* doc update

* Java version upgrade
2025-09-16 13:23:22 -05:00
Chiranjib Swain
8c57fa3627
Clarify JAVA_HOME and PATH setup in README (#841)
* Update README to clarify JAVA_HOME and PATH setup

* Clarify instructions for setting up multiple JDKs in README
2025-09-16 13:19:02 -05:00
Markus Hoffrogge
48a9cd523f Update compiled dist scripts after re-base to main 2025-09-01 11:33:51 +02:00
Markus Hoffrogge
8e7a4e4ee9 Update from npm run format to fix prettier check
- missed in initial commit
- took re-built dist from GH actions
2025-09-01 11:33:50 +02:00
Markus Hoffrogge
6d93654659 Update README.md 2025-09-01 11:33:50 +02:00
Markus Hoffrogge
890bd33679 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}`
2025-09-01 11:33:50 +02:00
14 changed files with 170 additions and 73 deletions

View File

@ -55,7 +55,13 @@ For information about the latest releases, recent updates, and newly supported d
#### 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`: By default action overwrites the settings.xml and adds a toolchain entry to toolchains.xml. In order to skip generation of settings.xml and skip adding a toolchain entry to toolchains.xml if the according file exists, set this to `false`.
- `update-env-javahome`: By default action updates `env.JAVA_HOME` with the path of java installed. In order to skip update of JAVA_HOME, set this to `false`. The creation of the env variable JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }} is NOT affected by this item. That will be created for any setup.
- `update-env-path`: By default action adds `<java_install_dir>/bin` to `env.PATH`. In order to skip this, set this to `false`.
- `update-toolchains-only`: If set to true, then `overwrite-settings`, `update-env-javahome` and `update-env-path` are propagated to `false` if the specific one is not explicitly configured to `true`. Only a toolchain entry will be added to toolchains.xml. Default is `false`.
- `server-id`: ID of the distributionManagement repository in the pom.xml file. Default is `github`.
@ -244,7 +250,7 @@ jobs:
### Install multiple JDKs
All versions are added to the PATH. The last version will be used and available globally. Other Java versions can be accessed through env variables with such specification as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'.
All configured Java versions are added to the PATH. The last one added to the PATH (i.e., the last JDK set up by this action) will be used as the default and available globally. Other Java versions can be accessed through environment variables such as 'JAVA_HOME_{{ MAJOR_VERSION }}_{{ ARCHITECTURE }}'. To use a specific Java version, set the JAVA_HOME environment variable accordingly and prepend its bin directory to the PATH to ensure it takes priority during execution.
```yaml
steps:
@ -257,6 +263,8 @@ All versions are added to the PATH. The last version will be used and available
15
```
**NOTE:** An alternative option is to use multiple setup-java steps. In this case the behavior can be controlled more granular by making use of the input items `overwrite-settings`, `update-env-javahome`, `update-env-path` and `update-toolchains-only`.
### Using Maven Toolchains
In the example above multiple JDKs are installed for the same job. The result after the last JDK is installed is a Maven Toolchains declaration containing references to all three JDKs. The values for `id`, `version`, and `vendor` of the individual Toolchain entries are the given input values for `distribution` and `java-version` (`vendor` being the combination of `${distribution}_${java-version}`) by default.

View File

@ -43,9 +43,21 @@ 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 "!update-toolchains-only". If explcitly set "true", it will update settings.xml regardless of "update-toolchains-only"'
required: false
default: true
# DO NOT set a default here! The default will be propagated from input 'update-toolchains-only'!
update-toolchains-only:
description: 'Update toolchains.xml only. Default is "false". No update of settings.xml, no update of JAVA_HOME, no adding to PATH by default - unless "overwrite-settings", "update-env-javahome" or "add-to-env-path" are not explicitly set "true"'
required: false
default: false
update-env-javahome:
description: 'Update the JAVA_HOME environment variable. Default is "!update-toolchains-only"'
required: false
# DO NOT set a default here! The default will be propagated from input 'update-toolchains-only'!
add-to-env-path:
description: 'Add "<JDK home>/bin" to the PATH environment variable. Default is "!update-toolchains-only"'
required: false
# DO NOT set a default here! The default will be propagated from input 'update-toolchains-only'!
gpg-private-key:
description: 'GPG private key to import. Default is empty string.'
required: false

View File

@ -94435,7 +94435,7 @@ else {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_ADD_TO_PATH = exports.INPUT_UPDATE_JAVA_HOME = exports.INPUT_UPDATE_TOOLCHAINS_ONLY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
@ -94449,6 +94449,9 @@ exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
exports.INPUT_SETTINGS_PATH = 'settings-path';
exports.INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
exports.INPUT_UPDATE_TOOLCHAINS_ONLY = 'update-toolchains-only';
exports.INPUT_UPDATE_JAVA_HOME = 'update-env-javahome';
exports.INPUT_ADD_TO_PATH = 'add-to-env-path';
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
@ -94704,7 +94707,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;

73
dist/setup/index.js vendored
View File

@ -129275,15 +129275,13 @@ const os = __importStar(__nccwpck_require__(22037));
const xmlbuilder2_1 = __nccwpck_require__(70151);
const constants = __importStar(__nccwpck_require__(69042));
const gpg = __importStar(__nccwpck_require__(23759));
const util_1 = __nccwpck_require__(92629);
function configureAuthentication() {
function configureAuthentication(overwriteSettings) {
return __awaiter(this, void 0, void 0, function* () {
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 = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, true);
const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY) ||
constants.INPUT_DEFAULT_GPG_PRIVATE_KEY;
const gpgPassphrase = core.getInput(constants.INPUT_GPG_PASSPHRASE) ||
@ -129579,7 +129577,7 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_ADD_TO_PATH = exports.INPUT_UPDATE_JAVA_HOME = exports.INPUT_UPDATE_TOOLCHAINS_ONLY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
@ -129593,6 +129591,9 @@ exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
exports.INPUT_SETTINGS_PATH = 'settings-path';
exports.INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
exports.INPUT_UPDATE_TOOLCHAINS_ONLY = 'update-toolchains-only';
exports.INPUT_UPDATE_JAVA_HOME = 'update-env-javahome';
exports.INPUT_ADD_TO_PATH = 'add-to-env-path';
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
@ -129854,6 +129855,8 @@ class JavaBase {
this.architecture = installerOptions.architecture || os_1.default.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.updateEnvJavaHome = installerOptions.updateEnvJavaHome;
this.addToEnvPath = installerOptions.addToEnvPath;
}
setupJava() {
return __awaiter(this, void 0, void 0, function* () {
@ -129978,8 +129981,18 @@ class JavaBase {
}
setJavaDefault(version, toolPath) {
const majorVersion = version.split('.')[0];
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path_1.default.join(toolPath, 'bin'));
if (this.updateEnvJavaHome) {
core.exportVariable('JAVA_HOME', toolPath);
}
else {
core.info(`Skip updating env.JAVA_HOME according to ${constants_1.INPUT_UPDATE_JAVA_HOME}`);
}
if (this.addToEnvPath) {
core.addPath(path_1.default.join(toolPath, 'bin'));
}
else {
core.info(`Skip adding to env.PATH according to ${constants_1.INPUT_ADD_TO_PATH}`);
}
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
@ -132353,6 +132366,10 @@ function run() {
const cache = core.getInput(constants.INPUT_CACHE);
const cacheDependencyPath = core.getInput(constants.INPUT_CACHE_DEPENDENCY_PATH);
const checkLatest = (0, util_1.getBooleanInput)(constants.INPUT_CHECK_LATEST, false);
const updateToolchainsOnly = (0, util_1.getBooleanInput)(constants.INPUT_UPDATE_TOOLCHAINS_ONLY, false);
const overwriteSettings = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, !updateToolchainsOnly);
const updateEnvJavaHome = (0, util_1.getBooleanInput)(constants.INPUT_UPDATE_JAVA_HOME, !updateToolchainsOnly);
const addToEnvPath = (0, util_1.getBooleanInput)(constants.INPUT_ADD_TO_PATH, !updateToolchainsOnly);
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
core.startGroup('Installed distributions');
if (versions.length !== toolchainIds.length) {
@ -132367,7 +132384,11 @@ function run() {
checkLatest,
distributionName,
jdkFile,
toolchainIds
toolchainIds,
updateToolchainsOnly,
overwriteSettings,
updateEnvJavaHome,
addToEnvPath
};
if (!versions.length) {
core.debug('java-version input is empty, looking for java-version-file input');
@ -132385,7 +132406,7 @@ function run() {
core.endGroup();
const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
yield auth.configureAuthentication();
yield auth.configureAuthentication(overwriteSettings);
if (cache && (0, util_1.isCacheFeatureAvailable)()) {
yield (0, cache_1.restore)(cache, cacheDependencyPath);
}
@ -132398,19 +132419,21 @@ function run() {
run();
function installVersion(version, options, toolchainId = 0) {
return __awaiter(this, void 0, void 0, function* () {
const { distributionName, jdkFile, architecture, packageType, checkLatest, toolchainIds } = options;
const { distributionName, jdkFile, architecture, packageType, checkLatest, toolchainIds, updateToolchainsOnly, overwriteSettings, updateEnvJavaHome, addToEnvPath } = options;
const installerOptions = {
version,
architecture,
packageType,
checkLatest,
version
updateEnvJavaHome,
addToEnvPath
};
const distribution = (0, distribution_factory_1.getJavaDistribution)(distributionName, installerOptions, jdkFile);
if (!distribution) {
throw new Error(`No supported distribution was found for input ${distributionName}`);
}
const result = yield distribution.setupJava();
yield toolchains.configureToolchains(version, distributionName, result.path, toolchainIds[toolchainId]);
yield toolchains.configureToolchains(version, distributionName, result.path, overwriteSettings || updateToolchainsOnly, toolchainIds[toolchainId]);
core.info('');
core.info('Java configuration:');
core.info(` Distribution: ${distributionName}`);
@ -132468,15 +132491,13 @@ const path = __importStar(__nccwpck_require__(71017));
const core = __importStar(__nccwpck_require__(42186));
const io = __importStar(__nccwpck_require__(47351));
const constants = __importStar(__nccwpck_require__(69042));
const util_1 = __nccwpck_require__(92629);
const xmlbuilder2_1 = __nccwpck_require__(70151);
function configureToolchains(version, distributionName, jdkHome, toolchainId) {
function configureToolchains(version, distributionName, jdkHome, updateToolchains, toolchainId) {
return __awaiter(this, void 0, void 0, function* () {
const vendor = core.getInput(constants.INPUT_MVN_TOOLCHAIN_VENDOR) || distributionName;
const id = toolchainId || `${vendor}_${version}`;
const settingsDirectory = core.getInput(constants.INPUT_SETTINGS_PATH) ||
path.join(os.homedir(), constants.M2_DIR);
const overwriteSettings = (0, util_1.getBooleanInput)(constants.INPUT_OVERWRITE_SETTINGS, true);
yield createToolchainsSettings({
jdkInfo: {
version,
@ -132485,20 +132506,20 @@ function configureToolchains(version, distributionName, jdkHome, toolchainId) {
jdkHome
},
settingsDirectory,
overwriteSettings
updateToolchains
});
});
}
exports.configureToolchains = configureToolchains;
function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSettings }) {
function createToolchainsSettings({ jdkInfo, settingsDirectory, updateToolchains }) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Creating ${constants.MVN_TOOLCHAINS_FILE} for JDK version ${jdkInfo.version} from ${jdkInfo.vendor}`);
core.info(`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
yield io.mkdirP(settingsDirectory);
const originalToolchains = yield readExistingToolchainsFile(settingsDirectory);
const updatedToolchains = generateToolchainDefinition(originalToolchains, jdkInfo.version, jdkInfo.vendor, jdkInfo.id, jdkInfo.jdkHome);
yield writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, overwriteSettings);
yield writeToolchainsFileToDisk(settingsDirectory, updatedToolchains, updateToolchains);
});
}
exports.createToolchainsSettings = createToolchainsSettings;
@ -132564,18 +132585,18 @@ function readExistingToolchainsFile(directory) {
return '';
});
}
function writeToolchainsFileToDisk(directory, settings, overwriteSettings) {
function writeToolchainsFileToDisk(directory, settings, updateToolchains) {
return __awaiter(this, void 0, void 0, function* () {
const location = path.join(directory, constants.MVN_TOOLCHAINS_FILE);
const settingsExists = fs.existsSync(location);
if (settingsExists && overwriteSettings) {
core.info(`Overwriting existing file ${location}`);
const toolchainsExists = fs.existsSync(location);
if (toolchainsExists && updateToolchains) {
core.info(`Updating existing file ${location}`);
}
else if (!settingsExists) {
core.info(`Writing to ${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`);
core.info(`Skipping update of ${location} since file already exists and updating is not enabled`);
return;
}
return fs.writeFileSync(location, settings, {
@ -132739,7 +132760,7 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;

View File

@ -614,5 +614,9 @@ major versions: 8, 11, 16, 17, 21
more specific versions: 8.0.282+8, 8.0.232, 11.0, 11.0.4, 17.0
early access (EA) versions: 15-ea, 15.0.0-ea
versions with specified distribution: openjdk64-11.0.2
LTS versions : temurin-21.0.5+11.0.LTS
```
If the file contains multiple versions, only the first one will be recognized.
***NOTE***:
For the tool-version file, ensure that you use standard semantic versioning (semver) formats, as non-standard formats (such as jetbrains-21b212.1) may not be parsed correctly. Additionally, for complex version strings containing multiple version-like segments (for example, java semeru-openj9-11.0.15+10_openj9-0.32.0), the extraction logic may incorrectly capture the last segment (0.32.0) instead of the main version (11.0.15+10).

1
package-lock.json generated
View File

@ -1,3 +1,4 @@
{
"name": "setup-java",
"version": "5.0.0",

View File

@ -60,4 +60,4 @@
"url": "https://github.com/actions/setup-java/issues"
},
"homepage": "https://github.com/actions/setup-java#readme"
}
}

View File

@ -10,17 +10,13 @@ import * as constants from './constants';
import * as gpg from './gpg';
import {getBooleanInput} from './util';
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;

View File

@ -11,6 +11,9 @@ 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_UPDATE_TOOLCHAINS_ONLY = 'update-toolchains-only';
export const INPUT_UPDATE_JAVA_HOME = 'update-env-javahome';
export const INPUT_ADD_TO_PATH = 'add-to-env-path';
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
export const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';

View File

@ -10,7 +10,11 @@ import {
JavaInstallerOptions,
JavaInstallerResults
} from './base-models';
import {MACOS_JAVA_CONTENT_POSTFIX} from '../constants';
import {
MACOS_JAVA_CONTENT_POSTFIX,
INPUT_UPDATE_JAVA_HOME,
INPUT_ADD_TO_PATH
} from '../constants';
import os from 'os';
export abstract class JavaBase {
@ -20,6 +24,8 @@ export abstract class JavaBase {
protected packageType: string;
protected stable: boolean;
protected checkLatest: boolean;
protected updateEnvJavaHome: boolean;
protected addToEnvPath: boolean;
constructor(
protected distribution: string,
@ -36,6 +42,8 @@ export abstract class JavaBase {
this.architecture = installerOptions.architecture || os.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.updateEnvJavaHome = installerOptions.updateEnvJavaHome;
this.addToEnvPath = installerOptions.addToEnvPath;
}
protected abstract downloadTool(
@ -185,8 +193,18 @@ export abstract class JavaBase {
protected setJavaDefault(version: string, toolPath: string) {
const majorVersion = version.split('.')[0];
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path.join(toolPath, 'bin'));
if (this.updateEnvJavaHome) {
core.exportVariable('JAVA_HOME', toolPath);
} else {
core.info(
`Skip updating env.JAVA_HOME according to ${INPUT_UPDATE_JAVA_HOME}`
);
}
if (this.addToEnvPath) {
core.addPath(path.join(toolPath, 'bin'));
} else {
core.info(`Skip adding to env.PATH according to ${INPUT_ADD_TO_PATH}`);
}
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);

View File

@ -3,6 +3,8 @@ export interface JavaInstallerOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
updateEnvJavaHome: boolean;
addToEnvPath: boolean;
}
export interface JavaInstallerResults {

View File

@ -13,6 +13,19 @@ import * as path from 'path';
import {getJavaDistribution} from './distributions/distribution-factory';
import {JavaInstallerOptions} from './distributions/base-models';
interface IInstallerInputsOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
distributionName: string;
jdkFile: string;
toolchainIds: Array<string>;
updateToolchainsOnly: boolean;
overwriteSettings: boolean;
updateEnvJavaHome: boolean;
addToEnvPath: boolean;
}
async function run() {
try {
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
@ -28,6 +41,23 @@ async function run() {
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const updateToolchainsOnly = getBooleanInput(
constants.INPUT_UPDATE_TOOLCHAINS_ONLY,
false
);
const overwriteSettings = getBooleanInput(
constants.INPUT_OVERWRITE_SETTINGS,
!updateToolchainsOnly
);
const updateEnvJavaHome = getBooleanInput(
constants.INPUT_UPDATE_JAVA_HOME,
!updateToolchainsOnly
);
const addToEnvPath = getBooleanInput(
constants.INPUT_ADD_TO_PATH,
!updateToolchainsOnly
);
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
core.startGroup('Installed distributions');
@ -40,13 +70,17 @@ async function run() {
throw new Error('java-version or java-version-file input expected');
}
const installerInputsOptions: installerInputsOptions = {
const installerInputsOptions: IInstallerInputsOptions = {
architecture,
packageType,
checkLatest,
distributionName,
jdkFile,
toolchainIds
toolchainIds,
updateToolchainsOnly,
overwriteSettings,
updateEnvJavaHome,
addToEnvPath
};
if (!versions.length) {
@ -78,7 +112,7 @@ async function run() {
const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
await auth.configureAuthentication();
await auth.configureAuthentication(overwriteSettings);
if (cache && isCacheFeatureAvailable()) {
await restore(cache, cacheDependencyPath);
}
@ -91,7 +125,7 @@ run();
async function installVersion(
version: string,
options: installerInputsOptions,
options: IInstallerInputsOptions,
toolchainId = 0
) {
const {
@ -100,14 +134,20 @@ async function installVersion(
architecture,
packageType,
checkLatest,
toolchainIds
toolchainIds,
updateToolchainsOnly,
overwriteSettings,
updateEnvJavaHome,
addToEnvPath
} = options;
const installerOptions: JavaInstallerOptions = {
version,
architecture,
packageType,
checkLatest,
version
updateEnvJavaHome,
addToEnvPath
};
const distribution = getJavaDistribution(
@ -126,6 +166,7 @@ async function installVersion(
version,
distributionName,
result.path,
overwriteSettings || updateToolchainsOnly,
toolchainIds[toolchainId]
);
@ -136,12 +177,3 @@ async function installVersion(
core.info(` Path: ${result.path}`);
core.info('');
}
interface installerInputsOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
distributionName: string;
jdkFile: string;
toolchainIds: Array<string>;
}

View File

@ -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
@ -71,7 +68,7 @@ export async function createToolchainsSettings({
await writeToolchainsFileToDisk(
settingsDirectory,
updatedToolchains,
overwriteSettings
updateToolchains
);
}
@ -146,17 +143,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;
}

View File

@ -133,7 +133,7 @@ export function getVersionFromFileContent(
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}