Skip to content

Commit

Permalink
Update: architecture.md
Browse files Browse the repository at this point in the history
build - Prepare for 3.15.0 (#1523)

refactor - Merge Task Server & Build Server (#1512)

fix - Catch the error when running gradle tests (#1524)

Update: doc
  • Loading branch information
Jiaaming committed Jul 22, 2024
1 parent d904c27 commit fcfbec8
Show file tree
Hide file tree
Showing 38 changed files with 919 additions and 258 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # required by sonarqube
- name: Use Java 11
- name: Use Java 17
uses: actions/setup-java@v1
with:
java-version: "11"
java-version: "17"
architecture: x64
- name: Use Node 16.14.2
uses: actions/setup-node@v4
Expand All @@ -31,6 +31,14 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Checkout microsoft/build-server-for-gradle
uses: actions/checkout@v2
with:
repository: microsoft/build-server-for-gradle
path: extension/build-server-for-gradle
- name: Build Jars
run: ../gradlew buildJars
working-directory: extension/
- name: Lint
uses: gradle/gradle-build-action@v2
with:
Expand Down Expand Up @@ -61,7 +69,7 @@ jobs:
fail-fast: false
matrix:
node-version: [16.14.2]
java-version: ["8", "11", "17", "21"]
java-version: ["17", "21"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
Expand Down
61 changes: 12 additions & 49 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@
},
{
"type": "java",
"name": "Debug Server",
"request": "launch",
"mainClass": "com.github.badsyntax.gradle.GradleServer",
"projectName": "gradle-server",
"cwd": "${workspaceFolder}/gradle-server",
"presentation": {
"group": "debug",
"order": 2,
"hidden": true
}
"name": "Attach to Gradle Server",
"request": "attach",
"hostName": "localhost",
"port": "8089",
"projectName": "com.github.badsyntax.gradle"
},
{
"name": "Debug Extension with Debug Server",
"name": "Debug Gradle Server & Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
Expand All @@ -54,12 +49,13 @@
"${workspaceFolder}/extension/dist/**/*.js"
],
"preLaunchTask": "Gradle: Build",
"presentation": {
"group": "debug",
"order": 2
},
"env": {
"VSCODE_DEBUG_SERVER": "true"
"GRADLE_SERVER_OPTS":"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8089"
},
"presentation": {
"hidden": true
}
},
{
"name": "Debug Extension & Gradle Plugin",
Expand All @@ -76,30 +72,10 @@
"env": {
"VSCODE_DEBUG_PLUGIN": "true"
},
"presentation": {
"group": "debug",
"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",
Expand Down Expand Up @@ -372,17 +348,4 @@
}
},
],
"compounds": [
{
"name": "Debug Server & Extension",
"configurations": [
"Debug Server",
"Debug Extension with Debug Server"
],
"presentation": {
"group": "debug",
"order": 3
}
}
]
}
21 changes: 16 additions & 5 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ This extension contains three major components:

# Gradle Server and Gradle Language Server

<img src="images/gradle-tasks-architecture.svg" />
<img src="images/gradle-server-architecture.svg" />
The gradle server is a long-running Java process that include two threads: 1. Build Server 2. Task Server

