You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by en...@apache.org on 2021/11/01 16:53:23 UTC
[netbeans] branch master updated: Handle any script's URI and
provide script content when not readable from file.
This is an automated email from the ASF dual-hosted git repository.
entl 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 4078eeb Handle any script's URI and provide script content when not readable from file.
4078eeb is described below
commit 4078eeb7c3ab73c21ce669f1a81b8477332afac1
Author: Martin Entlicher <ma...@oracle.com>
AuthorDate: Wed Oct 27 21:15:31 2021 +0200
Handle any script's URI and provide script content when not readable from file.
---
.../jpda/truffle/frames/models/TruffleDVFrame.java | 20 ++++++++++--------
.../debugger/jpda/truffle/source/Source.java | 11 +++++++++-
.../lsp/server/debugging/NbProtocolServer.java | 24 ++++++++++++++++++----
3 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java
index c1c0395..27f7e7a 100644
--- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java
+++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java
@@ -21,6 +21,7 @@ package org.netbeans.modules.debugger.jpda.truffle.frames.models;
import java.io.InvalidObjectException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import org.netbeans.api.debugger.jpda.JPDADebugger;
import org.netbeans.api.debugger.jpda.JPDAThread;
import org.netbeans.modules.debugger.jpda.truffle.access.CurrentPCInfo;
@@ -77,15 +78,18 @@ public final class TruffleDVFrame implements DVFrame {
return null;
}
Source source = sourcePosition.getSource();
- URI uri = source.getURI();
- if (uri != null && "file".equalsIgnoreCase(uri.getScheme())) {
- return uri;
- }
- try {
- return source.getUrl().toURI();
- } catch (URISyntaxException ex) {
- return null;
+ URL url = source.getUrl();
+ URI uri;
+ if (url != null) {
+ try {
+ uri = url.toURI();
+ } catch (URISyntaxException ex) {
+ uri = source.getURI();
+ }
+ } else {
+ uri = source.getURI();
}
+ return uri;
}
@Override
diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java
index 1d618d3..ce43ef5 100644
--- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java
+++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java
@@ -20,6 +20,7 @@
package org.netbeans.modules.debugger.jpda.truffle.source;
import com.sun.jdi.StringReference;
+import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
@@ -64,7 +65,7 @@ public final class Source {
this.codeRef = codeRef;
URL url = null;
if (hostMethodName == null) {
- if (uri == null || !"file".equalsIgnoreCase(uri.getScheme())) {
+ if (uri == null || !"file".equalsIgnoreCase(uri.getScheme()) || !fileIsReadable(uri)) { // NOI18N
try {
url = SourceFilesCache.get(jpda).getSourceFile(name, hash, uri, getContent());
} catch (IOException ex) {
@@ -87,6 +88,14 @@ public final class Source {
this.hash = hash;
}
+ private static boolean fileIsReadable(URI uri) {
+ try {
+ return new File(uri).canRead();
+ } catch (IllegalArgumentException | SecurityException ex) {
+ return false;
+ }
+ }
+
public static Source getExistingSource(JPDADebugger debugger, long id) {
synchronized (KNOWN_SOURCES) {
Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/NbProtocolServer.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/NbProtocolServer.java
index 7807fdb..458f146 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/NbProtocolServer.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/NbProtocolServer.java
@@ -23,6 +23,8 @@ import java.io.IOException;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.file.FileSystemNotFoundException;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
@@ -325,15 +327,29 @@ public final class NbProtocolServer implements IDebugProtocolServer, LspSession.
sourceURI = URI.create(URITranslator.getDefault().uriToLSP(sourceURI.toString()));
Source source = new Source();
String scheme = sourceURI.getScheme();
- if (null == scheme || scheme.isEmpty() || "file".equalsIgnoreCase(scheme)) {
- source.setName(Paths.get(sourceURI).getFileName().toString());
- source.setPath(sourceURI.getPath());
+ Path sourcePath = null;
+ if (null == scheme) {
+ sourcePath = Paths.get(sourceURI.getPath());
+ } else if ("file".equalsIgnoreCase(scheme)) { // NOI18N
+ try {
+ sourcePath = Paths.get(sourceURI);
+ } catch (FileSystemNotFoundException | SecurityException | IllegalArgumentException ex) {
+ sourcePath = null;
+ }
+ }
+ if (sourcePath != null) {
+ source.setName(sourcePath.getFileName().toString());
+ source.setPath(sourcePath.toString());
source.setSourceReference(0);
} else {
int ref = context.createSourceReference(sourceURI, frame.getSourceMimeType());
String path = sourceURI.getPath();
- if (path == null) {
+ if (path == null || path.isEmpty()) {
path = sourceURI.getSchemeSpecificPart();
+ while (path.startsWith("//")) {
+ // Remove multiple initial slashes
+ path = path.substring(1);
+ }
}
if (path != null) {
int sepIndex = Math.max(path.lastIndexOf('/'), path.lastIndexOf(File.separatorChar));
---------------------------------------------------------------------
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