mirror of
https://gitea.com/actions/setup-java.git
synced 2025-05-10 17:56:53 +08:00
rafactor: using xmlbuilder2 instead of regex
This commit is contained in:
parent
6abf828e83
commit
bc6665734d
35106
dist/cleanup/index.js
vendored
35106
dist/cleanup/index.js
vendored
File diff suppressed because it is too large
Load Diff
27
dist/setup/index.js
vendored
27
dist/setup/index.js
vendored
@ -105361,6 +105361,7 @@ const cache = __importStar(__nccwpck_require__(7799));
|
|||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const tc = __importStar(__nccwpck_require__(7784));
|
const tc = __importStar(__nccwpck_require__(7784));
|
||||||
const constants_1 = __nccwpck_require__(9042);
|
const constants_1 = __nccwpck_require__(9042);
|
||||||
|
const xmlbuilder2_1 = __nccwpck_require__(151);
|
||||||
function getTempDir() {
|
function getTempDir() {
|
||||||
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
|
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
|
||||||
return tempDirectory;
|
return tempDirectory;
|
||||||
@ -105489,37 +105490,37 @@ function parseJavaVersionFile(content) {
|
|||||||
}
|
}
|
||||||
return fileContent;
|
return fileContent;
|
||||||
}
|
}
|
||||||
function parsePomXmlFile(xmlFile) {
|
function parsePomXmlFile(xmlFileAsString) {
|
||||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||||
for (var definitionType of versionDefinitionTypes) {
|
for (var definitionType of versionDefinitionTypes) {
|
||||||
var version = definitionType(xmlFile);
|
var version = definitionType(xmlbuilder2_1.create(xmlFileAsString));
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
function getByMavenCompilerSpecification(xmlFile) {
|
function getByMavenCompilerSpecification(xmlDoc) {
|
||||||
const possibleTagsRegex = [
|
const possibleTagsRegex = [
|
||||||
'<maven\.compiler\.source>(.*?)<\/maven\.compiler\.source>',
|
'maven.compiler.source',
|
||||||
'<maven.compiler.release>(.*?)<\/maven.compiler.release>',
|
'maven.compiler.release',
|
||||||
];
|
];
|
||||||
for (var tag of possibleTagsRegex) {
|
for (var tag of possibleTagsRegex) {
|
||||||
const version = getVersionByTagName(xmlFile, tag);
|
const version = getVersionByTagName(xmlDoc, tag);
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
function getBySpringBootSpecification(xmlFile) {
|
function getBySpringBootSpecification(xmlDoc) {
|
||||||
return getVersionByTagName(xmlFile, '<java.version>(.*?)<\/java.version>');
|
return getVersionByTagName(xmlDoc, 'java.version');
|
||||||
}
|
}
|
||||||
function getVersionByTagName(xmlFile, regex) {
|
function getVersionByTagName(xmlDoc, tag) {
|
||||||
const match = xmlFile.match(new RegExp(regex));
|
const match = xmlDoc.find(n => n.node.nodeName === tag);
|
||||||
if (match) {
|
if (match !== undefined) {
|
||||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`);
|
||||||
return match[1];
|
return match.first().toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
28
src/util.ts
28
src/util.ts
@ -7,6 +7,8 @@ import * as core from '@actions/core';
|
|||||||
|
|
||||||
import * as tc from '@actions/tool-cache';
|
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 { XMLBuilder } from 'xmlbuilder2/lib/interfaces';
|
||||||
|
|
||||||
export function getTempDir() {
|
export function getTempDir() {
|
||||||
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
let tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
|
||||||
@ -155,11 +157,11 @@ function parseJavaVersionFile(content: string): string | null {
|
|||||||
return fileContent;
|
return fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parsePomXmlFile(xmlFile: string): string | null {
|
function parsePomXmlFile(xmlFileAsString: string): string | null {
|
||||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||||
|
|
||||||
for (var definitionType of versionDefinitionTypes) {
|
for (var definitionType of versionDefinitionTypes) {
|
||||||
var version = definitionType(xmlFile);
|
var version = definitionType(create(xmlFileAsString));
|
||||||
|
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
@ -169,14 +171,14 @@ function parsePomXmlFile(xmlFile: string): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getByMavenCompilerSpecification(xmlFile: string): string | null {
|
function getByMavenCompilerSpecification(xmlDoc: XMLBuilder): string | null {
|
||||||
const possibleTagsRegex = [
|
const possibleTagsRegex = [
|
||||||
'<maven\.compiler\.source>(.*?)<\/maven\.compiler\.source>',
|
'maven.compiler.source',
|
||||||
'<maven.compiler.release>(.*?)<\/maven.compiler.release>',
|
'maven.compiler.release',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var tag of possibleTagsRegex) {
|
for (var tag of possibleTagsRegex) {
|
||||||
const version = getVersionByTagName(xmlFile, tag);
|
const version = getVersionByTagName(xmlDoc, tag);
|
||||||
|
|
||||||
if (version !== null) {
|
if (version !== null) {
|
||||||
return version;
|
return version;
|
||||||
@ -186,16 +188,16 @@ function getByMavenCompilerSpecification(xmlFile: string): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBySpringBootSpecification(xmlFile: string): string | null {
|
function getBySpringBootSpecification(xmlDoc: XMLBuilder): string | null {
|
||||||
return getVersionByTagName(xmlFile, '<java.version>(.*?)<\/java.version>');
|
return getVersionByTagName(xmlDoc, 'java.version');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVersionByTagName(xmlFile: string, regex: string): string | null {
|
function getVersionByTagName(xmlDoc: XMLBuilder, tag: string): string | null {
|
||||||
const match = xmlFile.match(new RegExp(regex));
|
const match = xmlDoc.find(n => n.node.nodeName === tag);
|
||||||
|
|
||||||
if (match) {
|
if (match !== undefined) {
|
||||||
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
|
core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`);
|
||||||
return match[1];
|
return match.first().toString();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user