From fde2f0fa888157b38029b84b71d8dd0d044f39e0 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 12 Mar 2021 17:46:54 +0300 Subject: [PATCH] make java-version and distribution required for action --- action.yml | 4 +-- dist/setup/index.js | 49 ++++++++++++----------------- src/auth.ts | 8 +---- src/distributions/base-installer.ts | 2 +- src/distributions/base-models.ts | 2 +- src/setup-java.ts | 48 ++++++++++++---------------- 6 files changed, 45 insertions(+), 68 deletions(-) diff --git a/action.yml b/action.yml index 1d0863a2..df59abdc 100644 --- a/action.yml +++ b/action.yml @@ -5,10 +5,10 @@ author: 'GitHub' inputs: java-version: description: 'The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file' - required: false + required: true distribution: description: 'Java distribution. See the list of supported distributions in README file' - required: false + required: true java-package: description: 'The package type (jdk, jre, jdk+fx, jre+fx)' required: false diff --git a/dist/setup/index.js b/dist/setup/index.js index 6202df80..bd0168df 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -3963,7 +3963,7 @@ class JavaBase { maxRetries: 3 }); ({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version)); - this.architecture = installerOptions.arch; + this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; } setupJava() { @@ -13281,11 +13281,7 @@ function configureAuthentication() { exports.configureAuthentication = configureAuthentication; function createAuthenticationSettings(id, username, password, gpgPassphrase = undefined) { return __awaiter(this, void 0, void 0, function* () { - core.info(`Creating ${exports.SETTINGS_FILE} with server-id: ${id}; - environment variables: - username=\$${username}, - password=\$${password}, - and gpg-passphrase=${gpgPassphrase ? '$' + gpgPassphrase : null}`); + core.info(`Creating ${exports.SETTINGS_FILE} with server-id: ${id}`); // when an alternate m2 location is specified use only that location (no .m2 directory) // otherwise use the home/.m2/ path const settingsDirectory = path.join(core.getInput(constants.INPUT_SETTINGS_PATH) || os.homedir(), core.getInput(constants.INPUT_SETTINGS_PATH) ? '' : exports.M2_DIR); @@ -35640,32 +35636,27 @@ const distribution_factory_1 = __webpack_require__(24); function run() { return __awaiter(this, void 0, void 0, function* () { try { - const version = core.getInput(constants.INPUT_JAVA_VERSION); - const arch = core.getInput(constants.INPUT_ARCHITECTURE); - const distributionName = core.getInput(constants.INPUT_DISTRIBUTION); + const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); + const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); - if (version || distributionName) { - if (!version || !distributionName) { - throw new Error(`Both ‘${constants.INPUT_JAVA_VERSION}’ and ‘${constants.INPUT_DISTRIBUTION}’ inputs are required if one of them is specified`); - } - const installerOptions = { - arch, - packageType, - version - }; - const distribution = 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(); - core.info(''); - core.info('Java configuration:'); - core.info(` Distribution: ${distributionName}`); - core.info(` Version: ${result.version}`); - core.info(` Path: ${result.path}`); - core.info(''); + const installerOptions = { + architecture, + packageType, + version + }; + const distribution = 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(); + core.info(''); + core.info('Java configuration:'); + core.info(` Distribution: ${distributionName}`); + core.info(` Version: ${result.version}`); + core.info(` Path: ${result.path}`); + core.info(''); const matchersPath = path.join(__dirname, '..', '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); yield auth.configureAuthentication(); diff --git a/src/auth.ts b/src/auth.ts index c7ebe0d6..30810bb8 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -41,13 +41,7 @@ export async function createAuthenticationSettings( password: string, gpgPassphrase: string | undefined = undefined ) { - core.info( - `Creating ${SETTINGS_FILE} with server-id: ${id}; - environment variables: - username=\$${username}, - password=\$${password}, - and gpg-passphrase=${gpgPassphrase ? '$' + gpgPassphrase : null}` - ); + core.info(`Creating ${SETTINGS_FILE} with server-id: ${id}`); // when an alternate m2 location is specified use only that location (no .m2 directory) // otherwise use the home/.m2/ path const settingsDirectory: string = path.join( diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index e174acbd..8c4698cb 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -22,7 +22,7 @@ export abstract class JavaBase { ({ version: this.version, stable: this.stable } = this.normalizeVersion( installerOptions.version )); - this.architecture = installerOptions.arch; + this.architecture = installerOptions.architecture; this.packageType = installerOptions.packageType; } diff --git a/src/distributions/base-models.ts b/src/distributions/base-models.ts index aa31b154..d7a7af76 100644 --- a/src/distributions/base-models.ts +++ b/src/distributions/base-models.ts @@ -1,6 +1,6 @@ export interface JavaInstallerOptions { version: string; - arch: string; + architecture: string; packageType: string; } diff --git a/src/setup-java.ts b/src/setup-java.ts index c3447653..1641b782 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -8,40 +8,32 @@ import { JavaInstallerOptions } from './distributions/base-models'; async function run() { try { - const version = core.getInput(constants.INPUT_JAVA_VERSION); - const arch = core.getInput(constants.INPUT_ARCHITECTURE); - const distributionName = core.getInput(constants.INPUT_DISTRIBUTION); + const version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); + const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, { required: true }); + const architecture = core.getInput(constants.INPUT_ARCHITECTURE); const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE); const jdkFile = core.getInput(constants.INPUT_JDK_FILE); - if (version || distributionName) { - if (!version || !distributionName) { - throw new Error( - `Both ‘${constants.INPUT_JAVA_VERSION}’ and ‘${constants.INPUT_DISTRIBUTION}’ inputs are required if one of them is specified` - ); - } + const installerOptions: JavaInstallerOptions = { + architecture, + packageType, + version + }; - const installerOptions: JavaInstallerOptions = { - arch, - packageType, - 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(); - - core.info(''); - core.info('Java configuration:'); - core.info(` Distribution: ${distributionName}`); - core.info(` Version: ${result.version}`); - core.info(` Path: ${result.path}`); - core.info(''); + const distribution = getJavaDistribution(distributionName, installerOptions, jdkFile); + if (!distribution) { + throw new Error(`No supported distribution was found for input ${distributionName}`); } + const result = await distribution.setupJava(); + + core.info(''); + core.info('Java configuration:'); + core.info(` Distribution: ${distributionName}`); + core.info(` Version: ${result.version}`); + core.info(` Path: ${result.path}`); + core.info(''); + const matchersPath = path.join(__dirname, '..', '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);