Add java-package parameter to action, support jre, jdk, and jdk+fx (#1)

* Add java-package parameter to action, support jre, jdk, and jdk+fx (#1)

* Update tests to use 'jdk', 'jre', and 'jdk+fx' javaPackage parameters

* Match extension only at end of line

* Update README.md

* Update workflow to use 'node-version' instead of deprecated 'version'
This commit is contained in:
Gil Tene
2019-11-02 21:39:35 -07:00
committed by GitHub
parent 204b974cf4
commit 7d219e5bd5
8 changed files with 112 additions and 42 deletions

View File

@ -52,8 +52,8 @@ describe('installer tests', () => {
}, 100000);
it('Installs version of Java from jdkFile if no matching version is installed', async () => {
await installer.getJava('12', 'x64', javaFilePath);
const JavaDir = path.join(toolDir, 'Java', '12.0.0', 'x64');
await installer.getJava('12', 'x64', javaFilePath, 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '12.0.0', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
@ -62,7 +62,7 @@ describe('installer tests', () => {
it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'x64', 'bad path');
await installer.getJava('1000', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
@ -70,33 +70,59 @@ describe('installer tests', () => {
});
it('Downloads java if no file given', async () => {
await installer.getJava('8.0.102', 'x64', '');
const JavaDir = path.join(toolDir, 'Java', '8.0.102', 'x64');
await installer.getJava('8.0.102', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '8.0.102', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);
it('Downloads java with 1.x syntax', async () => {
await installer.getJava('1.10', 'x64', '');
const JavaDir = path.join(toolDir, 'Java', '10.0.2', 'x64');
await installer.getJava('1.10', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '10.0.2', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);
it('Downloads java with normal semver syntax', async () => {
await installer.getJava('9.0.x', 'x64', '');
const JavaDir = path.join(toolDir, 'Java', '9.0.7', 'x64');
await installer.getJava('9.0.x', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '9.0.7', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);
it('Downloads java if package is jre', async () => {
await installer.getJava('8.0.222', 'x64', '', 'jre');
const JavaDir = path.join(toolDir, 'jre', '8.0.222', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);
it('Downloads java if package is jdk+fx', async () => {
await installer.getJava('8.0.222', 'x64', '', 'jdk+fx');
const JavaDir = path.join(toolDir, 'jdk+fx', '8.0.222', 'x64');
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
}, 100000);
it('Throws if invalid java package is specified', async () => {
let thrown = false;
try {
await installer.getJava('8.0.222', 'x64', '', 'bad jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});
it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'x64', 'bad path');
await installer.getJava('1000', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
@ -104,25 +130,26 @@ describe('installer tests', () => {
});
it('Uses version of Java installed in cache', async () => {
const JavaDir: string = path.join(toolDir, 'Java', '250.0.0', 'x64');
const JavaDir: string = path.join(toolDir, 'jdk', '250.0.0', 'x64');
await io.mkdirP(JavaDir);
fs.writeFileSync(`${JavaDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getJava(
'250',
'x64',
'path shouldnt matter, found in cache'
'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, 'Java', '251.0.0', 'x64');
const JavaDir: string = path.join(toolDir, 'jdk', '251.0.0', 'x64');
await io.mkdirP(JavaDir);
let thrown = false;
try {
// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getJava('251', 'x64', 'bad path');
await installer.getJava('251', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}