forked from actions/setup-java
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-java.ts
More file actions
56 lines (46 loc) · 1.86 KB
/
setup-java.ts
File metadata and controls
56 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as core from '@actions/core';
import * as auth from './auth';
import * as constants from './constants';
import * as path from 'path';
import { getJavaDistributor } from './distributors/distributor-factory';
import { JavaInstallerOptions } from './distributors/base-models';
// To-Do need check resolving with 4 numbers
// To-Do add check that Java resolves from to toolcache to e2e
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 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 distributor = getJavaDistributor(distributionName, installerOptions, jdkFile);
if (!distributor) {
throw new Error(`No supported distributor was found for input ${distributionName}`);
}
const result = await distributor.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')}`);
await auth.configureAuthentication();
} catch (error) {
core.setFailed(error.message);
}
}
run();