Skip to content

Commit

Permalink
chores: Add build server debug config (microsoft#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming committed Jul 15, 2024
1 parent 5fefb56 commit 37593df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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();
Expand Down

0 comments on commit 37593df

Please sign in to comment.