From 9f383a9b45c75c641386a36796e955ff61a990ca Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Thu, 1 Mar 2018 22:24:26 -0800 Subject: [PATCH] Switch vscode-spring-boot to properties launcher --- .../spring-boot-language-server/pom.xml | 5 +- vscode-extensions/commons-vscode/package.json | 2 +- .../commons-vscode/src/launch-util.ts | 38 ++++++++------- .../vscode-spring-boot/.vscode/launch.json | 47 ++++++++----------- .../vscode-spring-boot/.vscode/tasks.json | 46 +++++++----------- .../vscode-spring-boot/lib/Main.ts | 11 +---- .../vscode-spring-boot/package.json | 8 ++-- .../vscode-spring-boot/scripts/preinstall.sh | 3 +- 8 files changed, 70 insertions(+), 90 deletions(-) diff --git a/headless-services/spring-boot-language-server/pom.xml b/headless-services/spring-boot-language-server/pom.xml index 9ef562b8d..7c197b297 100644 --- a/headless-services/spring-boot-language-server/pom.xml +++ b/headless-services/spring-boot-language-server/pom.xml @@ -103,7 +103,10 @@ org.springframework.boot spring-boot-maven-plugin - 1.4.1.RELEASE + 2.0.0.RELEASE + + ZIP + diff --git a/vscode-extensions/commons-vscode/package.json b/vscode-extensions/commons-vscode/package.json index 51b3a6e0b..abeaf6160 100644 --- a/vscode-extensions/commons-vscode/package.json +++ b/vscode-extensions/commons-vscode/package.json @@ -25,7 +25,7 @@ "prepack": "node ./node_modules/vscode/bin/install && tsc -p ./" }, "dependencies": { - "@pivotal-tools/jvm-launch-utils": "0.0.9", + "@pivotal-tools/jvm-launch-utils": "0.0.10", "portfinder": "^0.4.0" }, "devDependencies": { diff --git a/vscode-extensions/commons-vscode/src/launch-util.ts b/vscode-extensions/commons-vscode/src/launch-util.ts index 9b0df7534..eeb5e389a 100644 --- a/vscode-extensions/commons-vscode/src/launch-util.ts +++ b/vscode-extensions/commons-vscode/src/launch-util.ts @@ -32,10 +32,9 @@ export interface ActivatorOptions { TRACE?: boolean; extensionId: string; clientOptions: LanguageClientOptions; - launcher: (context: VSCode.ExtensionContext) => string; jvmHeap?: string; workspaceOptions?: VSCode.WorkspaceConfiguration; - classpath?: (context: VSCode.ExtensionContext, jvm: JVM) => string[]; + checkjvm?: (context: VSCode.ExtensionContext, jvm: JVM) => any; preferJdk?: boolean; } @@ -81,7 +80,7 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon VSCode.window.showErrorMessage("Error trying to find JVM: "+error); return Promise.reject(error); }) - .then(jvm => { + .then((jvm) => { if (!jvm) { VSCode.window.showErrorMessage("Couldn't locate java in $JAVA_HOME or $PATH"); return; @@ -111,7 +110,6 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon let processLaunchoptions = { cwd: VSCode.workspace.rootPath }; - let child: ChildProcess.ChildProcess; let logfile = Path.join(tmpdir(), options.extensionId + '-' + Date.now()+'.log'); log('Redirecting server logs to ' + logfile); const args = [ @@ -119,28 +117,19 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon '-Dsts.lsp.client=vscode', '-Dsts.log.file=' + logfile ]; - if (options.classpath) { - const classpath = options.classpath(context, jvm); - if (classpath) { - args.push('-cp'); - args.push(classpath.join(Path.delimiter)); - } + if (options.checkjvm) { + options.checkjvm(context, jvm); } - const launcher = options.launcher(context); - if (launcher.endsWith('.jar')) { - args.push('-jar'); - } - args.push(options.launcher(context)); if (jvmHeap) { args.unshift("-Xmx"+jvmHeap); } if (DEBUG) { args.unshift(DEBUG_ARG); } - log("CMD = " + javaExecutablePath + ' ' + args.join(' ')); // Start the child java process - child = ChildProcess.execFile(javaExecutablePath, args, processLaunchoptions); + let launcher = findServerJar(Path.resolve(context.extensionPath, 'jars')); + let child = jvm.jarLaunch(launcher, args, processLaunchoptions); child.stdout.on('data', (data) => { log("" + data); }); @@ -156,6 +145,21 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon } } +function findServerJar(jarsDir) : string { + let serverJars = FS.readdirSync(jarsDir).filter(jar => + jar.indexOf('language-server')>=0 && + jar.endsWith(".jar") + ); + if (serverJars.length==0) { + throw new Error("Server jar not found in "+jarsDir); + } + if (serverJars.length>1) { + throw new Error("Multiple server jars found in "+jarsDir); + } + return Path.resolve(jarsDir, serverJars[0]); +} + + function connectToLS(context: VSCode.ExtensionContext, options: ActivatorOptions): Promise { let connectionInfo = { port: 5007 diff --git a/vscode-extensions/vscode-spring-boot/.vscode/launch.json b/vscode-extensions/vscode-spring-boot/.vscode/launch.json index 07e1c6011..90805734a 100644 --- a/vscode-extensions/vscode-spring-boot/.vscode/launch.json +++ b/vscode-extensions/vscode-spring-boot/.vscode/launch.json @@ -1,31 +1,22 @@ // A launch configuration that compiles the extension and then opens it inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.1.0", - "configurations": [ - { - "type": "extensionHost", - "request": "launch", - "name": "Launch Extension", - "runtimeExecutable": "${execPath}", - "args": [ - "--extensionDevelopmentPath=${workspaceRoot}" - ], - "sourceMaps": true, - "outFiles": [ - "${workspaceRoot}/out/**/*.js" - ], - "preLaunchTask": "npm" - }, - { - "name": "Launch Tests", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], - "stopOnEntry": false, - "sourceMaps": true, - "outDir": "${workspaceRoot}/out/test", - "preLaunchTask": "npm" - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "preLaunchTask": "npm: watch" + } + ] } diff --git a/vscode-extensions/vscode-spring-boot/.vscode/tasks.json b/vscode-extensions/vscode-spring-boot/.vscode/tasks.json index 1cbb9fd45..604e38f5a 100644 --- a/vscode-extensions/vscode-spring-boot/.vscode/tasks.json +++ b/vscode-extensions/vscode-spring-boot/.vscode/tasks.json @@ -1,30 +1,20 @@ -// Available variables which can be used inside of strings. -// ${workspaceRoot}: the root folder of the team -// ${file}: the current opened file -// ${fileBasename}: the current opened file's basename -// ${fileDirname}: the current opened file's dirname -// ${fileExtname}: the current opened file's extension -// ${cwd}: the current working directory of the spawned process - -// A task runner that calls a custom npm script that compiles the extension. +// See https://go.microsoft.com/fwlink/?LinkId=733558 +// for the documentation about the tasks.json format { - "version": "0.1.0", - - // we want to run npm - "command": "npm", - - // the command is a shell script - "isShellCommand": true, - - // show the output window only if unrecognized errors occur. - "showOutput": "silent", - - // we run the custom script "compile" as defined in package.json - "args": ["run", "compile"], //, "--loglevel", "silent"], - - // The tsc compiler is started in watching mode - "isWatching": true, - - // use the standard tsc in watch mode problem matcher to find compile problems in the output. - "problemMatcher": "$tsc-watch" + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] } \ No newline at end of file diff --git a/vscode-extensions/vscode-spring-boot/lib/Main.ts b/vscode-extensions/vscode-spring-boot/lib/Main.ts index a07ad3734..6b5ae76d8 100644 --- a/vscode-extensions/vscode-spring-boot/lib/Main.ts +++ b/vscode-extensions/vscode-spring-boot/lib/Main.ts @@ -23,19 +23,10 @@ export function activate(context: VSCode.ExtensionContext) { CONNECT_TO_LS: false, extensionId: 'vscode-spring-boot', preferJdk: true, - launcher: (context: VSCode.ExtensionContext) => 'org.springframework.boot.loader.JarLauncher', - classpath: (context: VSCode.ExtensionContext, jvm: commons.JVM) => { - const classpath = [ - Path.resolve(context.extensionPath, 'jars/language-server.jar') - ]; + checkjvm: (context: VSCode.ExtensionContext, jvm: commons.JVM) => { if (!jvm.isJdk()) { VSCode.window.showWarningMessage('JAVA_HOME or PATH environment variable seems to point to a JRE. A JDK is required, hence Boot Hints are unavailable.'); } - const toolsJar = jvm.getToolsJar(); - if (toolsJar) { - classpath.unshift(toolsJar); - } - return classpath; }, clientOptions: { documentSelector: [ PROPERTIES_LANGUAGE_ID, YAML_LANGUAGE_ID, JAVA_LANGUAGE_ID ], diff --git a/vscode-extensions/vscode-spring-boot/package.json b/vscode-extensions/vscode-spring-boot/package.json index 5a9e1321d..5053eb2e4 100644 --- a/vscode-extensions/vscode-spring-boot/package.json +++ b/vscode-extensions/vscode-spring-boot/package.json @@ -73,9 +73,9 @@ "vscode:prepublish": "npm run compile", "compile": "tsc -p ./", "watch": "tsc -watch -p ./", - "clean": "rm -fr node_modules out *.vsix package-lock.json", - "preinstall": "./scripts/preinstall.sh", "postinstall": "node ./node_modules/vscode/bin/install", + "test": "npm run compile && node ./node_modules/vscode/bin/test", + "preinstall": "./scripts/preinstall.sh", "vsce-package": "vsce package" }, "dependencies": { @@ -84,8 +84,8 @@ }, "devDependencies": { "vsce": "^1.36.1", - "typescript": "2.6.1", - "@types/node": "^7.0.43", + "typescript": "2.7.2", + "@types/node": "^9.4.6", "vscode": "^1.1.10" } } diff --git a/vscode-extensions/vscode-spring-boot/scripts/preinstall.sh b/vscode-extensions/vscode-spring-boot/scripts/preinstall.sh index e45045e16..61c80406a 100755 --- a/vscode-extensions/vscode-spring-boot/scripts/preinstall.sh +++ b/vscode-extensions/vscode-spring-boot/scripts/preinstall.sh @@ -15,6 +15,7 @@ curl https://raw.githubusercontent.com/textmate/java.tmbundle/master/Syntaxes/Ja cd ../../headless-services/spring-boot-language-server ./build.sh +rm -fr ${workdir}/jars mkdir -p ${workdir}/jars -cp target/*.jar ${workdir}/jars/language-server.jar +cp target/*.jar ${workdir}/jars