Skip to content

Commit

Permalink
Merge pull request apache#4975 from sdedic/lsp/ci-prepare
Browse files Browse the repository at this point in the history
Test bugfixes: preparation for GH action migration
  • Loading branch information
sdedic authored Nov 23, 2022
2 parents 67393d2 + eb1edbd commit 23b4c52
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ private static void ensureProjectAttrs(Map<String, Object> map, FileObject paren
// in order to get through the freemarker, the path needs to "absolute" in freemarker terms - http://freemarker.sourceforge.net/docs/ref_directive_include.html
// relative would mean relative to the template and we cannot be sure what the path from template to license template is..
// it used to be, ../Licenses/ or ../../Licenses but can be anything similar, just based on where the template resides.
map.put(ATTR_LICENSE_PATH, "/" + url);
// Note: ensure reentrancy, so if 'url' starts with slash, do not prepend
if (!url.startsWith("/")) { // NOI18N
map.put(ATTR_LICENSE_PATH, "/" + url); // NOI18N
}
//appears to cover both the new and old default value of the include path
}
if (map.get(ATTR_ENCODING) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.Inet4Address;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand All @@ -46,7 +47,10 @@
final class ConnectionSpec implements Closeable {
private final Boolean listen;
private final int port;
// @GuardedBy (this)
private final List<Closeable> close = new ArrayList<>();
// @GuardedBy (this)
private final List<Closeable> closed = new ArrayList<>();

private ConnectionSpec(Boolean listen, int port) {
this.listen = listen;
Expand Down Expand Up @@ -110,11 +114,15 @@ public <ServerType extends LspSession.ScheduledServer> void prepare(
@Override
public void run() {
while (true) {
Socket socket = null;
try {
Socket socket = server.accept();
socket = server.accept();
close.add(socket);
connectToSocket(socket, prefix, session, serverSetter, launcher);
} catch (IOException ex) {
if (isClosed(server)) {
break;
}
Exceptions.printStackTrace(ex);
}
}
Expand Down Expand Up @@ -144,19 +152,34 @@ public void run() {
serverSetter.accept(session, connectionObject);
connectionObject.getRunningFuture().get();
} catch (IOException | InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
if (!isClosed(socket)) {
Exceptions.printStackTrace(ex);
}
} finally {
serverSetter.accept(session, null);
}
}
};
connectedThread.start();
}

private boolean isClosed(Closeable c) {
synchronized (this) {
return closed.contains(c);
}
}

@Override
public void close() throws IOException {
for (Closeable c : close) {
c.close();
synchronized (this) {
for (Closeable c : close) {
try {
c.close();
closed.add(c);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.MessageIssueException;
import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage;
Expand Down Expand Up @@ -119,6 +120,7 @@
import org.netbeans.spi.project.ActionProvider;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
Expand Down Expand Up @@ -180,6 +182,10 @@ private static Launcher<NbCodeLanguageClient> createLauncher(LanguageServerImpl
}
});
})
.setExceptionHandler((t) -> {
LOG.log(Level.WARNING, "Error occurred during LSP message dispatch", t);
return RemoteEndpoint.DEFAULT_EXCEPTION_HANDLER.apply(t);
})
.create();
}

Expand Down Expand Up @@ -255,6 +261,9 @@ public void consume(Message msg) throws MessageIssueException, JsonRpcException
Lookups.executeWith(ll, () -> {
try {
delegate.consume(msg);
} catch (RuntimeException | Error e) {
LOG.log(Level.WARNING, "Error occurred during message dispatch", e);
throw e;
} finally {
// cancel while the OperationContext is still active.
if (ftoCancel != null) {
Expand Down Expand Up @@ -1079,10 +1088,17 @@ public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) {
private static void hackConfigureGroovySupport(NbCodeClientCapabilities caps) {
boolean b = caps != null && caps.wantsGroovySupport();
try {
Class clazz = Lookup.getDefault().lookup(ClassLoader.class).loadClass("org.netbeans.modules.groovy.editor.api.GroovyIndexer");
Class<?> clazz = Lookup.getDefault().lookup(ClassLoader.class).loadClass("org.netbeans.modules.groovy.editor.api.GroovyIndexer");
Method m = clazz.getDeclaredMethod("setIndexingEnabled", Boolean.TYPE);
m.setAccessible(true);
m.invoke(null, b);
} catch (ClassNotFoundException ex) {
// java.lang.ClassNotFoundException is expected when Groovy support is not activated / enabled. Do not log, if the
// client wants groovy disabled, which is obviuously true in this case :)
if (b && !groovyClassWarningLogged) {
groovyClassWarningLogged = true;
LOG.log(Level.WARNING, "Unable to configure Groovy indexing: Groovy support is not enabled");
}
} catch (ReflectiveOperationException ex) {
if (!groovyClassWarningLogged) {
groovyClassWarningLogged = true;
Expand Down
Loading

0 comments on commit 23b4c52

Please sign in to comment.