mirror of
https://github.com/actions/setup-java.git
synced 2025-04-22 02:46:46 +00:00
Add support for maven-compiler-plugin configuration (#1)
This commit is contained in:
parent
bc6665734d
commit
f5e27775fa
4 changed files with 178 additions and 12 deletions
50
src/util.ts
50
src/util.ts
|
@ -158,10 +158,15 @@ function parseJavaVersionFile(content: string): string | null {
|
|||
}
|
||||
|
||||
function parsePomXmlFile(xmlFileAsString: string): string | null {
|
||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||
const xmlDoc = create(xmlFileAsString);
|
||||
const versionDefinitionTypes = [
|
||||
getByMavenProperties,
|
||||
getBySpringBootSpecification,
|
||||
getByMavenCompilerPluginConfig
|
||||
];
|
||||
|
||||
for (var definitionType of versionDefinitionTypes) {
|
||||
var version = definitionType(create(xmlFileAsString));
|
||||
for (const definitionType of versionDefinitionTypes) {
|
||||
const version = definitionType(xmlDoc);
|
||||
|
||||
if (version !== null) {
|
||||
return version;
|
||||
|
@ -171,7 +176,7 @@ function parsePomXmlFile(xmlFileAsString: string): string | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
function getByMavenCompilerSpecification(xmlDoc: XMLBuilder): string | null {
|
||||
function getByMavenProperties(xmlDoc: XMLBuilder): string | null {
|
||||
const possibleTagsRegex = [
|
||||
'maven.compiler.source',
|
||||
'maven.compiler.release',
|
||||
|
@ -204,6 +209,43 @@ function getVersionByTagName(xmlDoc: XMLBuilder, tag: string): string | null {
|
|||
|
||||
}
|
||||
|
||||
function getByMavenCompilerPluginConfig(xmlDoc: XMLBuilder): string | null {
|
||||
const source = xmlDoc.find(n => {
|
||||
// Find <source> node
|
||||
if (n.node.nodeName !== "source") {
|
||||
return false;
|
||||
}
|
||||
if (n.node.childNodes.length !== 1) {
|
||||
return false;
|
||||
}
|
||||
// Must be within <configuration>
|
||||
if (n.up().node.nodeName !== "configuration") {
|
||||
return false;
|
||||
}
|
||||
// Which must be inside <plugin>
|
||||
if (n.up().up().node.nodeName !== "plugin") {
|
||||
return false;
|
||||
}
|
||||
// Make sure the plugin is maven-compiler-plugin
|
||||
const isCompilerPlugin = n.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;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return source?.first().toString() ?? null;
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
function avoidOldNotation(content: string): string {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue