mirror of
https://github.com/actions/setup-java.git
synced 2026-07-08 16:20:44 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9051c81518 | |||
| e8aa5c4d23 | |||
| f29bb0b8db | |||
| a2081b9e85 | |||
| 39f01ea699 |
@@ -669,107 +669,3 @@ jobs:
|
||||
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
||||
run: bash __tests__/verify-java.sh "17.0.10" "$JAVA_PATH"
|
||||
shell: bash
|
||||
|
||||
setup-java-version-from-file-with-inferred-dist:
|
||||
name: distribution inferred from file '${{ matrix.java-version-file }}' - ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
java-version-file: ['.java-version', '.tool-versions']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Create .java-version file
|
||||
shell: bash
|
||||
run: echo "temurin-17.0.10" > .java-version
|
||||
- name: Create .tool-versions file
|
||||
shell: bash
|
||||
run: echo "java temurin-17.0.10" > .tool-versions
|
||||
- name: setup-java
|
||||
uses: ./
|
||||
id: setup-java
|
||||
with:
|
||||
java-version-file: ${{matrix.java-version-file }}
|
||||
- name: Verify Java
|
||||
env:
|
||||
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
||||
run: bash __tests__/verify-java.sh "17.0.10" "$JAVA_PATH"
|
||||
shell: bash
|
||||
|
||||
setup-java-set-default:
|
||||
name: set-default option - ${{ matrix.os }}
|
||||
needs: setup-java-major-versions
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: Setup Java 17 as default
|
||||
uses: ./
|
||||
id: setup-java-17
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Setup Java 21 without setting as default
|
||||
uses: ./
|
||||
id: setup-java-21
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
set-default: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Verify JAVA_HOME still points to Java 17
|
||||
run: |
|
||||
echo "JAVA_HOME=$JAVA_HOME"
|
||||
echo "Java 17 path=${{ steps.setup-java-17.outputs.path }}"
|
||||
if [ "$JAVA_HOME" != "${{ steps.setup-java-17.outputs.path }}" ]; then
|
||||
echo "JAVA_HOME should still point to Java 17"
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
- name: Verify java -version reports Java 17
|
||||
run: |
|
||||
JAVA_VERSION=$(java -version 2>&1 | head -1)
|
||||
echo "java -version: $JAVA_VERSION"
|
||||
if ! echo "$JAVA_VERSION" | grep -q "17"; then
|
||||
echo "Default java should still be version 17"
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
- name: Verify JAVA_HOME_21 env var is set
|
||||
run: |
|
||||
$envName = "JAVA_HOME_21_${env:RUNNER_ARCH}"
|
||||
$JavaVersionPath = [Environment]::GetEnvironmentVariable($envName)
|
||||
if (-not $JavaVersionPath) {
|
||||
Write-Host "$envName is not set"
|
||||
exit 1
|
||||
}
|
||||
if (-not (Test-Path "$JavaVersionPath")) {
|
||||
Write-Host "$envName path does not exist: $JavaVersionPath"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "$envName=$JavaVersionPath"
|
||||
shell: pwsh
|
||||
- name: Verify Java 21 outputs are set
|
||||
run: |
|
||||
echo "Java 21 path=${{ steps.setup-java-21.outputs.path }}"
|
||||
echo "Java 21 version=${{ steps.setup-java-21.outputs.version }}"
|
||||
if [ -z "${{ steps.setup-java-21.outputs.path }}" ]; then
|
||||
echo "Java 21 path output should be set"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "${{ steps.setup-java-21.outputs.version }}" ]; then
|
||||
echo "Java 21 version output should be set"
|
||||
exit 1
|
||||
fi
|
||||
shell: bash
|
||||
|
||||
@@ -29,9 +29,9 @@ For more details, see the full release notes on the [releases page](https://git
|
||||
|
||||
- `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 a file containing java version. Supported file types are `.java-version`, `.tool-versions`, and `.sdkmanrc`. 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`: Java [distribution](#supported-distributions). Required unless `java-version-file` specifies a recognized distribution, for example a `.sdkmanrc` distribution suffix (`java=21.0.5-tem`) or a `.java-version`/`.tool-versions` distribution prefix (`temurin-21.0.5`).
|
||||
- `distribution`: _(required)_ Java [distribution](#supported-distributions).
|
||||
|
||||
- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`.
|
||||
|
||||
@@ -41,8 +41,6 @@ For more details, see the full release notes on the [releases page](https://git
|
||||
|
||||
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
||||
|
||||
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
|
||||
|
||||
- `verify-signature`: Verifies downloaded Java package signatures when supported by the selected distribution. Currently supported for `temurin` and `microsoft`. If set to `true` for unsupported distributions, the action fails.
|
||||
|
||||
- `verify-signature-public-key`: ASCII-armored GPG public key used to verify the downloaded package signature. Overrides the default bundled key for the selected distribution.
|
||||
@@ -147,8 +145,6 @@ The workflow output `cache-hit` is set to indicate if an exact match was found f
|
||||
|
||||
The cache input is optional, and caching is turned off by default.
|
||||
|
||||
**Maven Wrapper:** when `cache: 'maven'` is enabled, the action also caches and restores the Maven Wrapper distribution downloaded to `~/.m2/wrapper/dists` (in addition to the local repository), so wrapper-based (`./mvnw`) builds don't re-download the wrapper on every run. This is keyed on `**/.mvn/wrapper/maven-wrapper.properties` as shown above.
|
||||
|
||||
#### Caching gradle dependencies
|
||||
```yaml
|
||||
steps:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
7.0.352-zulu, 7.0.352
|
||||
8.0.282-trava, 8.0.282
|
||||
8.0.432-albba, 8.0.432
|
||||
8.0.432-amzn, 8
|
||||
8.0.432-amzn, 8.0.432
|
||||
8.0.432-kona, 8.0.432
|
||||
8.0.432-librca, 8.0.432
|
||||
8.0.432-sem, 8.0.432
|
||||
@@ -10,7 +10,7 @@
|
||||
8.0.432-zulu, 8.0.432
|
||||
8.0.432.fx-librca, 8.0.432
|
||||
8.0.432.fx-zulu, 8.0.432
|
||||
8.0.442-amzn, 8
|
||||
8.0.442-amzn, 8.0.442
|
||||
8.0.442-librca, 8.0.442
|
||||
8.0.442-tem, 8.0.442
|
||||
8.0.442-zulu, 8.0.442
|
||||
@@ -19,7 +19,7 @@
|
||||
11.0.14.1-jbr, 11.0.14
|
||||
11.0.15-trava, 11.0.15
|
||||
11.0.25-albba, 11.0.25
|
||||
11.0.25-amzn, 11
|
||||
11.0.25-amzn, 11.0.25
|
||||
11.0.25-kona, 11.0.25
|
||||
11.0.25-librca, 11.0.25
|
||||
11.0.25-ms, 11.0.25
|
||||
@@ -29,7 +29,7 @@
|
||||
11.0.25-zulu, 11.0.25
|
||||
11.0.25.fx-librca, 11.0.25
|
||||
11.0.25.fx-zulu, 11.0.25
|
||||
11.0.26-amzn, 11
|
||||
11.0.26-amzn, 11.0.26
|
||||
11.0.26-librca, 11.0.26
|
||||
11.0.26-ms, 11.0.26
|
||||
11.0.26-sapmchn, 11.0.26
|
||||
@@ -40,7 +40,7 @@
|
||||
17.0.12-jbr, 17.0.12
|
||||
17.0.12-oracle, 17.0.12
|
||||
17.0.13-albba, 17.0.13
|
||||
17.0.13-amzn, 17
|
||||
17.0.13-amzn, 17.0.13
|
||||
17.0.13-kona, 17.0.13
|
||||
17.0.13-librca, 17.0.13
|
||||
17.0.13-ms, 17.0.13
|
||||
@@ -52,7 +52,7 @@
|
||||
17.0.13.crac-zulu, 17.0.13
|
||||
17.0.13.fx-librca, 17.0.13
|
||||
17.0.13.fx-zulu, 17.0.13
|
||||
17.0.14-amzn, 17
|
||||
17.0.14-amzn, 17.0.14
|
||||
17.0.14-librca, 17.0.14
|
||||
17.0.14-ms, 17.0.14
|
||||
17.0.14-sapmchn, 17.0.14
|
||||
@@ -62,7 +62,7 @@
|
||||
17.0.9-graalce, 17.0.9
|
||||
21.0.2-graalce, 21.0.2
|
||||
21.0.2-open, 21.0.2
|
||||
21.0.5-amzn, 21
|
||||
21.0.5-amzn, 21.0.5
|
||||
21.0.5-graal, 21.0.5
|
||||
21.0.5-jbr, 21.0.5
|
||||
21.0.5-kona, 21.0.5
|
||||
@@ -77,7 +77,7 @@
|
||||
21.0.5.crac-zulu, 21.0.5
|
||||
21.0.5.fx-librca, 21.0.5
|
||||
21.0.5.fx-zulu, 21.0.5
|
||||
21.0.6-amzn, 21
|
||||
21.0.6-amzn, 21.0.6
|
||||
21.0.6-graal, 21.0.6
|
||||
21.0.6-librca, 21.0.6
|
||||
21.0.6-ms, 21.0.6
|
||||
@@ -94,7 +94,7 @@
|
||||
22.3.5.r17-mandrel, 22.3.5
|
||||
22.3.5.r17-nik, 22.3.5
|
||||
23-open, 23
|
||||
23.0.1-amzn, 23
|
||||
23.0.1-amzn, 23.0.1
|
||||
23.0.1-graal, 23.0.1
|
||||
23.0.1-graalce, 23.0.1
|
||||
23.0.1-librca, 23.0.1
|
||||
@@ -106,7 +106,7 @@
|
||||
23.0.1.crac-zulu, 23.0.1
|
||||
23.0.1.fx-librca, 23.0.1
|
||||
23.0.1.fx-zulu, 23.0.1
|
||||
23.0.2-amzn, 23
|
||||
23.0.2-amzn, 23.0.2
|
||||
23.0.2-graal, 23.0.2
|
||||
23.0.2-graalce, 23.0.2
|
||||
23.0.2-librca, 23.0.2
|
||||
|
||||
|
@@ -563,110 +563,6 @@ describe('setupJava', () => {
|
||||
expect(spyCoreExportVariable).not.toHaveBeenCalled();
|
||||
expect(spyCoreSetOutput).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not set JAVA_HOME and PATH when setDefault is false', async () => {
|
||||
mockJavaBase = new EmptyJavaBase({
|
||||
version: '11',
|
||||
architecture: 'x86',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false,
|
||||
setDefault: false
|
||||
});
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||
version: installedJavaVersion,
|
||||
path: javaPath
|
||||
});
|
||||
expect(spyCoreExportVariable).not.toHaveBeenCalledWith(
|
||||
'JAVA_HOME',
|
||||
expect.anything()
|
||||
);
|
||||
expect(spyCoreAddPath).not.toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'JAVA_HOME_11_X86',
|
||||
javaPath
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalledWith(
|
||||
'version',
|
||||
installedJavaVersion
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalledWith('path', javaPath);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalledWith('distribution', 'Empty');
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||
`Installing Java ${installedJavaVersion} (not setting as default)`
|
||||
);
|
||||
});
|
||||
|
||||
it('should set JAVA_HOME and PATH when setDefault is true', async () => {
|
||||
mockJavaBase = new EmptyJavaBase({
|
||||
version: '11',
|
||||
architecture: 'x86',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false,
|
||||
setDefault: true
|
||||
});
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||
version: installedJavaVersion,
|
||||
path: javaPath
|
||||
});
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith('JAVA_HOME', javaPath);
|
||||
expect(spyCoreAddPath).toHaveBeenCalledWith(path.join(javaPath, 'bin'));
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'JAVA_HOME_11_X86',
|
||||
javaPath
|
||||
);
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||
`Setting Java ${installedJavaVersion} as the default`
|
||||
);
|
||||
});
|
||||
|
||||
it('should default to setting as default when setDefault is not specified', async () => {
|
||||
mockJavaBase = new EmptyJavaBase({
|
||||
version: '11',
|
||||
architecture: 'x86',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||
version: installedJavaVersion,
|
||||
path: javaPath
|
||||
});
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith('JAVA_HOME', javaPath);
|
||||
expect(spyCoreAddPath).toHaveBeenCalledWith(path.join(javaPath, 'bin'));
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||
`Setting Java ${installedJavaVersion} as the default`
|
||||
);
|
||||
});
|
||||
|
||||
it('should download and not set default when setDefault is false', async () => {
|
||||
mockJavaBase = new EmptyJavaBase({
|
||||
version: '11',
|
||||
architecture: 'x64',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false,
|
||||
setDefault: false
|
||||
});
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||
version: '11.0.9',
|
||||
path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||
});
|
||||
expect(spyCoreExportVariable).not.toHaveBeenCalledWith(
|
||||
'JAVA_HOME',
|
||||
expect.anything()
|
||||
);
|
||||
expect(spyCoreAddPath).not.toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
'JAVA_HOME_11_X64',
|
||||
path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalledWith('version', '11.0.9');
|
||||
expect(spyCoreSetOutput).toHaveBeenCalledWith(
|
||||
'path',
|
||||
path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||
);
|
||||
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||
'Installing Java 11.0.9 (not setting as default)'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalizeVersion', () => {
|
||||
|
||||
+10
-126
@@ -166,60 +166,15 @@ describe('validatePaginationUrl', () => {
|
||||
describe('getVersionFromFileContent', () => {
|
||||
describe('.sdkmanrc', () => {
|
||||
it.each([
|
||||
['java=11.0.20.1-tem', '11.0.20', 'temurin'],
|
||||
['java = 11.0.20.1-tem', '11.0.20', 'temurin'],
|
||||
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20', 'temurin'],
|
||||
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
|
||||
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
|
||||
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20', 'temurin'], // first one is 'commented' in .sdkmanrc
|
||||
['java=21.0.5-zulu', '21.0.5', 'zulu'],
|
||||
['java=17.0.13-albba', '17.0.13', 'dragonwell'],
|
||||
['java=17.0.13-amzn', '17', 'corretto'],
|
||||
['java=21.0.5-graal', '21.0.5', 'graalvm'],
|
||||
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
|
||||
['java=11.0.25-librca', '11.0.25', 'liberica'],
|
||||
['java=11.0.25-ms', '11.0.25', 'microsoft'],
|
||||
['java=21.0.5-oracle', '21.0.5', 'oracle'],
|
||||
['java=11.0.25-sapmchn', '11.0.25', 'sapmachine'],
|
||||
['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
|
||||
['java=11.0.25-sem', '11.0.25', 'semeru'],
|
||||
['java=17.0.13-dragonwell', '17.0.13', 'dragonwell'],
|
||||
['java=21.0.5-kona', '21.0.5', 'kona']
|
||||
])(
|
||||
'parsing %s should return version %s and distribution %s',
|
||||
(content: string, expectedVersion: string, expectedDist: string) => {
|
||||
const actual = getVersionFromFileContent(
|
||||
content,
|
||||
'openjdk',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBe(expectedDist);
|
||||
}
|
||||
);
|
||||
|
||||
it('should warn and return undefined distribution for unknown identifier', () => {
|
||||
const warnSpy = jest.spyOn(core, 'warning');
|
||||
const actual = getVersionFromFileContent(
|
||||
'java=21.0.5-unknown',
|
||||
'temurin',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual?.version).toBe('21.0.5');
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Unknown SDKMAN distribution identifier')
|
||||
);
|
||||
});
|
||||
|
||||
it('should return version without distribution when no suffix provided', () => {
|
||||
const actual = getVersionFromFileContent(
|
||||
'java=11.0.20',
|
||||
'temurin',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual?.version).toBe('11.0.20');
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
['java=11.0.20.1-tem', '11.0.20'],
|
||||
['java = 11.0.20.1-tem', '11.0.20'],
|
||||
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
|
||||
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
|
||||
])('parsing %s should return %s', (content: string, expected: string) => {
|
||||
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
|
||||
describe('known versions', () => {
|
||||
@@ -238,82 +193,11 @@ describe('getVersionFromFileContent', () => {
|
||||
'openjdk',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual?.version).toBe(expected);
|
||||
expect(actual).toBe(expected);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.java-version', () => {
|
||||
it.each([
|
||||
['temurin-21.0.5', '21.0.5', 'temurin'],
|
||||
['temurin-17', '17', 'temurin'], // hyphen separator is not captured into the distribution
|
||||
['temurin-21.0.5+11.0.LTS', '21.0.5+11.0.LTS', 'temurin'],
|
||||
['zulu64-8.0.202', '8.0.202', 'zulu'],
|
||||
['temurin64-17', '17', 'temurin'],
|
||||
['corretto-17', '17', 'corretto'], // corretto reduced to major version
|
||||
['graalvm-community-17.0.9', '17.0.9', 'graalvm-community']
|
||||
])(
|
||||
'parsing %s should return version %s and distribution %s',
|
||||
(content: string, expectedVersion: string, expectedDist: string) => {
|
||||
const actual = getVersionFromFileContent(content, '', '.java-version');
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBe(expectedDist);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['17.0.7', '17.0.7'],
|
||||
['17', '17'],
|
||||
['15-ea', '15-ea'],
|
||||
['15.0.0-ea', '15.0.0-ea'],
|
||||
['8.0.282+8', '8.0.282+8'],
|
||||
['1.8.0.202', '8.0.202'],
|
||||
['openjdk64-11.0.2', '11.0.2'] // generic openjdk prefix is not a supported distribution
|
||||
])(
|
||||
'parsing %s should return version %s and undefined distribution',
|
||||
(content: string, expectedVersion: string) => {
|
||||
const actual = getVersionFromFileContent(
|
||||
content,
|
||||
'temurin',
|
||||
'.java-version'
|
||||
);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('.tool-versions', () => {
|
||||
it.each([
|
||||
['java temurin-21.0.5+11.0.LTS', '21.0.5+11.0.LTS', 'temurin'],
|
||||
['java corretto-11', '11', 'corretto']
|
||||
])(
|
||||
'parsing %s should return version %s and distribution %s',
|
||||
(content: string, expectedVersion: string, expectedDist: string) => {
|
||||
const actual = getVersionFromFileContent(content, '', '.tool-versions');
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBe(expectedDist);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['java 17', '17'],
|
||||
['java 17.0.10', '17.0.10'],
|
||||
['java openjdk64-17.0.10', '17.0.10'] // generic openjdk prefix is ignored
|
||||
])(
|
||||
'parsing %s should return version %s and undefined distribution',
|
||||
(content: string, expectedVersion: string) => {
|
||||
const actual = getVersionFromFileContent(
|
||||
content,
|
||||
'temurin',
|
||||
'.tool-versions'
|
||||
);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isGhes', () => {
|
||||
|
||||
+2
-6
@@ -10,8 +10,8 @@ inputs:
|
||||
description: 'The path to a file containing the Java version to set up (.java-version, .tool-versions, .sdkmanrc). Used when java-version is not set. See examples of supported syntax in README file'
|
||||
required: false
|
||||
distribution:
|
||||
description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file specifies a recognized distribution (e.g., .sdkmanrc suffix java=21.0.5-tem, or .java-version/.tool-versions prefix temurin-21.0.5).'
|
||||
required: false
|
||||
description: 'Java distribution. See the list of supported distributions in README file'
|
||||
required: true
|
||||
java-package:
|
||||
description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
|
||||
required: false
|
||||
@@ -26,10 +26,6 @@ inputs:
|
||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||
required: false
|
||||
default: false
|
||||
set-default:
|
||||
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
|
||||
required: false
|
||||
default: true
|
||||
verify-signature:
|
||||
description: 'Verify downloaded Java package signatures when supported by the selected distribution'
|
||||
required: false
|
||||
|
||||
Vendored
+10
-102
@@ -52241,7 +52241,7 @@ else {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.SUPPORTED_DISTRIBUTIONS = exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_SET_DEFAULT = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
@@ -52250,7 +52250,6 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||
exports.INPUT_SET_DEFAULT = 'set-default';
|
||||
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||
exports.INPUT_SERVER_ID = 'server-id';
|
||||
@@ -52276,26 +52275,6 @@ exports.MAVEN_ARGS_ENV = 'MAVEN_ARGS';
|
||||
exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
|
||||
exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
|
||||
// Distribution names supported by the `distribution` input. Used to validate
|
||||
// distribution identifiers inferred from a `.java-version`/`.tool-versions` file.
|
||||
exports.SUPPORTED_DISTRIBUTIONS = [
|
||||
'adopt',
|
||||
'adopt-hotspot',
|
||||
'adopt-openj9',
|
||||
'temurin',
|
||||
'zulu',
|
||||
'liberica',
|
||||
'microsoft',
|
||||
'semeru',
|
||||
'corretto',
|
||||
'oracle',
|
||||
'dragonwell',
|
||||
'sapmachine',
|
||||
'graalvm',
|
||||
'graalvm-community',
|
||||
'jetbrains',
|
||||
'kona'
|
||||
];
|
||||
|
||||
|
||||
/***/ }),
|
||||
@@ -52592,48 +52571,25 @@ function isCacheFeatureAvailable() {
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c, _d, _e;
|
||||
let javaVersionRegExp;
|
||||
let extractedDistribution;
|
||||
function getFileName(versionFile) {
|
||||
return path_1.default.basename(versionFile);
|
||||
}
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
javaVersionRegExp =
|
||||
/^java\s+(?:(?<distribution>\S*?)-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
}
|
||||
else if (versionFileName == '.sdkmanrc') {
|
||||
// Match both version and optional distribution identifier
|
||||
javaVersionRegExp =
|
||||
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
|
||||
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
|
||||
}
|
||||
else {
|
||||
// .java-version (jenv), version optionally prefixed with a distribution
|
||||
// identifier, e.g. `temurin-21.0.5` or `openjdk64-11.0.2`.
|
||||
javaVersionRegExp =
|
||||
/(?:(?<distribution>[a-zA-Z][a-zA-Z0-9-]*?)-)?(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
}
|
||||
const match = content.match(javaVersionRegExp);
|
||||
const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
|
||||
? match.groups.version
|
||||
const capturedVersion = ((_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
|
||||
: '';
|
||||
// Extract distribution from .sdkmanrc file
|
||||
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
|
||||
const sdkmanDist = match.groups.distribution;
|
||||
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
|
||||
}
|
||||
// Extract distribution from .java-version (jenv) or .tool-versions (asdf) file
|
||||
if (versionFileName != '.sdkmanrc' &&
|
||||
((_c = match === null || match === void 0 ? void 0 : match.groups) === null || _c === void 0 ? void 0 : _c.distribution) &&
|
||||
capturedVersion) {
|
||||
const fileDistribution = match.groups.distribution;
|
||||
extractedDistribution = mapJavaVersionFileDistribution(fileDistribution);
|
||||
if (extractedDistribution) {
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from identifier '${fileDistribution}' in '${versionFileName}'`);
|
||||
}
|
||||
}
|
||||
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
|
||||
if (!capturedVersion) {
|
||||
return null;
|
||||
@@ -52647,61 +52603,13 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
|
||||
// (either explicitly provided or extracted from the version file) is in the list.
|
||||
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
|
||||
const coerceVersion = (_d = semver.coerce(version)) !== null && _d !== void 0 ? _d : version;
|
||||
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
return {
|
||||
version: version.toString(),
|
||||
distribution: extractedDistribution
|
||||
};
|
||||
return version.toString();
|
||||
}
|
||||
exports.getVersionFromFileContent = getVersionFromFileContent;
|
||||
// Map SDKMAN distribution identifiers to setup-java distribution names
|
||||
function mapSdkmanDistribution(sdkmanDist) {
|
||||
const distributionMap = {
|
||||
tem: 'temurin',
|
||||
sem: 'semeru',
|
||||
albba: 'dragonwell',
|
||||
zulu: 'zulu',
|
||||
amzn: 'corretto',
|
||||
graal: 'graalvm',
|
||||
graalce: 'graalvm',
|
||||
librca: 'liberica',
|
||||
ms: 'microsoft',
|
||||
oracle: 'oracle',
|
||||
sapmchn: 'sapmachine',
|
||||
jbr: 'jetbrains',
|
||||
dragonwell: 'dragonwell',
|
||||
kona: 'kona'
|
||||
};
|
||||
const mapped = distributionMap[sdkmanDist.toLowerCase()];
|
||||
if (!mapped) {
|
||||
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// Map a distribution identifier found in a `.java-version` (jenv) or
|
||||
// `.tool-versions` (asdf) file to a setup-java distribution name.
|
||||
// jenv-style identifiers may carry an architecture suffix (e.g. `openjdk64`,
|
||||
// `temurin64`), which is stripped before matching. Identifiers that do not map
|
||||
// to a supported distribution (e.g. the generic `openjdk`) are ignored so the
|
||||
// `distribution` input is used instead.
|
||||
function mapJavaVersionFileDistribution(identifier) {
|
||||
const normalized = identifier.toLowerCase();
|
||||
if (constants_1.SUPPORTED_DISTRIBUTIONS.includes(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
// Strip a trailing architecture suffix (e.g. `temurin64` -> `temurin`).
|
||||
const withoutArch = normalized.replace(/(32|64)$/, '');
|
||||
if (constants_1.SUPPORTED_DISTRIBUTIONS.includes(withoutArch)) {
|
||||
return withoutArch;
|
||||
}
|
||||
core.debug(`Distribution identifier '${identifier}' from version file is not a supported distribution; falling back to the 'distribution' input.`);
|
||||
return undefined;
|
||||
}
|
||||
// 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;
|
||||
|
||||
Vendored
+30
-167
@@ -78001,7 +78001,7 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.SUPPORTED_DISTRIBUTIONS = exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_SET_DEFAULT = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
@@ -78010,7 +78010,6 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||
exports.INPUT_SET_DEFAULT = 'set-default';
|
||||
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||
exports.INPUT_SERVER_ID = 'server-id';
|
||||
@@ -78036,26 +78035,6 @@ exports.MAVEN_ARGS_ENV = 'MAVEN_ARGS';
|
||||
exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
|
||||
exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
|
||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
|
||||
// Distribution names supported by the `distribution` input. Used to validate
|
||||
// distribution identifiers inferred from a `.java-version`/`.tool-versions` file.
|
||||
exports.SUPPORTED_DISTRIBUTIONS = [
|
||||
'adopt',
|
||||
'adopt-hotspot',
|
||||
'adopt-openj9',
|
||||
'temurin',
|
||||
'zulu',
|
||||
'liberica',
|
||||
'microsoft',
|
||||
'semeru',
|
||||
'corretto',
|
||||
'oracle',
|
||||
'dragonwell',
|
||||
'sapmachine',
|
||||
'graalvm',
|
||||
'graalvm-community',
|
||||
'jetbrains',
|
||||
'kona'
|
||||
];
|
||||
|
||||
|
||||
/***/ }),
|
||||
@@ -78346,10 +78325,6 @@ class JavaBase {
|
||||
this.architecture = installerOptions.architecture || os_1.default.arch();
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
this.setDefault =
|
||||
installerOptions.setDefault !== undefined
|
||||
? installerOptions.setDefault
|
||||
: true;
|
||||
this.verifySignature = (_a = installerOptions.verifySignature) !== null && _a !== void 0 ? _a : false;
|
||||
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
||||
}
|
||||
@@ -78470,14 +78445,8 @@ class JavaBase {
|
||||
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
if (this.setDefault) {
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
}
|
||||
else {
|
||||
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
|
||||
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||
}
|
||||
return foundJava;
|
||||
});
|
||||
}
|
||||
@@ -78578,12 +78547,9 @@ class JavaBase {
|
||||
return error;
|
||||
}
|
||||
setJavaDefault(version, toolPath) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path_1.default.join(toolPath, 'bin'));
|
||||
this.setJavaEnvironment(version, toolPath);
|
||||
}
|
||||
setJavaEnvironment(version, toolPath) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
@@ -80082,14 +80048,8 @@ class LocalDistribution extends base_installer_1.JavaBase {
|
||||
if (process.platform === 'darwin' && fs_1.default.existsSync(macOSPostfixPath)) {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
if (this.setDefault) {
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
core.info(`Setting Java ${foundJava.version} as default`);
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
}
|
||||
else {
|
||||
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
|
||||
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||
}
|
||||
return foundJava;
|
||||
});
|
||||
}
|
||||
@@ -81562,7 +81522,9 @@ function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
|
||||
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, {
|
||||
required: true
|
||||
});
|
||||
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
@@ -81570,7 +81532,6 @@ function run() {
|
||||
const cache = core.getInput(constants.INPUT_CACHE);
|
||||
const cacheDependencyPath = core.getInput(constants.INPUT_CACHE_DEPENDENCY_PATH);
|
||||
const checkLatest = (0, util_1.getBooleanInput)(constants.INPUT_CHECK_LATEST, false);
|
||||
const setDefault = (0, util_1.getBooleanInput)(constants.INPUT_SET_DEFAULT, true);
|
||||
const verifySignature = (0, util_1.getBooleanInput)(constants.INPUT_VERIFY_SIGNATURE, false);
|
||||
const verifySignaturePublicKey = core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||
@@ -81581,55 +81542,29 @@ function run() {
|
||||
if (!versions.length && !versionFile) {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
const installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
if (!versions.length) {
|
||||
core.debug('java-version input is empty, looking for java-version-file input');
|
||||
const content = fs_1.default.readFileSync(versionFile).toString().trim();
|
||||
const versionInfo = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
|
||||
core.debug(`Parsed version from file '${versionInfo === null || versionInfo === void 0 ? void 0 : versionInfo.version}'`);
|
||||
if (!versionInfo) {
|
||||
const version = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
if (!version) {
|
||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||
}
|
||||
// Use distribution from file if available, otherwise use the input
|
||||
if (versionInfo.distribution) {
|
||||
core.info(`Using distribution '${versionInfo.distribution}' from ${versionFile}`);
|
||||
distributionName = versionInfo.distribution;
|
||||
yield installVersion(version, installerInputsOptions);
|
||||
}
|
||||
else if (!distributionName) {
|
||||
throw new Error('distribution input is required when not specified in the version file');
|
||||
}
|
||||
const installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
yield installVersion(versionInfo.version, installerInputsOptions);
|
||||
}
|
||||
else {
|
||||
// When using java-version input, distribution is still required
|
||||
if (!distributionName) {
|
||||
throw new Error('distribution input is required');
|
||||
}
|
||||
const installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
for (const [index, version] of versions.entries()) {
|
||||
yield installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
@@ -81647,12 +81582,11 @@ function run() {
|
||||
run();
|
||||
function installVersion(version, options, toolchainId = 0) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
||||
const { distributionName, jdkFile, architecture, packageType, checkLatest, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
||||
const installerOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
version
|
||||
@@ -82010,48 +81944,25 @@ function isCacheFeatureAvailable() {
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
var _a, _b, _c, _d;
|
||||
var _a, _b, _c, _d, _e;
|
||||
let javaVersionRegExp;
|
||||
let extractedDistribution;
|
||||
function getFileName(versionFile) {
|
||||
return path_1.default.basename(versionFile);
|
||||
}
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
javaVersionRegExp =
|
||||
/^java\s+(?:(?<distribution>\S*?)-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
}
|
||||
else if (versionFileName == '.sdkmanrc') {
|
||||
// Match both version and optional distribution identifier
|
||||
javaVersionRegExp =
|
||||
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
|
||||
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
|
||||
}
|
||||
else {
|
||||
// .java-version (jenv), version optionally prefixed with a distribution
|
||||
// identifier, e.g. `temurin-21.0.5` or `openjdk64-11.0.2`.
|
||||
javaVersionRegExp =
|
||||
/(?:(?<distribution>[a-zA-Z][a-zA-Z0-9-]*?)-)?(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
}
|
||||
const match = content.match(javaVersionRegExp);
|
||||
const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
|
||||
? match.groups.version
|
||||
const capturedVersion = ((_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
|
||||
: '';
|
||||
// Extract distribution from .sdkmanrc file
|
||||
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
|
||||
const sdkmanDist = match.groups.distribution;
|
||||
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
|
||||
}
|
||||
// Extract distribution from .java-version (jenv) or .tool-versions (asdf) file
|
||||
if (versionFileName != '.sdkmanrc' &&
|
||||
((_c = match === null || match === void 0 ? void 0 : match.groups) === null || _c === void 0 ? void 0 : _c.distribution) &&
|
||||
capturedVersion) {
|
||||
const fileDistribution = match.groups.distribution;
|
||||
extractedDistribution = mapJavaVersionFileDistribution(fileDistribution);
|
||||
if (extractedDistribution) {
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from identifier '${fileDistribution}' in '${versionFileName}'`);
|
||||
}
|
||||
}
|
||||
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
|
||||
if (!capturedVersion) {
|
||||
return null;
|
||||
@@ -82065,61 +81976,13 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
|
||||
// (either explicitly provided or extracted from the version file) is in the list.
|
||||
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
|
||||
const coerceVersion = (_d = semver.coerce(version)) !== null && _d !== void 0 ? _d : version;
|
||||
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
return {
|
||||
version: version.toString(),
|
||||
distribution: extractedDistribution
|
||||
};
|
||||
return version.toString();
|
||||
}
|
||||
exports.getVersionFromFileContent = getVersionFromFileContent;
|
||||
// Map SDKMAN distribution identifiers to setup-java distribution names
|
||||
function mapSdkmanDistribution(sdkmanDist) {
|
||||
const distributionMap = {
|
||||
tem: 'temurin',
|
||||
sem: 'semeru',
|
||||
albba: 'dragonwell',
|
||||
zulu: 'zulu',
|
||||
amzn: 'corretto',
|
||||
graal: 'graalvm',
|
||||
graalce: 'graalvm',
|
||||
librca: 'liberica',
|
||||
ms: 'microsoft',
|
||||
oracle: 'oracle',
|
||||
sapmchn: 'sapmachine',
|
||||
jbr: 'jetbrains',
|
||||
dragonwell: 'dragonwell',
|
||||
kona: 'kona'
|
||||
};
|
||||
const mapped = distributionMap[sdkmanDist.toLowerCase()];
|
||||
if (!mapped) {
|
||||
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// Map a distribution identifier found in a `.java-version` (jenv) or
|
||||
// `.tool-versions` (asdf) file to a setup-java distribution name.
|
||||
// jenv-style identifiers may carry an architecture suffix (e.g. `openjdk64`,
|
||||
// `temurin64`), which is stripped before matching. Identifiers that do not map
|
||||
// to a supported distribution (e.g. the generic `openjdk`) are ignored so the
|
||||
// `distribution` input is used instead.
|
||||
function mapJavaVersionFileDistribution(identifier) {
|
||||
const normalized = identifier.toLowerCase();
|
||||
if (constants_1.SUPPORTED_DISTRIBUTIONS.includes(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
// Strip a trailing architecture suffix (e.g. `temurin64` -> `temurin`).
|
||||
const withoutArch = normalized.replace(/(32|64)$/, '');
|
||||
if (constants_1.SUPPORTED_DISTRIBUTIONS.includes(withoutArch)) {
|
||||
return withoutArch;
|
||||
}
|
||||
core.debug(`Distribution identifier '${identifier}' from version file is not a supported distribution; falling back to the 'distribution' input.`);
|
||||
return undefined;
|
||||
}
|
||||
// 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;
|
||||
|
||||
+5
-104
@@ -16,7 +16,6 @@
|
||||
- [Installing custom Java package type](#Installing-custom-Java-package-type)
|
||||
- [JavaFX Maven project](#JavaFX-Maven-project)
|
||||
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
|
||||
- [Installing JDK without setting as default](#Installing-JDK-without-setting-as-default)
|
||||
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
|
||||
- [Testing against different Java distributions](#Testing-against-different-Java-distributions)
|
||||
- [Testing against different platforms](#Testing-against-different-platforms)
|
||||
@@ -298,34 +297,6 @@ steps:
|
||||
- run: java --version
|
||||
```
|
||||
|
||||
## Installing JDK without setting as default
|
||||
|
||||
When installing multiple JDKs, the last one installed becomes the default (`JAVA_HOME`, `PATH`). Use the `set-default` option to install a JDK without overriding the default. The installed JDK is still discoverable via the `JAVA_HOME_<major>_<arch>` environment variable (e.g. `JAVA_HOME_21_X64`).
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
- uses: actions/setup-java@v5
|
||||
id: setup-java-21
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
set-default: false
|
||||
- run: |
|
||||
echo "Default java:"
|
||||
java -version
|
||||
echo "Java 21 home: $JAVA_HOME_21_X64"
|
||||
echo "Java 21 path from output: ${{ steps.setup-java-21.outputs.path }}"
|
||||
```
|
||||
|
||||
In this example, `JAVA_HOME` and `java` on `PATH` point to Java 17, while Java 21 is available via `JAVA_HOME_21_X64` or the step output `path`.
|
||||
|
||||
> **Note:** When a single step installs multiple JDKs via a multiline `java-version`, the `set-default` value applies to all of them. With `set-default: false`, none of those JDKs become the default; each remains discoverable through its `JAVA_HOME_<major>_<arch>` variable. Regardless of `set-default`, installed JDKs are still registered in the Maven toolchains file, so they can be selected via Maven toolchains.
|
||||
|
||||
## Installing Java from local file
|
||||
If your use-case requires a custom distribution or a version that is not provided by setup-java, you can download it manually and setup-java will take care of the installation and caching on the VM:
|
||||
|
||||
@@ -516,8 +487,6 @@ The two `settings.xml` files created from the above example look like the follow
|
||||
|
||||
***NOTE***: The `settings.xml` file is created in the Actions `$HOME/.m2` directory. If you have an existing `settings.xml` file at that location, it will be overwritten. See [below](#apache-maven-with-a-settings-path) for using the `settings-path` to change your `settings.xml` file location.
|
||||
|
||||
***NOTE***: The generated `settings.xml` sets `<interactiveMode>false</interactiveMode>` so that Maven never blocks a CI run waiting on an interactive prompt. This is applied automatically whenever the action generates `settings.xml`.
|
||||
|
||||
If you don't want to overwrite the `settings.xml` file, you can set `overwrite-settings: false`
|
||||
|
||||
### Extra setup for pom.xml:
|
||||
@@ -603,44 +572,6 @@ jobs:
|
||||
- This setting only affects Maven. It has no effect on Gradle, sbt, or other build tools.
|
||||
- `-ntp` only controls transfer/progress output; it does not change whether Maven runs in batch mode. Use `-B`/`--batch-mode` (or `<interactiveMode>false</interactiveMode>` in `settings.xml`) if you also want non-interactive runs.
|
||||
|
||||
## Java problem matcher (compiler annotations)
|
||||
|
||||
`setup-java` registers a [problem matcher](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) for Java after installing the JDK. It scans the log output of subsequent steps and turns `javac` diagnostics into GitHub [annotations](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message) that appear in the run summary and inline on the affected files. It matches two kinds of lines:
|
||||
|
||||
- Compiler errors and warnings, e.g. `App.java:12: error: cannot find symbol` (owner `javac`).
|
||||
- Uncaught-exception header lines, e.g. `Exception in thread "main" ...`; because these lines have no file or line captures, they appear as log/run-level annotations rather than inline file annotations (owner `java`).
|
||||
|
||||
This is enabled by default and requires no configuration.
|
||||
|
||||
### Disabling the problem matcher
|
||||
|
||||
There is no action input to turn the matcher off, but you can disable it for the rest of the job with the built-in [`remove-matcher`](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md#remove-a-problem-matcher) workflow command. Pass the matcher **owner** (not a file name); the Java matcher defines two owners, `javac` and `java`, so remove both to fully suppress it:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: '<distribution>'
|
||||
java-version: '21'
|
||||
|
||||
- name: Disable the Java problem matcher
|
||||
run: |
|
||||
echo "::remove-matcher owner=javac::"
|
||||
echo "::remove-matcher owner=java::"
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
```
|
||||
|
||||
***NOTES***:
|
||||
- `remove-matcher` only stops annotations from being created; the underlying compiler output is unchanged, so a failing `javac`/build still fails the step.
|
||||
- The command is scoped to the job, so add the step right after `setup-java` (and before your build) in every job where you want the matcher disabled.
|
||||
|
||||
## Publishing using Gradle
|
||||
```yaml
|
||||
jobs:
|
||||
@@ -779,36 +710,20 @@ steps:
|
||||
If the `java-version-file` input is specified, the action will extract the version from the file and install it.
|
||||
|
||||
Supported files are `.java-version`, `.tool-versions` and `.sdkmanrc`.
|
||||
* In `.java-version` file, only the version should be specified (e.g., 17.0.7). The `.java-version` file recognizes all variants of the version description according to [jenv](https://github.com/jenv/jenv). A [supported distribution](#supported-distributions) may optionally be specified as a prefix (e.g., `temurin-17.0.7`), in which case setup-java infers the `distribution` input automatically. Generic prefixes that are not a supported distribution (e.g., `openjdk64-17.0.7`) are ignored and require setting `distribution` explicitly.
|
||||
* In `.tool-versions` file, java version should be preceded by the java keyword (e.g., java 17.0.7). The `.tool-versions` file supports version specifications in accordance with [asdf](https://github.com/asdf-vm/asdf) standards, adhering to Semantic Versioning ([semver](https://semver.org/)). As with `.java-version`, a supported distribution may be specified as a prefix (e.g., `java temurin-17.0.7`) to infer the `distribution` input automatically.
|
||||
* In `.sdkmanrc` file, java version should be preceded by the `java=` prefix (e.g., `java=17.0.7-tem`). When a recognized SDKMAN distribution suffix is present, setup-java can infer the `distribution` input automatically. Unrecognized suffixes require setting `distribution` explicitly. The `.sdkmanrc` file supports version specifications in accordance with [file format](https://sdkman.io/usage#env-command), see [Sdkman! documentation](https://sdkman.io/jdks) for more information.
|
||||
|
||||
Supported SDKMAN suffix mappings:
|
||||
|
||||
| SDKMAN suffix | setup-java distribution |
|
||||
| ------------- | ----------------------- |
|
||||
| `tem` | `temurin` |
|
||||
| `sem` | `semeru` |
|
||||
| `albba`, `dragonwell` | `dragonwell` |
|
||||
| `zulu` | `zulu` |
|
||||
| `amzn` | `corretto` |
|
||||
| `graal`, `graalce` | `graalvm` |
|
||||
| `librca` | `liberica` |
|
||||
| `ms` | `microsoft` |
|
||||
| `oracle` | `oracle` |
|
||||
| `sapmchn` | `sapmachine` |
|
||||
| `jbr` | `jetbrains` |
|
||||
| `kona` | `kona` |
|
||||
* In `.java-version` file, only the version should be specified (e.g., 17.0.7). The `.java-version` file recognizes all variants of the version description according to [jenv](https://github.com/jenv/jenv).
|
||||
* In `.tool-versions` file, java version should be preceded by the java keyword (e.g., java 17.0.7). The `.tool-versions` file supports version specifications in accordance with [asdf](https://github.com/asdf-vm/asdf) standards, adhering to Semantic Versioning ([semver](https://semver.org/)).
|
||||
* In `.sdkmanrc` file, java version should be preceded by the `java=` prefix (e.g., java=17.0.7-tem) and include the distribution. The `.sdkmanrc` file supports version specifications in accordance with [file format](https://sdkman.io/usage#env-command), see [Sdkman! documentation](https://sdkman.io/jdks) for more information.
|
||||
|
||||
|
||||
If both `java-version` and `java-version-file` **inputs** are provided, the `java-version` input will be used.
|
||||
|
||||
**Example step using `Sdkman!`** (distribution inferred from `.sdkmanrc`):
|
||||
**Example step using `Sdkman!`**:
|
||||
```yml
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version-file: '.sdkmanrc'
|
||||
distribution: 'temurin'
|
||||
```
|
||||
|
||||
**Example `.sdkmanrc`**:
|
||||
@@ -816,26 +731,12 @@ steps:
|
||||
java=17.0.7-tem
|
||||
```
|
||||
|
||||
**Example step using `.java-version`** (distribution inferred from the file):
|
||||
```yml
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version-file: '.java-version'
|
||||
```
|
||||
|
||||
**Example `.java-version`** (distribution inferred from the `temurin-` prefix):
|
||||
```
|
||||
temurin-17.0.7
|
||||
```
|
||||
|
||||
Valid entry options (does not apply to `.sdkmanrc`):
|
||||
```
|
||||
major versions: 8, 11, 16, 17, 21
|
||||
more specific versions: 8.0.282+8, 8.0.232, 11.0, 11.0.4, 17.0
|
||||
early access (EA) versions: 15-ea, 15.0.0-ea
|
||||
versions with specified distribution: openjdk64-11.0.2
|
||||
versions with inferred distribution: temurin-17.0.7, corretto-21
|
||||
LTS versions : temurin-21.0.5+11.0.LTS
|
||||
```
|
||||
If the file contains multiple versions, only the first one will be recognized.
|
||||
|
||||
@@ -6,7 +6,6 @@ export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
export const INPUT_JDK_FILE = 'jdkFile';
|
||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||
export const INPUT_SET_DEFAULT = 'set-default';
|
||||
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||
export const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||
export const INPUT_SERVER_ID = 'server-id';
|
||||
@@ -38,24 +37,3 @@ export const MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
|
||||
export const MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
|
||||
|
||||
export const DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
|
||||
|
||||
// Distribution names supported by the `distribution` input. Used to validate
|
||||
// distribution identifiers inferred from a `.java-version`/`.tool-versions` file.
|
||||
export const SUPPORTED_DISTRIBUTIONS = [
|
||||
'adopt',
|
||||
'adopt-hotspot',
|
||||
'adopt-openj9',
|
||||
'temurin',
|
||||
'zulu',
|
||||
'liberica',
|
||||
'microsoft',
|
||||
'semeru',
|
||||
'corretto',
|
||||
'oracle',
|
||||
'dragonwell',
|
||||
'sapmachine',
|
||||
'graalvm',
|
||||
'graalvm-community',
|
||||
'jetbrains',
|
||||
'kona'
|
||||
];
|
||||
|
||||
@@ -20,7 +20,6 @@ export abstract class JavaBase {
|
||||
protected packageType: string;
|
||||
protected stable: boolean;
|
||||
protected checkLatest: boolean;
|
||||
protected setDefault: boolean;
|
||||
protected verifySignature: boolean;
|
||||
protected verifySignaturePublicKey: string | undefined;
|
||||
|
||||
@@ -39,10 +38,6 @@ export abstract class JavaBase {
|
||||
this.architecture = installerOptions.architecture || os.arch();
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
this.setDefault =
|
||||
installerOptions.setDefault !== undefined
|
||||
? installerOptions.setDefault
|
||||
: true;
|
||||
this.verifySignature = installerOptions.verifySignature ?? false;
|
||||
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
||||
}
|
||||
@@ -184,15 +179,8 @@ export abstract class JavaBase {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
|
||||
if (this.setDefault) {
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
} else {
|
||||
core.info(
|
||||
`Installing Java ${foundJava.version} (not setting as default)`
|
||||
);
|
||||
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||
}
|
||||
|
||||
return foundJava;
|
||||
}
|
||||
@@ -324,13 +312,9 @@ export abstract class JavaBase {
|
||||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
this.setJavaEnvironment(version, toolPath);
|
||||
}
|
||||
|
||||
protected setJavaEnvironment(version: string, toolPath: string) {
|
||||
const majorVersion = version.split('.')[0];
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
|
||||
@@ -3,7 +3,6 @@ export interface JavaInstallerOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
setDefault?: boolean;
|
||||
verifySignature?: boolean;
|
||||
verifySignaturePublicKey?: string;
|
||||
}
|
||||
|
||||
@@ -69,15 +69,9 @@ export class LocalDistribution extends JavaBase {
|
||||
foundJava.path = macOSPostfixPath;
|
||||
}
|
||||
|
||||
if (this.setDefault) {
|
||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||
core.info(`Setting Java ${foundJava.version} as default`);
|
||||
|
||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||
} else {
|
||||
core.info(
|
||||
`Installing Java ${foundJava.version} (not setting as default)`
|
||||
);
|
||||
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||
}
|
||||
return foundJava;
|
||||
}
|
||||
|
||||
|
||||
+18
-50
@@ -17,7 +17,9 @@ import {configureMavenArgs} from './maven-args';
|
||||
async function run() {
|
||||
try {
|
||||
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
|
||||
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
|
||||
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, {
|
||||
required: true
|
||||
});
|
||||
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
@@ -27,7 +29,6 @@ async function run() {
|
||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||
);
|
||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
|
||||
const verifySignature = getBooleanInput(
|
||||
constants.INPUT_VERIFY_SIGNATURE,
|
||||
false
|
||||
@@ -46,72 +47,42 @@ async function run() {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
if (!versions.length) {
|
||||
core.debug(
|
||||
'java-version input is empty, looking for java-version-file input'
|
||||
);
|
||||
const content = fs.readFileSync(versionFile).toString().trim();
|
||||
|
||||
const versionInfo = getVersionFromFileContent(
|
||||
const version = getVersionFromFileContent(
|
||||
content,
|
||||
distributionName,
|
||||
versionFile
|
||||
);
|
||||
core.debug(`Parsed version from file '${versionInfo?.version}'`);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
|
||||
if (!versionInfo) {
|
||||
if (!version) {
|
||||
throw new Error(
|
||||
`No supported version was found in file ${versionFile}`
|
||||
);
|
||||
}
|
||||
|
||||
// Use distribution from file if available, otherwise use the input
|
||||
if (versionInfo.distribution) {
|
||||
core.info(
|
||||
`Using distribution '${versionInfo.distribution}' from ${versionFile}`
|
||||
);
|
||||
distributionName = versionInfo.distribution;
|
||||
} else if (!distributionName) {
|
||||
throw new Error(
|
||||
'distribution input is required when not specified in the version file'
|
||||
);
|
||||
await installVersion(version, installerInputsOptions);
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
await installVersion(versionInfo.version, installerInputsOptions);
|
||||
} else {
|
||||
// When using java-version input, distribution is still required
|
||||
if (!distributionName) {
|
||||
throw new Error('distribution input is required');
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
|
||||
@@ -139,7 +110,6 @@ async function installVersion(
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
toolchainIds
|
||||
@@ -149,7 +119,6 @@ async function installVersion(
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
setDefault,
|
||||
verifySignature,
|
||||
verifySignaturePublicKey,
|
||||
version
|
||||
@@ -186,7 +155,6 @@ interface installerInputsOptions {
|
||||
architecture: string;
|
||||
packageType: string;
|
||||
checkLatest: boolean;
|
||||
setDefault: boolean;
|
||||
verifySignature: boolean;
|
||||
verifySignaturePublicKey: string | undefined;
|
||||
distributionName: string;
|
||||
|
||||
+9
-113
@@ -6,11 +6,7 @@ import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import {
|
||||
INPUT_JOB_STATUS,
|
||||
DISTRIBUTIONS_ONLY_MAJOR_VERSION,
|
||||
SUPPORTED_DISTRIBUTIONS
|
||||
} from './constants';
|
||||
import {INPUT_JOB_STATUS, DISTRIBUTIONS_ONLY_MAJOR_VERSION} from './constants';
|
||||
import {OutgoingHttpHeaders} from 'http';
|
||||
|
||||
export function getTempDir() {
|
||||
@@ -131,18 +127,12 @@ export function isCacheFeatureAvailable(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
version: string;
|
||||
distribution?: string;
|
||||
}
|
||||
|
||||
export function getVersionFromFileContent(
|
||||
content: string,
|
||||
distributionName: string,
|
||||
versionFile: string
|
||||
): VersionInfo | null {
|
||||
): string | null {
|
||||
let javaVersionRegExp: RegExp;
|
||||
let extractedDistribution: string | undefined;
|
||||
|
||||
function getFileName(versionFile: string) {
|
||||
return path.basename(versionFile);
|
||||
@@ -151,47 +141,17 @@ export function getVersionFromFileContent(
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
javaVersionRegExp =
|
||||
/^java\s+(?:(?<distribution>\S*?)-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
|
||||
} else if (versionFileName == '.sdkmanrc') {
|
||||
// Match both version and optional distribution identifier
|
||||
javaVersionRegExp =
|
||||
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
|
||||
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
|
||||
} else {
|
||||
// .java-version (jenv), version optionally prefixed with a distribution
|
||||
// identifier, e.g. `temurin-21.0.5` or `openjdk64-11.0.2`.
|
||||
javaVersionRegExp =
|
||||
/(?:(?<distribution>[a-zA-Z][a-zA-Z0-9-]*?)-)?(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
}
|
||||
|
||||
const match = content.match(javaVersionRegExp);
|
||||
const capturedVersion = match?.groups?.version
|
||||
? (match.groups.version as string)
|
||||
const capturedVersion = content.match(javaVersionRegExp)?.groups?.version
|
||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||
: '';
|
||||
|
||||
// Extract distribution from .sdkmanrc file
|
||||
if (versionFileName == '.sdkmanrc' && match?.groups?.distribution) {
|
||||
const sdkmanDist = match.groups.distribution;
|
||||
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
|
||||
core.debug(
|
||||
`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`
|
||||
);
|
||||
}
|
||||
|
||||
// Extract distribution from .java-version (jenv) or .tool-versions (asdf) file
|
||||
if (
|
||||
versionFileName != '.sdkmanrc' &&
|
||||
match?.groups?.distribution &&
|
||||
capturedVersion
|
||||
) {
|
||||
const fileDistribution = match.groups.distribution;
|
||||
extractedDistribution = mapJavaVersionFileDistribution(fileDistribution);
|
||||
if (extractedDistribution) {
|
||||
core.debug(
|
||||
`Parsed distribution '${extractedDistribution}' from identifier '${fileDistribution}' in '${versionFileName}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(
|
||||
`Parsed version '${capturedVersion}' from file '${versionFileName}'`
|
||||
);
|
||||
@@ -212,76 +172,12 @@ export function getVersionFromFileContent(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
|
||||
// (either explicitly provided or extracted from the version file) is in the list.
|
||||
if (
|
||||
DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(
|
||||
extractedDistribution || distributionName
|
||||
)
|
||||
) {
|
||||
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
const coerceVersion = semver.coerce(version) ?? version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
|
||||
return {
|
||||
version: version.toString(),
|
||||
distribution: extractedDistribution
|
||||
};
|
||||
}
|
||||
|
||||
// Map SDKMAN distribution identifiers to setup-java distribution names
|
||||
function mapSdkmanDistribution(sdkmanDist: string): string | undefined {
|
||||
const distributionMap: Record<string, string> = {
|
||||
tem: 'temurin',
|
||||
sem: 'semeru',
|
||||
albba: 'dragonwell',
|
||||
zulu: 'zulu',
|
||||
amzn: 'corretto',
|
||||
graal: 'graalvm',
|
||||
graalce: 'graalvm',
|
||||
librca: 'liberica',
|
||||
ms: 'microsoft',
|
||||
oracle: 'oracle',
|
||||
sapmchn: 'sapmachine',
|
||||
jbr: 'jetbrains',
|
||||
dragonwell: 'dragonwell',
|
||||
kona: 'kona'
|
||||
};
|
||||
|
||||
const mapped = distributionMap[sdkmanDist.toLowerCase()];
|
||||
if (!mapped) {
|
||||
core.warning(
|
||||
`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`
|
||||
);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// Map a distribution identifier found in a `.java-version` (jenv) or
|
||||
// `.tool-versions` (asdf) file to a setup-java distribution name.
|
||||
// jenv-style identifiers may carry an architecture suffix (e.g. `openjdk64`,
|
||||
// `temurin64`), which is stripped before matching. Identifiers that do not map
|
||||
// to a supported distribution (e.g. the generic `openjdk`) are ignored so the
|
||||
// `distribution` input is used instead.
|
||||
function mapJavaVersionFileDistribution(
|
||||
identifier: string
|
||||
): string | undefined {
|
||||
const normalized = identifier.toLowerCase();
|
||||
|
||||
if (SUPPORTED_DISTRIBUTIONS.includes(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
// Strip a trailing architecture suffix (e.g. `temurin64` -> `temurin`).
|
||||
const withoutArch = normalized.replace(/(32|64)$/, '');
|
||||
if (SUPPORTED_DISTRIBUTIONS.includes(withoutArch)) {
|
||||
return withoutArch;
|
||||
}
|
||||
|
||||
core.debug(
|
||||
`Distribution identifier '${identifier}' from version file is not a supported distribution; falling back to the 'distribution' input.`
|
||||
);
|
||||
return undefined;
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
|
||||
Reference in New Issue
Block a user