Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Task Server & Build Server #1512

Merged
merged 37 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9006161
merge
Jiaaming Apr 29, 2024
bbe05ef
merge server
Jiaaming Jul 1, 2024
7f79375
merge both server
Jiaaming Jul 1, 2024
bfac717
fix lint
Jiaaming Jul 1, 2024
b1e2962
fix generateRandomPipeName
Jiaaming Jul 2, 2024
42f3a9f
refine named pipe repost design
Jiaaming Jul 2, 2024
38038da
refine jdk search logic
Jiaaming Jul 3, 2024
1d916bb
update messageProxy, add error handling for task server, fix bugs
Jiaaming Jul 3, 2024
29aa9ef
fix nit
Jiaaming Jul 3, 2024
d60ff9f
fix nit
Jiaaming Jul 3, 2024
383aabc
Merge remote-tracking branch 'origin' into merge-with-named-pipe
Jiaaming Jul 4, 2024
1f8122f
fix comments
Jiaaming Jul 4, 2024
58b85f8
expand jdk search logic and fix comments
Jiaaming Jul 5, 2024
d713497
fix typo
Jiaaming Jul 5, 2024
c117618
fix typo
Jiaaming Jul 5, 2024
d0ec674
fix comments
Jiaaming Jul 5, 2024
a097a87
fix comments
Jiaaming Jul 5, 2024
5f7b4d7
Merge branch 'develop' into merge-with-named-pipe
jdneo Jul 5, 2024
c629a81
Merge branch 'develop' into merge-with-named-pipe
Jiaaming Jul 10, 2024
c201306
1. Add local build-server-for-gradle jar import and related gradle bu…
Jiaaming Jul 10, 2024
609a781
Fix: handle empty param in bspProxy repost
Jiaaming Jul 10, 2024
f582668
Fix: comments
Jiaaming Jul 11, 2024
9365ac6
Merge branch 'develop' into merge-with-named-pipe
Jiaaming Jul 11, 2024
9214957
1.Fix: comment
Jiaaming Jul 12, 2024
d7e3668
1.Add error handle for rpc connection
Jiaaming Jul 15, 2024
807f9a9
Fix: typo
Jiaaming Jul 16, 2024
9deaeb6
1.Update github workflow to feat local dependency
Jiaaming Jul 17, 2024
6f1701f
Update: lint ignore
Jiaaming Jul 17, 2024
3291eb6
fix: powermock jdk17
Jiaaming Jul 17, 2024
b2eaba7
Merge branch 'develop' into merge-with-named-pipe
jdneo Jul 19, 2024
8b5e1d9
Refine jdk search logic that start gradle-server
Jiaaming Jul 19, 2024
b3c13e3
Fix: comments
Jiaaming Jul 19, 2024
d59d605
Fix: comment
Jiaaming Jul 19, 2024
7507a3c
fix comments
Jiaaming Jul 22, 2024
7446361
Fix: comment
Jiaaming Jul 22, 2024
722406a
Fix: build.gradle file
Jiaaming Jul 22, 2024
be63f6d
Fix: extension start sequence
Jiaaming Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
]
}
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) {
Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
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/'
Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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;
}

Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
if (!Utils.isBuildServerEnabled(getPreferences())) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

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 @@ -38,8 +35,6 @@ public class ImporterPlugin extends Plugin {
*/
private DigestStore digestStore;

private static String bundleDirectory;

private static String bundleVersion = "";

@Override
Expand All @@ -52,7 +47,6 @@ public void start(BundleContext context) throws Exception {
if (!bundleFile.isPresent()) {
throw new IllegalStateException("Failed to get bundle location.");
}
bundleDirectory = bundleFile.get().getParent();
}

@Override
Expand Down Expand Up @@ -102,31 +96,18 @@ public static BuildServerConnection getBuildServerConnection(IPath rootPath, boo
return null;
}

Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
String javaExecutablePath = getJavaExecutablePath();
String[] classpaths = getBuildServerClasspath();

String pluginPath = getBuildServerPluginPath();

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");
if (instance.buildServers.size() > 0) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID,
"Not support multiple workspaces."));
jdneo marked this conversation as resolved.
Show resolved Hide resolved
}
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();
NamedPipeStream pipeStream = new NamedPipeStream();

GradleBuildClient client = new GradleBuildClient();
Launcher<BuildServerConnection> launcher = new Launcher.Builder<BuildServerConnection>()
.setOutput(process.getOutputStream())
.setInput(process.getInputStream())
.setOutput(pipeStream.getOutputStream())
.setInput(pipeStream.getInputStream())
.setLocalService(client)
.setExecutorService(Executors.newCachedThreadPool())
.setRemoteInterface(BuildServerConnection.class)
Expand All @@ -142,37 +123,4 @@ public static BuildServerConnection getBuildServerConnection(IPath rootPath, boo
"Failed to start build server.", e));
}
}

/**
* Get the Java executable used by JDT.LS, which will be higher than JDK 17.
*/
private static String getJavaExecutablePath() {
Optional<String> command = ProcessHandle.current().info().command();
if (command.isPresent()) {
return command.get();
}

throw new IllegalStateException("Failed to get Java executable path.");
}

private static String[] getBuildServerClasspath() {
return new String[]{
Paths.get(bundleDirectory, "server.jar").toString(),
Paths.get(bundleDirectory, "runtime").toString() + File.separatorChar + "*"
};
}

private static String getBuildServerPluginPath() {
return Paths.get(bundleDirectory, "plugins").toString();
}

private static String getClasspathSeparator() {
String os = System.getProperty("os.name").toLowerCase();

if (os.contains("win")) {
return ";";
}

return ":"; // Linux or Mac
}
}
Loading
Loading