Skip to content

Commit 446711c

Browse files
committed
added Notebook congif tests for vm options, updated description label for vm options, updated config values flow so that they are set to default if nothing is sent by lsp client
1 parent 53d7256 commit 446711c

File tree

8 files changed

+80
-17
lines changed

8 files changed

+80
-17
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import com.google.gson.JsonObject;
2020
import java.io.File;
2121
import java.util.ArrayList;
22+
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.concurrent.CompletableFuture;
2425
import java.util.logging.Level;
2526
import java.util.logging.Logger;
2627
import org.eclipse.lsp4j.ConfigurationItem;
2728
import org.eclipse.lsp4j.ConfigurationParams;
29+
import org.netbeans.api.annotations.common.NonNull;
2830
import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient;
2931

3032
/**
@@ -46,7 +48,7 @@ public class NotebookConfigs {
4648
private volatile String addModules = null;
4749
private volatile boolean enablePreview = false;
4850
private volatile JsonObject notebookProjectMapping = new JsonObject();
49-
private volatile List<String> notebookVmOptions = new ArrayList<>();
51+
private volatile List<String> notebookVmOptions = Collections.emptyList();
5052
private volatile List<String> implicitImports = null;
5153
private volatile CompletableFuture<Void> initialized;
5254

@@ -77,7 +79,8 @@ public List<String> getImplicitImports() {
7779
public JsonObject getNotebookProjectMapping() {
7880
return notebookProjectMapping;
7981
}
80-
82+
83+
@NonNull
8184
public List<String> getNotebookVmOptions() {
8285
return notebookVmOptions;
8386
}
@@ -125,36 +128,50 @@ private CompletableFuture<Void> initializeConfigs() {
125128
JsonArray classPathConfig = NotebookUtils.getArgument(c, 0, JsonArray.class);
126129
if (classPathConfig != null) {
127130
classPath = String.join(File.pathSeparator,classPathConfig.asList().stream().map((elem) -> elem.getAsString()).toList());
131+
} else {
132+
classPath = null;
128133
}
129134

130135
JsonArray modulePathConfig = NotebookUtils.getArgument(c, 1, JsonArray.class);
131136
if (modulePathConfig != null) {
132137
modulePath = String.join(File.pathSeparator,modulePathConfig.asList().stream().map((elem) -> elem.getAsString()).toList());
138+
} else {
139+
modulePath = null;
133140
}
134141

135142
JsonArray addModulesConfig = NotebookUtils.getArgument(c, 2, JsonArray.class);
136143
if (addModulesConfig != null) {
137144
addModules = String.join(",",addModulesConfig.asList().stream().map((elem) -> elem.getAsString()).toList());
145+
} else {
146+
addModules = null;
138147
}
139148

140149
Boolean enablePreviewConfig = NotebookUtils.getArgument(c, 3, Boolean.class);
141150
if (enablePreviewConfig != null) {
142151
enablePreview = enablePreviewConfig;
152+
} else {
153+
enablePreview = false;
143154
}
144155

145156
JsonArray implicitImportsConfig = NotebookUtils.getArgument(c, 4, JsonArray.class);
146157
if (implicitImportsConfig != null) {
147158
implicitImports = implicitImportsConfig.asList().stream().map((elem) -> elem.getAsString()).toList();
159+
} else {
160+
implicitImports = null;
148161
}
149162

150163
JsonObject notebookProjectMappingConfig = NotebookUtils.getArgument(c, 5, JsonObject.class);
151164
if (notebookProjectMappingConfig != null) {
152165
notebookProjectMapping = notebookProjectMappingConfig;
166+
} else {
167+
notebookProjectMapping = new JsonObject();
153168
}
154169

155170
JsonArray notebookVmOptionsConfig = NotebookUtils.getArgument(c, 6, JsonArray.class);
156171
if (notebookVmOptionsConfig != null) {
157172
notebookVmOptions = notebookVmOptionsConfig.asList().stream().map(el -> el.getAsString()).toList();
173+
} else {
174+
notebookVmOptions = Collections.emptyList();
158175
}
159176
}
160177
});

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ private JShell jshellBuildWithProject(String notebookUri, Project prj, JshellStr
9494
List<String> compilerOptions = getCompilerOptions(prj);
9595
List<String> remoteOptions = getRemoteVmOptions(prj);
9696
setSystemPropertiesForRemoteVm(remoteOptions, notebookUri);
97-
9897
JShell.Builder builder = JShell.builder()
9998
.out(streamsHandler.getPrintOutStream())
10099
.err(streamsHandler.getPrintErrStream())
101100
.in(streamsHandler.getInputStream());
102101

103-
LOG.log(Level.INFO, "Initializing Notebook kernel for {0}", notebookUri);
104-
LOG.log(Level.INFO, "Compiler options being passed: {0}", compilerOptions.toString());
105-
LOG.log(Level.INFO, "VM Options being passed to notebook kernel: {0}", remoteOptions.toString());
102+
LOG.log(Level.FINE, "Initializing Notebook kernel for {0}", notebookUri);
103+
LOG.log(Level.FINE, "Compiler options being passed: {0}", compilerOptions);
104+
LOG.log(Level.FINE, "VM Options being passed to notebook kernel: {0}", remoteOptions);
106105
if (!compilerOptions.isEmpty()) {
107106
builder.compilerOptions(compilerOptions.toArray(new String[0]))
108107
.remoteVMOptions(remoteOptions.toArray(new String[0]));

nbcode/notebooks/test/unit/src/org/netbeans/modules/nbcode/java/notebook/NotebookConfigsTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.gson.JsonObject;
2020
import com.google.gson.JsonArray;
21+
import com.google.gson.JsonElement;
2122
import com.google.gson.JsonPrimitive;
2223
import java.io.File;
2324
import java.util.ArrayList;
@@ -193,7 +194,47 @@ public void testGetNotebookVmOptions() {
193194
fail("Configuration initialization failed");
194195
}
195196
}
197+
198+
/**
199+
* Test of getNotebookVmOptions method when the configuration key is
200+
* missing. Verifies that the system handles a null/missing key gracefully
201+
* (likely returning an empty list).
202+
*/
203+
@Test
204+
public void testGetNotebookVmOptionsWhenMissing() {
205+
try {
206+
updateConfigValue(VM_OPTIONS_KEY, null);
207+
List<String> result = instance.getNotebookVmOptions();
208+
assertNotNull("Result should not be null even if key is missing", result);
209+
assertTrue("Result should be empty when key is missing", result.isEmpty());
196210

211+
} catch (Exception ex) {
212+
fail("Failed to handle missing VM_OPTIONS_KEY: " + ex.getMessage());
213+
}
214+
}
215+
216+
/**
217+
* Test of getNotebookVmOptions with quoted spaces.
218+
* Verifies that options containing spaces (like directory paths) are preserved.
219+
*/
220+
@Test
221+
public void testGetNotebookVmOptionsWithQuotedSpaces() {
222+
try {
223+
String quotedOption = "\"-Djava.io.tmpdir=C:\\Temp Folder\\java\"";
224+
225+
JsonArray vmOptions = new JsonArray();
226+
vmOptions.add(new JsonPrimitive(quotedOption));
227+
updateConfigValue(VM_OPTIONS_KEY, vmOptions);
228+
List<String> result = instance.getNotebookVmOptions();
229+
230+
assertTrue("Result should contain the quoted option", result.contains(quotedOption));
231+
assertEquals("Should have exactly 1 option", 1, result.size());
232+
233+
} catch (Exception ex) {
234+
fail("Configuration with quoted spaces failed");
235+
}
236+
}
237+
197238
private void setConfigObject() {
198239
JsonArray imports = new JsonArray();
199240
imports.add(new JsonPrimitive("java.math.*"));
@@ -222,6 +263,12 @@ private void setConfigObject() {
222263
configsObj.add(VM_OPTIONS_KEY, vmOptions);
223264

224265
}
266+
267+
private void updateConfigValue(String key, JsonElement value){
268+
configsObj.add(key, value);
269+
instance.initConfigs();
270+
instance.getInitialized();
271+
}
225272

226273
private class MockNbClientConfigs extends MockNbClient {
227274

vscode/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@
300300
"default": {},
301301
"description": "%jdk.notebook.projects.mapping.description%"
302302
},
303+
"jdk.notebook.vmOptions": {
304+
"type": "array",
305+
"default": [],
306+
"description": "%jdk.notebook.vmOptions.description%"
307+
},
303308
"jdk.telemetry.enabled": {
304309
"type": "boolean",
305310
"description": "%jdk.configuration.telemetry.enabled.description%",
@@ -331,11 +336,6 @@
331336
"%jdk.configuration.inlay.enabled.enum.var.markdownDescription%"
332337
]
333338
}
334-
},
335-
"jdk.notebook.vmOptions": {
336-
"description": "%jdk.configuration.notebook.vmOptions.description%",
337-
"type": "array",
338-
"default": []
339339
}
340340
}
341341
},

