diff --git a/.vscode/launch.json b/.vscode/launch.json index 5101fbb89..3c3f33f82 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -81,6 +81,26 @@ "order": 2 } }, + { + "name": "Debug Extension & Build Server", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}/extension" + ], + "outFiles": [ + "${workspaceFolder}/extension/dist/**/*.js" + ], + "preLaunchTask": "Gradle: Build", + "presentation": { + "group": "debug", + "order": 3 + }, + "env": { + "DEBUG_GRADLE_BUILD_SERVER":"true" + }, + }, { "name": "Debug Language Server: Launch Extension", "type": "extensionHost", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed0a5b509..3ade961ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,6 +40,25 @@ The extension uses a Gradle plugin (`com.microsoft.gradle.GradlePlugin`) to get > Note: There is a known issue that when the Gradle project stores in a sub-folder of the root folder, the `Attach to Gradle Plugin` will fail to attach. See [#1237](https://github.com/microsoft/vscode-gradle/issues/1237). +## Debugging Gradle Build Server + +To debug the Extension with the [Gradle Build Server](https://github.com/microsoft/build-server-for-gradle), follow these steps: + +1. Open the `extension/build-server-for-gradle` directory, which you should have [imported previously](#build-gradle-project-importer) as a separate project. +2. In the `.vscode/launch.json` of the build-server-for-gradle project, ensure you have the following configuration to attach the debugger: + ```json + { + "type": "java", + "name": "Attach to Gradle Build Server", + "request": "attach", + "hostName": "localhost", + "port": "8989", + "projectName": "server" + } + ``` +3. In your main project (vscode-gradle), start the `Debug Extension & Build Server` launch configuration. +4. In the build-server-for-gradle project, start the `Attach to Gradle Build Server` launch configuration. + ## Debugging Gradle Language Server (editing feature related) 1. Run vscode launch configuration `Debug Language Server: Launch Extension`. diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java index c6d915185..81a4264d4 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java @@ -3,6 +3,8 @@ import java.io.File; import java.io.IOException; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -84,17 +86,20 @@ public static BuildServerConnection getBuildServerConnection(IPath rootPath) thr String pluginPath = getBuildServerPluginPath(); - ProcessBuilder build = new ProcessBuilder( - javaExecutablePath, - "--add-opens=java.base/java.lang=ALL-UNNAMED", - "--add-opens=java.base/java.io=ALL-UNNAMED", - "--add-opens=java.base/java.util=ALL-UNNAMED", - "-Dplugin.dir=" + pluginPath, - "-cp", - String.join(getClasspathSeparator(), classpaths), - "com.microsoft.java.bs.core.Launcher" - ); - + List command = new ArrayList<>(); + command.add(javaExecutablePath); + if (Boolean.parseBoolean(System.getenv("DEBUG_GRADLE_BUILD_SERVER"))) { + command.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8989"); + } + command.add("--add-opens=java.base/java.lang=ALL-UNNAMED"); + command.add("--add-opens=java.base/java.io=ALL-UNNAMED"); + command.add("--add-opens=java.base/java.util=ALL-UNNAMED"); + command.add("-Dplugin.dir=" + pluginPath); + command.add("-cp"); + command.add(String.join(getClasspathSeparator(), classpaths)); + command.add("com.microsoft.java.bs.core.Launcher"); + + ProcessBuilder build = new ProcessBuilder(command); try { Process process = build.start(); BuildClient client = new GradleBuildClient();