diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index a1010163..eb910901 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -103805,7 +103805,7 @@ function getVersionFromFile(fileName, content, distributionName) { parsedVersion = parseBuildGradleFile(content); } 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' 'pom.xml' and 'build.gradle'`); } if (!parsedVersion) { return null; @@ -103865,7 +103865,7 @@ function getBySpringBootSpecification(xmlDoc) { return getVersionByTagName(xmlDoc, 'java.version'); } function getVersionByTagName(xmlDoc, tag) { - const match = xmlDoc.find(n => n.node.nodeName === tag); + const match = xmlDoc.find(n => n.node.nodeName === tag, false, true); if (match !== undefined) { core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`); return match.first().toString(); @@ -103875,42 +103875,19 @@ function getVersionByTagName(xmlDoc, tag) { } } function getByMavenCompilerPluginConfig(xmlDoc) { - var _a; - const source = xmlDoc.find(n => { - // Find node - if (n.node.nodeName !== 'source') { - return false; - } - if (n.node.childNodes.length !== 1) { - return false; - } - // Must be within - if (n.up().node.nodeName !== 'configuration') { - return false; - } - // Which must be inside - if (n.up().up().node.nodeName !== 'plugin') { - return false; - } - // Make sure the plugin is maven-compiler-plugin - const isCompilerPlugin = n + const mavenCompilePlugin = xmlDoc.find(n => n.node.nodeName === 'artifactId' && n.first().toString() === 'maven-compiler-plugin', false, true); + if (mavenCompilePlugin != undefined) { + const sourceOrTag = mavenCompilePlugin .up() - .up() - .some(c => { - if (c.node.nodeName !== 'artifactId') { - return false; - } - if (c.node.childNodes.length !== 1) { - return false; - } - return c.first().toString() === 'maven-compiler-plugin'; - }, false, true); - if (!isCompilerPlugin) { - return false; + .find(n => n.node.nodeName === 'source' || n.node.nodeName === 'target', false, true); + if (sourceOrTag !== undefined) { + core.debug(`Found java version: '${sourceOrTag + .first() + .toString()}' defined on the maven-compiler-plugin'`); + return sourceOrTag.first().toString(); } - return true; - }); - return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null; + } + return null; } function parseBuildGradleFile(buildGradle) { const versionDefinitionTypes = [getByJavaLibraryPlugin, getByJavaPlugin]; @@ -103923,12 +103900,12 @@ function parseBuildGradleFile(buildGradle) { return null; } function getByJavaLibraryPlugin(buildGradle) { - return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))'); + return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of\\((\\d+)\\)'); } function getByJavaPlugin(buildGradle) { const possibleRegex = [ - 'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)', - 'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)' + 'sourceCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)', + 'targetCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)' ]; for (var regex of possibleRegex) { const version = getVersionByRegex(buildGradle, regex); diff --git a/dist/setup/index.js b/dist/setup/index.js index 33f2f171..277e1e9e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -105462,7 +105462,7 @@ function getVersionFromFile(fileName, content, distributionName) { parsedVersion = parseBuildGradleFile(content); } 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' 'pom.xml' and 'build.gradle'`); } if (!parsedVersion) { return null; @@ -105522,7 +105522,7 @@ function getBySpringBootSpecification(xmlDoc) { return getVersionByTagName(xmlDoc, 'java.version'); } function getVersionByTagName(xmlDoc, tag) { - const match = xmlDoc.find(n => n.node.nodeName === tag); + const match = xmlDoc.find(n => n.node.nodeName === tag, false, true); if (match !== undefined) { core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`); return match.first().toString(); @@ -105532,42 +105532,19 @@ function getVersionByTagName(xmlDoc, tag) { } } function getByMavenCompilerPluginConfig(xmlDoc) { - var _a; - const source = xmlDoc.find(n => { - // Find node - if (n.node.nodeName !== 'source') { - return false; - } - if (n.node.childNodes.length !== 1) { - return false; - } - // Must be within - if (n.up().node.nodeName !== 'configuration') { - return false; - } - // Which must be inside - if (n.up().up().node.nodeName !== 'plugin') { - return false; - } - // Make sure the plugin is maven-compiler-plugin - const isCompilerPlugin = n + const mavenCompilePlugin = xmlDoc.find(n => n.node.nodeName === 'artifactId' && n.first().toString() === 'maven-compiler-plugin', false, true); + if (mavenCompilePlugin != undefined) { + const sourceOrTag = mavenCompilePlugin .up() - .up() - .some(c => { - if (c.node.nodeName !== 'artifactId') { - return false; - } - if (c.node.childNodes.length !== 1) { - return false; - } - return c.first().toString() === 'maven-compiler-plugin'; - }, false, true); - if (!isCompilerPlugin) { - return false; + .find(n => n.node.nodeName === 'source' || n.node.nodeName === 'target', false, true); + if (sourceOrTag !== undefined) { + core.debug(`Found java version: '${sourceOrTag + .first() + .toString()}' defined on the maven-compiler-plugin'`); + return sourceOrTag.first().toString(); } - return true; - }); - return (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null; + } + return null; } function parseBuildGradleFile(buildGradle) { const versionDefinitionTypes = [getByJavaLibraryPlugin, getByJavaPlugin]; @@ -105580,12 +105557,12 @@ function parseBuildGradleFile(buildGradle) { return null; } function getByJavaLibraryPlugin(buildGradle) { - return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))'); + return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of\\((\\d+)\\)'); } function getByJavaPlugin(buildGradle) { const possibleRegex = [ - 'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)', - 'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)' + 'sourceCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)', + 'targetCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)' ]; for (var regex of possibleRegex) { const version = getVersionByRegex(buildGradle, regex); diff --git a/src/util.ts b/src/util.ts index a8748805..d228925b 100644 --- a/src/util.ts +++ b/src/util.ts @@ -119,7 +119,7 @@ export function getVersionFromFile( parsedVersion = parseBuildGradleFile(content); } else { throw new Error( - `File ${fileName} not supported, files supported: '.java-version' and 'pom.xml'` + `File ${fileName} not supported, files supported: '.java-version' 'pom.xml' and 'build.gradle'` ); } @@ -198,7 +198,7 @@ function getBySpringBootSpecification(xmlDoc: XMLBuilder): string | null { } function getVersionByTagName(xmlDoc: XMLBuilder, tag: string): string | null { - const match = xmlDoc.find(n => n.node.nodeName === tag); + const match = xmlDoc.find(n => n.node.nodeName === tag, false, true); if (match !== undefined) { core.debug(`Found java version: '${match.first().toString()}' using tag: '${tag}'`); @@ -209,47 +209,28 @@ function getVersionByTagName(xmlDoc: XMLBuilder, tag: string): string | null { } function getByMavenCompilerPluginConfig(xmlDoc: XMLBuilder): string | null { - const source = xmlDoc.find(n => { - // Find node - if (n.node.nodeName !== 'source') { - return false; - } - if (n.node.childNodes.length !== 1) { - return false; - } - // Must be within - if (n.up().node.nodeName !== 'configuration') { - return false; - } - // Which must be inside - if (n.up().up().node.nodeName !== 'plugin') { - return false; - } - // Make sure the plugin is maven-compiler-plugin - const isCompilerPlugin = n + const mavenCompilePlugin = xmlDoc.find( + n => n.node.nodeName === 'artifactId' && n.first().toString() === 'maven-compiler-plugin', + false, + true + ); + + if (mavenCompilePlugin != undefined) { + const sourceOrTag = mavenCompilePlugin .up() - .up() - .some( - c => { - if (c.node.nodeName !== 'artifactId') { - return false; - } - if (c.node.childNodes.length !== 1) { - return false; - } - return c.first().toString() === 'maven-compiler-plugin'; - }, - false, - true + .find(n => n.node.nodeName === 'source' || n.node.nodeName === 'target', false, true); + + if (sourceOrTag !== undefined) { + core.debug( + `Found java version: '${sourceOrTag + .first() + .toString()}' defined on the maven-compiler-plugin'` ); - if (!isCompilerPlugin) { - return false; + return sourceOrTag.first().toString(); } + } - return true; - }); - - return source?.first().toString() ?? null; + return null; } function parseBuildGradleFile(buildGradle: string): any { @@ -267,13 +248,13 @@ function parseBuildGradleFile(buildGradle: string): any { } function getByJavaLibraryPlugin(buildGradle: string) { - return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of((d+))'); + return getVersionByRegex(buildGradle, 'JavaLanguageVersion.of\\((\\d+)\\)'); } function getByJavaPlugin(buildGradle: string) { const possibleRegex = [ - 'sourceCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)', - 'targetCompatibilitys?=s?JavaVersion.VERSION_(?:1_)?(d+)' + 'sourceCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)', + 'targetCompatibility\\s?=\\s?JavaVersion.VERSION_(?:1_)?(\\d+)' ]; for (var regex of possibleRegex) {