mirror of
https://gitea.com/actions/setup-java.git
synced 2026-07-09 19:22:05 +08:00
Compare commits
1 Commits
brunoborge
...
copilot/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cb7bd967e |
13
.github/java.json
vendored
13
.github/java.json
vendored
@@ -21,19 +21,6 @@
|
||||
"message": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"owner": "maven-javac",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^\\[(WARNING|ERROR)\\]\\s+(.+?\\.java):\\[(\\d+),(\\d+)\\]\\s+(.+)$",
|
||||
"severity": 1,
|
||||
"file": 2,
|
||||
"line": 3,
|
||||
"column": 4,
|
||||
"message": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
5
.github/workflows/e2e-local-file.yml
vendored
5
.github/workflows/e2e-local-file.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/${{ env.LocalFilename }}
|
||||
jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
|
||||
java-version: '11.0.0-ea'
|
||||
architecture: x64
|
||||
- name: Verify Java version
|
||||
@@ -88,7 +88,7 @@ jobs:
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/${{ env.LocalFilename }}
|
||||
jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
|
||||
java-version: '11.0.0-ea'
|
||||
architecture: x64
|
||||
- name: Verify Java version
|
||||
@@ -129,7 +129,6 @@ jobs:
|
||||
id: setup-java
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
# Intentionally uses the deprecated `jdkFile` alias to keep it covered.
|
||||
jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
|
||||
java-version: '11.0.0-ea'
|
||||
architecture: x64
|
||||
|
||||
@@ -41,7 +41,7 @@ For more details, see the full release notes on the [releases page](https://git
|
||||
|
||||
- `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: Derived from the runner machine.
|
||||
|
||||
- `jdk-file`: If a use-case requires a custom distribution setup-java uses the compressed JDK from the location pointed by this input and will take care of the installation and caching on the VM. Note: `distribution` must be set to 'jdkfile' (case-sensitive; all lowercase) when using this option. (The camelCase `jdkFile` input is still accepted as a deprecated alias and may be removed in a future release.)
|
||||
- `jdkFile`: If a use-case requires a custom distribution setup-java uses the compressed JDK from the location pointed by this input and will take care of the installation and caching on the VM. Note: `distribution` must be set to 'jdkfile' (case-sensitive; all lowercase) when using this option.
|
||||
|
||||
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
||||
|
||||
@@ -149,8 +149,6 @@ When the option `cache-dependency-path` is specified, the hash is based on the m
|
||||
|
||||
The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs).
|
||||
|
||||
The workflow output `cache-primary-key` exposes the primary cache key computed by the action for the configured build tool. It is useful for composing with [`actions/cache`](https://github.com/actions/cache) or [`actions/cache/restore`](https://github.com/actions/cache/tree/main/restore) in later steps or dependent jobs that need to reuse the exact same key. It is empty when caching is not enabled or when caching is skipped (for example, when the cache service is unavailable).
|
||||
|
||||
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.
|
||||
|
||||
@@ -133,7 +133,6 @@ describe('dependency cache', () => {
|
||||
describe('restore', () => {
|
||||
let spyCacheRestore: any;
|
||||
let spyGlobHashFiles: any;
|
||||
let spySetOutput: any;
|
||||
|
||||
beforeEach(() => {
|
||||
spyCacheRestore = (cache.restoreCache as any).mockImplementation(
|
||||
@@ -141,8 +140,6 @@ describe('dependency cache', () => {
|
||||
);
|
||||
spyGlobHashFiles = glob.hashFiles as jest.Mock;
|
||||
spyGlobHashFiles.mockResolvedValue('hash-stub');
|
||||
spySetOutput = core.setOutput as jest.Mock;
|
||||
spySetOutput.mockImplementation(() => null);
|
||||
spyWarning.mockImplementation(() => null);
|
||||
});
|
||||
|
||||
@@ -178,15 +175,6 @@ describe('dependency cache', () => {
|
||||
expect(spyWarning).not.toHaveBeenCalled();
|
||||
expect(spyInfo).toHaveBeenCalledWith('maven cache is not found');
|
||||
});
|
||||
it('sets the cache-primary-key output', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
|
||||
await restore('maven', '');
|
||||
expect(spySetOutput).toHaveBeenCalledWith(
|
||||
'cache-primary-key',
|
||||
expect.stringContaining('setup-java-')
|
||||
);
|
||||
});
|
||||
it('downloads cache based on maven-wrapper.properties', async () => {
|
||||
createDirectory(join(workspace, '.mvn'));
|
||||
createDirectory(join(workspace, '.mvn', 'wrapper'));
|
||||
|
||||
@@ -296,72 +296,6 @@ describe('getVersionFromFileContent', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.tool-versions', () => {
|
||||
it.each([
|
||||
['java temurin-17.0.3+7', '17.0.3+7', 'temurin'],
|
||||
['java temurin-jre-17.0.3+7', '17.0.3+7', 'temurin'],
|
||||
['java adoptopenjdk-11.0.16+8', '11.0.16+8', 'temurin'],
|
||||
['java adoptopenjdk-openj9-11.0.16+8', '11.0.16+8', 'temurin'],
|
||||
['java zulu-11.56.19', '11.56.19', 'zulu'],
|
||||
['java corretto-17.0.13.11.1', '17', 'corretto'], // corretto -> major only
|
||||
['java liberica-11.0.15+10', '11.0.15+10', 'liberica'],
|
||||
['java microsoft-11.0.13.8.1', '11.0.13', 'microsoft'],
|
||||
['java semeru-openj9-11.0.25+9', '11.0.25+9', 'semeru'],
|
||||
['java ibm-openj9-11.0.25+9', '11.0.25+9', 'semeru'],
|
||||
['java dragonwell-17.0.13.0.13+11', '17.0.13', 'dragonwell'],
|
||||
['java graalvm-22.3.0+java17', '22.3.0+java17', 'graalvm'],
|
||||
['java graalvm-community-22.3.0', '22.3.0', 'graalvm-community'],
|
||||
['java oracle-graalvm-21.0.5', '21.0.5', 'graalvm'],
|
||||
['java oracle-21.0.5', '21.0.5', 'oracle'],
|
||||
['java sapmachine-21.0.5', '21.0.5', 'sapmachine'],
|
||||
['java kona-17.0.13', '17.0.13', 'kona'],
|
||||
['java jetbrains-21.0.5', '21.0.5', 'jetbrains']
|
||||
])(
|
||||
'parsing %s should return version %s and distribution %s',
|
||||
(content: string, expectedVersion: string, expectedDist: string) => {
|
||||
const actual = getVersionFromFileContent(
|
||||
content,
|
||||
'openjdk',
|
||||
'.tool-versions'
|
||||
);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBe(expectedDist);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['java 17.0.7', '17.0.7'],
|
||||
['java 17', '17'],
|
||||
['java 1.8', '8'],
|
||||
['java 21-ea', '21-ea']
|
||||
])(
|
||||
'parsing prefix-less %s should return version %s and no distribution',
|
||||
(content: string, expectedVersion: string) => {
|
||||
const actual = getVersionFromFileContent(
|
||||
content,
|
||||
'temurin',
|
||||
'.tool-versions'
|
||||
);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
}
|
||||
);
|
||||
|
||||
it('should warn and return undefined distribution for unsupported vendor', () => {
|
||||
const warnSpy = jest.spyOn(core, 'warning');
|
||||
const actual = getVersionFromFileContent(
|
||||
'java openjdk-17.0.7',
|
||||
'temurin',
|
||||
'.tool-versions'
|
||||
);
|
||||
expect(actual?.version).toBe('17.0.7');
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Unknown asdf distribution identifier')
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isGhes', () => {
|
||||
|
||||
@@ -19,13 +19,9 @@ inputs:
|
||||
architecture:
|
||||
description: "The architecture of the package (defaults to the action runner's architecture)"
|
||||
required: false
|
||||
jdk-file:
|
||||
jdkFile:
|
||||
description: 'Path to where the compressed JDK is located'
|
||||
required: false
|
||||
jdkFile:
|
||||
description: 'Deprecated alias for `jdk-file`. Path to where the compressed JDK is located. Use `jdk-file` instead; this alias may be removed in a future release.'
|
||||
required: false
|
||||
deprecationMessage: 'The `jdkFile` input is deprecated. Use `jdk-file` instead.'
|
||||
check-latest:
|
||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||
required: false
|
||||
@@ -103,8 +99,6 @@ outputs:
|
||||
description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
cache-primary-key:
|
||||
description: 'The primary cache key computed by the action for the configured build tool. Empty when caching is not enabled or when caching is skipped (e.g. cache service unavailable). Useful for composing with actions/cache or actions/cache/restore across jobs.'
|
||||
runs:
|
||||
using: 'node24'
|
||||
main: 'dist/setup/index.js'
|
||||
|
||||
53
dist/cleanup/index.js
vendored
53
dist/cleanup/index.js
vendored
@@ -95834,8 +95834,7 @@ const INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
const INPUT_ARCHITECTURE = 'architecture';
|
||||
const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
const INPUT_DISTRIBUTION = 'distribution';
|
||||
const INPUT_JDK_FILE = 'jdk-file';
|
||||
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||
const INPUT_JDK_FILE = 'jdkFile';
|
||||
const INPUT_CHECK_LATEST = 'check-latest';
|
||||
const INPUT_SET_DEFAULT = 'set-default';
|
||||
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||
@@ -95966,10 +95965,8 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
}
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
// Capture an optional asdf-java vendor prefix (e.g. `temurin-`, `corretto-`)
|
||||
// in the `distribution` group so it can be mapped to a setup-java distribution.
|
||||
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
|
||||
@@ -95989,14 +95986,6 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
|
||||
}
|
||||
// Extract distribution from asdf .tool-versions file
|
||||
if (versionFileName == '.tool-versions' && match?.groups?.distribution) {
|
||||
const asdfDist = match.groups.distribution;
|
||||
extractedDistribution = mapAsdfDistribution(asdfDist);
|
||||
if (extractedDistribution) {
|
||||
core.debug(`Parsed distribution '${extractedDistribution}' from asdf identifier '${asdfDist}'`);
|
||||
}
|
||||
}
|
||||
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
|
||||
if (!capturedVersion) {
|
||||
return null;
|
||||
@@ -96045,43 +96034,6 @@ function mapSdkmanDistribution(sdkmanDist) {
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// Map asdf-java (.tool-versions) vendor identifiers to setup-java distribution names.
|
||||
// asdf-java encodes the vendor as a prefix on the version string, e.g.
|
||||
// `java temurin-17.0.3+7` or `java semeru-openj9-11.0.25+9`. Packaging variants
|
||||
// (`-jre`, `-musl`, `-openj9`, `-crac`, `-javafx`, ...) are collapsed onto the
|
||||
// base vendor since setup-java does not distinguish them here.
|
||||
function mapAsdfDistribution(asdfDist) {
|
||||
const normalized = asdfDist.toLowerCase();
|
||||
// Multi-segment vendors that map to a distinct setup-java distribution.
|
||||
if (normalized.startsWith('graalvm-community')) {
|
||||
return 'graalvm-community';
|
||||
}
|
||||
if (normalized.startsWith('oracle-graalvm')) {
|
||||
return 'graalvm';
|
||||
}
|
||||
const baseVendor = normalized.split('-')[0];
|
||||
const distributionMap = {
|
||||
temurin: 'temurin',
|
||||
adoptopenjdk: 'temurin',
|
||||
zulu: 'zulu',
|
||||
corretto: 'corretto',
|
||||
liberica: 'liberica',
|
||||
microsoft: 'microsoft',
|
||||
semeru: 'semeru',
|
||||
ibm: 'semeru',
|
||||
dragonwell: 'dragonwell',
|
||||
graalvm: 'graalvm',
|
||||
oracle: 'oracle',
|
||||
sapmachine: 'sapmachine',
|
||||
kona: 'kona',
|
||||
jetbrains: 'jetbrains'
|
||||
};
|
||||
const mapped = distributionMap[baseVendor];
|
||||
if (!mapped) {
|
||||
core.warning(`Unknown asdf distribution identifier '${asdfDist}'. Please specify the distribution explicitly.`);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// 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;
|
||||
@@ -99735,7 +99687,6 @@ async function restore(id, cacheDependencyPath) {
|
||||
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
core.setOutput('cache-primary-key', primaryKey);
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
|
||||
63
dist/setup/index.js
vendored
63
dist/setup/index.js
vendored
@@ -73279,8 +73279,7 @@ const INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
const INPUT_ARCHITECTURE = 'architecture';
|
||||
const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
const INPUT_DISTRIBUTION = 'distribution';
|
||||
const INPUT_JDK_FILE = 'jdk-file';
|
||||
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||
const INPUT_JDK_FILE = 'jdkFile';
|
||||
const INPUT_CHECK_LATEST = 'check-latest';
|
||||
const INPUT_SET_DEFAULT = 'set-default';
|
||||
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||
@@ -126958,10 +126957,8 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
}
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
// Capture an optional asdf-java vendor prefix (e.g. `temurin-`, `corretto-`)
|
||||
// in the `distribution` group so it can be mapped to a setup-java distribution.
|
||||
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
|
||||
@@ -126981,14 +126978,6 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
|
||||
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
|
||||
core_debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
|
||||
}
|
||||
// Extract distribution from asdf .tool-versions file
|
||||
if (versionFileName == '.tool-versions' && match?.groups?.distribution) {
|
||||
const asdfDist = match.groups.distribution;
|
||||
extractedDistribution = mapAsdfDistribution(asdfDist);
|
||||
if (extractedDistribution) {
|
||||
core_debug(`Parsed distribution '${extractedDistribution}' from asdf identifier '${asdfDist}'`);
|
||||
}
|
||||
}
|
||||
core_debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
|
||||
if (!capturedVersion) {
|
||||
return null;
|
||||
@@ -127037,43 +127026,6 @@ function mapSdkmanDistribution(sdkmanDist) {
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// Map asdf-java (.tool-versions) vendor identifiers to setup-java distribution names.
|
||||
// asdf-java encodes the vendor as a prefix on the version string, e.g.
|
||||
// `java temurin-17.0.3+7` or `java semeru-openj9-11.0.25+9`. Packaging variants
|
||||
// (`-jre`, `-musl`, `-openj9`, `-crac`, `-javafx`, ...) are collapsed onto the
|
||||
// base vendor since setup-java does not distinguish them here.
|
||||
function mapAsdfDistribution(asdfDist) {
|
||||
const normalized = asdfDist.toLowerCase();
|
||||
// Multi-segment vendors that map to a distinct setup-java distribution.
|
||||
if (normalized.startsWith('graalvm-community')) {
|
||||
return 'graalvm-community';
|
||||
}
|
||||
if (normalized.startsWith('oracle-graalvm')) {
|
||||
return 'graalvm';
|
||||
}
|
||||
const baseVendor = normalized.split('-')[0];
|
||||
const distributionMap = {
|
||||
temurin: 'temurin',
|
||||
adoptopenjdk: 'temurin',
|
||||
zulu: 'zulu',
|
||||
corretto: 'corretto',
|
||||
liberica: 'liberica',
|
||||
microsoft: 'microsoft',
|
||||
semeru: 'semeru',
|
||||
ibm: 'semeru',
|
||||
dragonwell: 'dragonwell',
|
||||
graalvm: 'graalvm',
|
||||
oracle: 'oracle',
|
||||
sapmachine: 'sapmachine',
|
||||
kona: 'kona',
|
||||
jetbrains: 'jetbrains'
|
||||
};
|
||||
const mapped = distributionMap[baseVendor];
|
||||
if (!mapped) {
|
||||
warning(`Unknown asdf distribution identifier '${asdfDist}'. Please specify the distribution explicitly.`);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
// 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;
|
||||
@@ -130957,7 +130909,6 @@ async function restore(id, cacheDependencyPath) {
|
||||
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
|
||||
core_debug(`primary key is ${primaryKey}`);
|
||||
saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
setOutput('cache-primary-key', primaryKey);
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await restoreCache(packageManager.path, primaryKey);
|
||||
if (matchedKey) {
|
||||
@@ -133562,7 +133513,7 @@ async function run() {
|
||||
const versionFile = getInput(INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = getInput(INPUT_ARCHITECTURE);
|
||||
const packageType = getInput(INPUT_JAVA_PACKAGE);
|
||||
const jdkFile = getJdkFileInput();
|
||||
const jdkFile = getInput(INPUT_JDK_FILE);
|
||||
const cache = getInput(INPUT_CACHE);
|
||||
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
|
||||
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
|
||||
@@ -133640,14 +133591,6 @@ async function run() {
|
||||
}
|
||||
}
|
||||
run();
|
||||
function getJdkFileInput() {
|
||||
const jdkFile = getInput(INPUT_JDK_FILE);
|
||||
const deprecatedJdkFile = getInput(INPUT_JDK_FILE_DEPRECATED);
|
||||
if (deprecatedJdkFile) {
|
||||
warning(`The '${INPUT_JDK_FILE_DEPRECATED}' input is deprecated and may be removed in a future release. Please use '${INPUT_JDK_FILE}' instead.`);
|
||||
}
|
||||
return jdkFile || deprecatedJdkFile;
|
||||
}
|
||||
async function installVersion(version, options, toolchainId = 0) {
|
||||
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
||||
const installerOptions = {
|
||||
|
||||
@@ -330,7 +330,7 @@ In this example, `JAVA_HOME` and `java` on `PATH` point to Java 17, while Java 2
|
||||
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:
|
||||
|
||||
> [!NOTE]
|
||||
> This approach also lets you use builds that setup-java does not provide directly, such as **Early Access (EA)** or other unreleased JDK builds (for example, an upcoming feature release or a Loom/Valhalla preview build). Download the desired archive in a prior step and point `jdk-file` at it; setup-java will extract, install, and cache it just like a supported distribution. When targeting multiple architectures, select the correct binary per architecture in your workflow (for example, with a build matrix).
|
||||
> This approach also lets you use builds that setup-java does not provide directly, such as **Early Access (EA)** or other unreleased JDK builds (for example, an upcoming feature release or a Loom/Valhalla preview build). Download the desired archive in a prior step and point `jdkFile` at it; setup-java will extract, install, and cache it just like a supported distribution. When targeting multiple architectures, select the correct binary per architecture in your workflow (for example, with a build matrix).
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
@@ -340,7 +340,7 @@ steps:
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/java_package.tar.gz
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '11.0.0'
|
||||
architecture: x64
|
||||
|
||||
@@ -357,7 +357,7 @@ steps:
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/java_package.tar.gz
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '25.0.0-ea.36'
|
||||
architecture: x64
|
||||
|
||||
@@ -383,7 +383,7 @@ If your use-case requires a custom distribution (in the example, alpine-linux is
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/java_package.tar.gz
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: {{ steps.fetch_latest_jdk.outputs.java_version }}
|
||||
architecture: x64
|
||||
- run: java --version
|
||||
@@ -708,7 +708,7 @@ The result is a Toolchain with entries for JDKs 8, 11 and 15. You can even combi
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/java_package.tar.gz
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '1.6'
|
||||
architecture: x64
|
||||
```
|
||||
@@ -725,7 +725,7 @@ Each JDK provider will receive a default `vendor` using the `distribution` input
|
||||
- uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'jdkfile'
|
||||
jdk-file: ${{ runner.temp }}/java_package.tar.gz
|
||||
jdkFile: ${{ runner.temp }}/java_package.tar.gz
|
||||
java-version: '1.6'
|
||||
architecture: x64
|
||||
mvn-toolchain-vendor: 'Oracle'
|
||||
@@ -780,27 +780,7 @@ steps:
|
||||
|
||||
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).
|
||||
* 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/)). When the entry includes an [asdf-java](https://github.com/halcyon/asdf-java) vendor prefix (e.g. `java temurin-17.0.3+7`), setup-java can infer the `distribution` input automatically. Unrecognized vendor prefixes require setting `distribution` explicitly.
|
||||
|
||||
Supported asdf-java vendor prefix mappings (packaging variants such as `-jre`, `-musl`, `-openj9`, `-crac`, `-javafx` are collapsed onto the base vendor):
|
||||
|
||||
| asdf-java vendor prefix | setup-java distribution |
|
||||
| ----------------------- | ----------------------- |
|
||||
| `temurin` | `temurin` |
|
||||
| `adoptopenjdk` | `temurin` |
|
||||
| `zulu` | `zulu` |
|
||||
| `corretto` | `corretto` |
|
||||
| `liberica` | `liberica` |
|
||||
| `microsoft` | `microsoft` |
|
||||
| `semeru`, `ibm` | `semeru` |
|
||||
| `dragonwell` | `dragonwell` |
|
||||
| `graalvm`, `oracle-graalvm` | `graalvm` |
|
||||
| `graalvm-community` | `graalvm-community` |
|
||||
| `oracle` | `oracle` |
|
||||
| `sapmachine` | `sapmachine` |
|
||||
| `kona` | `kona` |
|
||||
| `jetbrains` | `jetbrains` |
|
||||
|
||||
* 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`). 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:
|
||||
@@ -836,19 +816,6 @@ steps:
|
||||
java=17.0.7-tem
|
||||
```
|
||||
|
||||
**Example step using `asdf`** (distribution inferred from `.tool-versions`):
|
||||
```yml
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version-file: '.tool-versions'
|
||||
```
|
||||
|
||||
**Example `.tool-versions`**:
|
||||
```
|
||||
java temurin-17.0.7+7
|
||||
```
|
||||
|
||||
Valid entry options (does not apply to `.sdkmanrc`):
|
||||
```
|
||||
major versions: 8, 11, 16, 17, 21
|
||||
|
||||
@@ -118,7 +118,6 @@ export async function restore(id: string, cacheDependencyPath: string) {
|
||||
const primaryKey = await computeCacheKey(packageManager, cacheDependencyPath);
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
core.setOutput(STATE_CACHE_PRIMARY_KEY, primaryKey);
|
||||
|
||||
// No "restoreKeys" is set, to start with a clear cache after dependency update (see https://github.com/actions/setup-java/issues/269)
|
||||
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey);
|
||||
|
||||
@@ -4,8 +4,7 @@ export const INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||
export const INPUT_ARCHITECTURE = 'architecture';
|
||||
export const INPUT_JAVA_PACKAGE = 'java-package';
|
||||
export const INPUT_DISTRIBUTION = 'distribution';
|
||||
export const INPUT_JDK_FILE = 'jdk-file';
|
||||
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
|
||||
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';
|
||||
|
||||
@@ -22,7 +22,7 @@ async function run() {
|
||||
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
|
||||
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
|
||||
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
|
||||
const jdkFile = getJdkFileInput();
|
||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||
const cache = core.getInput(constants.INPUT_CACHE);
|
||||
const cacheDependencyPath = core.getInput(
|
||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||
@@ -134,19 +134,6 @@ async function run() {
|
||||
|
||||
run();
|
||||
|
||||
function getJdkFileInput(): string {
|
||||
const jdkFile = core.getInput(constants.INPUT_JDK_FILE);
|
||||
const deprecatedJdkFile = core.getInput(constants.INPUT_JDK_FILE_DEPRECATED);
|
||||
|
||||
if (deprecatedJdkFile) {
|
||||
core.warning(
|
||||
`The '${constants.INPUT_JDK_FILE_DEPRECATED}' input is deprecated and may be removed in a future release. Please use '${constants.INPUT_JDK_FILE}' instead.`
|
||||
);
|
||||
}
|
||||
|
||||
return jdkFile || deprecatedJdkFile;
|
||||
}
|
||||
|
||||
async function installVersion(
|
||||
version: string,
|
||||
options: installerInputsOptions,
|
||||
|
||||
58
src/util.ts
58
src/util.ts
@@ -149,10 +149,8 @@ export function getVersionFromFileContent(
|
||||
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
// Capture an optional asdf-java vendor prefix (e.g. `temurin-`, `corretto-`)
|
||||
// in the `distribution` group so it can be mapped to a setup-java distribution.
|
||||
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 =
|
||||
@@ -175,17 +173,6 @@ export function getVersionFromFileContent(
|
||||
);
|
||||
}
|
||||
|
||||
// Extract distribution from asdf .tool-versions file
|
||||
if (versionFileName == '.tool-versions' && match?.groups?.distribution) {
|
||||
const asdfDist = match.groups.distribution;
|
||||
extractedDistribution = mapAsdfDistribution(asdfDist);
|
||||
if (extractedDistribution) {
|
||||
core.debug(
|
||||
`Parsed distribution '${extractedDistribution}' from asdf identifier '${asdfDist}'`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(
|
||||
`Parsed version '${capturedVersion}' from file '${versionFileName}'`
|
||||
);
|
||||
@@ -251,49 +238,6 @@ function mapSdkmanDistribution(sdkmanDist: string): string | undefined {
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// Map asdf-java (.tool-versions) vendor identifiers to setup-java distribution names.
|
||||
// asdf-java encodes the vendor as a prefix on the version string, e.g.
|
||||
// `java temurin-17.0.3+7` or `java semeru-openj9-11.0.25+9`. Packaging variants
|
||||
// (`-jre`, `-musl`, `-openj9`, `-crac`, `-javafx`, ...) are collapsed onto the
|
||||
// base vendor since setup-java does not distinguish them here.
|
||||
function mapAsdfDistribution(asdfDist: string): string | undefined {
|
||||
const normalized = asdfDist.toLowerCase();
|
||||
|
||||
// Multi-segment vendors that map to a distinct setup-java distribution.
|
||||
if (normalized.startsWith('graalvm-community')) {
|
||||
return 'graalvm-community';
|
||||
}
|
||||
if (normalized.startsWith('oracle-graalvm')) {
|
||||
return 'graalvm';
|
||||
}
|
||||
|
||||
const baseVendor = normalized.split('-')[0];
|
||||
const distributionMap: Record<string, string> = {
|
||||
temurin: 'temurin',
|
||||
adoptopenjdk: 'temurin',
|
||||
zulu: 'zulu',
|
||||
corretto: 'corretto',
|
||||
liberica: 'liberica',
|
||||
microsoft: 'microsoft',
|
||||
semeru: 'semeru',
|
||||
ibm: 'semeru',
|
||||
dragonwell: 'dragonwell',
|
||||
graalvm: 'graalvm',
|
||||
oracle: 'oracle',
|
||||
sapmachine: 'sapmachine',
|
||||
kona: 'kona',
|
||||
jetbrains: 'jetbrains'
|
||||
};
|
||||
|
||||
const mapped = distributionMap[baseVendor];
|
||||
if (!mapped) {
|
||||
core.warning(
|
||||
`Unknown asdf distribution identifier '${asdfDist}'. Please specify the distribution explicitly.`
|
||||
);
|
||||
}
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
function avoidOldNotation(content: string): string {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
|
||||
Reference in New Issue
Block a user