vscode/package.nls.ja.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"jdk.notebook.implicitImports.description": "Javaノートブックで暗黙的にインポートする要素のリスト。空のときのデフォルトはjava.util、java.ioおよびjava.mathパッケージのスター・インポート。",
7979
"jdk.notebook.implicitImports.markdownDescription": "Javaノートブックで暗黙的にインポートする要素のリスト。空のときのデフォルトは`java.util`、`java.io`および`java.math`パッケージのスター・インポート。",
8080
"jdk.notebook.projects.mapping.description": "Javaノートブック・パスの、コンテキストを提供するプロジェクトのパスへのマッピング。",
81-
"jdk.configuration.notebook.vmOptions.description": "The specific JVM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
81+
"jdk.configuration.notebook.vmOptions.description": "The specific Java VM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
8282
"jdk.configuration.java.completion.commit.chars": "コード補完の提案の受入れをトリガーする文字を指定します。たとえば、ピリオド(.)を入力したときに提案を受け入れるには、これを[\".\"]に設定します",
8383
"jdk.initialConfigurations.launchJavaApp.name": "Javaアプリケーションの起動",
8484
"jdk.configurationSnippets.name": "Javaアプリケーションの起動",

vscode/package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"jdk.notebook.implicitImports.description": "List of elements to implicitly import in Java notebooks. Defaults to star-imports of java.util, java.io and java.math packages, when empty.",
7979
"jdk.notebook.implicitImports.markdownDescription": "List of elements to implicitly import in Java notebooks. Defaults to star-imports of `java.util`, `java.io` and `java.math` packages, when empty.",
8080
"jdk.notebook.projects.mapping.description": "Mapping of Java notebook paths to the path of the project that provides it context.",
81-
"jdk.configuration.notebook.vmOptions.description": "The specific JVM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
81+
"jdk.configuration.notebook.vmOptions.description": "The specific Java VM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
8282
"jdk.configuration.java.completion.commit.chars": "Specifies the characters that trigger accepting a code completion suggestion. For example, to accept suggestions when typing a dot (.), set this to [\".\"]",
8383
"jdk.initialConfigurations.launchJavaApp.name": "Launch Java App",
8484
"jdk.configurationSnippets.name": "Launch Java App",

