Skip to content

Commit

Permalink
add support for adoptopenjdk binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams committed May 26, 2020
1 parent 4003c04 commit 199d480
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest]
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '9.0.4' # The JDK version to make available on the path.
java-version: '11' # The JDK version to make available on the path.
vendor: zulu # (adoptopenjdk or zulu) - defaults to zulu
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64
- run: java -cp java HelloWorldApp
Expand All @@ -30,13 +31,13 @@ Examples of version specifications that the java-version parameter will accept:
e.g. ```6, 7, 8, 9, 10, 11, 12, 13, ...```

- A semver Java version specification
- A semver Java version specification (Zulu only)

e.g. ```8.0.232, 7.0.181, 11.0.4```

e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212```

- An early access (EA) Java version
- An early access (EA) Java version (Zulu only)

e.g. ```14-ea, 15-ea```

Expand All @@ -46,7 +47,7 @@ Examples of version specifications that the java-version parameter will accept:

Note that, per semver rules, EA builds will be matched by explicit EA version specifications.

- 1.x syntax
- 1.x syntax (Zulu only)

e.g. ```1.8``` (same as ```8```)

Expand Down
79 changes: 62 additions & 17 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import * as installer from '../src/installer';

let javaFilePath = '';
let javaUrl = '';
let additionalPath = '';
if (process.platform === 'win32') {
javaFilePath = path.join(javaDir, 'java_win.zip');
javaUrl =
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_windows-x64_bin.zip';
} else if (process.platform === 'darwin') {
javaFilePath = path.join(javaDir, 'java_mac.tar.gz');
// macOS tarballs are in bundle format
additionalPath = "/Contents/Home";
javaUrl =
'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz';
} else {
Expand Down Expand Up @@ -51,68 +54,109 @@ describe('installer tests', () => {
}
}, 100000);

it('Installs version of Java from jdkFile if no matching version is installed', async () => {
await installer.getJava('12', 'x64', javaFilePath, 'jdk');
it('Installs version of Java from jdkFile if no matching version is installed AdoptOpenJDK', async () => {
await installer.getJava('12', 'adoptopenjdk', '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, additionalPath, 'bin'))).toBe(true);
}, 100000);

it('Installs version of Java from jdkFile if no matching version is installed Zulu', async () => {
await installer.getJava('12', 'zulu', '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);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);

it('Throws if invalid directory to jdk', async () => {
it('Throws if invalid directory to jdk AdoptOpenJDK', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'x64', 'bad path', 'jdk');
await installer.getJava('1000', 'adoptopenjdk', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});

it('Downloads java if no file given', async () => {
await installer.getJava('8.0.102', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '8.0.102', 'x64');
it('Throws if invalid directory to jdk Zulu', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'zulu', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});

it('Downloads java if no file given AdoptOpenJDK', async () => {
await installer.getJava('8', 'adoptopenjdk', 'x64', '', 'jdk');
const JavaDir = path.join(toolDir, 'jdk', '8.0.0', 'x64');

expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);

it('Downloads java if no file given Zulu', async () => {
await installer.getJava('8.0.102', 'zulu', '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', '', 'jdk');
await installer.getJava('1.10', 'zulu', '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', '', 'jdk');
await installer.getJava('9.0.x', 'zulu', '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');
it('Downloads java if package is jre AdoptOpenJDK', async () => {
await installer.getJava('11', 'adoptopenjdk', 'x64', '', 'jre');
const JavaDir = path.join(toolDir, 'jre', '11.0.0', 'x64');

expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true);
}, 100000);

it('Downloads java if package is jre Zulu', async () => {
await installer.getJava('8.0.222', 'zulu', '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');
await installer.getJava('8.0.222', 'zulu', '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 () => {
it('Throws if invalid java package is specified AdoptOpenJDK', async () => {
let thrown = false;
try {
await installer.getJava('8', 'adoptopenjdk', 'x64', '', 'bad jdk');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});

it('Throws if invalid java package is specified Zulu', async () => {
let thrown = false;
try {
await installer.getJava('8.0.222', 'x64', '', 'bad jdk');
await installer.getJava('8.0.222', 'zulu', 'x64', '', 'bad jdk');
} catch {
thrown = true;
}
Expand All @@ -122,7 +166,7 @@ describe('installer tests', () => {
it('Throws if invalid directory to jdk', async () => {
let thrown = false;
try {
await installer.getJava('1000', 'x64', 'bad path', 'jdk');
await installer.getJava('1000', 'zulu', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
Expand All @@ -136,6 +180,7 @@ describe('installer tests', () => {
// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getJava(
'250',
'zulu',
'x64',
'path shouldnt matter, found in cache',
'jdk'
Expand All @@ -149,7 +194,7 @@ describe('installer tests', () => {
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', 'jdk');
await installer.getJava('251', 'zulu', 'x64', 'bad path', 'jdk');
} catch {
thrown = true;
}
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ inputs:
Early access versions can be specified in the form of e.g. 14-ea,
14.0.0-ea, or 14.0.0-ea.28'
required: true
vendor:
description: 'The vendor to fetch the binary from (adoptopenjdk, zulu).
Defaults to zulu'
required: false
default: 'jdk'
java-package:
description: 'The package type (jre, jdk, jdk+fx)'
required: false
Expand Down
Loading

0 comments on commit 199d480

Please sign in to comment.