You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sk...@apache.org on 2020/02/05 09:56:36 UTC

[netbeans] branch master updated: [NETBEANS-3793]: fixed Single Source file debugger for windows and code refactoring of Single Source debuging

This is an automated email from the ASF dual-hosted git repository.

skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 3186690  [NETBEANS-3793]: fixed Single Source file debugger for windows and code refactoring of Single Source debuging
     new 57f811b  Merge pull request #1920 from arusinha/netbeans-3793
3186690 is described below

commit 31866909a9ad3a08404d437a371b98f538898c26
Author: Arunava Sinha <ar...@oracle.com>
AuthorDate: Wed Feb 5 00:04:22 2020 +0530

    [NETBEANS-3793]: fixed Single Source file debugger for windows and code refactoring of Single Source debuging
---
 .../common/singlesourcefile/CompileProcess.java    | 37 ++++++++---------
 .../api/common/singlesourcefile/DebugProcess.java  | 46 +++++++++++++---------
 .../api/common/singlesourcefile/JPDAStart.java     | 32 ---------------
 .../SingleJavaSourceDebugActionProvider.java       |  4 +-
 4 files changed, 45 insertions(+), 74 deletions(-)

diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/CompileProcess.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/CompileProcess.java
index 32bb429..480e123 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/CompileProcess.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/CompileProcess.java
@@ -20,43 +20,41 @@ package org.netbeans.modules.java.api.common.singlesourcefile;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import org.netbeans.api.java.platform.JavaPlatformManager;
 import org.openide.filesystems.FileObject;
-import org.openide.util.Utilities;
+import org.openide.filesystems.FileUtil;
 
 /**
  *
  * @author Arunava Sinha
  */
-class CompileProcess  {
+class CompileProcess {
 
     private static final Logger LOG = Logger.getLogger(CompileProcess.class.getName());
-    FileObject fileObject;
 
-    
-    public CompileProcess(FileObject fileObject) {
-        this.fileObject = fileObject;
-    }
+    public Process setupProcess(FileObject fileObject) {
 
-    public Process setupProcess() {
-        File javaBinPath = new File(new File(System.getProperty("java.home")), "bin");  //NOI18N
-        String javaPath = javaBinPath.getAbsolutePath() + "//java";  //NOI18N
+        FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
+        File javacFile = FileUtil.toFile(javac);
+        String javacPath = javacFile.getAbsolutePath();
 
-        String javacPath = javaBinPath.getAbsolutePath() + "//javac";  //NOI18N
         List<String> compileCommandList = new ArrayList<>();
-        if (Utilities.isUnix()) {
-            compileCommandList.add("bash"); //NOI18N
-            compileCommandList.add("-c"); //NOI18N
-        }
 
         Object compilerVmOptionsObj = fileObject.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS);
-        String vmOptions = compilerVmOptionsObj != null ? (String) compilerVmOptionsObj : "";
+        compileCommandList.add(javacPath);
+        compileCommandList.add("-g");  //NOI18N
+
+        String vmOptions = compilerVmOptionsObj != null ? ((String) compilerVmOptionsObj).trim() : ""; // NOI18N
+        if (!vmOptions.isEmpty()) {
+            compileCommandList.addAll(Arrays.asList(vmOptions.split(" "))); //NOI18N
+        }
 
-        compileCommandList.add(javacPath + " -g" + " " + vmOptions + " " + fileObject.getPath());
+        compileCommandList.add(fileObject.getPath());
         ProcessBuilder compileProcessBuilder = new ProcessBuilder(compileCommandList);
         compileProcessBuilder.directory(new File(fileObject.getParent().getPath()));
         compileProcessBuilder.redirectErrorStream(true);
@@ -69,9 +67,6 @@ class CompileProcess  {
                     Level.WARNING,
                     "Could not get InputStream of Compile Process"); //NOI18N
         }
-           
         return null;
-
     }
-
 }
diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/DebugProcess.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/DebugProcess.java
index 18775ac..6bc5d5b 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/DebugProcess.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/DebugProcess.java
@@ -21,13 +21,15 @@ package org.netbeans.modules.java.api.common.singlesourcefile;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.netbeans.api.java.platform.JavaPlatformManager;
 import org.openide.filesystems.FileObject;
