From 012e07621e2f7abe0da069c9b9245d82f1e541e6 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 15 Jul 2019 11:26:32 -0400 Subject: [PATCH] Dont fail if jdkFile not set until checking cache --- action.yml | 2 +- lib/installer.js | 3 +++ lib/setup-java.js | 2 +- src/installer.ts | 5 +++++ src/setup-java.ts | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index b9d95e17..e5664344 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: default: 'x64' jdkFile: description: 'Path to where the compressed JDK is located. The path could be in your source repository or a local path on the agent.' - required: true + required: false runs: using: 'node12' main: 'lib/setup-java.js' diff --git a/lib/installer.js b/lib/installer.js index 1c5c8c52..c5a98278 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -46,6 +46,9 @@ function getJava(version, arch, jdkFile) { core.debug(`Tool found in cache ${toolPath}`); } else { + if (!jdkFile) { + throw new Error(`Failed to find Java ${version} in the cache. Please specify a valid jdk file to install from instead.`); + } core.debug('Retrieving Jdk from local path'); const compressedFileExtension = getFileEnding(jdkFile); let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000)); diff --git a/lib/setup-java.js b/lib/setup-java.js index f0135a3e..1e229175 100644 --- a/lib/setup-java.js +++ b/lib/setup-java.js @@ -23,7 +23,7 @@ function run() { try { const version = core.getInput('version', { required: true }); const arch = core.getInput('architecture', { required: true }); - const jdkFile = core.getInput('jdkFile', { required: true }); + const jdkFile = core.getInput('jdkFile', { required: false }) || ''; yield installer.getJava(version, arch, jdkFile); const matchersPath = path.join(__dirname, '..', '.github'); console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); diff --git a/src/installer.ts b/src/installer.ts index dbd114bc..9a7bea20 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -34,6 +34,11 @@ export async function getJava( if (toolPath) { core.debug(`Tool found in cache ${toolPath}`); } else { + if (!jdkFile) { + throw new Error( + `Failed to find Java ${version} in the cache. Please specify a valid jdk file to install from instead.` + ); + } core.debug('Retrieving Jdk from local path'); const compressedFileExtension = getFileEnding(jdkFile); let tempDir: string = path.join( diff --git a/src/setup-java.ts b/src/setup-java.ts index d5c11da0..86b225d5 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -6,7 +6,7 @@ async function run() { try { const version = core.getInput('version', {required: true}); const arch = core.getInput('architecture', {required: true}); - const jdkFile = core.getInput('jdkFile', {required: true}); + const jdkFile = core.getInput('jdkFile', {required: false}) || ''; await installer.getJava(version, arch, jdkFile);