mirror of
https://github.com/actions/setup-java.git
synced 2025-04-18 00:46:45 +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
44
.github/workflows/e2e-versions.yml
vendored
44
.github/workflows/e2e-versions.yml
vendored
|
@ -469,3 +469,47 @@ 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-plugin-configuration:
|
||||
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>FooBar</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
|
||||
|
|
48
dist/cleanup/index.js
vendored
48
dist/cleanup/index.js
vendored
|
@ -103834,16 +103834,21 @@ function parseJavaVersionFile(content) {
|
|||
return fileContent;
|
||||
}
|
||||
function parsePomXmlFile(xmlFileAsString) {
|
||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||
for (var definitionType of versionDefinitionTypes) {
|
||||
var version = definitionType(xmlbuilder2_1.create(xmlFileAsString));
|
||||
const xmlDoc = xmlbuilder2_1.create(xmlFileAsString);
|
||||
const versionDefinitionTypes = [
|
||||
getByMavenProperties,
|
||||
getBySpringBootSpecification,
|
||||
getByMavenCompilerPluginConfig
|
||||
];
|
||||
for (const definitionType of versionDefinitionTypes) {
|
||||
const version = definitionType(xmlDoc);
|
||||
if (version !== null) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getByMavenCompilerSpecification(xmlDoc) {
|
||||
function getByMavenProperties(xmlDoc) {
|
||||
const possibleTagsRegex = [
|
||||
'maven.compiler.source',
|
||||
'maven.compiler.release',
|
||||
|
@ -103869,6 +103874,41 @@ function getVersionByTagName(xmlDoc, tag) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
function getByMavenCompilerPluginConfig(xmlDoc) {
|
||||
var _a;
|
||||
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 (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
function avoidOldNotation(content) {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
|
|
48
dist/setup/index.js
vendored
48
dist/setup/index.js
vendored
|
@ -105491,16 +105491,21 @@ function parseJavaVersionFile(content) {
|
|||
return fileContent;
|
||||
}
|
||||
function parsePomXmlFile(xmlFileAsString) {
|
||||
const versionDefinitionTypes = [getByMavenCompilerSpecification, getBySpringBootSpecification];
|
||||
for (var definitionType of versionDefinitionTypes) {
|
||||
var version = definitionType(xmlbuilder2_1.create(xmlFileAsString));
|
||||
const xmlDoc = xmlbuilder2_1.create(xmlFileAsString);
|
||||
const versionDefinitionTypes = [
|
||||
getByMavenProperties,
|
||||
getBySpringBootSpecification,
|
||||
getByMavenCompilerPluginConfig
|
||||
];
|
||||
for (const definitionType of versionDefinitionTypes) {
|
||||
const version = definitionType(xmlDoc);
|
||||
if (version !== null) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getByMavenCompilerSpecification(xmlDoc) {
|
||||
function getByMavenProperties(xmlDoc) {
|
||||
const possibleTagsRegex = [
|
||||
'maven.compiler.source',
|
||||
'maven.compiler.release',
|
||||
|
@ -105526,6 +105531,41 @@ function getVersionByTagName(xmlDoc, tag) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
function getByMavenCompilerPluginConfig(xmlDoc) {
|
||||
var _a;
|
||||
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 (_a = source === null || source === void 0 ? void 0 : source.first().toString()) !== null && _a !== void 0 ? _a : null;
|
||||
}
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
function avoidOldNotation(content) {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
|
|
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