Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit e1f4ee7

Browse files
authored
Restore compatibility with joschi/setup-jdk@v1 for java-version (#12)
The normalization of the `java-version` setting to treat "openjdk14" as a valid Java release version was accidentally dropped while moving to joschi/setup-jdk 2.x. Closes #9
1 parent 5f767b2 commit e1f4ee7

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

__tests__/installer.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,25 @@ describe('installer tests', () => {
344344
expect(thrown).toBe(true);
345345
return;
346346
});
347+
348+
it('GitHub issue #9: Allow openjdk[0-9]+ as Java release version', async () => {
349+
await installer.getAdoptOpenJDK(
350+
'ga',
351+
'openjdk14',
352+
'jdk',
353+
'hotspot',
354+
'x64',
355+
'normal',
356+
'latest',
357+
''
358+
);
359+
const JavaDir = path.join(
360+
toolDir,
361+
toolName,
362+
`1.0.0-ga-14-jdk-hotspot-${os}-x64-normal-latest`,
363+
'x64'
364+
);
365+
366+
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
367+
}, 100000);
347368
});

dist/index.js

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/installer.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
let tempDirectory = process.env['RUNNER_TEMP'] || '';
22

33
import * as core from '@actions/core';
4-
import * as io from '@actions/io';
54
import * as exec from '@actions/exec';
6-
import * as httpm from '@actions/http-client';
7-
import * as tc from '@actions/tool-cache';
85
import * as fs from 'fs';
6+
import * as httpm from '@actions/http-client';
7+
import * as io from '@actions/io';
98
import * as path from 'path';
109
import * as semver from 'semver';
10+
import * as tc from '@actions/tool-cache';
1111

1212
const IS_WINDOWS = process.platform === 'win32';
1313
const IS_MACOS = process.platform === 'darwin';
@@ -408,9 +408,10 @@ async function downloadJavaBinary(
408408
jdkFile: string
409409
): Promise<void> {
410410
const normalizedArchitecture = architectureAliases.get(arch) || arch;
411+
const normalizedVersion = version.replace('openjdk', '');
411412
const versionSpec = getCacheVersionSpec(
412413
release_type,
413-
version,
414+
normalizedVersion,
414415
image_type,
415416
jvm_impl,
416417
os,
@@ -428,14 +429,15 @@ async function downloadJavaBinary(
428429
core.debug('Downloading JDK from AdoptOpenJDK');
429430
const url: string = getAdoptOpenJdkUrl(
430431
release_type,
431-
version,
432+
normalizedVersion,
432433
image_type,
433434
jvm_impl,
434435
os,
435436
normalizedArchitecture,
436437
heap_size,
437438
release
438439
);
440+
core.debug(`AdoptOpenJDK URL: ${url}`);
439441
jdkFile = await tc.downloadTool(url);
440442
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
441443
}
@@ -459,7 +461,7 @@ async function downloadJavaBinary(
459461
);
460462
}
461463

462-
let extendedJavaHome = `JAVA_HOME_${version}_${normalizedArchitecture}`;
464+
let extendedJavaHome = `JAVA_HOME_${normalizedVersion}_${normalizedArchitecture}`;
463465
core.exportVariable(extendedJavaHome, toolPath); //TODO: remove for v2
464466
// For portability reasons environment variables should only consist of
465467
// uppercase letters, digits, and the underscore. Therefore we convert
@@ -470,5 +472,5 @@ async function downloadJavaBinary(
470472
core.exportVariable(extendedJavaHome, toolPath);
471473
core.addPath(path.join(toolPath, 'bin'));
472474
core.setOutput('path', toolPath);
473-
core.setOutput('version', version);
475+
core.setOutput('version', normalizedVersion);
474476
}

0 commit comments

Comments
 (0)