This is an automated email from the ASF dual-hosted git repository. mbalin 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 eebcd26 Comand for updating run configuration with DB env variables (#3612) eebcd26 is described below commit eebcd26b951919d4aa540c9725474c72b7938a9a Author: jhorvath <j...@horvath.cz> AuthorDate: Mon Mar 7 13:36:43 2022 +0100 Comand for updating run configuration with DB env variables (#3612) --- .../java/lsp/server/db/DBSetEnvCommand.java | 80 ++++++++++++++++++++++ .../lsp/server/protocol/NbCodeClientWrapper.java | 6 ++ .../lsp/server/protocol/NbCodeLanguageClient.java | 9 +++ .../modules/java/lsp/server/protocol/Server.java | 6 ++ .../lsp/server/protocol/UpdateConfigParams.java | 77 +++++++++++++++++++++ .../java/lsp/server/TestCodeLanguageClient.java | 7 ++ .../java/lsp/server/explorer/ProjectViewTest.java | 6 ++ .../server/progress/TestProgressHandlerTest.java | 6 ++ java/java.lsp.server/vscode/package.json | 5 ++ java/java.lsp.server/vscode/src/extension.ts | 11 ++- java/java.lsp.server/vscode/src/protocol.ts | 13 ++++ .../java.lsp.server/vscode/src/runConfiguration.ts | 17 +++-- 12 files changed, 237 insertions(+), 6 deletions(-) diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBSetEnvCommand.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBSetEnvCommand.java new file mode 100644 index 0000000..6a94a08 --- /dev/null +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBSetEnvCommand.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.lsp.server.db; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.CodeActionParams; +import org.netbeans.api.db.explorer.ConnectionManager; +import org.netbeans.api.db.explorer.DatabaseConnection; +import org.netbeans.modules.java.lsp.server.protocol.CodeActionsProvider; +import org.netbeans.modules.java.lsp.server.protocol.NbCodeLanguageClient; +import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams; +import org.netbeans.modules.parsing.api.ResultIterator; +import org.openide.util.lookup.ServiceProvider; + +/** + * Updates Run Configuratoin with Database env variables. + * + * @author Jan Horvath + */ +@ServiceProvider(service = CodeActionsProvider.class) +public class DBSetEnvCommand extends CodeActionsProvider { + private static final String COMMAND_SET_DB_ENV = "java.db.set.env"; //NOI18N + private static final String CONFIG_SECTION = "java8+.runConfig"; //NOI18N + + private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList( + COMMAND_SET_DB_ENV + )); + + @Override + public List<CodeAction> getCodeActions(ResultIterator resultIterator, CodeActionParams params) throws Exception { + return Collections.emptyList(); + } + @Override + public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, String command, List<Object> arguments) { + if (!COMMAND_SET_DB_ENV.equals(command)) { + return null; + } + DatabaseConnection conn = ConnectionManager.getDefault().getPreferredConnection(true); + Map<String, String> props = new HashMap<>(); + props.put("DATASOURCE_DEFAULT_URL", conn.getDatabaseURL()); //NOI18N + props.put("DATASOURCE_DEFAULT_USERNAME", conn.getUser()); //NOI18N + props.put("DATASOURCE_DEFAULT_PASSWORD", conn.getPassword()); //NOI18N + props.put("DATASOURCE_DEFAULT_DRIVER_CLASS_NAME", conn.getDriverClass()); //NOI18N + String values = props.entrySet().stream() + .map(e -> e.getKey() + "=" + e.getValue()) //NOI18N + .collect(Collectors.joining(",")); //NOI18N + client.configurationUpdate(new UpdateConfigParams(CONFIG_SECTION, "env", values)); //NOI18N + return CompletableFuture.completedFuture(props); + } + + @Override + public Set<String> getCommands() { + return COMMANDS; + } +} diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java index 4658b9f..71debd3 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeClientWrapper.java @@ -192,4 +192,10 @@ class NbCodeClientWrapper implements NbCodeLanguageClient { public void notifyNodeChange(NodeChangedParams params) { remote.notifyNodeChange(params); } + + @Override + public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) { + return remote.configurationUpdate(params); + } + } diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java index a4f7408..09c6adf 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/NbCodeLanguageClient.java @@ -120,4 +120,13 @@ public interface NbCodeLanguageClient extends LanguageClient { public default boolean isRequestDispatcherThread() { return Boolean.TRUE.equals(Server.DISPATCHERS.get()); } + + /** + * Update a configuration value. The updated configuration values are persisted. + * + * @param params configuration update information. + */ + @JsonRequest("config/update") + public CompletableFuture<Void> configurationUpdate(@NonNull UpdateConfigParams params); + } diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java index 084b21e..61f9af1 100644 --- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java @@ -1005,6 +1005,12 @@ public final class Server { logWarning(params); return CompletableFuture.completedFuture(null); } + + @Override + public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) { + logWarning(params); + return CompletableFuture.completedFuture(null); + } }; diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/UpdateConfigParams.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/UpdateConfigParams.java new file mode 100644 index 0000000..64314b3 --- /dev/null +++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/UpdateConfigParams.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.java.lsp.server.protocol; + +import org.eclipse.lsp4j.jsonrpc.validation.NonNull; + +/** + * Information specifying configuration update. + * + * @author Jan Horvath + */ +public class UpdateConfigParams { + + /** + * Configuration name, supports dotted names. + */ + @NonNull + String section; + + /** + * Configuration name, supports dotted names. + */ + String key; + + /** + * The new value. + */ + String value; + + public UpdateConfigParams(String section, String key, String value) { + this.section = section; + this.key = key; + this.value = value; + } + + public String getSection() { + return section; + } + + public void setSection(String section) { + this.section = section; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + +} diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java index 607f9f6..abfa6eb 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/TestCodeLanguageClient.java @@ -42,6 +42,7 @@ import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams; import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams; import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams; import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams; +import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams; public abstract class TestCodeLanguageClient implements NbCodeLanguageClient { @@ -136,4 +137,10 @@ public abstract class TestCodeLanguageClient implements NbCodeLanguageClient { public void notifyNodeChange(NodeChangedParams params) { throw new UnsupportedOperationException(); } + + @Override + public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) { + throw new UnsupportedOperationException(); + } + } diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java index a5b63be..5dc3a03 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/explorer/ProjectViewTest.java @@ -76,6 +76,7 @@ import org.netbeans.modules.java.lsp.server.protocol.ShowInputBoxParams; import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams; import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams; import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams; +import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams; import org.netbeans.modules.parsing.api.ResultIterator; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -252,6 +253,11 @@ public class ProjectViewTest extends NbTestCase { client.nodeChanges.drainPermits(); } } + + @Override + public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) { + return CompletableFuture.completedFuture(null); + } } private static Launcher<NbLanguageServer> createLauncher(NbCodeLanguageClient client, InputStream in, OutputStream out, diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java index 6575dd5..a68bcbb 100644 --- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java +++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/progress/TestProgressHandlerTest.java @@ -49,6 +49,7 @@ import org.netbeans.modules.java.lsp.server.protocol.ShowQuickPickParams; import org.netbeans.modules.java.lsp.server.protocol.ShowStatusMessageParams; import org.netbeans.modules.java.lsp.server.protocol.TestProgressParams; import org.netbeans.modules.java.lsp.server.protocol.TestSuiteInfo; +import org.netbeans.modules.java.lsp.server.protocol.UpdateConfigParams; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; @@ -221,5 +222,10 @@ public class TestProgressHandlerTest extends NbTestCase { fail(); } + @Override + public CompletableFuture<Void> configurationUpdate(UpdateConfigParams params) { + return CompletableFuture.completedFuture(null); + } + } } diff --git a/java/java.lsp.server/vscode/package.json b/java/java.lsp.server/vscode/package.json index 17da32c..a972753 100644 --- a/java/java.lsp.server/vscode/package.json +++ b/java/java.lsp.server/vscode/package.json @@ -512,6 +512,11 @@ { "command": "nbls:Tools:org.netbeans.modules.cloud.oracle.actions.CreateAutonomousDBAction", "title": "Create Autonomous Database" + }, + { + "command": "java.db.set.env", + "title": "Set Database Environment Variables", + "category": "Database" } ], "keybindings": [ diff --git a/java/java.lsp.server/vscode/src/extension.ts b/java/java.lsp.server/vscode/src/extension.ts index 2ea7e43..df666be 100644 --- a/java/java.lsp.server/vscode/src/extension.ts +++ b/java/java.lsp.server/vscode/src/extension.ts @@ -47,14 +47,17 @@ import {NbTestAdapter} from './testAdapter'; import { asRanges, StatusMessageRequest, ShowStatusMessageParams, QuickPickRequest, InputBoxRequest, TestProgressNotification, DebugConnector, TextEditorDecorationCreateRequest, TextEditorDecorationSetNotification, TextEditorDecorationDisposeNotification, HtmlPageRequest, HtmlPageParams, SetTextEditorDecorationParams, - ProjectActionParams + ProjectActionParams, + UpdateConfigurationRequest, + UpdateConfigParams } from './protocol'; import * as launchConfigurations from './launchConfigurations'; import { createTreeViewService, TreeViewService, TreeItemDecorator, Visualizer, CustomizableTreeDataProvider } from './explorer'; -import { initializeRunConfiguration, runConfigurationProvider, runConfigurationNodeProvider, configureRunSettings } from './runConfiguration'; +import { initializeRunConfiguration, runConfigurationProvider, runConfigurationNodeProvider, configureRunSettings, runConfigurationUpdateAll } from './runConfiguration'; import { TLSSocket } from 'tls'; const API_VERSION : string = "1.0"; +const DATABASE: string = 'Database'; let client: Promise<NbLanguageClient>; let testAdapter: NbTestAdapter | undefined; let nbProcess : ChildProcess | null = null; @@ -774,6 +777,10 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex const selected = await window.showQuickPick(param.items, { placeHolder: param.placeHolder, canPickMany: param.canPickMany }); return selected ? Array.isArray(selected) ? selected : [selected] : undefined; }); + c.onRequest(UpdateConfigurationRequest.type, async (param) => { + await vscode.workspace.getConfiguration(param.section).update(param.key, param.value); + runConfigurationUpdateAll(); + }); c.onRequest(InputBoxRequest.type, async param => { return await window.showInputBox({ prompt: param.prompt, value: param.value, password: param.password }); }); diff --git a/java/java.lsp.server/vscode/src/protocol.ts b/java/java.lsp.server/vscode/src/protocol.ts index 00d462c..de6a61c 100644 --- a/java/java.lsp.server/vscode/src/protocol.ts +++ b/java/java.lsp.server/vscode/src/protocol.ts @@ -47,6 +47,19 @@ export interface ShowStatusMessageParams extends ShowMessageParams { timeout?: number; } +export interface UpdateConfigParams { + /** + * Information specifying configuration update. + */ + section: string; + key: string; + value: string; +} + +export namespace UpdateConfigurationRequest { + export const type = new ProtocolRequestType<UpdateConfigParams, void, never, void, void>('config/update'); +} + export namespace StatusMessageRequest { export const type = new ProtocolNotificationType<ShowStatusMessageParams, void>('window/showStatusBarMessage'); }; diff --git a/java/java.lsp.server/vscode/src/runConfiguration.ts b/java/java.lsp.server/vscode/src/runConfiguration.ts index b0dbfa6..c4ec096 100644 --- a/java/java.lsp.server/vscode/src/runConfiguration.ts +++ b/java/java.lsp.server/vscode/src/runConfiguration.ts @@ -159,12 +159,15 @@ class RunConfigurationNode extends vscode.TreeItem { this.value = value; this.getConfig().update(this.settingsKey, this.value, false); this.updateNode(); - runConfigurationNodeProvider.refresh(); } - updateNode() { - this.description = this.value ? this.value : '<default>'; - this.tooltip = `${this.label} ${this.description}`; + updateNode(reload?: boolean) { + if (reload) { + this.value = this.getConfig().get(this.settingsKey) as string; + } + this.description = this.value ? this.value : '<default>'; + this.tooltip = `${this.label} ${this.description}`; + runConfigurationNodeProvider.refresh(); } getConfig(): vscode.WorkspaceConfiguration { @@ -219,3 +222,9 @@ export function configureRunSettings(context: vscode.ExtensionContext, ...params (params[0][0] as RunConfigurationNode).configure(context); } } +export function runConfigurationUpdateAll() { + argumentsNode.updateNode(true); + vmOptionsNode.updateNode(true); + environmentVariablesNode.updateNode(true); + workingDirectoryNode.updateNode(true); +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists