diff options
author | George Fraser <george@fivetran.com> | 2018-12-28 19:31:38 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2018-12-28 19:31:38 -0800 |
commit | 9a02922e98d84bb1ea0b19ff8d2259b5cb7b0e9c (patch) | |
tree | a8621acc6a35e55d33627bb2f77cd85aef358e73 /lib | |
parent | 3bdefe1c30f531c7a646df9b9b14eec232f1fe1b (diff) | |
download | java-language-server-9a02922e98d84bb1ea0b19ff8d2259b5cb7b0e9c.zip |
Use jlink to build self-contained distribution
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extension.ts | 88 |
1 files changed, 4 insertions, 84 deletions
diff --git a/lib/extension.ts b/lib/extension.ts index a735493..dddda06 100644 --- a/lib/extension.ts +++ b/lib/extension.ts @@ -2,7 +2,6 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import * as Path from "path"; -import * as FS from "fs"; import { window, workspace, ExtensionContext, commands, tasks, Task, TaskExecution, ShellExecution, Uri, TaskDefinition, languages, IndentAction, Progress, ProgressLocation } from 'vscode'; import {LanguageClient, LanguageClientOptions, ServerOptions, NotificationType} from "vscode-languageclient"; @@ -11,13 +10,6 @@ import {LanguageClient, LanguageClientOptions, ServerOptions, NotificationType} export function activate(context: ExtensionContext) { console.log('Activating Java'); - let javaExecutablePath = findJavaExecutable('java'); - - if (javaExecutablePath == null) { - window.showErrorMessage("Couldn't locate java in $JAVA_HOME or $PATH"); - - return; - } // Options to control the language client let clientOptions: LanguageClientOptions = { // Register the server for java documents @@ -39,22 +31,14 @@ export function activate(context: ExtensionContext) { revealOutputChannelOn: 4 // never } - let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar"); + let launcher = Path.resolve(context.extensionPath, "dist", "bin", "javacs"); - let args = [ - '-cp', fatJar, - '-Xverify:none', // helps VisualVM avoid 'error 62' - '-Xdebug', - // '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005', - 'org.javacs.Main' - ]; - - console.log(javaExecutablePath + ' ' + args.join(' ')); + console.log(launcher); // Start the child java process let serverOptions: ServerOptions = { - command: javaExecutablePath, - args: args, + command: launcher, + args: [], options: { cwd: context.extensionPath } } @@ -110,70 +94,6 @@ export function activate(context: ExtensionContext) { client.onReady().then(() => createProgressListeners(client)); } -function findJavaExecutable(binname: string) { - binname = correctBinname(binname); - - // First search java.home setting - let userJavaHome = workspace.getConfiguration('java').get('home') as string; - - if (userJavaHome != null) { - console.log('Looking for java in settings java.home ' + userJavaHome + '...'); - - let candidate = findJavaExecutableInJavaHome(userJavaHome, binname); - - if (candidate != null) - return candidate; - } - - // Then search each JAVA_HOME - let envJavaHome = process.env['JAVA_HOME']; - - if (envJavaHome) { - console.log('Looking for java in environment variable JAVA_HOME ' + envJavaHome + '...'); - - let candidate = findJavaExecutableInJavaHome(envJavaHome, binname); - - if (candidate != null) - return candidate; - } - - // Then search PATH parts - if (process.env['PATH']) { - console.log('Looking for java in PATH'); - - let pathparts = process.env['PATH'].split(Path.delimiter); - for (let i = 0; i < pathparts.length; i++) { - let binpath = Path.join(pathparts[i], binname); - if (FS.existsSync(binpath)) { - return binpath; - } - } - } - - // Else return the binary name directly (this will likely always fail downstream) - return null; -} - -function correctBinname(binname: string) { - if (process.platform === 'win32') - return binname + '.exe'; - else - return binname; -} - -function findJavaExecutableInJavaHome(javaHome: string, binname: string) { - let workspaces = javaHome.split(Path.delimiter); - - for (let i = 0; i < workspaces.length; i++) { - let binpath = Path.join(workspaces[i], 'bin', binname); - - if (FS.existsSync(binpath)) - return binpath; - } - - return null; -} - // this method is called when your extension is deactivated export function deactivate() { } |