Skip to content

Commit b68696c

Browse files
authored
Java DAP prerelease cleanup (#46)
* Patch python script with correct shebang * Patch java-debug to bind to loopback
1 parent a2f6a40 commit b68696c

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

pkgs/java-debug/bind-address.patch

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
From a97603787acc1430b7e129ec3da9dea9b549efb0 Mon Sep 17 00:00:00 2001
2+
From: lhchavez <lhchavez@lhchavez.com>
3+
Date: Tue, 8 Jun 2021 17:03:38 +0000
4+
Subject: [PATCH] Add a System property to allow binding to a specific
5+
interface/port
6+
7+
This change adds support to read the value of the
8+
`com.microsoft.java.debug.serverAddress` system property when
9+
constructing the JavaDebugServer. This allows callers to specify a
10+
specific interface to bind to (e.g. `localhost:0`), a specific port
11+
(e.g. `:12345`), or both (e.g. `localhost:12345`).
12+
---
13+
.../plugin/internal/JavaDebugServer.java | 29 ++++++++++++++++++-
14+
1 file changed, 28 insertions(+), 1 deletion(-)
15+
16+
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
17+
index 32ab195b..12c2955c 100644
18+
--- a/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
19+
+++ b/com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/JavaDebugServer.java
20+
@@ -12,8 +12,10 @@
21+
package com.microsoft.java.debug.plugin.internal;
22+
23+
import java.io.IOException;
24+
+import java.net.InetAddress;
25+
import java.net.ServerSocket;
26+
import java.net.Socket;
27+
+import java.net.UnknownHostException;
28+
import java.util.concurrent.ExecutorService;
29+
import java.util.concurrent.SynchronousQueue;
30+
import java.util.concurrent.ThreadPoolExecutor;
31+
@@ -33,8 +35,33 @@
32+
private ExecutorService executor = null;
33+
34+
private JavaDebugServer() {
35+
+ int port = 0;
36+
+ InetAddress bindAddr = null;
37+
+ String serverAddress = System.getProperty("com.microsoft.java.debug.serverAddress");
38+
+ if (serverAddress != null) {
39+
+ int portIndex = serverAddress.lastIndexOf(':');
40+
+ if (portIndex == -1) {
41+
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": missing port", serverAddress));
42+
+ return;
43+
+ }
44+
+ try {
45+
+ port = Integer.parseInt(serverAddress.substring(portIndex + 1));
46+
+ } catch (NumberFormatException e) {
47+
+ logger.log(Level.SEVERE, String.format("Malformed server address \"%s\": %s", serverAddress, e.toString()), e);
48+
+ return;
49+
+ }
50+
+
51+
+ if (portIndex > 0) {
52+
+ try {
53+
+ bindAddr = InetAddress.getByName(serverAddress.substring(0, portIndex));
54+
+ } catch (UnknownHostException e) {
55+
+ logger.log(Level.SEVERE, String.format("Invalid server address \"%s\": %s", serverAddress, e.toString()), e);
56+
+ return;
57+
+ }
58+
+ }
59+
+ }
60+
try {
61+
- this.serverSocket = new ServerSocket(0, 1);
62+
+ this.serverSocket = new ServerSocket(port, 1, bindAddr);
63+
} catch (IOException e) {
64+
logger.log(Level.SEVERE, String.format("Failed to create Java Debug Server: %s", e.toString()), e);
65+
}

pkgs/java-debug/debug-plugin.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ in stdenv.mkDerivation {
2020
sha256 = "1syrzp8syisnd8fkj3lis5rv83chzj4gwm63ygib41c428yyw20a";
2121
};
2222

23+
patches = [ ./bind-address.patch ];
2324
buildInputs = [ maven graalvm11-ce ];
2425
buildPhase = ''
2526
# Maven tries to grab lockfiles in the repository, so it has to be writeable

pkgs/java-debug/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
, callPackage
33
, makeWrapper
44
, jdt-language-server
5+
, python3
56
}:
67
let
78
debug-plugin = callPackage ./debug-plugin.nix { };
@@ -12,11 +13,12 @@ in stdenv.mkDerivation {
1213
unpackPhase = "true";
1314
dontBuild = true;
1415

15-
#"-Dcom.microsoft.java.debug.serverAddress=localhost:0"
16+
nativeBuildInputs = [ python3 ];
1617
buildInputs = [ makeWrapper ];
1718
installPhase = ''
1819
mkdir -p $out/bin
1920
cp ${./java-dap} $out/bin/java-dap
21+
patchShebangs $out/bin/java-dap
2022
2123
makeWrapper $out/bin/java-dap $out/bin/java-debug \
2224
--add-flags --use-ephemeral-port \

0 commit comments

Comments
 (0)