mirror of
https://github.com/actions/setup-java.git
synced 2026-06-29 16:42:36 +00:00
Compare commits
No commits in common. "c8dd9f9d18e88a7e1c1a8a52733a8450b7be28b1" and "f5e27775fa693fb30602e87692cbf6b3542e0703" have entirely different histories.
c8dd9f9d18
...
f5e27775fa
84
.github/workflows/e2e-versions.yml
vendored
84
.github/workflows/e2e-versions.yml
vendored
@ -469,6 +469,7 @@ jobs:
|
|||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-java-version-from-pom-maven-compiler-plugin-configuration:
|
setup-java-version-from-pom-maven-compiler-plugin-configuration:
|
||||||
name: ${{ matrix.distribution }} version from pom.xml - ${{ matrix.os }}
|
name: ${{ matrix.distribution }} version from pom.xml - ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@ -512,86 +513,3 @@ jobs:
|
|||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
setup-java-version-from-build-gradle-java-library-plugin-specification:
|
|
||||||
name: ${{ matrix.distribution }} version from build.gradle - ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
|
||||||
distribution: ['adopt', 'zulu', 'liberica']
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Create build.gradle file
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "java {" > build.gradle
|
|
||||||
echo " toolchain {" >> build.gradle
|
|
||||||
echo " languageVersion.set(JavaLanguageVersion.of(11))" >> build.gradle
|
|
||||||
echo " }" >> build.gradle
|
|
||||||
echo "}" >> build.gradle
|
|
||||||
- name: setup-java
|
|
||||||
uses: ./
|
|
||||||
id: setup-java
|
|
||||||
with:
|
|
||||||
distribution: ${{ matrix.distribution }}
|
|
||||||
java-version-file: 'build.gradle'
|
|
||||||
- name: Verify Java
|
|
||||||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
setup-java-version-from-build-gradle-java-plugin-source-compatibility-specification:
|
|
||||||
name: ${{ matrix.distribution }} version from build.gradle - ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
|
||||||
distribution: ['adopt', 'zulu', 'liberica']
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Create pom.xml file
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "java {" > build.gradle
|
|
||||||
echo " sourceCompatibility = JavaVersion.VERSION_1_8" >> build.gradle
|
|
||||||
echo " targetCompatibility = JavaVersion.VERSION_1_8" >> build.gradle
|
|
||||||
echo "}" >> build.gradle
|
|
||||||
- name: setup-java
|
|
||||||
uses: ./
|
|
||||||
id: setup-java
|
|
||||||
with:
|
|
||||||
distribution: ${{ matrix.distribution }}
|
|
||||||
java-version-file: 'build.gradle'
|
|
||||||
- name: Verify Java
|
|
||||||
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
setup-java-version-from-build-gradle-java-plugin-target-compatibility-specification:
|
|
||||||
name: ${{ matrix.distribution }} version from build.gradle - ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
|
||||||
distribution: ['adopt', 'zulu', 'liberica']
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Create pom.xml file
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "java {" > build.gradle
|
|
||||||
echo " targetCompatibility = JavaVersion.VERSION_21" >> build.gradle
|
|
||||||
echo "}" >> build.gradle
|
|
||||||
- name: setup-java
|
|
||||||
uses: ./
|
|
||||||
id: setup-java
|
|
||||||
with:
|
|
||||||
distribution: ${{ matrix.distribution }}
|
|
||||||
java-version-file: 'build.gradle'
|
|
||||||
- name: Verify Java
|
|
||||||
run: bash __tests__/verify-java.sh "21" "${{ steps.setup-java.outputs.path }}"
|
|
||||||
shell: bash
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ This action allows you to work with Java and Scala projects.
|
|||||||
|
|
||||||
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
|
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
|
||||||
|
|
||||||
- `java-version-file`: The path to the `.java-version` or `pom.xml` or `build.gradle` file. See more details in [about `.java-version` file](docs/advanced-usage.md#Java-version-file).
|
- `java-version-file`: The path to the `.java-version` file. See more details in [about `.java-version` file](docs/advanced-usage.md#Java-version-file).
|
||||||
|
|
||||||
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
|
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
|
||||||
|
|
||||||
|
|||||||
79
dist/cleanup/index.js
vendored
79
dist/cleanup/index.js
vendored
@ -103695,7 +103695,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getVersionFromFile = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
@ -103791,27 +103791,24 @@ function isCacheFeatureAvailable() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFile(fileName, content, distributionName) {
|
function getVersionFromFileContent(fileName, content, distributionName) {
|
||||||
var _a;
|
var _a;
|
||||||
let parsedVersion = null;
|
let fileContent = null;
|
||||||
core.debug(`Getting version from: '${fileName}'`);
|
core.debug(`Getting version from: '${fileName}'`);
|
||||||
if (fileName.includes('.java-version')) {
|
if (fileName.includes('.java-version')) {
|
||||||
parsedVersion = parseJavaVersionFile(content);
|
fileContent = parseJavaVersionFile(content);
|
||||||
}
|
}
|
||||||
else if (fileName.includes('pom.xml')) {
|
else if (fileName.includes('pom.xml')) {
|
||||||
parsedVersion = parsePomXmlFile(content);
|
fileContent = parsePomXmlFile(content);
|
||||||
}
|
|
||||||
else if (fileName.includes('build.gradle')) {
|
|
||||||
parsedVersion = parseBuildGradleFile(content);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error(`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`);
|
throw new Error(`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`);
|
||||||
}
|
}
|
||||||
if (!parsedVersion) {
|
if (!fileContent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
core.debug(`Version from file '${parsedVersion}'`);
|
core.debug(`Version from file '${fileContent}'`);
|
||||||
const tentativeVersion = avoidOldNotation(parsedVersion);
|
const tentativeVersion = avoidOldNotation(fileContent);
|
||||||
const rawVersion = tentativeVersion.split('-')[0];
|
const rawVersion = tentativeVersion.split('-')[0];
|
||||||
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
||||||
core.debug(`Range version from file is '${version}'`);
|
core.debug(`Range version from file is '${version}'`);
|
||||||
@ -103824,7 +103821,7 @@ function getVersionFromFile(fileName, content, distributionName) {
|
|||||||
}
|
}
|
||||||
return version.toString();
|
return version.toString();
|
||||||
}
|
}
|
||||||
exports.getVersionFromFile = getVersionFromFile;
|
exports.getVersionFromFileContent = getVersionFromFileContent;
|
||||||
function parseJavaVersionFile(content) {
|
function parseJavaVersionFile(content) {
|
||||||
var _a, _b, _c, _d;
|
var _a, _b, _c, _d;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
||||||
@ -103852,8 +103849,11 @@ function parsePomXmlFile(xmlFileAsString) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
function getByMavenProperties(xmlDoc) {
|
function getByMavenProperties(xmlDoc) {
|
||||||
const versionTags = ['maven.compiler.source', 'maven.compiler.release'];
|
const possibleTagsRegex = [
|
||||||
for (const tag of versionTags) {
|
'maven.compiler.source',
|
||||||
|
'maven.compiler.release',
|
||||||
|
];
|
||||||
|
for (var tag of possibleTagsRegex) {
|
||||||
const version = getVersionByTagName(xmlDoc, tag);
|
const version = getVersionByTagName(xmlDoc, tag);
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
@ -103878,32 +103878,29 @@ function getByMavenCompilerPluginConfig(xmlDoc) {
|
|||||||
var _a;
|
var _a;
|
||||||
const source = xmlDoc.find(n => {
|
const source = xmlDoc.find(n => {
|
||||||
// Find <source> node
|
// Find <source> node
|
||||||
if (n.node.nodeName !== 'source') {
|
if (n.node.nodeName !== "source") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (n.node.childNodes.length !== 1) {
|
if (n.node.childNodes.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Must be within <configuration>
|
// Must be within <configuration>
|
||||||
if (n.up().node.nodeName !== 'configuration') {
|
if (n.up().node.nodeName !== "configuration") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Which must be inside <plugin>
|
// Which must be inside <plugin>
|
||||||
if (n.up().up().node.nodeName !== 'plugin') {
|
if (n.up().up().node.nodeName !== "plugin") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Make sure the plugin is maven-compiler-plugin
|
// Make sure the plugin is maven-compiler-plugin
|
||||||
const isCompilerPlugin = n
|
const isCompilerPlugin = n.up().up().some(c => {
|
||||||
.up()
|
if (c.node.nodeName !== "artifactId") {
|
||||||
.up()
|
|
||||||
.some(c => {
|
|
||||||
if (c.node.nodeName !== 'artifactId') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (c.node.childNodes.length !== 1) {
|
if (c.node.childNodes.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return c.first().toString() === 'maven-compiler-plugin';
|
return c.first().toString() === "maven-compiler-plugin";
|
||||||
}, false, true);
|
}, false, true);
|
||||||
if (!isCompilerPlugin) {
|
if (!isCompilerPlugin) {
|
||||||
return false;
|
return false;
|
||||||
@ -103912,42 +103909,6 @@ function getByMavenCompilerPluginConfig(xmlDoc) {
|
|||||||
});
|
});
|
||||||
return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
||||||
}
|
}
|
||||||
function parseBuildGradleFile(buildGradle) {
|
|
||||||
const versionDefinitionTypes = [getByJavaLibraryPlugin, getByJavaPlugin];
|
|
||||||
for (const definitionType of versionDefinitionTypes) {
|
|
||||||
const version = definitionType(buildGradle);
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
function getByJavaLibraryPlugin(buildGradle) {
|
|
||||||
return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))');
|
|
||||||
}
|
|
||||||
function getByJavaPlugin(buildGradle) {
|
|
||||||
const possibleRegex = [
|
|
||||||
'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)',
|
|
||||||
'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)'
|
|
||||||
];
|
|
||||||
for (var regex of possibleRegex) {
|
|
||||||
const version = getVersionByRegex(buildGradle, regex);
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
function getVersionByRegex(content, regex) {
|
|
||||||
const match = content.match(new RegExp(regex));
|
|
||||||
if (match) {
|
|
||||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
|
||||||
return match[1];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||||
function avoidOldNotation(content) {
|
function avoidOldNotation(content) {
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
return content.startsWith('1.') ? content.substring(2) : content;
|
||||||
|
|||||||
81
dist/setup/index.js
vendored
81
dist/setup/index.js
vendored
@ -105104,7 +105104,7 @@ function run() {
|
|||||||
.readFileSync(versionFile)
|
.readFileSync(versionFile)
|
||||||
.toString()
|
.toString()
|
||||||
.trim();
|
.trim();
|
||||||
const version = util_1.getVersionFromFile(versionFile, content, distributionName);
|
const version = util_1.getVersionFromFileContent(versionFile, content, distributionName);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||||
@ -105352,7 +105352,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getVersionFromFile = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
exports.getVersionFromFileContent = exports.isCacheFeatureAvailable = exports.isGhes = exports.isJobStatusSuccess = exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getBooleanInput = exports.getTempDir = void 0;
|
||||||
const os_1 = __importDefault(__nccwpck_require__(2037));
|
const os_1 = __importDefault(__nccwpck_require__(2037));
|
||||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
@ -105448,27 +105448,24 @@ function isCacheFeatureAvailable() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFile(fileName, content, distributionName) {
|
function getVersionFromFileContent(fileName, content, distributionName) {
|
||||||
var _a;
|
var _a;
|
||||||
let parsedVersion = null;
|
let fileContent = null;
|
||||||
core.debug(`Getting version from: '${fileName}'`);
|
core.debug(`Getting version from: '${fileName}'`);
|
||||||
if (fileName.includes('.java-version')) {
|
if (fileName.includes('.java-version')) {
|
||||||
parsedVersion = parseJavaVersionFile(content);
|
fileContent = parseJavaVersionFile(content);
|
||||||
}
|
}
|
||||||
else if (fileName.includes('pom.xml')) {
|
else if (fileName.includes('pom.xml')) {
|
||||||
parsedVersion = parsePomXmlFile(content);
|
fileContent = parsePomXmlFile(content);
|
||||||
}
|
|
||||||
else if (fileName.includes('build.gradle')) {
|
|
||||||
parsedVersion = parseBuildGradleFile(content);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error(`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`);
|
throw new Error(`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`);
|
||||||
}
|
}
|
||||||
if (!parsedVersion) {
|
if (!fileContent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
core.debug(`Version from file '${parsedVersion}'`);
|
core.debug(`Version from file '${fileContent}'`);
|
||||||
const tentativeVersion = avoidOldNotation(parsedVersion);
|
const tentativeVersion = avoidOldNotation(fileContent);
|
||||||
const rawVersion = tentativeVersion.split('-')[0];
|
const rawVersion = tentativeVersion.split('-')[0];
|
||||||
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
||||||
core.debug(`Range version from file is '${version}'`);
|
core.debug(`Range version from file is '${version}'`);
|
||||||
@ -105481,7 +105478,7 @@ function getVersionFromFile(fileName, content, distributionName) {
|
|||||||
}
|
}
|
||||||
return version.toString();
|
return version.toString();
|
||||||
}
|
}
|
||||||
exports.getVersionFromFile = getVersionFromFile;
|
exports.getVersionFromFileContent = getVersionFromFileContent;
|
||||||
function parseJavaVersionFile(content) {
|
function parseJavaVersionFile(content) {
|
||||||
var _a, _b, _c, _d;
|
var _a, _b, _c, _d;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
const javaVersionRegExp = /(?<version>(?<=(^|\s|\-))(\d+\S*))(\s|$)/;
|
||||||
@ -105509,8 +105506,11 @@ function parsePomXmlFile(xmlFileAsString) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
function getByMavenProperties(xmlDoc) {
|
function getByMavenProperties(xmlDoc) {
|
||||||
const versionTags = ['maven.compiler.source', 'maven.compiler.release'];
|
const possibleTagsRegex = [
|
||||||
for (const tag of versionTags) {
|
'maven.compiler.source',
|
||||||
|
'maven.compiler.release',
|
||||||
|
];
|
||||||
|
for (var tag of possibleTagsRegex) {
|
||||||
const version = getVersionByTagName(xmlDoc, tag);
|
const version = getVersionByTagName(xmlDoc, tag);
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
@ -105535,32 +105535,29 @@ function getByMavenCompilerPluginConfig(xmlDoc) {
|
|||||||
var _a;
|
var _a;
|
||||||
const source = xmlDoc.find(n => {
|
const source = xmlDoc.find(n => {
|
||||||
// Find <source> node
|
// Find <source> node
|
||||||
if (n.node.nodeName !== 'source') {
|
if (n.node.nodeName !== "source") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (n.node.childNodes.length !== 1) {
|
if (n.node.childNodes.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Must be within <configuration>
|
// Must be within <configuration>
|
||||||
if (n.up().node.nodeName !== 'configuration') {
|
if (n.up().node.nodeName !== "configuration") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Which must be inside <plugin>
|
// Which must be inside <plugin>
|
||||||
if (n.up().up().node.nodeName !== 'plugin') {
|
if (n.up().up().node.nodeName !== "plugin") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Make sure the plugin is maven-compiler-plugin
|
// Make sure the plugin is maven-compiler-plugin
|
||||||
const isCompilerPlugin = n
|
const isCompilerPlugin = n.up().up().some(c => {
|
||||||
.up()
|
if (c.node.nodeName !== "artifactId") {
|
||||||
.up()
|
|
||||||
.some(c => {
|
|
||||||
if (c.node.nodeName !== 'artifactId') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (c.node.childNodes.length !== 1) {
|
if (c.node.childNodes.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return c.first().toString() === 'maven-compiler-plugin';
|
return c.first().toString() === "maven-compiler-plugin";
|
||||||
}, false, true);
|
}, false, true);
|
||||||
if (!isCompilerPlugin) {
|
if (!isCompilerPlugin) {
|
||||||
return false;
|
return false;
|
||||||
@ -105569,42 +105566,6 @@ function getByMavenCompilerPluginConfig(xmlDoc) {
|
|||||||
});
|
});
|
||||||
return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
||||||
}
|
}
|
||||||
function parseBuildGradleFile(buildGradle) {
|
|
||||||
const versionDefinitionTypes = [getByJavaLibraryPlugin, getByJavaPlugin];
|
|
||||||
for (const definitionType of versionDefinitionTypes) {
|
|
||||||
const version = definitionType(buildGradle);
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
function getByJavaLibraryPlugin(buildGradle) {
|
|
||||||
return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))');
|
|
||||||
}
|
|
||||||
function getByJavaPlugin(buildGradle) {
|
|
||||||
const possibleRegex = [
|
|
||||||
'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)',
|
|
||||||
'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)'
|
|
||||||
];
|
|
||||||
for (var regex of possibleRegex) {
|
|
||||||
const version = getVersionByRegex(buildGradle, regex);
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
function getVersionByRegex(content, regex) {
|
|
||||||
const match = content.match(new RegExp(regex));
|
|
||||||
if (match) {
|
|
||||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
|
||||||
return match[1];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||||
function avoidOldNotation(content) {
|
function avoidOldNotation(content) {
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
return content.startsWith('1.') ? content.substring(2) : content;
|
||||||
|
|||||||
@ -485,8 +485,4 @@ It is able to parse the following files as `java-version-file`:
|
|||||||
- Maven compiler plugin
|
- Maven compiler plugin
|
||||||
- Setting the [source](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html).
|
- Setting the [source](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html).
|
||||||
- Setting the [release](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html).
|
- Setting the [release](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html).
|
||||||
- `build.gradle`
|
- **Note:** Since we are using a RegExp to find the java version, it doesn't grab the values from the tags `source` or `release` on `maven-compiler-plugin`.
|
||||||
- Java library plugin: uses what is defined by `JavaLanguageVersion` example: `JavaLanguageVersion.of(11)`
|
|
||||||
- Java plugin [docs](https://docs.gradle.org/current/userguide/java_plugin.html#toolchain_and_compatibility):
|
|
||||||
- sourceCompatibility
|
|
||||||
- targetCompatibility
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as auth from './auth';
|
import * as auth from './auth';
|
||||||
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFile } from './util';
|
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFileContent } from './util';
|
||||||
import * as toolchains from './toolchains';
|
import * as toolchains from './toolchains';
|
||||||
import * as constants from './constants';
|
import * as constants from './constants';
|
||||||
import { restore } from './cache';
|
import { restore } from './cache';
|
||||||
@ -47,7 +47,7 @@ async function run() {
|
|||||||
.toString()
|
.toString()
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
const version = getVersionFromFile(versionFile, content, distributionName);
|
const version = getVersionFromFileContent(versionFile, content, distributionName);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
|
|||||||
102
src/util.ts
102
src/util.ts
@ -9,7 +9,6 @@ import * as tc from '@actions/tool-cache';
|
|||||||
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
||||||
import { create } from 'xmlbuilder2';
|
import { create } from 'xmlbuilder2';
|
||||||
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
||||||
import { on } from 'events';
|
|
||||||
|
|
||||||
export function getTempDir() {
|
export function getTempDir() {
|
||||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||||
@ -103,33 +102,31 @@ export function isCacheFeatureAvailable(): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getVersionFromFile(
|
export function getVersionFromFileContent(
|
||||||
fileName: string,
|
fileName: string,
|
||||||
content: string,
|
content: string,
|
||||||
distributionName: string
|
distributionName: string
|
||||||
): string | null {
|
): string | null {
|
||||||
let parsedVersion = null;
|
let fileContent = null;
|
||||||
|
|
||||||
core.debug(`Getting version from: '${fileName}'`);
|
core.debug(`Getting version from: '${fileName}'`);
|
||||||
if (fileName.includes('.java-version')) {
|
if (fileName.includes('.java-version')) {
|
||||||
parsedVersion = parseJavaVersionFile(content);
|
fileContent = parseJavaVersionFile(content);
|
||||||
} else if (fileName.includes('pom.xml')) {
|
} else if (fileName.includes('pom.xml')) {
|
||||||
parsedVersion = parsePomXmlFile(content);
|
fileContent = parsePomXmlFile(content);
|
||||||
} else if (fileName.includes('build.gradle')) {
|
|
||||||
parsedVersion = parseBuildGradleFile(content);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`
|
`File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parsedVersion) {
|
if (!fileContent) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Version from file '${parsedVersion}'`);
|
core.debug(`Version from file '${fileContent}'`);
|
||||||
|
|
||||||
const tentativeVersion = avoidOldNotation(parsedVersion);
|
const tentativeVersion = avoidOldNotation(fileContent);
|
||||||
const rawVersion = tentativeVersion.split('-')[0];
|
const rawVersion = tentativeVersion.split('-')[0];
|
||||||
|
|
||||||
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
||||||
@ -180,9 +177,12 @@ function parsePomXmlFile(xmlFileAsString: string): string | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getByMavenProperties(xmlDoc: XMLBuilder): string | null {
|
function getByMavenProperties(xmlDoc: XMLBuilder): string | null {
|
||||||
const versionTags = ['maven.compiler.source', 'maven.compiler.release'];
|
const possibleTagsRegex = [
|
||||||
|
'maven.compiler.source',
|
||||||
|
'maven.compiler.release',
|
||||||
|
];
|
||||||
|
|
||||||
for (const tag of versionTags) {
|
for (var tag of possibleTagsRegex) {
|
||||||
const version = getVersionByTagName(xmlDoc, tag);
|
const version = getVersionByTagName(xmlDoc, tag);
|
||||||
|
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
@ -206,42 +206,36 @@ function getVersionByTagName(xmlDoc: XMLBuilder, tag: string): string | null {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getByMavenCompilerPluginConfig(xmlDoc: XMLBuilder): string | null {
|
function getByMavenCompilerPluginConfig(xmlDoc: XMLBuilder): string | null {
|
||||||
const source = xmlDoc.find(n => {
|
const source = xmlDoc.find(n => {
|
||||||
// Find <source> node
|
// Find <source> node
|
||||||
if (n.node.nodeName !== 'source') {
|
if (n.node.nodeName !== "source") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (n.node.childNodes.length !== 1) {
|
if (n.node.childNodes.length !== 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Must be within <configuration>
|
// Must be within <configuration>
|
||||||
if (n.up().node.nodeName !== 'configuration') {
|
if (n.up().node.nodeName !== "configuration") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Which must be inside <plugin>
|
// Which must be inside <plugin>
|
||||||
if (n.up().up().node.nodeName !== 'plugin') {
|
if (n.up().up().node.nodeName !== "plugin") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Make sure the plugin is maven-compiler-plugin
|
// Make sure the plugin is maven-compiler-plugin
|
||||||
const isCompilerPlugin = n
|
const isCompilerPlugin = n.up().up().some(c => {
|
||||||
.up()
|
if (c.node.nodeName !== "artifactId") {
|
||||||
.up()
|
return false;
|
||||||
.some(
|
}
|
||||||
c => {
|
if (c.node.childNodes.length !== 1) {
|
||||||
if (c.node.nodeName !== 'artifactId') {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
return c.first().toString() === "maven-compiler-plugin";
|
||||||
if (c.node.childNodes.length !== 1) {
|
}, false, true);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return c.first().toString() === 'maven-compiler-plugin';
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
if (!isCompilerPlugin) {
|
if (!isCompilerPlugin) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -252,52 +246,6 @@ function getByMavenCompilerPluginConfig(xmlDoc: XMLBuilder): string | null {
|
|||||||
return source?.first().toString() ?? null;
|
return source?.first().toString() ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBuildGradleFile(buildGradle: string): any {
|
|
||||||
const versionDefinitionTypes = [getByJavaLibraryPlugin, getByJavaPlugin];
|
|
||||||
|
|
||||||
for (const definitionType of versionDefinitionTypes) {
|
|
||||||
const version = definitionType(buildGradle);
|
|
||||||
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getByJavaLibraryPlugin(buildGradle: string) {
|
|
||||||
return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getByJavaPlugin(buildGradle: string) {
|
|
||||||
const possibleRegex = [
|
|
||||||
'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)',
|
|
||||||
'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)'
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var regex of possibleRegex) {
|
|
||||||
const version = getVersionByRegex(buildGradle, regex);
|
|
||||||
|
|
||||||
if (version !== null) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVersionByRegex(content: string, regex: string): string | null {
|
|
||||||
const match = content.match(new RegExp(regex));
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
|
||||||
return match[1];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||||
function avoidOldNotation(content: string): string {
|
function avoidOldNotation(content: string): string {
|
||||||
return content.startsWith('1.') ? content.substring(2) : content;
|
return content.startsWith('1.') ? content.substring(2) : content;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user