mirror of
https://github.com/actions/setup-java.git
synced 2026-07-01 09:31:41 +00:00
Compare commits
3 Commits
6e934eb76f
...
9b38f457c5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b38f457c5 | ||
|
|
5896cecc08 | ||
|
|
b8162e8075 |
24
.github/workflows/e2e-versions.yml
vendored
24
.github/workflows/e2e-versions.yml
vendored
@ -288,19 +288,23 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
distribution: ['temurin', 'microsoft', 'corretto']
|
distribution: ['temurin', 'microsoft', 'corretto']
|
||||||
|
java-version-file: ['.java-version', '.tool-versions']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Create .java-version file
|
- name: Create .java-version file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "8" > .java-version
|
run: echo "8" > .java-version
|
||||||
|
- name: Create .tool-versions file
|
||||||
|
shell: bash
|
||||||
|
run: echo "java 8" > .tool-versions
|
||||||
- name: setup-java
|
- name: setup-java
|
||||||
uses: ./
|
uses: ./
|
||||||
id: setup-java
|
id: setup-java
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version: 11
|
java-version: 11
|
||||||
java-version-file: '.java-version'
|
java-version-file: ${{matrix.java-version-file }}
|
||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -313,18 +317,22 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
distribution: ['temurin', 'zulu', 'liberica', 'microsoft', 'corretto']
|
distribution: ['temurin', 'zulu', 'liberica', 'microsoft', 'corretto']
|
||||||
|
java-version-file: ['.java-version', '.tool-versions']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Create .java-version file
|
- name: Create .java-version file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "11" > .java-version
|
run: echo "11" > .java-version
|
||||||
|
- name: Create .tool-versions file
|
||||||
|
shell: bash
|
||||||
|
run: echo "java 11" > .tool-versions
|
||||||
- name: setup-java
|
- name: setup-java
|
||||||
uses: ./
|
uses: ./
|
||||||
id: setup-java
|
id: setup-java
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version-file: '.java-version'
|
java-version-file: ${{matrix.java-version-file }}
|
||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "11" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -337,18 +345,22 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
distribution: ['adopt', 'adopt-openj9', 'zulu']
|
distribution: ['adopt', 'adopt-openj9', 'zulu']
|
||||||
|
java-version-file: ['.java-version', '.tool-versions']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Create .java-version file
|
- name: Create .java-version file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "11.0.2" > .java-version
|
run: echo "11.0.2" > .java-version
|
||||||
|
- name: Create .tool-versions file
|
||||||
|
shell: bash
|
||||||
|
run: echo "java 11.0.2" > .tool-versions
|
||||||
- name: setup-java
|
- name: setup-java
|
||||||
uses: ./
|
uses: ./
|
||||||
id: setup-java
|
id: setup-java
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version-file: '.java-version'
|
java-version-file: ${{matrix.java-version-file }}
|
||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -361,18 +373,22 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
distribution: ['adopt', 'zulu', 'liberica']
|
distribution: ['adopt', 'zulu', 'liberica']
|
||||||
|
java-version-file: ['.java-version', '.tool-versions']
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Create .java-version file
|
- name: Create .java-version file
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "openjdk64-11.0.2" > .java-version
|
run: echo "openjdk64-11.0.2" > .java-version
|
||||||
|
- name: Create .tool-versions file
|
||||||
|
shell: bash
|
||||||
|
run: echo "java openjdk64-11.0.2" > .tool-versions
|
||||||
- name: setup-java
|
- name: setup-java
|
||||||
uses: ./
|
uses: ./
|
||||||
id: setup-java
|
id: setup-java
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version-file: '.java-version'
|
java-version-file: ${{matrix.java-version-file }}
|
||||||
- name: Verify Java
|
- name: Verify Java
|
||||||
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "11.0.2" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@ -27,7 +27,7 @@ This action allows you to work with Java and Scala projects.
|
|||||||
|
|
||||||
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
|
- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.
|
||||||
|
|
||||||
- `java-version-file`: The path to the `.java-version` file. See more details in [about `.java-version` file](docs/advanced-usage.md#Java-version-file).
|
- `java-version-file`: The path to a file containing java version. Supported file types are `.java-version` and `.tool-versions`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).
|
||||||
|
|
||||||
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
|
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
|
||||||
|
|
||||||
@ -266,6 +266,7 @@ In the example above multiple JDKs are installed for the same job. The result af
|
|||||||
- [Publishing using Gradle](docs/advanced-usage.md#Publishing-using-Gradle)
|
- [Publishing using Gradle](docs/advanced-usage.md#Publishing-using-Gradle)
|
||||||
- [Hosted Tool Cache](docs/advanced-usage.md#Hosted-Tool-Cache)
|
- [Hosted Tool Cache](docs/advanced-usage.md#Hosted-Tool-Cache)
|
||||||
- [Modifying Maven Toolchains](docs/advanced-usage.md#Modifying-Maven-Toolchains)
|
- [Modifying Maven Toolchains](docs/advanced-usage.md#Modifying-Maven-Toolchains)
|
||||||
|
- [Java Version File](docs/advanced-usage.md#Java-version-file)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@ -143,7 +143,20 @@ describe('toolchains tests', () => {
|
|||||||
</toolchain>
|
</toolchain>
|
||||||
</toolchains>`;
|
</toolchains>`;
|
||||||
const result = `<?xml version="1.0"?>
|
const result = `<?xml version="1.0"?>
|
||||||
<toolchains>
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
<toolchain>
|
<toolchain>
|
||||||
<type>jdk</type>
|
<type>jdk</type>
|
||||||
<provides>
|
<provides>
|
||||||
@ -155,6 +168,442 @@ describe('toolchains tests', () => {
|
|||||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||||
</configuration>
|
</configuration>
|
||||||
</toolchain>
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('does not discard custom elements in existing toolchain definitions', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = `<toolchains>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>1.6</version>
|
||||||
|
<vendor>Sun</vendor>
|
||||||
|
<id>sun_1.6</id>
|
||||||
|
<custom>foo</custom>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||||
|
<fooHome>/usr/local/bin/bash</fooHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>1.6</version>
|
||||||
|
<vendor>Sun</vendor>
|
||||||
|
<id>sun_1.6</id>
|
||||||
|
<custom>foo</custom>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||||
|
<fooHome>/usr/local/bin/bash</fooHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('does not discard existing, custom toolchain definitions', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = `<toolchains>
|
||||||
|
<toolchain>
|
||||||
|
<type>foo</type>
|
||||||
|
<provides>
|
||||||
|
<custom>baz</custom>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<fooHome>/usr/local/bin/foo</fooHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
<toolchain>
|
||||||
|
<type>foo</type>
|
||||||
|
<provides>
|
||||||
|
<custom>baz</custom>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<fooHome>/usr/local/bin/foo</fooHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('does not duplicate existing toolchain definitions', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = `<toolchains>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('does not duplicate existing toolchain definitions if multiple exist', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = `<toolchains>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>1.6</version>
|
||||||
|
<vendor>Sun</vendor>
|
||||||
|
<id>sun_1.6</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>1.6</version>
|
||||||
|
<vendor>Sun</vendor>
|
||||||
|
<id>sun_1.6</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('handles an empty list of existing toolchains correctly', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = `<toolchains>
|
||||||
|
</toolchains>`;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
|
<toolchain>
|
||||||
|
<type>jdk</type>
|
||||||
|
<provides>
|
||||||
|
<version>17</version>
|
||||||
|
<vendor>Eclipse Temurin</vendor>
|
||||||
|
<id>temurin_17</id>
|
||||||
|
</provides>
|
||||||
|
<configuration>
|
||||||
|
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||||
|
</configuration>
|
||||||
|
</toolchain>
|
||||||
|
</toolchains>`;
|
||||||
|
|
||||||
|
fs.mkdirSync(m2Dir, {recursive: true});
|
||||||
|
fs.writeFileSync(toolchainsFile, originalFile);
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
|
||||||
|
await toolchains.createToolchainsSettings({
|
||||||
|
jdkInfo,
|
||||||
|
settingsDirectory: m2Dir,
|
||||||
|
overwriteSettings: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||||
|
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||||
|
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
toolchains.generateToolchainDefinition(
|
||||||
|
originalFile,
|
||||||
|
jdkInfo.version,
|
||||||
|
jdkInfo.vendor,
|
||||||
|
jdkInfo.id,
|
||||||
|
jdkInfo.jdkHome
|
||||||
|
)
|
||||||
|
).toEqual(result);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('handles an empty existing toolchains.xml correctly', async () => {
|
||||||
|
const jdkInfo = {
|
||||||
|
version: '17',
|
||||||
|
vendor: 'Eclipse Temurin',
|
||||||
|
id: 'temurin_17',
|
||||||
|
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||||
|
};
|
||||||
|
|
||||||
|
const originalFile = ``;
|
||||||
|
const result = `<?xml version="1.0"?>
|
||||||
|
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||||
<toolchain>
|
<toolchain>
|
||||||
<type>jdk</type>
|
<type>jdk</type>
|
||||||
<provides>
|
<provides>
|
||||||
|
|||||||
14
dist/cleanup/index.js
vendored
14
dist/cleanup/index.js
vendored
@ -88352,9 +88352,19 @@ function isCacheFeatureAvailable() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFileContent(content, distributionName) {
|
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp =
|
||||||
|
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
|
||||||
|
}
|
||||||
|
else if (versionFile == '.java-version') {
|
||||||
|
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('Invalid version file');
|
||||||
|
}
|
||||||
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
|
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
|
||||||
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
|
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
95
dist/setup/index.js
vendored
95
dist/setup/index.js
vendored
@ -125372,7 +125372,7 @@ function run() {
|
|||||||
if (!versions.length) {
|
if (!versions.length) {
|
||||||
core.debug('java-version input is empty, looking for java-version-file input');
|
core.debug('java-version input is empty, looking for java-version-file input');
|
||||||
const content = fs_1.default.readFileSync(versionFile).toString().trim();
|
const content = fs_1.default.readFileSync(versionFile).toString().trim();
|
||||||
const version = (0, util_1.getVersionFromFileContent)(content, distributionName);
|
const version = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||||
@ -125504,46 +125504,53 @@ function createToolchainsSettings({ jdkInfo, settingsDirectory, overwriteSetting
|
|||||||
exports.createToolchainsSettings = createToolchainsSettings;
|
exports.createToolchainsSettings = createToolchainsSettings;
|
||||||
// only exported for testing purposes
|
// only exported for testing purposes
|
||||||
function generateToolchainDefinition(original, version, vendor, id, jdkHome) {
|
function generateToolchainDefinition(original, version, vendor, id, jdkHome) {
|
||||||
let xmlObj;
|
let jsToolchains = [
|
||||||
|
{
|
||||||
|
type: 'jdk',
|
||||||
|
provides: {
|
||||||
|
version: `${version}`,
|
||||||
|
vendor: `${vendor}`,
|
||||||
|
id: `${id}`
|
||||||
|
},
|
||||||
|
configuration: {
|
||||||
|
jdkHome: `${jdkHome}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
if (original === null || original === void 0 ? void 0 : original.length) {
|
if (original === null || original === void 0 ? void 0 : original.length) {
|
||||||
xmlObj = (0, xmlbuilder2_1.create)(original)
|
// convert existing toolchains into TS native objects for better handling
|
||||||
|
// xmlbuilder2 will convert the document into a `{toolchains: { toolchain: [] | {} }}` structure
|
||||||
|
// instead of the desired `toolchains: [{}]` one or simply `[{}]`
|
||||||
|
const jsObj = (0, xmlbuilder2_1.create)(original)
|
||||||
.root()
|
.root()
|
||||||
.ele({
|
.toObject();
|
||||||
toolchain: {
|
if (jsObj.toolchains && jsObj.toolchains.toolchain) {
|
||||||
type: 'jdk',
|
// in case only a single child exists xmlbuilder2 will not create an array and using verbose = true equally doesn't work here
|
||||||
provides: {
|
// See https://oozcitak.github.io/xmlbuilder2/serialization.html#js-object-and-map-serializers for details
|
||||||
version: `${version}`,
|
if (Array.isArray(jsObj.toolchains.toolchain)) {
|
||||||
vendor: `${vendor}`,
|
jsToolchains.push(...jsObj.toolchains.toolchain);
|
||||||
id: `${id}`
|
|
||||||
},
|
|
||||||
configuration: {
|
|
||||||
jdkHome: `${jdkHome}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
jsToolchains.push(jsObj.toolchains.toolchain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// remove potential duplicates based on type & id (which should be a unique combination);
|
||||||
|
// self.findIndex will only return the first occurrence, ensuring duplicates are skipped
|
||||||
|
jsToolchains = jsToolchains.filter((value, index, self) =>
|
||||||
|
// ensure non-jdk toolchains are kept in the results, we must not touch them because they belong to the user
|
||||||
|
value.type !== 'jdk' ||
|
||||||
|
index ===
|
||||||
|
self.findIndex(t => t.type === value.type && t.provides.id === value.provides.id));
|
||||||
}
|
}
|
||||||
else
|
// TODO: technically bad because we shouldn't re-create the toolchains root node (with possibly different schema values) if it already exists, however, just overriding the toolchain array with xmlbuilder2 is … uh non-trivial
|
||||||
xmlObj = (0, xmlbuilder2_1.create)({
|
return (0, xmlbuilder2_1.create)({
|
||||||
toolchains: {
|
toolchains: {
|
||||||
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
|
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
|
||||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
'@xsi:schemaLocation': 'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
'@xsi:schemaLocation': 'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
||||||
toolchain: [
|
toolchain: jsToolchains
|
||||||
{
|
}
|
||||||
type: 'jdk',
|
}).end({
|
||||||
provides: {
|
|
||||||
version: `${version}`,
|
|
||||||
vendor: `${vendor}`,
|
|
||||||
id: `${id}`
|
|
||||||
},
|
|
||||||
configuration: {
|
|
||||||
jdkHome: `${jdkHome}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return xmlObj.end({
|
|
||||||
format: 'xml',
|
format: 'xml',
|
||||||
wellFormed: false,
|
wellFormed: false,
|
||||||
headless: false,
|
headless: false,
|
||||||
@ -125726,9 +125733,19 @@ function isCacheFeatureAvailable() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||||
function getVersionFromFileContent(content, distributionName) {
|
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp =
|
||||||
|
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
|
||||||
|
}
|
||||||
|
else if (versionFile == '.java-version') {
|
||||||
|
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error('Invalid version file');
|
||||||
|
}
|
||||||
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
|
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
|
||||||
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
|
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
@ -525,14 +525,21 @@ steps:
|
|||||||
something_other
|
something_other
|
||||||
```
|
```
|
||||||
|
|
||||||
## Java-version file
|
## Java version file
|
||||||
If the `java-version-file` input is specified, the action will try to extract the version from the file and install it.
|
If the `java-version-file` input is specified, the action will extract the version from the file and install it.
|
||||||
Action is able to recognize all variants of the version description according to [jenv](https://github.com/jenv/jenv).
|
|
||||||
|
Supported files are .java-version and .tool-versions.
|
||||||
|
In .java-version file, only the version should be specified, e.g., 17.0.7.
|
||||||
|
In .tool-versions file, java version should be preceded by the java keyword, e.g., java 17.0.7.
|
||||||
|
.java-version recognizes all variants of the version description according to [jenv](https://github.com/jenv/jenv) and .tool-version recognizes all variants of the version description according to [asdf](https://github.com/asdf-vm/asdf).
|
||||||
|
|
||||||
|
If both java-version and java-version-file inputs are provided, the java-version input will be used.
|
||||||
|
|
||||||
Valid entry options:
|
Valid entry options:
|
||||||
```
|
```
|
||||||
major versions: 8, 11, 16, 17, 21
|
major versions: 8, 11, 16, 17, 21
|
||||||
more specific versions: 1.8.0.2, 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8
|
more specific versions: 1.8.0.2, 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8
|
||||||
early access (EA) versions: 15-ea, 15.0.0-ea, 15.0.0-ea.2, 15.0.0+2-ea
|
early access (EA) versions: 15-ea, 15.0.0-ea
|
||||||
versions with specified distribution: openjdk64-11.0.2
|
versions with specified distribution: openjdk64-11.0.2
|
||||||
```
|
```
|
||||||
If the file contains multiple versions, only the first one will be recognized.
|
If the file contains multiple versions, only the first one will be recognized.
|
||||||
|
|||||||
@ -55,7 +55,11 @@ async function run() {
|
|||||||
);
|
);
|
||||||
const content = fs.readFileSync(versionFile).toString().trim();
|
const content = fs.readFileSync(versionFile).toString().trim();
|
||||||
|
|
||||||
const version = getVersionFromFileContent(content, distributionName);
|
const version = getVersionFromFileContent(
|
||||||
|
content,
|
||||||
|
distributionName,
|
||||||
|
versionFile
|
||||||
|
);
|
||||||
core.debug(`Parsed version from file '${version}'`);
|
core.debug(`Parsed version from file '${version}'`);
|
||||||
|
|
||||||
if (!version) {
|
if (!version) {
|
||||||
|
|||||||
@ -84,47 +84,59 @@ export function generateToolchainDefinition(
|
|||||||
id: string,
|
id: string,
|
||||||
jdkHome: string
|
jdkHome: string
|
||||||
) {
|
) {
|
||||||
let xmlObj;
|
let jsToolchains: Toolchain[] = [
|
||||||
if (original?.length) {
|
{
|
||||||
xmlObj = xmlCreate(original)
|
type: 'jdk',
|
||||||
.root()
|
provides: {
|
||||||
.ele({
|
version: `${version}`,
|
||||||
toolchain: {
|
vendor: `${vendor}`,
|
||||||
type: 'jdk',
|
id: `${id}`
|
||||||
provides: {
|
},
|
||||||
version: `${version}`,
|
configuration: {
|
||||||
vendor: `${vendor}`,
|
jdkHome: `${jdkHome}`
|
||||||
id: `${id}`
|
|
||||||
},
|
|
||||||
configuration: {
|
|
||||||
jdkHome: `${jdkHome}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else
|
|
||||||
xmlObj = xmlCreate({
|
|
||||||
toolchains: {
|
|
||||||
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
|
|
||||||
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
||||||
'@xsi:schemaLocation':
|
|
||||||
'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
|
||||||
toolchain: [
|
|
||||||
{
|
|
||||||
type: 'jdk',
|
|
||||||
provides: {
|
|
||||||
version: `${version}`,
|
|
||||||
vendor: `${vendor}`,
|
|
||||||
id: `${id}`
|
|
||||||
},
|
|
||||||
configuration: {
|
|
||||||
jdkHome: `${jdkHome}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
];
|
||||||
|
if (original?.length) {
|
||||||
|
// convert existing toolchains into TS native objects for better handling
|
||||||
|
// xmlbuilder2 will convert the document into a `{toolchains: { toolchain: [] | {} }}` structure
|
||||||
|
// instead of the desired `toolchains: [{}]` one or simply `[{}]`
|
||||||
|
const jsObj = xmlCreate(original)
|
||||||
|
.root()
|
||||||
|
.toObject() as unknown as ExtractedToolchains;
|
||||||
|
if (jsObj.toolchains && jsObj.toolchains.toolchain) {
|
||||||
|
// in case only a single child exists xmlbuilder2 will not create an array and using verbose = true equally doesn't work here
|
||||||
|
// See https://oozcitak.github.io/xmlbuilder2/serialization.html#js-object-and-map-serializers for details
|
||||||
|
if (Array.isArray(jsObj.toolchains.toolchain)) {
|
||||||
|
jsToolchains.push(...jsObj.toolchains.toolchain);
|
||||||
|
} else {
|
||||||
|
jsToolchains.push(jsObj.toolchains.toolchain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return xmlObj.end({
|
// remove potential duplicates based on type & id (which should be a unique combination);
|
||||||
|
// self.findIndex will only return the first occurrence, ensuring duplicates are skipped
|
||||||
|
jsToolchains = jsToolchains.filter(
|
||||||
|
(value, index, self) =>
|
||||||
|
// ensure non-jdk toolchains are kept in the results, we must not touch them because they belong to the user
|
||||||
|
value.type !== 'jdk' ||
|
||||||
|
index ===
|
||||||
|
self.findIndex(
|
||||||
|
t => t.type === value.type && t.provides.id === value.provides.id
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: technically bad because we shouldn't re-create the toolchains root node (with possibly different schema values) if it already exists, however, just overriding the toolchain array with xmlbuilder2 is … uh non-trivial
|
||||||
|
return xmlCreate({
|
||||||
|
toolchains: {
|
||||||
|
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
|
||||||
|
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
|
'@xsi:schemaLocation':
|
||||||
|
'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
|
||||||
|
toolchain: jsToolchains
|
||||||
|
}
|
||||||
|
}).end({
|
||||||
format: 'xml',
|
format: 'xml',
|
||||||
wellFormed: false,
|
wellFormed: false,
|
||||||
headless: false,
|
headless: false,
|
||||||
@ -167,3 +179,22 @@ async function writeToolchainsFileToDisk(
|
|||||||
flag: 'w'
|
flag: 'w'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ExtractedToolchains {
|
||||||
|
toolchains: {
|
||||||
|
toolchain: Toolchain[] | Toolchain;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toolchain type definition according to Maven Toolchains XSD 1.1.0
|
||||||
|
interface Toolchain {
|
||||||
|
type: string;
|
||||||
|
provides:
|
||||||
|
| {
|
||||||
|
version: string;
|
||||||
|
vendor: string;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
| any;
|
||||||
|
configuration: any;
|
||||||
|
}
|
||||||
|
|||||||
14
src/util.ts
14
src/util.ts
@ -115,9 +115,19 @@ export function isCacheFeatureAvailable(): boolean {
|
|||||||
|
|
||||||
export function getVersionFromFileContent(
|
export function getVersionFromFileContent(
|
||||||
content: string,
|
content: string,
|
||||||
distributionName: string
|
distributionName: string,
|
||||||
|
versionFile: string
|
||||||
): string | null {
|
): string | null {
|
||||||
const javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
let javaVersionRegExp: RegExp;
|
||||||
|
if (versionFile == '.tool-versions') {
|
||||||
|
javaVersionRegExp =
|
||||||
|
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
|
||||||
|
} else if (versionFile == '.java-version') {
|
||||||
|
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid version file');
|
||||||
|
}
|
||||||
|
|
||||||
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
||||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||||
: '';
|
: '';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user