Make the test for node coming from GraalVM installation more reliable.
1.1 --- a/debugger.jpda.trufflenode/src/org/netbeans/modules/debugger/jpda/truffle/node/GraalVmStartupExtender.java Tue Jul 26 13:07:08 2016 +0200
1.2 +++ b/debugger.jpda.trufflenode/src/org/netbeans/modules/debugger/jpda/truffle/node/GraalVmStartupExtender.java Tue Jul 26 18:58:25 2016 +0200
1.3 @@ -41,6 +41,7 @@
1.4 */
1.5 package org.netbeans.modules.debugger.jpda.truffle.node;
1.6
1.7 +import java.io.File;
1.8 import java.util.Arrays;
1.9 import java.util.Collections;
1.10 import java.util.List;
1.11 @@ -48,14 +49,19 @@
1.12 import org.netbeans.api.project.Project;
1.13 import org.netbeans.modules.javascript.nodejs.api.NodeJsSupport;
1.14 import org.netbeans.spi.extexecution.startup.StartupExtenderImplementation;
1.15 +import org.openide.filesystems.FileObject;
1.16 +import org.openide.filesystems.FileUtil;
1.17 +import org.openide.util.BaseUtilities;
1.18 import org.openide.util.Exceptions;
1.19 import org.openide.util.Lookup;
1.20 +import org.openide.util.NbBundle;
1.21 import org.openide.windows.IOProvider;
1.22 import org.openide.windows.InputOutput;
1.23
1.24 @StartupExtenderImplementation.Registration(displayName = "Debug GraalVM Node.js", startMode = StartupExtender.StartMode.DEBUG)
1.25 public class GraalVmStartupExtender implements StartupExtenderImplementation {
1.26
1.27 + @NbBundle.Messages("CTL_DebugName=GraalVM node Debugger")
1.28 @Override
1.29 public List<String> getArguments(Lookup context, StartupExtender.StartMode mode) {
1.30 Project p = context.lookup(Project.class);
1.31 @@ -70,10 +76,17 @@
1.32 return Collections.emptyList();
1.33 }
1.34 final String node = s.getNode(p);
1.35 - if (node == null || !node.endsWith("jre/bin/node")) {
1.36 + File nodeFile = new File(node);
1.37 + nodeFile = FileUtil.normalizeFile(nodeFile);
1.38 + FileObject nodeFO = FileUtil.toFileObject(nodeFile);
1.39 + if (nodeFO == null) {
1.40 return Collections.emptyList();
1.41 }
1.42 - final String debugName = "GraalVM node Debugger";
1.43 + FileObject bin = nodeFO.getParent();
1.44 + if (bin == null || !isJavaPlatformBinDir(bin)) {
1.45 + return Collections.emptyList();
1.46 + }
1.47 + final String debugName = Bundle.CTL_DebugName();
1.48
1.49 InputOutput io = IOProvider.getDefault().getIO(debugName, false);
1.50 JPDAStart start = new JPDAStart(io, debugName);
1.51 @@ -86,4 +99,16 @@
1.52 return Arrays.asList("-J-Xrunjdwp:transport=dt_socket,address=" + res + ",server=n,suspend=y");
1.53 }
1.54
1.55 + private static boolean isJavaPlatformBinDir(FileObject dir) {
1.56 + if (!"bin".equals(dir.getName())) {
1.57 + return false;
1.58 + }
1.59 + FileObject file = dir.getFileObject("java", BaseUtilities.isWindows() ? "exe" : null);
1.60 + if (file == null) {
1.61 + return false;
1.62 + }
1.63 + file = dir.getFileObject("graalvm", BaseUtilities.isWindows() ? "exe" : null);
1.64 + return file != null;
1.65 + }
1.66 +
1.67 }