vscode/package.nls.zh-cn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"jdk.notebook.implicitImports.description": "要在 Java 记事本中隐式导入的元素列表。为空时,默认为 java.util、java.io 和 java.math 程序包的星型导入。",
7979
"jdk.notebook.implicitImports.markdownDescription": "要在 Java 记事本中隐式导入的元素列表。为空时,默认为 `java.util`、`java.io` 和 `java.math` 程序包的星型导入。",
8080
"jdk.notebook.projects.mapping.description": "将 Java 记事本路径映射到提供记事本上下文的项目的路径。",
81-
"jdk.configuration.notebook.vmOptions.description": "The specific JVM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
81+
"jdk.configuration.notebook.vmOptions.description": "The specific Java VM options for use in Java notebooks. These options are added in addition to the project configuration, including class-path, module-path, preview features, and added modules.",
8282
"jdk.configuration.java.completion.commit.chars": "指定用于触发接受代码补全建议的字符。例如,要在键入点 (.) 时接受建议,请将该字符设为 [\".\"]",
8383
"jdk.initialConfigurations.launchJavaApp.name": "启动 Java 应用程序",
8484
"jdk.configurationSnippets.name": "启动 Java 应用程序",

vscode/src/configurations/configuration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2023-2024, Oracle and/or its affiliates.
2+
Copyright (c) 2023-2026, Oracle and/or its affiliates.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -36,9 +36,9 @@ export const configKeys = {
3636
notebookAddModules: "notebook.addmodules",
3737
notebookEnablePreview: "notebook.enablePreview",
3838
notebookImplicitImports: "notebook.implicitImports",
39-
telemetryEnabled: 'telemetry.enabled',
4039
notebookProjectMapping: "notebook.projects.mapping",
41-
notebookVmOptions: "notebook.vmOptions"
40+
notebookVmOptions: "notebook.vmOptions",
41+
telemetryEnabled: 'telemetry.enabled'
4242
};
4343

4444
export const builtInConfigKeys = {

0 commit comments

Comments
 (0)