entlicher commented on a change in pull request #3180:
URL: https://github.com/apache/netbeans/pull/3180#discussion_r715662805



##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
##########
@@ -344,19 +338,54 @@ public void propertyChange(PropertyChangeEvent evt) {
                     notifyFinished(context, exitCode != null && exitCode == 0);
                 });
                 Lookups.executeWith(execLookup, () -> {
-                    execNative(nativeImageFile, args, context, ed, 
launchFuture);
+                    execNative(nativeImageFile, args, context, ed, params, 
launchFuture);
                 });
             }
         }
         return launchFuture;
     }
 
-    private static void execNative(File nativeImageFile, List<String> args, 
DebugAdapterContext context, ExecutionDescriptor executionDescriptor, 
CompletableFuture<Void> launchFuture) {
+    private static ExplicitProcessParameters 
createExplicitProcessParameters(Map<String, Object> launchArguments) {
+        List<String> args = argsToStringList(launchArguments.get("args"));
+        List<String> vmArgs = argsToStringList(launchArguments.get("vmArgs"));
+        String cwd = Objects.toString(launchArguments.get("cwd"), 
System.getProperty("user.dir"));
+        Object envObj = launchArguments.get("env");
+        Map<String, String> env = envObj != null ? (Map<String, String>) 
envObj : Collections.emptyMap();
+        ExplicitProcessParameters.Builder bld = 
ExplicitProcessParameters.builder();
+        if (!args.isEmpty()) {
+            bld.launcherArgs(vmArgs);
+        }
+        if (!vmArgs.isEmpty()) {
+            bld.args(args);
+        }
+        bld.replaceArgs(false);
+        bld.workingDirectory(new File(cwd));
+        if (!env.isEmpty()) {
+            bld.environmentVariables(env);
+        }
+        ExplicitProcessParameters params = bld.build();
+        return params;
+    }
+
+    private static void execNative(File nativeImageFile, List<String> args,
+                                   DebugAdapterContext context,
+                                   ExecutionDescriptor executionDescriptor,
+                                   ExplicitProcessParameters params,
+                                   CompletableFuture<Void> launchFuture) {
         ExecutionService.newService(() -> {
             launchFuture.complete(null);
-            List<String> command = args.isEmpty() ? 
Collections.singletonList(nativeImageFile.getAbsolutePath()) : 
join(nativeImageFile.getAbsolutePath(), args);
+            List<String> command = join(nativeImageFile.getAbsolutePath(), 
args);
             try {
-                return new ProcessBuilder(command).start();
+                ProcessBuilder pb = new ProcessBuilder(command);
+                File workingDirectory = params.getWorkingDirectory();
+                if (workingDirectory != null) {
+                    pb.directory(workingDirectory);
+                }
+                Map<String, String> env = params.getEnvironmentVariables();
+                if (!env.isEmpty()) {
+                    pb.environment().putAll(env);

Review comment:
       `null` values are now interpreted as removal of that variable from the 
environment.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to