Skip to content

Commit

Permalink
Support for string[] vmArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
sdedic committed Aug 26, 2024
1 parent 6c6beed commit dcf0ffa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,19 +468,18 @@ private static void startNativeDebug(File nativeImageFile, List<String> args,
}

@NonNull
private static List<String> argsToStringList(Object o) {
static List<String> argsToStringList(Object o) {
if (o == null) {
return Collections.emptyList();
}
if (o instanceof List) {
for (Object item : (List)o) {
if (!(o instanceof String)) {
if (!(item instanceof String)) {
throw new IllegalArgumentException("Only string parameters expected");
}
}
return (List<String>)o;
} else if (o instanceof String) {
List<String> res = new ArrayList<>();
return Arrays.asList(BaseUtilities.parseParameters(o.toString()));
} else {
throw new IllegalArgumentException("Expected String or String list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ public CompletableFuture<Void> launch(Map<String, Object> launchArguments, Debug
}

if (!isNative) {
if (StringUtils.isBlank((String)launchArguments.get("vmArgs"))) {
List<String> vmArgList = NbLaunchDelegate.argsToStringList(launchArguments.get("vmArgs"));
if (vmArgList.isEmpty()) {
launchArguments.put("vmArgs", String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name()));
} else {
vmArgList = new ArrayList<>(vmArgList);
vmArgList.add(String.format("-Dfile.encoding=%s", context.getDebuggeeEncoding().name()));
// if vmArgs already has the file.encoding settings, duplicate options for jvm will not cause an error, the right most value wins
launchArguments.put("vmArgs", String.format("%s -Dfile.encoding=%s", launchArguments.get("vmArgs"), context.getDebuggeeEncoding().name()));
launchArguments.put("vmArgs", vmArgList);
}
}
context.setDebugMode(!noDebug);
Expand Down
9 changes: 7 additions & 2 deletions java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,13 @@
"vmArgs": {
"type": [
"string",
"array",
"null"
],
"items": {
"type": "string",
"description": "Single argument to the VM"
},
"description": "Arguments for the Java VM",
"default": null
},
Expand Down Expand Up @@ -618,7 +623,7 @@
{
"command": "nbls.project.buildPushImage",
"title": "Build and Push container image",
"icon": "$(live-share)"
"icon": "$(live-share)"
},
{
"command": "cloud.assets.policy.create",
Expand Down Expand Up @@ -1082,7 +1087,7 @@
"when": "viewItem =~ /publicIp:.*/ && viewItem =~ /imageUrl:.*/",
"group": "inline@10"
},
{
{
"command": "nbls.project.buildPushImage",
"when": "viewItem =~ /class:oracle.developer.ContainerRepositoryItem/",
"group": "inline@9"
Expand Down
6 changes: 5 additions & 1 deletion java/java.lsp.server/vscode/src/runConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RunConfigurationProvider implements vscode.DebugConfigurationProvider {
resolve(config);
});
}

resolveDebugConfigurationWithSubstitutedVariables?(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
return new Promise<vscode.DebugConfiguration>(resolve => {
const args = argumentsNode.getValue();
Expand All @@ -51,7 +51,11 @@ class RunConfigurationProvider implements vscode.DebugConfigurationProvider {
if (vmArgs) {
if (!config.vmArgs) {
config.vmArgs = vmArgs;
} else if (Array.isArray(config.vmArgs)) {
let cfg : string[] = config.vmArgs;
cfg.push(vmArgs);
} else {
// assume the config is a string
config.vmArgs = `${config.vmArgs} ${vmArgs}`;
}
}
Expand Down

0 comments on commit dcf0ffa

Please sign in to comment.