The extension uses client/server architecture using [gRPC](https://grpc.io/) as the interface between the client and server. It uses TypeScript (Node.js) on the client and Java on the server. A long running server provides very good performance.
## Build Server
The Gradle Build Server uses the [Build Server Protocol](https://build-server-protocol.github.io/) to communicate with the server.

Historically, the Build Client and Build Server were connected via standard input/output, which posed security concerns. To address these issues and accommodate limitations with named pipe support in Java and JSON-RPC connections (based on the Java implementation [bsp4j](https://github.com/build-server-protocol/build-server-protocol/) of the Build Server Protocol, which itself relies on [lsp4j](https://github.com/eclipse-lsp4j/lsp4j)), a TypeScript layer named [bspProxy](./extension/src/bs/bspProxy.ts) was introduced.

This layer acts as a middleware, facilitating message forwarding and establishing a more secure named pipe JSON-RPC connection between the TypeScript and Java components.

For information about the Build Server itself, visit the [Gradle Build Server](https://github.com/microsoft/build-server-for-gradle).

## Task Server
The task server and client using [gRPC](https://grpc.io/) as the interface between each other. It uses TypeScript (Node.js) on the client and Java on the server. A long running server provides very good performance.

On extension activate, the client starts the Java gRPC server which remains running for the period the extension is activated. The server is packaged with the extension as a fat `.jar` file and is started by Node.js via executables generated by Gradle [CreateStartScripts](https://docs.gradle.org/current/dsl/org.gradle.jvm.application.tasks.CreateStartScripts.html).

[Protocol buffers](https://developers.google.com/protocol-buffers) are used to define the gRPC service & messages. The Java & JavaScript message classes, as well as the client and server interfaces, are generated from the Protobuf files via the `protoc` compiler. TypeScript type definitions are generated from the JavaScript classes.

The Java server uses the [Gradle Tooling Api](https://docs.gradle.org/current/userguide/third_party_integration.html#embedding) to discover projects & tasks, and to run Gradle tasks.

## Discovering Projects & Tasks
### Discovering Projects & Tasks

Tasks belong to projects and projects are hierarchical, meaning projects can have sub-projects, and any/all projects in the tree can have tasks.

Expand All @@ -29,7 +40,7 @@ Once the client has discovered the root projects for all workspaces, it requests

The extension models the project hierarchical structure using the vscode tree view. The tree view data provider consumes the vscode tasks, and builds a tree of projects & tasks using the information provided in the task definitions.

## Running Tasks
### Running Tasks

Gradle tasks can be run through either the [Tree View](https://code.visualstudio.com/api/extension-guides/tree-view) or the Command Palette.

Expand All @@ -41,6 +52,6 @@ Gradle is used as the build system for the extension, for both the client and th

Getting started on this extension is as simple as `./gradlew build`.

## Gradle Project Importer
# Gradle Project Importer

The Gradle project importer works as a client of the [Gradle Build Server](https://github.com/microsoft/build-server-for-gradle). The importer communicates with the Gradle build server via Build Server Protocol, and convert the build targets into Java Projects of JDT Language Server.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to the "vscode-gradle" extension will be documented in this
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### 3.15.0
## What's Changed
* feat - Support delegate tests to Gradle build Server by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1510
* fix - Only send request after initialization by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1503
* fix - Add java 22 to compatibility matrix by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1505
* refactor - Introduce gson to simplify the object parsing by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1509
* fix - Slice the build target list to 1 when running gradle tests by @jdneo in https://github.com/microsoft/vscode-gradle/pull/1518

### 3.14.1
### What's Changed
* fix - Fix the importer version.
Expand Down
34 changes: 11 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Start by opening an issue using one of the issue templates, or propose a change

### Build Gradle Server and Gradle Language Server.
1. Install [nvm](https://github.com/nvm-sh/nvm)
2. Install [Java version >= 8](https://adoptium.net/)
2. Install [Java version >= 17](https://adoptium.net/)
3. Change directory to the root of the project
4. Select Node version: `nvm use`
5. If using an Apple M1:
Expand Down Expand Up @@ -40,34 +40,22 @@ 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 Server

1. Run vscode launch configuration `Debug Gradle Server & Extension`.
2. Run vscode launch configuration `Attach to Gradle Server` when you notice the `Gradle: Connecting...` message in the bottom status bar.

> **Note:** If the "Java: Error" message appears in the bottom status bar and the following error is logged in the `.log` file:
> ```java
> java.lang.NullPointerException: Cannot invoke "ch.epfl.scala.bsp4j.WorkspaceBuildTargetsResult.getTargets()"
> ```
> it indicates that the connection attempt to the Gradle Server was too slow. The [GradleBuildClient](/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java#L107) requires an active Gradle Server to successfully establish a connection. If you encounter this issue, please retry the connection promptly to avoid this error.
## Debugging Gradle Language Server (editing feature related)
1. Run vscode launch configuration `Debug Language Server: Launch Extension`.
2. Run vscode launch configuration `Debug Language Server: Launch Language Server`.
## Debugging Gradle Server (work with Gradle daemon)

Run vscode launch configuration `Debug Server & Extension`.

## Development Workflow
Open the root of the project in VS Code.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
project.ext.set('grpcVersion', '1.53.0')
project.ext.set('protobufVersion', '3.12.0')
project.ext.set('protocVersion', project.protobufVersion)
project.ext.set('toolingAPIVersion', '8.0.2')
project.ext.set('toolingAPIVersion', '8.8')

allprojects {
group = 'vscode-gradle'
Expand Down
2 changes: 2 additions & 0 deletions extension/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ src/proto/
build/
beta/
webpack.config.js
build-server-for-gradle/
bin/
2 changes: 2 additions & 0 deletions extension/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ lib/
src/proto/
build/
src/java-test-runner.api.ts
build-server-for-gradle/
bin/
18 changes: 14 additions & 4 deletions extension/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,28 @@ task buildBuildServer(type: CrossPlatformExec) {
}
}

task copyBuildServerJars(type: Copy) {
task copyBuildServerPluginJars(type: Copy) {
dependsOn ':extension:buildBuildServer'
from('./build-server-for-gradle/server/build/libs/') {
include '**/*.jar'
include '**/init.gradle'
include 'plugins/'
}
into 'server'
mustRunAfter copyDocs
}

// TODO: This task can be removed once the build server is published.
task copyBuildServerJarsToGradleServer(type: Copy) {
dependsOn ':extension:buildBuildServer'
from('./build-server-for-gradle/server/build/libs/') {
include 'runtime/'
}
from('./build-server-for-gradle/server/build/libs/server.jar')
into '../gradle-server/build/libs/'
mustRunAfter copyDocs
}

task buildJars() {
dependsOn copyJdtlsPluginJar, copyBuildServerJars
dependsOn copyJdtlsPluginJar, copyBuildServerPluginJars, copyBuildServerJarsToGradleServer
}

build.finalizedBy buildProd, buildTest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.microsoft.gradle.jdtls.ext</groupId>
<artifactId>gradle-jdtls-ext-parent</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</parent>
<artifactId>com.microsoft.gradle.bs.importer.tp</artifactId>
<name>${base.name} :: Target Platform</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Gradle Build Server Importer
Bundle-SymbolicName: com.microsoft.gradle.bs.importer;singleton:=true
Bundle-Version: 0.3.0
Bundle-Version: 0.4.0
Bundle-Activator: com.microsoft.gradle.bs.importer.ImporterPlugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.microsoft.gradle.jdtls.ext</groupId>
<artifactId>gradle-jdtls-ext-parent</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</parent>
<artifactId>com.microsoft.gradle.bs.importer</artifactId>
<packaging>eclipse-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
return false;
}

//TODO: support multi-root workspaces
if (getPreferences().getRootPaths().size() != 1) {
return false;
}

if (!Utils.isBuildServerEnabled(getPreferences())) {
return false;
Expand Down
Loading

0 comments on commit fcfbec8

Please sign in to comment.