mirror of
https://github.com/actions/setup-java
synced 2024-11-14 01:22:39 +00:00
parent
f69f00b5e5
commit
ebc13aa0aa
8 changed files with 2186 additions and 2136 deletions
36
.github/workflows/e2e-local-file.yml
vendored
36
.github/workflows/e2e-local-file.yml
vendored
|
@ -121,3 +121,39 @@ jobs:
|
||||||
- name: Verify Java version
|
- name: Verify Java version
|
||||||
run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
|
run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
setup-java-remote-file-temurin:
|
||||||
|
name: Validate download from remote file Eclipse Temurin
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Download Eclipse Temurin file
|
||||||
|
run: |
|
||||||
|
if ($IsLinux) {
|
||||||
|
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz"
|
||||||
|
$localFilename = "java_package.tar.gz"
|
||||||
|
} elseif ($IsMacOS) {
|
||||||
|
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_mac_hotspot_11.0.12_7.tar.gz"
|
||||||
|
$localFilename = "java_package.tar.gz"
|
||||||
|
} elseif ($IsWindows) {
|
||||||
|
$downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_windows_hotspot_11.0.12_7.zip"
|
||||||
|
$localFilename = "java_package.zip"
|
||||||
|
}
|
||||||
|
echo "DownloadUrl=$downloadUrl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||||
|
shell: pwsh
|
||||||
|
- name: setup-java
|
||||||
|
uses: ./
|
||||||
|
id: setup-java
|
||||||
|
with:
|
||||||
|
distribution: 'jdkfile'
|
||||||
|
jdkFile: ${{ env.DownloadUrl }}
|
||||||
|
java-version: '11.0.0-ea'
|
||||||
|
architecture: x64
|
||||||
|
- name: Verify Java version
|
||||||
|
run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
|
||||||
|
shell: bash
|
||||||
|
|
|
@ -144,6 +144,7 @@ jobs:
|
||||||
- [Installing custom Java package type](docs/advanced-usage.md#Installing-custom-Java-package-type)
|
- [Installing custom Java package type](docs/advanced-usage.md#Installing-custom-Java-package-type)
|
||||||
- [Installing custom Java architecture](docs/advanced-usage.md#Installing-custom-Java-architecture)
|
- [Installing custom Java architecture](docs/advanced-usage.md#Installing-custom-Java-architecture)
|
||||||
- [Installing custom Java distribution from local file](docs/advanced-usage.md#Installing-Java-from-local-file)
|
- [Installing custom Java distribution from local file](docs/advanced-usage.md#Installing-Java-from-local-file)
|
||||||
|
- [Installing Java from remote archive](docs/advanced-usage.md#Installing-Java-from-remote-archive)
|
||||||
- [Testing against different Java distributions](docs/advanced-usage.md#Testing-against-different-Java-distributions)
|
- [Testing against different Java distributions](docs/advanced-usage.md#Testing-against-different-Java-distributions)
|
||||||
- [Testing against different platforms](docs/advanced-usage.md#Testing-against-different-platforms)
|
- [Testing against different platforms](docs/advanced-usage.md#Testing-against-different-platforms)
|
||||||
- [Publishing using Apache Maven](docs/advanced-usage.md#Publishing-using-Apache-Maven)
|
- [Publishing using Apache Maven](docs/advanced-usage.md#Publishing-using-Apache-Maven)
|
||||||
|
|
|
@ -161,6 +161,36 @@ describe('setupJava', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('java is downloaded from remote jdkfile', async () => {
|
||||||
|
const inputs = {
|
||||||
|
version: '11.0.289',
|
||||||
|
architecture: 'x86',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
};
|
||||||
|
const expected = {
|
||||||
|
version: '11.0.289',
|
||||||
|
path: path.join('Java_jdkfile_jdk', inputs.version, inputs.architecture)
|
||||||
|
};
|
||||||
|
|
||||||
|
const jdkFile = 'https://example.com/jdk.tar.gz';
|
||||||
|
|
||||||
|
const spyTcDownloadTool = jest.spyOn(tc, 'downloadTool');
|
||||||
|
spyTcDownloadTool.mockReturnValue(Promise.resolve(expectedJdkFile));
|
||||||
|
|
||||||
|
mockJavaBase = new LocalDistribution(inputs, jdkFile);
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||||
|
expect(spyTcFindAllVersions).toHaveBeenCalled();
|
||||||
|
expect(spyTcDownloadTool).toHaveBeenCalledWith(jdkFile);
|
||||||
|
expect(spyCoreInfo).not.toHaveBeenCalledWith(
|
||||||
|
`Resolved Java ${actualJavaVersion} from tool-cache`
|
||||||
|
);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(`Extracting Java from '${expectedJdkFile}'`);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||||
|
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('jdk file is not found', async () => {
|
it('jdk file is not found', async () => {
|
||||||
const inputs = {
|
const inputs = {
|
||||||
version: '11.0.289',
|
version: '11.0.289',
|
||||||
|
|
|
@ -18,7 +18,7 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: 'x64'
|
default: 'x64'
|
||||||
jdkFile:
|
jdkFile:
|
||||||
description: 'Path to where the compressed JDK is located'
|
description: 'Path to where the compressed JDK is located, or URL where it should be downloaded from'
|
||||||
required: false
|
required: false
|
||||||
check-latest:
|
check-latest:
|
||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||||
|
|
30
dist/cleanup/index.js
vendored
30
dist/cleanup/index.js
vendored
|
@ -43501,17 +43501,9 @@ AbortError.prototype = Object.create(Error.prototype);
|
||||||
AbortError.prototype.constructor = AbortError;
|
AbortError.prototype.constructor = AbortError;
|
||||||
AbortError.prototype.name = 'AbortError';
|
AbortError.prototype.name = 'AbortError';
|
||||||
|
|
||||||
const URL$1 = Url.URL || whatwgUrl.URL;
|
|
||||||
|
|
||||||
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
|
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
|
||||||
const PassThrough$1 = Stream.PassThrough;
|
const PassThrough$1 = Stream.PassThrough;
|
||||||
|
const resolve_url = Url.resolve;
|
||||||
const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
|
|
||||||
const orig = new URL$1(original).hostname;
|
|
||||||
const dest = new URL$1(destination).hostname;
|
|
||||||
|
|
||||||
return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch function
|
* Fetch function
|
||||||
|
@ -43599,19 +43591,7 @@ function fetch(url, opts) {
|
||||||
const location = headers.get('Location');
|
const location = headers.get('Location');
|
||||||
|
|
||||||
// HTTP fetch step 5.3
|
// HTTP fetch step 5.3
|
||||||
let locationURL = null;
|
const locationURL = location === null ? null : resolve_url(request.url, location);
|
||||||
try {
|
|
||||||
locationURL = location === null ? null : new URL$1(location, request.url).toString();
|
|
||||||
} catch (err) {
|
|
||||||
// error here can only be invalid URL in Location: header
|
|
||||||
// do not throw when options.redirect == manual
|
|
||||||
// let the user extract the errorneous redirect URL
|
|
||||||
if (request.redirect !== 'manual') {
|
|
||||||
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
|
|
||||||
finalize();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP fetch step 5.5
|
// HTTP fetch step 5.5
|
||||||
switch (request.redirect) {
|
switch (request.redirect) {
|
||||||
|
@ -43659,12 +43639,6 @@ function fetch(url, opts) {
|
||||||
size: request.size
|
size: request.size
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isDomainOrSubdomain(request.url, locationURL)) {
|
|
||||||
for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
|
|
||||||
requestOpts.headers.delete(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP-redirect fetch step 9
|
// HTTP-redirect fetch step 9
|
||||||
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
|
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
|
||||||
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
|
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
|
||||||
|
|
44
dist/setup/index.js
vendored
44
dist/setup/index.js
vendored
|
@ -11501,13 +11501,23 @@ class LocalDistribution extends base_installer_1.JavaBase {
|
||||||
if (!this.jdkFile) {
|
if (!this.jdkFile) {
|
||||||
throw new Error("'jdkFile' is not specified");
|
throw new Error("'jdkFile' is not specified");
|
||||||
}
|
}
|
||||||
const jdkFilePath = path_1.default.resolve(this.jdkFile);
|
let jdkFilePath;
|
||||||
|
let extension;
|
||||||
|
if (this.jdkFile.match(/^https?:\/\//)) {
|
||||||
|
core.info(`Downloading Java archive from ${this.jdkFile}...`);
|
||||||
|
const javaRelease = yield tc.downloadTool(this.jdkFile);
|
||||||
|
jdkFilePath = path_1.default.resolve(javaRelease);
|
||||||
|
extension = util_1.getDownloadArchiveExtension();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jdkFilePath = path_1.default.resolve(this.jdkFile);
|
||||||
|
}
|
||||||
const stats = fs_1.default.statSync(jdkFilePath);
|
const stats = fs_1.default.statSync(jdkFilePath);
|
||||||
if (!stats.isFile()) {
|
if (!stats.isFile()) {
|
||||||
throw new Error(`JDK file was not found in path '${jdkFilePath}'`);
|
throw new Error(`JDK file was not found in path '${jdkFilePath}'`);
|
||||||
}
|
}
|
||||||
core.info(`Extracting Java from '${jdkFilePath}'`);
|
core.info(`Extracting Java from '${jdkFilePath}'`);
|
||||||
const extractedJavaPath = yield util_1.extractJdkFile(jdkFilePath);
|
const extractedJavaPath = yield util_1.extractJdkFile(jdkFilePath, extension);
|
||||||
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
|
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
|
||||||
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
|
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
|
||||||
const javaVersion = this.version;
|
const javaVersion = this.version;
|
||||||
|
@ -30687,17 +30697,9 @@ AbortError.prototype = Object.create(Error.prototype);
|
||||||
AbortError.prototype.constructor = AbortError;
|
AbortError.prototype.constructor = AbortError;
|
||||||
AbortError.prototype.name = 'AbortError';
|
AbortError.prototype.name = 'AbortError';
|
||||||
|
|
||||||
const URL$1 = Url.URL || whatwgUrl.URL;
|
|
||||||
|
|
||||||
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
|
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
|
||||||
const PassThrough$1 = Stream.PassThrough;
|
const PassThrough$1 = Stream.PassThrough;
|
||||||
|
const resolve_url = Url.resolve;
|
||||||
const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
|
|
||||||
const orig = new URL$1(original).hostname;
|
|
||||||
const dest = new URL$1(destination).hostname;
|
|
||||||
|
|
||||||
return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch function
|
* Fetch function
|
||||||
|
@ -30785,19 +30787,7 @@ function fetch(url, opts) {
|
||||||
const location = headers.get('Location');
|
const location = headers.get('Location');
|
||||||
|
|
||||||
// HTTP fetch step 5.3
|
// HTTP fetch step 5.3
|
||||||
let locationURL = null;
|
const locationURL = location === null ? null : resolve_url(request.url, location);
|
||||||
try {
|
|
||||||
locationURL = location === null ? null : new URL$1(location, request.url).toString();
|
|
||||||
} catch (err) {
|
|
||||||
// error here can only be invalid URL in Location: header
|
|
||||||
// do not throw when options.redirect == manual
|
|
||||||
// let the user extract the errorneous redirect URL
|
|
||||||
if (request.redirect !== 'manual') {
|
|
||||||
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
|
|
||||||
finalize();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP fetch step 5.5
|
// HTTP fetch step 5.5
|
||||||
switch (request.redirect) {
|
switch (request.redirect) {
|
||||||
|
@ -30845,12 +30835,6 @@ function fetch(url, opts) {
|
||||||
size: request.size
|
size: request.size
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isDomainOrSubdomain(request.url, locationURL)) {
|
|
||||||
for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
|
|
||||||
requestOpts.headers.delete(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP-redirect fetch step 9
|
// HTTP-redirect fetch step 9
|
||||||
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
|
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
|
||||||
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
|
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
|
||||||
|
|
|
@ -120,6 +120,21 @@ steps:
|
||||||
- run: java -cp java HelloWorldApp
|
- run: java -cp java HelloWorldApp
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Installing Java from remote archive
|
||||||
|
If your use-case requires a custom distribution or a version that is not provided by setup-java, you can specify URL directly and setup-java will take care of the installation and caching on the VM:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'jdkfile'
|
||||||
|
jdkFile: https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz
|
||||||
|
java-version: '11.0.0'
|
||||||
|
architecture: x64
|
||||||
|
|
||||||
|
- run: java -cp java HelloWorldApp
|
||||||
|
```
|
||||||
|
|
||||||
## Testing against different Java distributions
|
## Testing against different Java distributions
|
||||||
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
|
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
|
||||||
```yaml
|
```yaml
|
||||||
|
|
|
@ -3,11 +3,10 @@ import * as core from '@actions/core';
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import semver from 'semver';
|
|
||||||
|
|
||||||
import { JavaBase } from '../base-installer';
|
import { JavaBase } from '../base-installer';
|
||||||
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
|
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
|
||||||
import { extractJdkFile } from '../../util';
|
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
|
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
|
||||||
|
|
||||||
export class LocalDistribution extends JavaBase {
|
export class LocalDistribution extends JavaBase {
|
||||||
|
@ -25,16 +24,27 @@ export class LocalDistribution extends JavaBase {
|
||||||
if (!this.jdkFile) {
|
if (!this.jdkFile) {
|
||||||
throw new Error("'jdkFile' is not specified");
|
throw new Error("'jdkFile' is not specified");
|
||||||
}
|
}
|
||||||
const jdkFilePath = path.resolve(this.jdkFile);
|
|
||||||
const stats = fs.statSync(jdkFilePath);
|
|
||||||
|
|
||||||
|
let jdkFilePath;
|
||||||
|
let extension;
|
||||||
|
|
||||||
|
if (this.jdkFile.match(/^https?:\/\//)) {
|
||||||
|
core.info(`Downloading Java archive from ${this.jdkFile}...`);
|
||||||
|
const javaRelease = await tc.downloadTool(this.jdkFile);
|
||||||
|
jdkFilePath = path.resolve(javaRelease);
|
||||||
|
extension = getDownloadArchiveExtension();
|
||||||
|
} else {
|
||||||
|
jdkFilePath = path.resolve(this.jdkFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
const stats = fs.statSync(jdkFilePath);
|
||||||
if (!stats.isFile()) {
|
if (!stats.isFile()) {
|
||||||
throw new Error(`JDK file was not found in path '${jdkFilePath}'`);
|
throw new Error(`JDK file was not found in path '${jdkFilePath}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Extracting Java from '${jdkFilePath}'`);
|
core.info(`Extracting Java from '${jdkFilePath}'`);
|
||||||
|
|
||||||
const extractedJavaPath = await extractJdkFile(jdkFilePath);
|
const extractedJavaPath = await extractJdkFile(jdkFilePath, extension);
|
||||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||||
const javaVersion = this.version;
|
const javaVersion = this.version;
|
||||||
|
|
Loading…
Reference in a new issue