rafactor: using xmlbuilder2 instead of regex

This commit is contained in:
augustomelo 2024-03-04 08:21:00 +00:00
parent 6abf828e83
commit bc6665734d
3 changed files with 35118 additions and 43 deletions

27
dist/setup/index.js vendored
View file

@ -105361,6 +105361,7 @@ const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const tc = __importStar(__nccwpck_require__(7784));
const constants_1 = __nccwpck_require__(9042);
const xmlbuilder2_1 = __nccwpck_require__(151);
function getTempDir() {
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
return tempDirectory;
@ -105489,37 +105490,37 @@ function parseJavaVersionFile(content) {
}
return fileContent;
}
function parsePomXmlFile(xmlFile) {
function parsePomXmlFile(xmlFileAsString) {
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
for (var definitionType of versionDefinitionTypes) {
var version = definitionType(xmlFile);
var version = definitionType(xmlbuilder2_1.create(xmlFileAsString));
if (version !== null) {
return version;
}
}
return null;
}
function getByMavenCompilerSpecification(xmlFile) {
function getByMavenCompilerSpecification(xmlDoc) {
const possibleTagsRegex = [
'<maven\.compiler\.source>(.*?)<\/maven\.compiler\.source>',
'<maven.compiler.release>(.*?)<\/maven.compiler.release>',
'maven.compiler.source',
'maven.compiler.release',
];
for (var tag of possibleTagsRegex) {
const version = getVersionByTagName(xmlFile, tag);
const version = getVersionByTagName(xmlDoc, tag);
if (version !== null) {
return version;
}
}
return null;
}
function getBySpringBootSpecification(xmlFile) {
return getVersionByTagName(xmlFile, '<java.version>(.*?)<\/java.version>');
function getBySpringBootSpecification(xmlDoc) {
return getVersionByTagName(xmlDoc, 'java.version');
}
function getVersionByTagName(xmlFile, regex) {
const match = xmlFile.match(new RegExp(regex));
if (match) {
core.debug(`Found java version: '${match[1]}' using regex: '${regex}'`);
return match[1];
function getVersionByTagName(xmlDoc, tag) {
const match = xmlDoc.find(n => n.node.nodeName === tag);
if (match !== undefined) {
core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`);
return match.first().toString();
}
else {
return null;