in customization-base/src/main/java/com/azure/autorest/customization/implementation/ls/EclipseLanguageServerFacade.java [35:101]
public EclipseLanguageServerFacade(String pathToLanguageServerPlugin, Logger logger) {
Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown));
try {
int javaVersion = Runtime.version().feature();
Path languageServerPath = (pathToLanguageServerPlugin == null)
? getLanguageServerDirectory(javaVersion, logger, false)
: Paths.get(pathToLanguageServerPlugin).resolve("jdt-language-server");
List<String> command = new ArrayList<>();
command.add("java");
command.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044");
command.add("-Declipse.application=org.eclipse.jdt.ls.core.id1");
command.add("-Dosgi.bundles.defaultStartLevel=4");
command.add("-Declipse.product=org.eclipse.jdt.ls.core.product");
command.add("-Dlog.protocol=true");
command.add("-Dlog.level=ALL");
command.add("-noverify");
command.add("-Xmx1G");
command.add("-jar");
// This will need to get update when the target version of Eclipse language server changes.
if (javaVersion < 17) {
// JAR to start v1.12.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar");
} else {
// JAR to start v1.39.0
command.add("./plugins/org.eclipse.equinox.launcher_1.6.900.v20240613-2009.jar");
}
command.add("--add-modules=ALL-SYSTEM");
command.add("--add-opens java.base/java.util=ALL-UNNAMED");
command.add("--add-opens java.base/java.lang=ALL-UNNAMED");
command.add("-configuration");
if (Utils.isWindows()) {
command.add("./config_win");
} else if (Utils.isMac()) {
command.add("./config_mac");
} else {
command.add("./config_linux");
}
Process server = startServer(command, languageServerPath, logger);
if (!server.isAlive()) {
if (pathToLanguageServerPlugin == null) {
// If user didn't specify language server path, we do a clean re-download.
logger
.warn("Eclipse language server failed to start. The folder may be corrupted. Try re-download.");
server = startServer(command, getLanguageServerDirectory(javaVersion, logger, true), logger);
if (!server.isAlive()) {
// if server failed to start anyway, throw with server output.
throw new RuntimeException(String.format(
"Eclipse language server failed to start, error output:\n %s", readServerOutput(server)));
}
} else {
// if user specify the language server path, we just throw with server output.
throw new RuntimeException(String.format(
"Eclipse language server failed to start, error output:\n %s", readServerOutput(server)));
}
}
this.server = server;
} catch (Exception e) {
throw new RuntimeException(e);
}
}