Skip to content

Commit

Permalink
Rename JDK to Java in messages shown to user (#692)
Browse files Browse the repository at this point in the history
JDK is not required, JRE is enough. JDK is renamed to Java in messages show to users to make them less restrictive.
  • Loading branch information
valfirst authored Sep 24, 2024
1 parent 326c62b commit 6ed1ae8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"null"
],
"default": null,
"description": "The directory path containing JDK to run the extension"
"description": "The directory path containing Java to run the extension"
},
"vividus-studio.stories-runner": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function activate(context: ExtensionContext) {
async function createServerOptions(context: ExtensionContext): Promise<StreamInfo> {

const javaRuntime: IJavaRuntime = await findJavaExecutable();
window.showInformationMessage(`Using JDK ${javaRuntime.version?.java_version}`);
window.showInformationMessage(`Using Java ${javaRuntime.version?.java_version}`);

return new Promise(async (res, rej) => {
const server = createServer(connection => res({ writer: connection, reader: connection }));
Expand Down
8 changes: 4 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export async function findJavaExecutable(): Promise<IJavaRuntime> {
const runtime: IJavaRuntime = await getRuntime(userJavaHome, { withVersion: true }) as IJavaRuntime;

if (!runtime) {
throw new Error(`Unable to find JDK at location specified by ${javaHomeProperty} user property: ${userJavaHome}`);
throw new Error(`Unable to find Java at location specified by ${javaHomeProperty} user property: ${userJavaHome}`);
}

if (runtime.version?.major as number < 17) {
throw new Error(`The ${javaHomeProperty} user property points to JDK ${runtime.version?.java_version} installation,`
+ ` but JDK 17 or higher is required`)
throw new Error(`The ${javaHomeProperty} user property points to Java ${runtime.version?.java_version} installation,`
+ ` but Java 17 or higher is required`)
}

return runtime;
Expand All @@ -26,7 +26,7 @@ export async function findJavaExecutable(): Promise<IJavaRuntime> {
}) as IJavaRuntime;

if (!runtime) {
throw new Error('Unable to find JDK 17 or higher installation');
throw new Error('Unable to find Java 17 or higher installation');
}

return runtime;
Expand Down
32 changes: 16 additions & 16 deletions src/test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ suite('Utils', () => {
sinon.restore()
})

const jdk13: IJavaRuntime = {
const java13: IJavaRuntime = {
homedir: 'home_dir',
version: {
java_version: '13.0.2',
major: 13
}
}

const jdk17: IJavaRuntime = {
const java17: IJavaRuntime = {
homedir: 'home_dir',
version: {
java_version: '17.0.2',
Expand All @@ -30,63 +30,63 @@ suite('Utils', () => {

const jdkUtilsModule = require('jdk-utils')

test('Should return JDK 17 installation pointed by vividus-studio.java-home property', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'getRuntime').returns(jdk17)
test('Should return Java 17 installation pointed by vividus-studio.java-home property', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'getRuntime').returns(java17)

sinon.stub(workspace, 'getConfiguration').returns(<WorkspaceConfiguration>{
get: (section: string) => { return 'home_dir' }
});

assert.equal(jdk17, await findJavaExecutable())
assert.equal(java17, await findJavaExecutable())
assert.equal(true, getRuntimeStub.calledWith('home_dir', { withVersion: true }))
})

test('Should return JDK 17 system installation', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'findRuntimes').returns([jdk17])
test('Should return Java 17 system installation', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'findRuntimes').returns([java17])

sinon.stub(workspace, 'getConfiguration').returns(<WorkspaceConfiguration>{
get: (section: string) => { return null }
});

assert.equal(jdk17, await findJavaExecutable())
assert.equal(java17, await findJavaExecutable())
assert.equal(true, getRuntimeStub.calledWith({ withVersion: true }))
})

test('Should fail if vividus-studio.java-home property points to not java dir', async () => {
test('Should fail if vividus-studio.java-home property points to not Java dir', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'getRuntime').returns(undefined)

sinon.stub(workspace, 'getConfiguration').returns(<WorkspaceConfiguration>{
get: (section: string) => { return 'home_dir' }
});

await assert.rejects(findJavaExecutable(),
{ message: 'Unable to find JDK at location specified by vividus-studio.java-home user property: home_dir' })
{ message: 'Unable to find Java at location specified by vividus-studio.java-home user property: home_dir' })
assert.equal(true, getRuntimeStub.calledOnce)
assert.equal(true, getRuntimeStub.calledWith('home_dir', { withVersion: true }))
})

test('Should fail if vividus-studio.java-home property points to old jdk versions', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'getRuntime').returns(jdk13)
test('Should fail if vividus-studio.java-home property points to old Java versions', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'getRuntime').returns(java13)

sinon.stub(workspace, 'getConfiguration').returns(<WorkspaceConfiguration>{
get: (section: string) => { return 'home_dir' }
});

await assert.rejects(findJavaExecutable(),
{ message: 'The vividus-studio.java-home user property points to JDK 13.0.2 installation, but JDK 17 or higher is required' })
{ message: 'The vividus-studio.java-home user property points to Java 13.0.2 installation, but Java 17 or higher is required' })
assert.equal(true, getRuntimeStub.calledOnce)
assert.equal(true, getRuntimeStub.calledWith('home_dir', { withVersion: true }))
})

test('Should fail if there is no JDK 17 installed in the system', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'findRuntimes').returns([jdk13])
test('Should fail if there is no Java 17 installed in the system', async () => {
const getRuntimeStub: SinonStub = sinon.stub(jdkUtilsModule, 'findRuntimes').returns([java13])

sinon.stub(workspace, 'getConfiguration').returns(<WorkspaceConfiguration>{
get: (section: string) => { return null }
});

await assert.rejects(findJavaExecutable(),
{ message: 'Unable to find JDK 17 or higher installation' })
{ message: 'Unable to find Java 17 or higher installation' })
assert.equal(true, getRuntimeStub.calledOnce)
assert.equal(true, getRuntimeStub.calledWith({ withVersion: true }))
})
Expand Down

0 comments on commit 6ed1ae8

Please sign in to comment.