Skip to content

Commit

Permalink
Fix build on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Apr 12, 2019
1 parent 5f4346f commit f3bf055
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ private void startConnection() throws IOException {
Launcher<JavaLanguageClient> launcher;
ExecutorService executorService = Executors.newCachedThreadPool();
protocol = new JDTLanguageServer(projectsManager, preferenceManager);
Function<MessageConsumer, MessageConsumer> wrapper = getWrapper();
if (JDTEnvironmentUtils.inSocketStreamDebugMode()) {
String host = JDTEnvironmentUtils.getClientHost();
Integer port = JDTEnvironmentUtils.getClientPort();
Expand All @@ -288,27 +289,39 @@ private void startConnection() throws IOException {
AsynchronousSocketChannel socketChannel = serverSocket.accept().get();
InputStream in = Channels.newInputStream(socketChannel);
OutputStream out = Channels.newOutputStream(socketChannel);
Function<MessageConsumer, MessageConsumer> messageConsumer = it -> it;
launcher = Launcher.createIoLauncher(protocol, JavaLanguageClient.class, in, out, executorService, messageConsumer);
launcher = Launcher.createIoLauncher(protocol, JavaLanguageClient.class, in, out, executorService, wrapper);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Error when opening a socket channel at " + host + ":" + port + ".", e);
}
} else {
ConnectionStreamFactory connectionFactory = new ConnectionStreamFactory();
InputStream in = connectionFactory.getInputStream();
OutputStream out = connectionFactory.getOutputStream();
Function<MessageConsumer, MessageConsumer> wrapper;
if ("false".equals(System.getProperty("watchParentProcess"))) {
wrapper = it -> it;
} else {
wrapper = new ParentProcessWatcher(this.languageServer);
}
launcher = Launcher.createLauncher(protocol, JavaLanguageClient.class, in, out, executorService, wrapper);
}
protocol.connectClient(launcher.getRemoteProxy());
launcher.startListening();
}

private Function<MessageConsumer, MessageConsumer> getWrapper() {
Function<MessageConsumer, MessageConsumer> wrapper;
int pollDelaySecs = ParentProcessWatcher.POLL_DELAY_SECS;
String watchParentProcess = System.getProperty("watchParentProcess");
if (watchParentProcess != null) {
try {
pollDelaySecs = Integer.parseInt(watchParentProcess);
} catch (Exception e) {
logException(e.getMessage(), e);
}
}
if (pollDelaySecs <= 0) {
wrapper = it -> it;
} else {
wrapper = new ParentProcessWatcher(this.languageServer, pollDelaySecs);
}
return wrapper;
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;

Expand All @@ -22,18 +25,26 @@ public class LanguageServer implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {

JavaLanguageServerPlugin.startLanguageServer(this);
synchronized(waitLock){
while (!shutdown) {
try {
context.applicationRunning();
JavaLanguageServerPlugin.logInfo("Main thread is waiting");
waitLock.wait();
} catch (InterruptedException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
JavaLanguageServerPlugin.startLanguageServer(this);
synchronized (waitLock) {
while (!shutdown) {
try {
context.applicationRunning();
JavaLanguageServerPlugin.logInfo("Main thread is waiting");
waitLock.wait();
} catch (InterruptedException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
try {
JavaLanguageServerPlugin.logInfo("Saving workspace");
long start = System.currentTimeMillis();
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
JavaLanguageServerPlugin.logInfo("Workspace saved. Took " + (System.currentTimeMillis() - start) + " ms");
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
}
return IApplication.EXIT_OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ public final class ParentProcessWatcher implements Runnable, Function<MessageCon

private static final long INACTIVITY_DELAY_SECS = 30 *1000;
private static final boolean isJava1x = System.getProperty("java.version").startsWith("1.");
private static final int POLL_DELAY_SECS = 10;
public static final int POLL_DELAY_SECS = 60;
private volatile long lastActivityTime;
private final LanguageServer server;
private ScheduledFuture<?> task;
private ScheduledExecutorService service;

public ParentProcessWatcher(LanguageServer server ) {
this(server, POLL_DELAY_SECS);
}

public ParentProcessWatcher(LanguageServer server, int pollDelaySecs) {
this.server = server;
service = Executors.newScheduledThreadPool(1);
task = service.scheduleWithFixedDelay(this, POLL_DELAY_SECS, POLL_DELAY_SECS, TimeUnit.SECONDS);
task = service.scheduleWithFixedDelay(this, pollDelaySecs, pollDelaySecs, TimeUnit.SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,10 @@ private CodeActionOptions getCodeActionOptions() {
public CompletableFuture<Object> shutdown() {
logInfo(">> shutdown");
return computeAsync((monitor) -> {
try {
JavaRuntime.removeVMInstallChangedListener(jvmConfigurator);
if (workspaceDiagnosticsHandler != null) {
workspaceDiagnosticsHandler.removeResourceChangeListener();
workspaceDiagnosticsHandler = null;
}
ResourcesPlugin.getWorkspace().save(true, monitor);
} catch (CoreException e) {
logException(e.getMessage(), e);
JavaRuntime.removeVMInstallChangedListener(jvmConfigurator);
if (workspaceDiagnosticsHandler != null) {
workspaceDiagnosticsHandler.removeResourceChangeListener();
workspaceDiagnosticsHandler = null;
}
return new Object();
});
Expand Down

0 comments on commit f3bf055

Please sign in to comment.