mirror of
https://github.com/actions/setup-java.git
synced 2026-07-02 02:11:46 +00:00
Compare commits
3 Commits
9c92f8d880
...
36f7a91e1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36f7a91e1b | ||
|
|
d0351b4837 | ||
|
|
d82312064b |
36
README.md
36
README.md
@ -23,6 +23,8 @@ This action allows you to work with Java and Scala projects.
|
|||||||
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK.
|
- V2 supports custom distributions and provides support for Azul Zulu OpenJDK, Eclipse Temurin and AdoptOpenJDK out of the box. V1 supports only Azul Zulu OpenJDK.
|
||||||
- V2 requires you to specify distribution along with the version. V1 defaults to Azul Zulu OpenJDK, only version input is required. Follow [the migration guide](docs/switching-to-v2.md) to switch from V1 to V2.
|
- V2 requires you to specify distribution along with the version. V1 defaults to Azul Zulu OpenJDK, only version input is required. Follow [the migration guide](docs/switching-to-v2.md) to switch from V1 to V2.
|
||||||
|
|
||||||
|
For information about the latest releases, recent updates, and newly supported distributions, please refer to the `setup-java` [Releases](https://github.com/actions/setup-java/releases).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- `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.
|
||||||
@ -69,8 +71,8 @@ This action allows you to work with Java and Scala projects.
|
|||||||
#### Eclipse Temurin
|
#### Eclipse Temurin
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin' # See 'Supported distributions' for available options
|
distribution: 'temurin' # See 'Supported distributions' for available options
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -80,8 +82,8 @@ steps:
|
|||||||
#### Azul Zulu OpenJDK
|
#### Azul Zulu OpenJDK
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu' # See 'Supported distributions' for available options
|
distribution: 'zulu' # See 'Supported distributions' for available options
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -136,8 +138,8 @@ The cache input is optional, and caching is turned off by default.
|
|||||||
#### Caching gradle dependencies
|
#### Caching gradle dependencies
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -151,8 +153,8 @@ steps:
|
|||||||
#### Caching maven dependencies
|
#### Caching maven dependencies
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -165,8 +167,8 @@ steps:
|
|||||||
#### Caching sbt dependencies
|
#### Caching sbt dependencies
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -185,8 +187,8 @@ Usually, cache gets downloaded in multiple segments of fixed sizes. Sometimes, a
|
|||||||
env:
|
env:
|
||||||
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5'
|
SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -205,8 +207,8 @@ For Java distributions that are not cached on Hosted images, `check-latest` alwa
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -224,9 +226,9 @@ jobs:
|
|||||||
java: [ '8', '11', '17', '21' ]
|
java: [ '8', '11', '17', '21' ]
|
||||||
name: Java ${{ matrix.Java }} sample
|
name: Java ${{ matrix.Java }} sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Setup java
|
- name: Setup java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
@ -239,7 +241,7 @@ All versions are added to the PATH. The last version will be used and available
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: |
|
java-version: |
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
79
dist/setup/index.js
vendored
79
dist/setup/index.js
vendored
@ -132504,46 +132504,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,
|
||||||
|
|||||||
@ -31,8 +31,8 @@ Inputs `java-version` and `distribution` are mandatory and needs to be provided.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -44,8 +44,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'adopt-hotspot'
|
distribution: 'adopt-hotspot'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -56,8 +56,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'zulu'
|
distribution: 'zulu'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -69,8 +69,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'liberica'
|
distribution: 'liberica'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -82,8 +82,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'microsoft'
|
distribution: 'microsoft'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -97,7 +97,7 @@ steps:
|
|||||||
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
distribution: 'microsoft'
|
distribution: 'microsoft'
|
||||||
@ -111,8 +111,8 @@ If the runner is not able to access github.com, any Java versions requested duri
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'corretto'
|
distribution: 'corretto'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -124,8 +124,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'oracle'
|
distribution: 'oracle'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -137,8 +137,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'dragonwell'
|
distribution: 'dragonwell'
|
||||||
java-version: '8'
|
java-version: '8'
|
||||||
@ -149,8 +149,8 @@ steps:
|
|||||||
**NOTE:** An OpenJDK release maintained and supported by SAP
|
**NOTE:** An OpenJDK release maintained and supported by SAP
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'sapmachine'
|
distribution: 'sapmachine'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -162,8 +162,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'graalvm'
|
distribution: 'graalvm'
|
||||||
java-version: '21'
|
java-version: '21'
|
||||||
@ -181,8 +181,8 @@ For example, `11.0.24` is not available but `11.0.16` is.
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jetbrains'
|
distribution: 'jetbrains'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -194,8 +194,8 @@ GitHub token to the action to increase the rate limit. Set the `GITHUB_TOKEN` en
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jetbrains'
|
distribution: 'jetbrains'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
@ -219,8 +219,8 @@ The available package types are:
|
|||||||
## Installing custom Java package type
|
## Installing custom Java package type
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -232,8 +232,8 @@ steps:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -249,7 +249,7 @@ steps:
|
|||||||
- run: |
|
- run: |
|
||||||
download_url="https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz"
|
download_url="https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz"
|
||||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jdkfile'
|
distribution: 'jdkfile'
|
||||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||||
@ -275,7 +275,7 @@ If your use-case requires a custom distribution (in the example, alpine-linux is
|
|||||||
latest_semver_version=$(curl -sL $latest_jdk_json_url | jq -r 'version.semver')
|
latest_semver_version=$(curl -sL $latest_jdk_json_url | jq -r 'version.semver')
|
||||||
echo "java_version=$latest_semver_version" >> "$GITHUB_OUTPUT"
|
echo "java_version=$latest_semver_version" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jdkfile'
|
distribution: 'jdkfile'
|
||||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||||
@ -296,9 +296,9 @@ jobs:
|
|||||||
java: [ '8', '11' ]
|
java: [ '8', '11' ]
|
||||||
name: Java ${{ matrix.Java }} (${{ matrix.distribution }}) sample
|
name: Java ${{ matrix.Java }} (${{ matrix.distribution }}) sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Setup java
|
- name: Setup java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: ${{ matrix.distribution }}
|
distribution: ${{ matrix.distribution }}
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
@ -316,9 +316,9 @@ jobs:
|
|||||||
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ]
|
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ]
|
||||||
name: Java ${{ matrix.Java }} (${{ matrix.os }}) sample
|
name: Java ${{ matrix.Java }} (${{ matrix.os }}) sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Setup java
|
- name: Setup java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
@ -333,9 +333,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 11
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -349,7 +349,7 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
|
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
|
||||||
|
|
||||||
- name: Set up Apache Maven Central
|
- name: Set up Apache Maven Central
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with: # running setup-java again overwrites the settings.xml
|
with: # running setup-java again overwrites the settings.xml
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -446,9 +446,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- name: Set up JDK 11 for Shared Runner
|
- name: Set up JDK 11 for Shared Runner
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -472,10 +472,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up JDK 11
|
- name: Set up JDK 11
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -509,14 +509,14 @@ Subsequent calls to `setup-java` with distinct distribution and version paramete
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: |
|
java-version: |
|
||||||
8
|
8
|
||||||
11
|
11
|
||||||
|
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: '15'
|
java-version: '15'
|
||||||
@ -528,7 +528,7 @@ The result is a Toolchain with entries for JDKs 8, 11 and 15. You can even combi
|
|||||||
- run: |
|
- run: |
|
||||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jdkfile'
|
distribution: 'jdkfile'
|
||||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||||
@ -545,7 +545,7 @@ Each JDK provider will receive a default `vendor` using the `distribution` input
|
|||||||
- run: |
|
- run: |
|
||||||
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
download_url="https://example.com/java/jdk/6u45-b06/jdk-6u45-linux-x64.tar.gz"
|
||||||
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
wget -O $RUNNER_TEMP/java_package.tar.gz $download_url
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'jdkfile'
|
distribution: 'jdkfile'
|
||||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||||
@ -560,7 +560,7 @@ In case you install multiple versions of Java at once with multi-line `java-vers
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: |
|
java-version: |
|
||||||
@ -574,8 +574,8 @@ Each JDK provider will receive a default `id` based on the combination of `distr
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
@ -587,7 +587,7 @@ In case you install multiple versions of Java at once you can use the same synta
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-java@v4
|
- uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: '<distribution>'
|
distribution: '<distribution>'
|
||||||
java-version: |
|
java-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;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user