From 249ea4386fad8f7c14880f77de6284159dfecb6b Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Tue, 14 Apr 2020 21:17:06 +0300 Subject: [PATCH 1/2] Normalize the version before it is looked up in the tool cache Currently the resolved version is cached. For example something like 8.0.141. On other hand when a version is looked up in the cache the string provided by the user is used. This may lead to unexpected behavior. 1.8 will not match 8.0.141. Normalizing the version string before looking up in the tool cache will solve the problem. The normalized version (8.x) will match the entry in the cache as expected. Normalizing the string in the beginning of the flow won't hurt as it is a valid version specification. What is more it the user can supply the normalized version directly so the code should be able to work with it. --- __tests__/installer.test.ts | 14 ++++++++++++++ src/installer.ts | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index ff2d61b5b..69efc0983 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -143,6 +143,20 @@ describe('installer tests', () => { return; }); + it('Uses 1.x version of Java installed in cache', async () => { + const JavaDir: string = path.join(toolDir, 'jdk', '8.0.181', 'x64'); + await io.mkdirP(JavaDir); + fs.writeFileSync(`${JavaDir}.complete`, 'hello'); + // This will throw if it doesn't find it in the cache + await installer.getJava( + '1.8', + 'x64', + 'path shouldnt matter, found in cache', + 'jdk' + ); + return; + }); + it('Doesnt use version of Java that was only partially installed in cache', async () => { const JavaDir: string = path.join(toolDir, 'jdk', '251.0.0', 'x64'); await io.mkdirP(JavaDir); diff --git a/src/installer.ts b/src/installer.ts index cce8fa3d3..367815171 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -32,6 +32,8 @@ export async function getJava( jdkFile: string, javaPackage: string ): Promise { + version = normalizeVersion(version); + let toolPath = tc.find(javaPackage, version); if (toolPath) { @@ -190,7 +192,6 @@ function getDownloadInfo( version: string, javaPackage: string ): {version: string; url: string} { - version = normalizeVersion(version); let extension = ''; if (IS_WINDOWS) { extension = `-win_x64.zip`; From 109dbacebe6a9c1f892b8e41c339e056e4a508a8 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Tue, 14 Apr 2020 21:31:28 +0300 Subject: [PATCH 2/2] Update index.js --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 966326536..60a3be911 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4668,6 +4668,7 @@ if (!tempDirectory) { } function getJava(version, arch, jdkFile, javaPackage) { return __awaiter(this, void 0, void 0, function* () { + version = normalizeVersion(version); let toolPath = tc.find(javaPackage, version); if (toolPath) { core.debug(`Tool found in cache ${toolPath}`); @@ -4805,7 +4806,6 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) { }); } function getDownloadInfo(refs, version, javaPackage) { - version = normalizeVersion(version); let extension = ''; if (IS_WINDOWS) { extension = `-win_x64.zip`;