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 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
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,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -22,7 +20,6 @@
import org.osgi.framework.BundleContext;

import com.microsoft.java.builder.BuildStateManager;

import ch.epfl.scala.bsp4j.BuildClient;

public class ImporterPlugin extends Plugin {
Expand All @@ -32,14 +29,11 @@ public class ImporterPlugin extends Plugin {
private Map<IPath, Pair<BuildServerConnection, BuildClient>> buildServers = new ConcurrentHashMap<>();

private static ImporterPlugin instance;

/**
* Digest store for the gradle configuration files.
*/
private DigestStore digestStore;

private static String bundleDirectory;

private static String bundleVersion = "";

@Override
Expand All @@ -52,7 +46,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 @@ -97,82 +90,29 @@ public static BuildServerConnection getBuildServerConnection(IPath rootPath, boo
if (pair != null) {
return pair.getLeft();
}

if (!createIfMissing) {
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");
}
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)
.create();

launcher.startListening();
BuildServerConnection server = launcher.getRemoteProxy();
client.onConnectWithServer(server);

instance.buildServers.put(rootPath, Pair.of(server, client));
return server;
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID,
"Failed to start build server.", e));
"Failed to start build server.", e));
Jiaaming marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* 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