Skip to content

Commit 77059a3

Browse files
committed
add dependendies and missing codes.
1 parent 05a53fd commit 77059a3

File tree

10 files changed

+208
-6
lines changed

10 files changed

+208
-6
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ dependencies {
211211
compile group: 'com.jcraft', name: 'jsch', version: '0.1.55'
212212
compile group: 'com.neovisionaries', name: 'nv-websocket-client', version: '2.9'
213213
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.23'
214+
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '9.3.1.jre8-preview'
214215

215216
testCompile 'junit:junit:4.13'
216217
testCompile 'info.cukes:cucumber-junit:1.2.6'

PluginsAndFeatures/azure-toolkit-for-intellij/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<fileEditorProvider implementation="com.microsoft.azure.toolkit.intellij.arm.ResourceTemplateViewProvider"/>
9696
<fileEditorProvider implementation="com.microsoft.azure.toolkit.intellij.springcloud.properties.SpringCloudAppPropertiesEditorProvider"/>
9797
<fileEditorProvider implementation="com.microsoft.azure.toolkit.intellij.mysql.MySQLPropertyViewProvider"/>
98+
<fileEditorProvider implementation="com.microsoft.azure.toolkit.intellij.sqlserver.properties.SqlServerPropertyViewProvider"/>
9899
<toolWindow
99100
anchor="left"
100101
factoryClass="com.microsoft.intellij.ui.ServerExplorerToolWindowFactory"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common;
7+
8+
import com.intellij.ide.plugins.PluginManagerCore;
9+
import com.intellij.openapi.extensions.PluginId;
10+
import com.intellij.openapi.project.Project;
11+
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
12+
import lombok.Builder;
13+
import lombok.Getter;
14+
import org.apache.commons.lang3.reflect.MethodUtils;
15+
16+
import java.lang.reflect.Constructor;
17+
import java.lang.reflect.InvocationTargetException;
18+
19+
public class IntellijDatasourceService {
20+
21+
private static final String DATABASE_TOOLS_PLUGIN_ID = "com.intellij.database";
22+
private static final String NOT_SUPPORT_ERROR_MESSAGE = "detect database plugin in your IDE.";
23+
private static final String NOT_SUPPORT_ERROR_ACTION = "note this action is only supported in Intellij Ultimate edition.";
24+
private static final String ERROR_MESSAGE_PATTERN = "Failed to open datasource management dialog for %s";
25+
private static final String ERROR_ACTION = "please try again.";
26+
private static final IntellijDatasourceService instance = new IntellijDatasourceService();
27+
28+
public static IntellijDatasourceService getInstance() {
29+
return IntellijDatasourceService.instance;
30+
}
31+
32+
private IntellijDatasourceService() {
33+
}
34+
35+
public void openDataSourceManagerDialog(Project project, DatasourceProperties properties) {
36+
if (PluginManagerCore.getPlugin(PluginId.findId(DATABASE_TOOLS_PLUGIN_ID)) == null) {
37+
throw new AzureToolkitRuntimeException(NOT_SUPPORT_ERROR_MESSAGE, NOT_SUPPORT_ERROR_ACTION);
38+
}
39+
Object registry = getDataSourceRegistry(project, properties);
40+
Object dbPsiFacade = getDbPsiFacade(project, properties);
41+
try {
42+
Object builder = MethodUtils.invokeMethod(registry, "getBuilder");
43+
MethodUtils.invokeMethod(builder, true, "withName", properties.getName());
44+
MethodUtils.invokeMethod(builder, true, "withDriverClass", properties.getDriverClassName());
45+
MethodUtils.invokeMethod(builder, true, "withUrl", properties.getUrl());
46+
MethodUtils.invokeMethod(builder, true, "withUser", properties.getUsername());
47+
MethodUtils.invokeMethod(builder, true, "commit");
48+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
49+
throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
50+
}
51+
showDataSourceManagerDialog(dbPsiFacade, registry, properties);
52+
}
53+
54+
private Object getDataSourceRegistry(Project project, DatasourceProperties properties) {
55+
try {
56+
Class[] parameterTypes = {Project.class};
57+
Class dataSourceRegistryClazz = Class.forName("com.intellij.database.autoconfig.DataSourceRegistry");
58+
Constructor constructor = dataSourceRegistryClazz.getConstructor(parameterTypes);
59+
return constructor.newInstance(project);
60+
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
61+
throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
62+
}
63+
}
64+
65+
private Object getDbPsiFacade(Object project, DatasourceProperties properties) {
66+
try {
67+
Class dbPsiFacadeClass = Class.forName("com.intellij.database.psi.DbPsiFacade");
68+
return MethodUtils.invokeStaticMethod(dbPsiFacadeClass, "getInstance", project);
69+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
70+
throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
71+
}
72+
}
73+
74+
private void showDataSourceManagerDialog(Object dbPsiFacade, Object registry, DatasourceProperties properties) {
75+
try {
76+
Class dataSourceManagerDialogClazz = Class.forName("com.intellij.database.view.ui.DataSourceManagerDialog");
77+
MethodUtils.invokeStaticMethod(dataSourceManagerDialogClazz, "showDialog", dbPsiFacade, registry);
78+
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
79+
throw new AzureToolkitRuntimeException(String.format(ERROR_MESSAGE_PATTERN, properties.getName()), ERROR_ACTION);
80+
}
81+
}
82+
83+
@Builder
84+
@Getter
85+
public static class DatasourceProperties {
86+
private String name;
87+
@Builder.Default
88+
private String driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
89+
private String url;
90+
private String username;
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.sqlserver.properties;
7+
8+
import com.intellij.openapi.fileEditor.FileEditor;
9+
import com.intellij.openapi.fileEditor.FileEditorPolicy;
10+
import com.intellij.openapi.fileEditor.FileEditorProvider;
11+
import com.intellij.openapi.project.DumbAware;
12+
import com.intellij.openapi.project.Project;
13+
import com.intellij.openapi.vfs.VirtualFile;
14+
import org.jetbrains.annotations.NotNull;
15+
16+
public class SqlServerPropertyViewProvider implements FileEditorProvider, DumbAware {
17+
18+
public static final String TYPE = "SQL_SERVER_PROPERTY_VIEW";
19+
20+
@Override
21+
public boolean accept(@NotNull Project project, @NotNull VirtualFile virtualFile) {
22+
return virtualFile.getFileType().getName().equals(TYPE);
23+
}
24+
25+
@NotNull
26+
@Override
27+
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile virtualFile) {
28+
SqlServerPropertyView propertyView = new SqlServerPropertyView();
29+
return propertyView;
30+
}
31+
32+
@NotNull
33+
@Override
34+
public String getEditorTypeId() {
35+
return TYPE;
36+
}
37+
38+
@NotNull
39+
@Override
40+
public FileEditorPolicy getPolicy() {
41+
return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
42+
}
43+
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/helpers/UIHelperImpl.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.microsoft.azure.toolkit.intellij.redis.RedisCachePropertyView;
3636
import com.microsoft.azure.toolkit.intellij.redis.RedisCachePropertyViewProvider;
3737
import com.microsoft.azure.toolkit.intellij.springcloud.properties.SpringCloudAppPropertiesEditorProvider;
38+
import com.microsoft.azure.toolkit.intellij.sqlserver.properties.SqlServerPropertyViewProvider;
39+
import com.microsoft.azure.toolkit.intellij.sqlserver.properties.SqlServerPropertyView;
3840
import com.microsoft.azure.toolkit.intellij.webapp.DeploymentSlotPropertyViewProvider;
3941
import com.microsoft.azure.toolkit.intellij.webapp.WebAppPropertyViewProvider;
4042
import com.microsoft.azure.toolkit.intellij.webapp.docker.ContainerRegistryPropertyView;
@@ -44,6 +46,7 @@
4446
import com.microsoft.azure.toolkit.lib.springcloud.AzureSpringCloud;
4547
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudApp;
4648
import com.microsoft.azure.toolkit.lib.springcloud.SpringCloudCluster;
49+
import com.microsoft.azure.toolkit.lib.sqlserver.model.SqlServerEntity;
4750
import com.microsoft.azuretools.ActionConstants;
4851
import com.microsoft.azuretools.azurecommons.helpers.AzureCmdException;
4952
import com.microsoft.azuretools.azurecommons.helpers.NotNull;
@@ -77,6 +80,7 @@
7780
import com.microsoft.tooling.msservices.serviceexplorer.azure.mysql.MySQLNode;
7881
import com.microsoft.tooling.msservices.serviceexplorer.azure.rediscache.RedisCacheNode;
7982
import com.microsoft.tooling.msservices.serviceexplorer.azure.springcloud.SpringCloudAppNode;
83+
import com.microsoft.tooling.msservices.serviceexplorer.azure.sqlserver.SqlServerNode;
8084
import com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.WebAppNode;
8185
import com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.deploymentslot.DeploymentSlotNode;
8286
import org.apache.commons.lang.ArrayUtils;
@@ -600,6 +604,31 @@ public void openMySQLPropertyView(@NotNull MySQLNode node) {
600604
});
601605
}
602606

607+
@Override
608+
public void openSqlServerPropertyView(@NotNull SqlServerNode node) {
609+
EventUtil.executeWithLog(ActionConstants.SqlServer.SHOW_PROPERTIES, (operation) -> {
610+
String name = node.getName();
611+
String subscriptionId = node.getSubscriptionId();
612+
String nodeId = node.getId();
613+
final FileEditorManager fileEditorManager = getFileEditorManager(subscriptionId, nodeId, (Project) node.getProject());
614+
if (fileEditorManager == null) {
615+
return;
616+
}
617+
LightVirtualFile itemVirtualFile = searchExistingFile(fileEditorManager, SqlServerPropertyViewProvider.TYPE, nodeId);
618+
if (itemVirtualFile == null) {
619+
itemVirtualFile = createVirtualFile(name, subscriptionId, nodeId);
620+
itemVirtualFile.setFileType(new AzureFileType(SqlServerPropertyViewProvider.TYPE, AzureIconLoader.loadIcon(AzureIconSymbol.SqlServer.MODULE)));
621+
}
622+
FileEditor[] editors = fileEditorManager.openFile(itemVirtualFile, true, true);
623+
for (FileEditor editor : editors) {
624+
if (editor.getName().equals(SqlServerPropertyView.ID) && editor instanceof SqlServerPropertyView) {
625+
SqlServerEntity entity = node.getServer().entity();
626+
((SqlServerPropertyView) editor).onReadProperty(subscriptionId, entity.getResourceGroup(), entity.getName());
627+
}
628+
}
629+
});
630+
}
631+
603632
@Nullable
604633
@Override
605634
public <T extends StorageServiceTreeItem> Object getOpenedFile(@NotNull Object projectObject,

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/serviceexplorer/NodeActionsMap.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import com.microsoft.azure.toolkit.intellij.function.action.CreateFunctionAppAction;
1313
import com.microsoft.azure.toolkit.intellij.function.action.DeployFunctionAppAction;
1414
import com.microsoft.azure.toolkit.intellij.mysql.action.CreateMySQLAction;
15-
import com.microsoft.azure.toolkit.intellij.mysql.action.MySQLConnectToServerAction;
15+
import com.microsoft.azure.toolkit.intellij.mysql.action.OpenMySQLByToolsAction;
1616
import com.microsoft.azure.toolkit.intellij.connector.mysql.ConnectToMySQLAction;
1717
import com.microsoft.azure.toolkit.intellij.sqlserver.CreateSqlServerAction;
18+
import com.microsoft.azure.toolkit.intellij.sqlserver.OpenSqlServerByToolsAction;
1819
import com.microsoft.azure.toolkit.intellij.webapp.action.CreateWebAppAction;
1920
import com.microsoft.azure.toolkit.intellij.webapp.action.DeployWebAppAction;
2021
import com.microsoft.azure.toolkit.intellij.appservice.action.ProfileFlightRecordAction;
@@ -49,6 +50,7 @@
4950
import com.microsoft.tooling.msservices.serviceexplorer.azure.rediscache.RedisCacheModule;
5051
import com.microsoft.tooling.msservices.serviceexplorer.azure.springcloud.SpringCloudAppNode;
5152
import com.microsoft.tooling.msservices.serviceexplorer.azure.sqlserver.SqlServerModule;
53+
import com.microsoft.tooling.msservices.serviceexplorer.azure.sqlserver.SqlServerNode;
5254
import com.microsoft.tooling.msservices.serviceexplorer.azure.storage.ExternalStorageNode;
5355
import com.microsoft.tooling.msservices.serviceexplorer.azure.storage.QueueModule;
5456
import com.microsoft.tooling.msservices.serviceexplorer.azure.storage.StorageModule;
@@ -122,7 +124,10 @@ public class NodeActionsMap {
122124
.add(StartStreamingLogsAction.class).add(StopStreamingLogsAction.class).add(DeployFunctionAppAction.class).build());
123125

124126
node2Actions.put(MySQLNode.class, new ImmutableList.Builder<Class<? extends NodeActionListener>>()
125-
.add(MySQLConnectToServerAction.class).add(ConnectToMySQLAction.class).build());
127+
.add(OpenMySQLByToolsAction.class).add(ConnectToMySQLAction.class).build());
128+
129+
node2Actions.put(SqlServerNode.class, new ImmutableList.Builder<Class<? extends NodeActionListener>>()
130+
.add(OpenSqlServerByToolsAction.class).build());
126131

127132
node2Actions.put(WebAppNode.class, new ImmutableList.Builder<Class<? extends NodeActionListener>>()
128133
.add(StartStreamingLogsAction.class).add(StopStreamingLogsAction.class).add(SSHIntoWebAppAction.class)

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/helpers/UIHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.microsoft.tooling.msservices.serviceexplorer.azure.mysql.MySQLNode;
2121
import com.microsoft.tooling.msservices.serviceexplorer.azure.rediscache.RedisCacheNode;
2222
import com.microsoft.tooling.msservices.serviceexplorer.azure.springcloud.SpringCloudAppNode;
23+
import com.microsoft.tooling.msservices.serviceexplorer.azure.sqlserver.SqlServerNode;
2324
import com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.WebAppNode;
2425
import com.microsoft.tooling.msservices.serviceexplorer.azure.webapp.deploymentslot.DeploymentSlotNode;
2526

@@ -102,6 +103,10 @@ default void openMySQLPropertyView(@NotNull MySQLNode node) {
102103

103104
}
104105

106+
default void openSqlServerPropertyView(@NotNull SqlServerNode node) {
107+
108+
}
109+
105110
@Nullable
106111
<T extends StorageServiceTreeItem> Object getOpenedFile(@NotNull Object projectObject,
107112
@NotNull String accountName,

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/AzureIconSymbol.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public interface SqlServer {
6464
AzureIconSymbol RUNNING = fillInPath("SqlServer/SqlServerRunning.svg");
6565
AzureIconSymbol STOPPED = fillInPath("SqlServer/SqlServerStopped.svg");
6666
AzureIconSymbol UPDATING = fillInPath("SqlServer/SqlServerUpdating.svg");
67+
68+
AzureIconSymbol CONNECT_TO_SERVER = fillInPath("SqlServer/ConnectToServer.svg");
69+
AzureIconSymbol BIND_INTO = fillInPath("SqlServer/BindInto.svg");
6770
}
6871

6972
public interface WebApp {

Utils/azure-explorer-common/src/com/microsoft/tooling/msservices/serviceexplorer/azure/sqlserver/SqlServerNode.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
import com.microsoft.azuretools.ActionConstants;
1111
import com.microsoft.azuretools.azurecommons.helpers.Nullable;
1212
import com.microsoft.azuretools.telemetry.TelemetryProperties;
13+
import com.microsoft.tooling.msservices.components.DefaultLoader;
1314
import com.microsoft.tooling.msservices.serviceexplorer.AzureActionEnum;
1415
import com.microsoft.tooling.msservices.serviceexplorer.AzureIconSymbol;
1516
import com.microsoft.tooling.msservices.serviceexplorer.AzureRefreshableNode;
1617
import com.microsoft.tooling.msservices.serviceexplorer.BasicActionBuilder;
1718
import com.microsoft.tooling.msservices.serviceexplorer.Node;
1819
import com.microsoft.tooling.msservices.serviceexplorer.NodeAction;
20+
import lombok.Getter;
1921

2022
import java.util.Collections;
2123
import java.util.List;
@@ -24,7 +26,9 @@
2426
public class SqlServerNode extends Node implements TelemetryProperties {
2527
private static final String SERVER_READY = "Ready";
2628
private static final String SERVER_UPDATING = "Updating";
29+
@Getter
2730
private final String subscriptionId;
31+
@Getter
2832
private final ISqlServer server;
2933
private String serverState;
3034

@@ -75,10 +79,7 @@ private void openInPortal() {
7579

7680
@AzureOperation(name = ActionConstants.MySQL.SHOW_PROPERTIES, type = AzureOperation.Type.ACTION)
7781
private void showProperties() {
78-
/**
79-
* TODO: implementation
80-
*/
81-
// DefaultLoader.getUIHelper().openMySQLPropertyView(MySQLNode.this);
82+
DefaultLoader.getUIHelper().openSqlServerPropertyView(SqlServerNode.this);
8283
}
8384

8485
@Override
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.tooling.msservices.serviceexplorer.azure.sqlserver;
7+
8+
import com.microsoft.azure.toolkit.lib.sqlserver.model.SqlFirewallRuleEntity;
9+
import com.microsoft.azure.toolkit.lib.sqlserver.service.ISqlServer;
10+
import lombok.Getter;
11+
import lombok.Setter;
12+
13+
import java.util.List;
14+
15+
@Getter
16+
@Setter
17+
public class SqlServerProperty {
18+
19+
private ISqlServer server;
20+
private List<SqlFirewallRuleEntity> firewallRules;
21+
22+
}

0 commit comments

Comments
 (0)