Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ 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.

- `force-download`: Set to `true` to always download Java and replace any matching version in the tool cache. This can help make builds reproducible when a runner image has modified a pre-installed JDK, such as its `cacerts` file. Default value: `false`.

- `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.

- `problem-matcher`: Set to `false` to disable Java problem matcher annotations (compiler diagnostics and uncaught exceptions). Default value: `true`. See [Java problem matcher](docs/advanced-usage.md#java-problem-matcher-compiler-annotations) for details and annotation limits.
Expand Down
29 changes: 29 additions & 0 deletions __tests__/distributors/base-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,35 @@ describe('setupJava', () => {
);
});

it('should download java when force-download is enabled, even if the version is cached', async () => {
mockJavaBase = new EmptyJavaBase({
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false,
forceDownload: true
});
const findInToolcache = jest.fn(() => ({
version: actualJavaVersion,
path: javaPathInstalled
}));
mockJavaBase['findInToolcache'] = findInToolcache;

await expect(mockJavaBase.setupJava()).resolves.toEqual({
version: actualJavaVersion,
path: javaPathInstalled
});

expect(findInToolcache).not.toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${actualJavaVersion} was downloaded`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
});

it.each([
[
{
Expand Down
23 changes: 23 additions & 0 deletions __tests__/distributors/local-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,29 @@ describe('setupJava', () => {
);
});

it('java is unpacked from jdkfile when force-download is enabled', async () => {
const inputs = {
version: actualJavaVersion,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false,
forceDownload: true
};

mockJavaBase = new LocalDistribution(inputs, expectedJdkFile);
await expect(mockJavaBase.setupJava()).resolves.toEqual({
version: actualJavaVersion,
path: javaPath
});

expect(spyGetToolcachePath).not.toHaveBeenCalled();
expect(spyUtilsExtractJdkFile).toHaveBeenCalledWith(expectedJdkFile);
expect(spyTcCacheDir).toHaveBeenCalled();
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
});

it("java is resolved from toolcache, jdkfile doesn't exist", async () => {
const inputs = {
version: actualJavaVersion,
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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
force-download:
description: 'Set this option to always download Java and replace any matching version in the tool cache'
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
Expand Down
1 change: 1 addition & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97311,6 +97311,7 @@ const INPUT_DISTRIBUTION = 'distribution';
const INPUT_JDK_FILE = 'jdk-file';
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
const INPUT_CHECK_LATEST = 'check-latest';
const INPUT_FORCE_DOWNLOAD = 'force-download';
const INPUT_SET_DEFAULT = 'set-default';
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
Expand Down
16 changes: 12 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72088,6 +72088,7 @@ const INPUT_DISTRIBUTION = 'distribution';
const INPUT_JDK_FILE = 'jdk-file';
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
const INPUT_CHECK_LATEST = 'check-latest';
const INPUT_FORCE_DOWNLOAD = 'force-download';
const INPUT_SET_DEFAULT = 'set-default';
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
Expand Down Expand Up @@ -129290,6 +129291,7 @@ class JavaBase {
stable;
latest;
checkLatest;
forceDownload;
setDefault;
verifySignature;
verifySignaturePublicKey;
Expand All @@ -129307,6 +129309,7 @@ class JavaBase {
this.architecture = installerOptions.architecture || external_os_default().arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.forceDownload = installerOptions.forceDownload ?? false;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
Expand All @@ -129318,7 +129321,7 @@ class JavaBase {
if (this.verifySignature && !this.supportsSignatureVerification()) {
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava && !this.checkLatest && !this.latest) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
Expand All @@ -129342,7 +129345,8 @@ class JavaBase {
}
const javaRelease = await this.findPackageForDownload(this.version);
info(`Resolved latest version as ${javaRelease.version}`);
if (foundJava?.version === javaRelease.version) {
if (!this.forceDownload &&
foundJava?.version === javaRelease.version) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
else {
Expand Down Expand Up @@ -129617,7 +129621,7 @@ class LocalDistribution extends JavaBase {
if (this.latest) {
throw new Error("The 'latest' version alias is not supported for the 'jdkfile' distribution. Please specify a concrete version.");
}
let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava) {
info(`Resolved Java ${foundJava.version} from tool-cache`);
}
Expand Down Expand Up @@ -132041,6 +132045,7 @@ async function run() {
const cache = getInput(INPUT_CACHE);
const cacheDependencyPath = getInput(INPUT_CACHE_DEPENDENCY_PATH);
const checkLatest = util_getBooleanInput(INPUT_CHECK_LATEST, false);
const forceDownload = util_getBooleanInput(INPUT_FORCE_DOWNLOAD, false);
const setDefault = util_getBooleanInput(INPUT_SET_DEFAULT, true);
const verifySignature = util_getBooleanInput(INPUT_VERIFY_SIGNATURE, false);
const verifySignaturePublicKey = getInput(INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
Expand Down Expand Up @@ -132072,6 +132077,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand All @@ -132090,6 +132096,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand Down Expand Up @@ -132124,11 +132131,12 @@ function getJdkFileInput() {
return jdkFile || deprecatedJdkFile;
}
async function installVersion(version, options, toolchainId = 0) {
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
const { distributionName, jdkFile, architecture, packageType, checkLatest, forceDownload, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
const installerOptions = {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const INPUT_DISTRIBUTION = 'distribution';
export const INPUT_JDK_FILE = 'jdk-file';
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
export const INPUT_CHECK_LATEST = 'check-latest';
export const INPUT_FORCE_DOWNLOAD = 'force-download';
export const INPUT_SET_DEFAULT = 'set-default';
export const INPUT_PROBLEM_MATCHER = 'problem-matcher';
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
Expand Down
9 changes: 7 additions & 2 deletions src/distributions/base-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export abstract class JavaBase {
protected stable: boolean;
protected latest: boolean;
protected checkLatest: boolean;
protected forceDownload: boolean;
protected setDefault: boolean;
protected verifySignature: boolean;
protected verifySignaturePublicKey: string | undefined;
Expand All @@ -46,6 +47,7 @@ export abstract class JavaBase {
this.architecture = installerOptions.architecture || os.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.forceDownload = installerOptions.forceDownload ?? false;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
Expand All @@ -68,7 +70,7 @@ export abstract class JavaBase {
);
}

let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();
if (foundJava && !this.checkLatest && !this.latest) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else {
Expand All @@ -91,7 +93,10 @@ export abstract class JavaBase {
}
const javaRelease = await this.findPackageForDownload(this.version);
core.info(`Resolved latest version as ${javaRelease.version}`);
if (foundJava?.version === javaRelease.version) {
if (
!this.forceDownload &&
foundJava?.version === javaRelease.version
) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else {
core.info('Trying to download...');
Expand Down
1 change: 1 addition & 0 deletions src/distributions/base-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface JavaInstallerOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
forceDownload?: boolean;
setDefault?: boolean;
verifySignature?: boolean;
verifySignaturePublicKey?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/local/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class LocalDistribution extends JavaBase {
);
}

let foundJava = this.findInToolcache();
let foundJava = this.forceDownload ? null : this.findInToolcache();

if (foundJava) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
Expand Down
9 changes: 9 additions & 0 deletions src/setup-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ async function run() {
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const forceDownload = getBooleanInput(
constants.INPUT_FORCE_DOWNLOAD,
false
);
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
const verifySignature = getBooleanInput(
constants.INPUT_VERIFY_SIGNATURE,
Expand Down Expand Up @@ -83,6 +87,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand All @@ -102,6 +107,7 @@ async function run() {
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand Down Expand Up @@ -159,6 +165,7 @@ async function installVersion(
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand All @@ -169,6 +176,7 @@ async function installVersion(
architecture,
packageType,
checkLatest,
forceDownload,
setDefault,
verifySignature,
verifySignaturePublicKey,
Expand Down Expand Up @@ -212,6 +220,7 @@ interface installerInputsOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
forceDownload: boolean;
setDefault: boolean;
verifySignature: boolean;
verifySignaturePublicKey: string | undefined;
Expand Down
Loading