Skip to content

Commit 33d78cc

Browse files
committed
Fixed URI issue while reading project context mapping for notebooks
1 parent 5e22af4 commit 33d78cc

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookSessionManager.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package org.netbeans.modules.nbcode.java.notebook;
1717

18+
import com.google.gson.JsonElement;
1819
import com.google.gson.JsonObject;
1920
import java.net.URI;
21+
import java.nio.file.Path;
2022
import java.nio.file.Paths;
2123
import java.util.ArrayList;
2224
import java.util.HashMap;
@@ -252,11 +254,19 @@ public void closeSession(String notebookUri) {
252254

253255
private CompletableFuture<Project> getProjectContextForNotebook(String notebookUri) {
254256
JsonObject mapping = NotebookConfigs.getInstance().getNotebookProjectMapping();
255-
String notebookPath = URI.create(notebookUri).getPath();
256-
String projectKey = mapping.has(notebookPath)
257-
? Paths.get(mapping.get(notebookPath).getAsString()).toUri().toString()
258-
: notebookUri;
259257

258+
URI uri = URI.create(notebookUri);
259+
String path = Path.of(uri).toAbsolutePath().toString();
260+
JsonElement el = mapping.get(path);
261+
262+
String value = null;
263+
if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
264+
value = Paths.get(el.getAsString()).toUri().toString();
265+
}
266+
267+
String projectKey = value != null ? value : notebookUri;
268+
269+
LOG.log(Level.FINE, "projectKey: {0}", projectKey);
260270
Project prj = ProjectContext.getProject(projectKey);
261271

262272
if (prj == null) {

0 commit comments

Comments
 (0)