Skip to content

Commit 53d7256

Browse files
committed
Added VM Options config for notebooks, fixed enable preview failing with EA versions bug and added logger for knowing with which options the kernel is being launched
1 parent bf694c0 commit 53d7256

File tree

8 files changed

+70
-12
lines changed

8 files changed

+70
-12
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates.
2+
* Copyright (c) 2025-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.
@@ -39,12 +39,14 @@ public class NotebookConfigs {
3939
"notebook.addmodules",
4040
"notebook.enablePreview",
4141
"notebook.implicitImports",
42-
"notebook.projects.mapping"};
42+
"notebook.projects.mapping",
43+
"notebook.vmOptions"};
4344
private volatile String classPath = null;
4445
private volatile String modulePath = null;
4546
private volatile String addModules = null;
4647
private volatile boolean enablePreview = false;
4748
private volatile JsonObject notebookProjectMapping = new JsonObject();
49+
private volatile List<String> notebookVmOptions = new ArrayList<>();
4850
private volatile List<String> implicitImports = null;
4951
private volatile CompletableFuture<Void> initialized;
5052

@@ -76,6 +78,10 @@ public JsonObject getNotebookProjectMapping() {
7678
return notebookProjectMapping;
7779
}
7880

81+
public List<String> getNotebookVmOptions() {
82+
return notebookVmOptions;
83+
}
84+
7985
private NotebookConfigs() {
8086

8187
}
@@ -145,6 +151,11 @@ private CompletableFuture<Void> initializeConfigs() {
145151
if (notebookProjectMappingConfig != null) {
146152
notebookProjectMapping = notebookProjectMappingConfig;
147153
}
154+
155+
JsonArray notebookVmOptionsConfig = NotebookUtils.getArgument(c, 6, JsonArray.class);
156+
if (notebookVmOptionsConfig != null) {
157+
notebookVmOptions = notebookVmOptionsConfig.asList().stream().map(el -> el.getAsString()).toList();
158+
}
148159
}
149160
});
150161

@@ -154,7 +165,8 @@ private CompletableFuture<Void> initializeConfigs() {
154165
}
155166

156167
public String getJdkVersion() {
157-
return System.getProperty("java.version").split("\\.")[0];
168+
// As per JEP-223
169+
return System.getProperty("java.specification.version");
158170
}
159171

