mirror of
https://github.com/actions/setup-java.git
synced 2025-04-19 09:26:46 +00:00
refactor!: removed xpath dependency
This commit is contained in:
parent
00ce31c5e7
commit
6abf828e83
7 changed files with 57 additions and 44939 deletions
87
.github/workflows/e2e-versions.yml
vendored
87
.github/workflows/e2e-versions.yml
vendored
|
@ -469,90 +469,3 @@ jobs:
|
|||
- name: Verify Java
|
||||
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-version-from-pom-maven-compiler-configuration-source-specification:
|
||||
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
|
||||
echo "<project>" >> pom.xml
|
||||
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
|
||||
echo " <groupId>foo.bar</groupId>" >> pom.xml
|
||||
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
|
||||
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
|
||||
echo " <build>" >> pom.xml
|
||||
echo " <plugins>" >> pom.xml
|
||||
echo " <plugin>" >> pom.xml
|
||||
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
|
||||
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
|
||||
echo " <version>3.10.1</version>" >> pom.xml
|
||||
echo " <configuration>" >> pom.xml
|
||||
echo " <source>1.8</source>" >> pom.xml
|
||||
echo " <target>1.8</target>" >> pom.xml
|
||||
echo " </configuration>" >> pom.xml
|
||||
echo " </plugin>" >> pom.xml
|
||||
echo " </plugins>" >> pom.xml
|
||||
echo " </build>" >> pom.xml
|
||||
echo "</project>" >> pom.xml
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
java-version-file: 'pom.xml'
|
||||
- name: Verify Java
|
||||
run: bash __tests__/verify-java.sh "8" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
||||
setup-java-version-from-pom-maven-compiler-configuration-release-specification:
|
||||
name: ${{ matrix.distribution }} version from pom.xml - ${{ 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 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > pom.xml
|
||||
echo "<project>" >> pom.xml
|
||||
echo " <modelVersion>4.0.0</modelVersion>" >> pom.xml
|
||||
echo " <groupId>foo.bar</groupId>" >> pom.xml
|
||||
echo " <artifactId>FooBarr</artifactId>" >> pom.xml
|
||||
echo " <version>0.0.1-SNAPSHOT</version>" >> pom.xml
|
||||
echo " <build>" >> pom.xml
|
||||
echo " <plugins>" >> pom.xml
|
||||
echo " <plugin>" >> pom.xml
|
||||
echo " <groupId>org.apache.maven.plugins</groupId>" >> pom.xml
|
||||
echo " <artifactId>maven-compiler-plugin</artifactId>" >> pom.xml
|
||||
echo " <version>3.10.1</version>" >> pom.xml
|
||||
echo " <configuration>" >> pom.xml
|
||||
echo " <release>11</release>" >> pom.xml
|
||||
echo " </configuration>" >> pom.xml
|
||||
echo " </plugin>" >> pom.xml
|
||||
echo " </plugins>" >> pom.xml
|
||||
echo " </build>" >> pom.xml
|
||||
echo "</project>" >> pom.xml
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
java-version-file: 'pom.xml'
|
||||
- name: Verify Java
|
||||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
||||
shell: bash
|
||||
|
|
39970
dist/cleanup/index.js
vendored
39970
dist/cleanup/index.js
vendored
File diff suppressed because it is too large
Load diff
4891
dist/setup/index.js
vendored
4891
dist/setup/index.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -485,3 +485,4 @@ It is able to parse the following files as `java-version-file`:
|
|||
- Maven compiler plugin
|
||||
- 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).
|
||||
- **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`.
|
||||
|
|
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -3658,11 +3658,6 @@
|
|||
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==",
|
||||
"dev": true
|
||||
},
|
||||
"xpath": {
|
||||
"version": "0.0.32",
|
||||
"resolved": "https://nexus.cicd.intra.oneweb.mercedes-benz.io/repository/npm-general/xpath/-/xpath-0.0.32.tgz",
|
||||
"integrity": "sha512-rxMJhSIoiO8vXcWvSifKqhvV96GjiD5wYb8/QHdoRyQvraTpp4IEv944nhGausZZ3u7dhQXteZuZbaqfpB7uYw=="
|
||||
},
|
||||
"y18n": {
|
||||
"version": "5.0.8",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||
|
|
|
@ -33,8 +33,7 @@
|
|||
"@actions/io": "^1.0.2",
|
||||
"@actions/tool-cache": "^1.6.1",
|
||||
"semver": "^7.3.4",
|
||||
"xmlbuilder2": "^2.4.0",
|
||||
"xpath": "0.0.32"
|
||||
"xmlbuilder2": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
|
|
39
src/util.ts
39
src/util.ts
|
@ -1,15 +1,12 @@
|
|||
import os, { version } from 'os';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import { create as xmlCreate } from 'xmlbuilder2';
|
||||
import { select } from 'xpath';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION } from './constants';
|
||||
import { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
||||
|
||||
export function getTempDir() {
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||
|
@ -158,12 +155,11 @@ function parseJavaVersionFile(content: string): string | null {
|
|||
return fileContent;
|
||||
}
|
||||
|
||||
function parsePomXmlFile(xmlString: string): string | null {
|
||||
const xmlDoc = xmlCreate(xmlString);
|
||||
function parsePomXmlFile(xmlFile: string): string | null {
|
||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||
|
||||
for (var definitionType of versionDefinitionTypes) {
|
||||
var version = definitionType(xmlDoc);
|
||||
var version = definitionType(xmlFile);
|
||||
|
||||
if (version !== null) {
|
||||
return version;
|
||||
|
@ -173,16 +169,14 @@ function parsePomXmlFile(xmlString: string): string | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
function getByMavenCompilerSpecification(xmlDoc: XMLBuilder): string | null {
|
||||
const possibleTags = [
|
||||
'//properties/maven.compiler.source',
|
||||
'//configuration/source',
|
||||
'//properties/maven.compiler.release',
|
||||
'//configuration/release'
|
||||
function getByMavenCompilerSpecification(xmlFile: string): string | null {
|
||||
const possibleTagsRegex = [
|
||||
'<maven\.compiler\.source>(.*?)<\/maven\.compiler\.source>',
|
||||
'<maven.compiler.release>(.*?)<\/maven.compiler.release>',
|
||||
];
|
||||
|
||||
for (var tag of possibleTags) {
|
||||
const version = getVersionByTagName(xmlDoc, tag);
|
||||
for (var tag of possibleTagsRegex) {
|
||||
const version = getVersionByTagName(xmlFile, tag);
|
||||
|
||||
if (version !== null) {
|
||||
return version;
|
||||
|
@ -192,19 +186,20 @@ function getByMavenCompilerSpecification(xmlDoc: XMLBuilder): string | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
function getBySpringBootSpecification(xmlDoc: XMLBuilder): string | null {
|
||||
return getVersionByTagName(xmlDoc, '//properties/java.version');
|
||||
function getBySpringBootSpecification(xmlFile: string): string | null {
|
||||
return getVersionByTagName(xmlFile, '<java.version>(.*?)<\/java.version>');
|
||||
}
|
||||
|
||||
function getVersionByTagName(xmlDoc: XMLBuilder, xpathQuery: string): string | null {
|
||||
const element = select(`string(${xpathQuery})`, xmlDoc.node as any);
|
||||
function getVersionByTagName(xmlFile: string, regex: string): string | null {
|
||||
const match = xmlFile.match(new RegExp(regex));
|
||||
|
||||
core.debug(`Found: '${element}' using xpath query: '${xpathQuery}'`);
|
||||
if (element == undefined || element.length == 0) {
|
||||
if (match) {
|
||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
||||
return match[1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return element.toString();
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue