Skip to content

Commit

Permalink
make java-version and distribution required for action
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Lobanov committed Mar 12, 2021
1 parent c94ef7c commit fde2f0f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 70 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 21 additions & 30 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 1 addition & 7 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/base-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/distributions/base-models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface JavaInstallerOptions {
version: string;
arch: string;
architecture: string;
packageType: string;
}

Expand Down
50 changes: 21 additions & 29 deletions src/setup-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
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 installerOptions: JavaInstallerOptions = {
architecture,
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 matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);

Expand Down

0 comments on commit fde2f0f

Please sign in to comment.