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

Java DAP prerelease cleanup #46

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
65 changes: 65 additions & 0 deletions pkgs/java-debug/bind-address.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
From a97603787acc1430b7e129ec3da9dea9b549efb0 Mon Sep 17 00:00:00 2001
From: lhchavez <[email protected]>
Date: Tue, 8 Jun 2021 17:03:38 +0000
Subject: [PATCH] Add a System property to allow binding to a specific
interface/port

This change adds support to read the value of the
`com.microsoft.java.debug.serverAddress` system property when
constructing the JavaDebugServer. This allows callers to specify a
specific interface to bind to (e.g. `localhost:0`), a specific port
(e.g. `:12345`), or both (e.g. `localhost:12345`).
---
.../plugin/internal/JavaDebugServer.java | 29 ++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
index 32ab195b..12c2955c 100644
--- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
+++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
@@ -12,8 +12,10 @@
package com.microsoft.java.debug.plugin.internal;

import java.io.IOException;
+import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -33,8 +35,33 @@
private ExecutorService executor = null;

private JavaDebugServer() {
+ int port = 0;
+ InetAddress bindAddr = null;
+ String serverAddress = System.getProperty("com.microsoft.java.debug.serverAddress");
+ if (serverAddress != null) {
+ int portIndex = serverAddress.lastIndexOf(':');
+ if (portIndex == -1) {
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": missing port", serverAddress));
+ return;
+ }
+ try {
+ port = Integer.parseInt(serverAddress.substring(portIndex + 1));
+ } catch (NumberFormatException e) {
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": %s", serverAddress, e.toString()), e);
+ return;
+ }
+
+ if (portIndex > 0) {
+ try {
+ bindAddr = InetAddress.getByName(serverAddress.substring(0, portIndex));
+ } catch (UnknownHostException e) {
+ logger.log(Level.SEVERE, String.format("Invalid server address \"%s\": %s", serverAddress, e.toString()), e);
+ return;
+ }
+ }
+ }
try {
- this.serverSocket = new ServerSocket(0, 1);
+ this.serverSocket = new ServerSocket(port, 1, bindAddr);
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("Failed to create Java Debug Server: %s", e.toString()), e);
}
1 change: 1 addition & 0 deletions pkgs/java-debug/debug-plugin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ in stdenv.mkDerivation {
sha256 = "1syrzp8syisnd8fkj3lis5rv83chzj4gwm63ygib41c428yyw20a";
};

patches = [ ./bind-address.patch ];
buildInputs = [ maven graalvm11-ce ];
buildPhase = ''
# Maven tries to grab lockfiles in the repository, so it has to be writeable
Expand Down
4 changes: 3 additions & 1 deletion pkgs/java-debug/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, callPackage
, makeWrapper
, jdt-language-server
, python3
}:
let
debug-plugin = callPackage ./debug-plugin.nix { };
Expand All @@ -12,11 +13,12 @@ in stdenv.mkDerivation {
unpackPhase = "true";
dontBuild = true;

#"-Dcom.microsoft.java.debug.serverAddress=localhost:0"
nativeBuildInputs = [ python3 ];
buildInputs = [ makeWrapper ];
installPhase = ''
mkdir -p $out/bin
cp ${./java-dap} $out/bin/java-dap
patchShebangs $out/bin/java-dap

makeWrapper $out/bin/java-dap $out/bin/java-debug \
--add-flags --use-ephemeral-port \
Expand Down