setup-java/src/setup-java.ts
Kian Cross 42dba1991e Add problem matcher for Checkstyle
This commit adds a problem matcher for Checkstyle to allow
automatic GitHub annotations.

When run through Gradle, an example line is:
```
[ant:checkstyle] [ERROR] /root/Bound.java:7:2: 'import' has incorrect indentation level 1, expected level should be 0. [Indentation]
```

Alternatively, when run standalone, an example output is:
```
[WARN] /root/test.java:2:1: The name of the outer type and the file do not match. [OuterTypeFilename]
```

The regular expression matches both cases.

In the latter example, `WARN`, rather than `WARNING` is output.
This is resolved by using a default severity of `warning`, which
will be overridden in the case that the severity is `ERROR`.
2021-07-20 12:08:03 +01:00

50 lines
1.7 KiB
TypeScript

import * as core from '@actions/core';
import * as auth from './auth';
import { getBooleanInput } from './util';
import * as constants from './constants';
import * as path from 'path';
import { getJavaDistribution } from './distributions/distribution-factory';
import { JavaInstallerOptions } from './distributions/base-models';
async function run() {
try {
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);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const installerOptions: JavaInstallerOptions = {
architecture,
packageType,
version,
checkLatest
};
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')}`);
core.info(`##[add-matcher]${path.join(matchersPath, 'checkstyle.json')}`);
await auth.configureAuthentication();
} catch (error) {
core.setFailed(error.message);
}
}
run();