160172
public void notebookConfigsChangeListener(JsonObject settings) {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates.
2+
* Copyright (c) 2025-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.
@@ -94,12 +94,15 @@ 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-
97+
9898
JShell.Builder builder = JShell.builder()
9999
.out(streamsHandler.getPrintOutStream())
100100
.err(streamsHandler.getPrintErrStream())
101101
.in(streamsHandler.getInputStream());
102102

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());
103106
if (!compilerOptions.isEmpty()) {
104107
builder.compilerOptions(compilerOptions.toArray(new String[0]))
105108
.remoteVMOptions(remoteOptions.toArray(new String[0]));
@@ -226,6 +229,10 @@ private List<String> getRemoteVmOptions(Project prj) {
226229
if (enablePreview) {
227230
remoteOptions.add(ENABLE_PREVIEW);
228231
}
232+
233+
List<String> extraVmOptions = NotebookConfigs.getInstance().getNotebookVmOptions();
234+
remoteOptions.addAll(extraVmOptions);
235+
229236
return remoteOptions;
230237
}
231238

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates.
2+
* Copyright (c) 2025-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.
@@ -37,11 +37,6 @@
3737
2.Missing keys
3838
*/
3939

40-
/*
41-
Version 1 21/08/25
42-
Version 2 25/09/25 Inline with frontend sending arrays for CP,MP,Add modules
43-
*/
44-
4540
/**
4641
* Mock LSP Client sending sample configurations
4742
* Verifies that the NotebookConfigs class
@@ -59,6 +54,7 @@ public class NotebookConfigsTest {
5954
private static final String ADD_MODULES_KEY = "jdk.notebook.addmodules";
6055
private static final String ENABLE_PREVIEW_KEY = "jdk.notebook.enablePreview";
6156
private static final String MODULEPATH_KEY = "jdk.notebook.modulepath";
57+
private static final String VM_OPTIONS_KEY = "jdk.notebook.vmOptions";
6258

6359
public NotebookConfigsTest() {
6460
}
@@ -173,24 +169,57 @@ public void testGetImplicitImports() {
173169
fail("Configuration initialization failed");
174170
}
175171
}
172+
173+
/**
174+
* Test of getNotebookVmOptions method, of class NotebookConfigs.
175+
*/
176+
@Test
177+
public void testGetNotebookVmOptions() {
178+
System.out.println("getNotebookVmOptions");
179+
try {
180+
initialized.get(5, TimeUnit.SECONDS);
181+
182+
List<String> expResult = configsObj.get(VM_OPTIONS_KEY)
183+
.getAsJsonArray()
184+
.asList()
185+
.stream()
186+
.map(elem -> elem.getAsString())
187+
.toList();
188+
189+
List<String> result = instance.getNotebookVmOptions();
190+
191+
assertEquals(expResult, result);
192+
} catch (Exception ex) {
193+
fail("Configuration initialization failed");
194+
}
195+
}
176196

177197
private void setConfigObject() {
178198
JsonArray imports = new JsonArray();
179199
imports.add(new JsonPrimitive("java.math.*"));
180200
imports.add(new JsonPrimitive("javafx.scene.control.*"));
181201
configsObj.add(IMPLICIT_IMPORTS_KEY, imports);
202+
182203
JsonArray classpath = new JsonArray();
183204
classpath.add(new JsonPrimitive(
184205
"path/to/javafx-sdk-24.0.1/lib/javafx.base.jar"));
185206
configsObj.add(CLASSPATH_KEY, classpath);
207+
186208
JsonArray modulepath = new JsonArray();
187209
modulepath.add(new JsonPrimitive("/path/to/javafx-sdk/lib"));
188210
configsObj.add(MODULEPATH_KEY, modulepath);
189211
configsObj.add(ENABLE_PREVIEW_KEY, new JsonPrimitive(false));
212+
190213
JsonArray addModules = new JsonArray();
191214
addModules.add(new JsonPrimitive("javafx.controls"));
192215
addModules.add(new JsonPrimitive("javafx.graphics"));
193216
configsObj.add(ADD_MODULES_KEY, addModules);
217+
218+
JsonArray vmOptions = new JsonArray();
219+
vmOptions.add(new JsonPrimitive("--add-opens=java.base/java.lang=ALL-UNNAMED"));
220+
vmOptions.add(new JsonPrimitive("--add-opens=java.base/java.util=ALL-UNNAMED"));
221+
vmOptions.add(new JsonPrimitive("-Xmx2G"));
222+
configsObj.add(VM_OPTIONS_KEY, vmOptions);
194223

195224
}
196225

vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@
331331
"%jdk.configuration.inlay.enabled.enum.var.markdownDescription%"
332332
]
333333
}
334+
},
335+
"jdk.notebook.vmOptions": {
336+
"description": "%jdk.configuration.notebook.vmOptions.description%",
337+
"type": "array",
338+
"default": []
334339
}
335340
}
336341
},

vscode/package.nls.ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +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.",
8182
"jdk.configuration.java.completion.commit.chars": "コード補完の提案の受入れをトリガーする文字を指定します。たとえば、ピリオド(.)を入力したときに提案を受け入れるには、これを[\".\"]に設定します",
8283
"jdk.initialConfigurations.launchJavaApp.name": "Javaアプリケーションの起動",
8384
"jdk.configurationSnippets.name": "Javaアプリケーションの起動",

vscode/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +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.",
8182
"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 [\".\"]",
8283
"jdk.initialConfigurations.launchJavaApp.name": "Launch Java App",
8384
"jdk.configurationSnippets.name": "Launch Java App",

vscode/package.nls.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +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.",
8182
"jdk.configuration.java.completion.commit.chars": "指定用于触发接受代码补全建议的字符。例如,要在键入点 (.) 时接受建议,请将该字符设为 [\".\"]",
8283
"jdk.initialConfigurations.launchJavaApp.name": "启动 Java 应用程序",
8384
"jdk.configurationSnippets.name": "启动 Java 应用程序",

vscode/src/configurations/configuration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const configKeys = {
3737
notebookEnablePreview: "notebook.enablePreview",
3838
notebookImplicitImports: "notebook.implicitImports",
3939
telemetryEnabled: 'telemetry.enabled',
40-
notebookProjectMapping: "notebook.projects.mapping"
40+
notebookProjectMapping: "notebook.projects.mapping",
41+
notebookVmOptions: "notebook.vmOptions"
4142
};
4243

4344
export const builtInConfigKeys = {
@@ -56,6 +57,7 @@ export const userConfigsListened: string[] = [
5657
appendPrefixToCommand(configKeys.notebookEnablePreview),
5758
appendPrefixToCommand(configKeys.notebookImplicitImports),
5859
appendPrefixToCommand(configKeys.notebookProjectMapping),
60+
appendPrefixToCommand(configKeys.notebookVmOptions),
5961
builtInConfigKeys.vscodeTheme,
6062
];
6163

0 commit comments

Comments
 (0)