-import org.openide.util.Utilities;
+import org.openide.filesystems.FileUtil;
 
 /**
  *
@@ -42,30 +44,37 @@ class DebugProcess {
         try {
 
             List<String> commandsList = new ArrayList<>();
-            if (Utilities.isUnix()) {
-                commandsList.add("bash");
-                commandsList.add("-c");
-            }
-            File javaBinPath = new File(new File(System.getProperty("java.home")), "bin"); //NOI18N
-            String javaPath = javaBinPath.getAbsolutePath() + "//java"; //NOI18N
+
+            FileObject java = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("java"); //NOI18N
+            File javaFile = FileUtil.toFile(java);
+            String javaPath = javaFile.getAbsolutePath();
 
             Object argumentsObject = fileObject.getAttribute(SingleSourceFileUtil.FILE_ARGUMENTS);
-            String arguments = argumentsObject != null ? (String) argumentsObject : ""; //NOI18N
+            String arguments = argumentsObject != null ? ((String) argumentsObject).trim() : ""; // NOI18N
 
             Object vmOptionsObj = fileObject.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS);
-            String vmOptions = vmOptionsObj != null ? (String) vmOptionsObj : ""; //NOI18N
-
-            //filtering out --source param from VM option
-            Matcher m1 = JVM_ARGS_PATTERN.matcher(vmOptions);
+            String vmOptions = vmOptionsObj != null ? ((String) vmOptionsObj) : ""; // NOI18N
 
-            while (m1.find()) {
-                String group1 = m1.group(1);
-                String group3 = m1.group(3);
-                vmOptions = group1 + group3;
+            commandsList.add(javaPath);
+            if (!vmOptions.isEmpty()) {
+                //filtering out --source param from VM option
+                Matcher m1 = JVM_ARGS_PATTERN.matcher(vmOptions);
+                while (m1.find()) {
+                    String group1 = m1.group(1);
+                    String group3 = m1.group(3);
+                    vmOptions = group1 + group3;
+                }
+                commandsList.addAll(Arrays.asList(vmOptions.split(" ")));  //NOI18N
             }
+            commandsList.add("-Xdebug");  //NOI18N
+            commandsList.add("-Xrunjdwp:transport=dt_socket,address=" + port + ",server=n"); //NOI18N
+            commandsList.add("-cp"); //NOI18N
+            commandsList.add(fileObject.getParent().getPath());
+            commandsList.add(fileObject.getName());
 
-            String JavaDebugParams = " " + vmOptions + " -Xdebug -Xrunjdwp:transport=dt_socket,address=" + port + ",server=n "; //NOI18N
-            commandsList.add(javaPath + JavaDebugParams + "-cp " + fileObject.getParent().getPath() + " " + fileObject.getName() + " " + arguments); //NOI18N
+            if (!arguments.isEmpty()) {
+                commandsList.addAll(Arrays.asList(arguments.split(" ")));  //NOI18N
+            }
 
             ProcessBuilder runFileProcessBuilder = new ProcessBuilder(commandsList);
             runFileProcessBuilder.directory(new File(System.getProperty("user.home"))); //NOI18N
@@ -73,7 +82,6 @@ class DebugProcess {
             runFileProcessBuilder.redirectOutput();
 
             return runFileProcessBuilder.start();
-
         } catch (IOException ex) {
             LOG.log(
                     Level.WARNING,
diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/JPDAStart.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/JPDAStart.java
index eac91a6..9049974 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/JPDAStart.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/JPDAStart.java
@@ -26,9 +26,6 @@ import com.sun.jdi.Bootstrap;
 import com.sun.jdi.connect.ListeningConnector;
 import com.sun.jdi.connect.Transport;
 import com.sun.jdi.connect.Connector;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
 import java.util.Iterator;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -42,7 +39,6 @@ import org.openide.filesystems.FileUtil;
 import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.debugger.jpda.JPDADebugger;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
-import org.openide.util.Exceptions;
 import org.openide.windows.InputOutput;
 
 /**
@@ -143,37 +139,9 @@ public class JPDAStart implements Runnable {
                 lock.notify();
             }
         }
-
     }
 
     public String getTransport() {
         return TRANSPORT;
     }
-
-    private static final class CopyReaderWriter implements Runnable {
-
-        private final Reader in;
-        private final Writer out;
-
-        public CopyReaderWriter(Reader in, Writer out) {
-            this.in = in;
-            this.out = out;
-        }
-
-        @Override
-        public void run() {
-            try {
-                char[] buf = new char[1024];
-                int read;
-
-                while ((read = in.read(buf)) != (-1)) {
-                    out.write(buf, 0, read);
-                }
-            } catch (IOException ex) {
-                Exceptions.printStackTrace(ex);
-            }
-        }
-
-    }
-
 }
diff --git a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleJavaSourceDebugActionProvider.java b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleJavaSourceDebugActionProvider.java
index 1552b42..a6a469f 100644
--- a/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleJavaSourceDebugActionProvider.java
+++ b/java/java.api.common/src/org/netbeans/modules/java/api/common/singlesourcefile/SingleJavaSourceDebugActionProvider.java
@@ -66,10 +66,10 @@ public final class SingleJavaSourceDebugActionProvider implements ActionProvider
                 new Callable<Process>() {
             @Override
             public Process call() {
-                CompileProcess compileProcess = new CompileProcess(fileObject);
+                CompileProcess compileProcess = new CompileProcess();
                 InputOutput io = IOProvider.getDefault().getIO(IONAME, false);
 
-                Process compilePreProcess = compileProcess.setupProcess();
+                Process compilePreProcess = compileProcess.setupProcess(fileObject);
                 try {
                     int processExitCode = compilePreProcess.waitFor();
                     if (processExitCode != 0) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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