Skip to content

Commit 367aef2

Browse files
Merge pull request #7737 from microsoft/hanli/fixes-202307
Workaround to swallow exception during DBTools workarounds
2 parents 7429863 + 7a57099 commit 367aef2

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/java/com/microsoft/azure/toolkit/intellij/cosmos/dbtools/DbToolsWorkaround.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
import com.intellij.database.dataSource.DatabaseDriverManagerImpl;
1111
import com.intellij.database.dataSource.url.ui.UrlPropertiesPanel;
1212
import com.intellij.openapi.application.ApplicationManager;
13-
import com.intellij.openapi.application.PreloadingActivity;
13+
import com.intellij.openapi.project.DumbAware;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.openapi.startup.ProjectActivity;
1416
import com.intellij.openapi.util.JDOMUtil;
1517
import com.intellij.openapi.util.registry.Registry;
1618
import com.microsoft.azure.toolkit.intellij.common.IntelliJAzureIcons;
19+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
20+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
21+
import kotlin.Unit;
22+
import kotlin.coroutines.Continuation;
1723
import lombok.SneakyThrows;
1824
import org.apache.commons.lang3.StringUtils;
1925
import org.apache.commons.lang3.reflect.FieldUtils;
@@ -22,11 +28,12 @@
2228
import javax.annotation.Nonnull;
2329
import java.lang.reflect.Field;
2430
import java.net.URL;
31+
import java.util.HashMap;
2532
import java.util.List;
2633
import java.util.Objects;
2734
import java.util.Optional;
2835

29-
public class DbToolsWorkaround extends PreloadingActivity {
36+
public class DbToolsWorkaround implements ProjectActivity, DumbAware {
3037
private static final String PARAM_NAME = "account";
3138
public static final String COSMOS_MONGO_ICON = "icons/Microsoft.DocumentDB/databaseAccounts/mongo.svg";
3239
public static final String COSMOS_MONGO_DRIVER_ID = "az_cosmos_mongo";
@@ -36,12 +43,18 @@ public class DbToolsWorkaround extends PreloadingActivity {
3643
public static final String COSMOS_CASSANDRA_DRIVER_CONFIG = "databaseDrivers/azure-cosmos-cassandra-drivers.xml";
3744

3845
@Override
39-
public void preload() {
46+
public Object execute(@Nonnull Project project, @Nonnull Continuation<? super Unit> continuation) {
4047
ApplicationManager.getApplication().executeOnPooledThread(() -> {
41-
DbToolsWorkaround.makeAccountShowAtTop();
42-
loadMongoDriver();
43-
loadCassandraDriver();
48+
try {
49+
DbToolsWorkaround.makeAccountShowAtTop();
50+
loadMongoDriver();
51+
loadCassandraDriver();
52+
} catch (final Throwable t) {
53+
// swallow exception for preloading workarounds
54+
AzureTelemeter.log(AzureTelemetry.Type.ERROR, new HashMap<>(), t);
55+
}
4456
});
57+
return null;
4558
}
4659

4760
private static void loadMongoDriver() {

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-cosmos/src/main/resources/META-INF/azure-intellij-plugin-cosmos-dbtools.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<registryKey key="azure.toolkit.cosmos_cassandra.dbtools.enabled"
1616
description="Enables DB tools related features of Azure cosmos DB API for cassandra"
1717
restartRequired="true" defaultValue="false"/>
18-
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.cosmos.dbtools.DbToolsWorkaround"/>
18+
<postStartupActivity implementation="com.microsoft.azure.toolkit.intellij.cosmos.dbtools.DbToolsWorkaround"/>
1919
</extensions>
2020
<extensions defaultExtensionNs="com.microsoft.tooling.msservices.intellij.azure">
2121
<actions implementation="com.microsoft.azure.toolkit.intellij.cosmos.IntelliJCosmosActionsContributorForUltimate"/>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-database/src/main/java/com/microsoft/azure/toolkit/intellij/database/dbtools/DatabaseDbToolsWorkaround.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,38 @@
99
import com.intellij.database.dataSource.DatabaseDriverManager;
1010
import com.intellij.database.dataSource.url.template.UrlTemplate;
1111
import com.intellij.openapi.application.ApplicationManager;
12-
import com.intellij.openapi.application.PreloadingActivity;
12+
import com.intellij.openapi.project.DumbAware;
13+
import com.intellij.openapi.project.Project;
14+
import com.intellij.openapi.startup.ProjectActivity;
15+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
16+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
17+
import kotlin.Unit;
18+
import kotlin.coroutines.Continuation;
1319

20+
import javax.annotation.Nonnull;
21+
import javax.annotation.Nullable;
22+
import java.util.HashMap;
1423
import java.util.LinkedList;
1524
import java.util.List;
1625
import java.util.Objects;
1726

18-
public class DatabaseDbToolsWorkaround extends PreloadingActivity {
27+
public class DatabaseDbToolsWorkaround implements ProjectActivity, DumbAware {
28+
29+
@Nullable
1930
@Override
20-
public void preload() {
31+
public Object execute(@Nonnull Project project, @Nonnull Continuation<? super Unit> continuation) {
2132
ApplicationManager.getApplication().executeOnPooledThread(() -> {
22-
loadMySqlAzureTemplates();
23-
loadPostgreSqlAzureTemplates();
24-
loadSqlServerAzureTemplates();
25-
loadAzureSqlDatabaseAzureTemplates();
33+
try {
34+
loadMySqlAzureTemplates();
35+
loadPostgreSqlAzureTemplates();
36+
loadSqlServerAzureTemplates();
37+
loadAzureSqlDatabaseAzureTemplates();
38+
} catch (final Throwable t) {
39+
// swallow exception for preloading workarounds
40+
AzureTelemeter.log(AzureTelemetry.Type.ERROR, new HashMap<>(), t);
41+
}
2642
});
43+
return null;
2744
}
2845

2946
private static void loadMySqlAzureTemplates() {

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-database/src/main/resources/META-INF/azure-intellij-plugin-database-dbtools.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<urlParamEditorUiProvider implementation="com.microsoft.azure.toolkit.intellij.database.dbtools.DatabaseServerTypeUIFactory" order="first"/>
66
</extensions>
77
<extensions defaultExtensionNs="com.intellij">
8-
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.database.dbtools.DatabaseDbToolsWorkaround"/>
8+
<postStartupActivity implementation="com.microsoft.azure.toolkit.intellij.database.dbtools.DatabaseDbToolsWorkaround"/>
99
</extensions>
1010
</idea-plugin>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-resource-connector-lib/src/main/java/com/microsoft/azure/toolkit/intellij/connector/projectexplorer/AzureFacetTreeStructureProvider.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ public final class AzureFacetTreeStructureProvider implements TreeStructureProvi
5151
public AzureFacetTreeStructureProvider(Project project) {
5252
myProject = project;
5353
final AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
54-
final JTree tree = currentProjectViewPane.getTree();
55-
ClientProperty.put(tree, ANIMATION_IN_RENDERER_ALLOWED, true);
54+
Optional.ofNullable(currentProjectViewPane)
55+
.map(AbstractProjectViewPane::getTree)
56+
.ifPresent(tree -> ClientProperty.put(tree, ANIMATION_IN_RENDERER_ALLOWED, true));
5657
}
5758

5859
@Override
@@ -69,7 +70,6 @@ public Collection<AbstractTreeNode<?>> modify(@Nonnull AbstractTreeNode<?> paren
6970
final boolean defaultShow = state == null && Objects.nonNull(azureModule) && (azureModule.hasAzureFacet() || azureModule.isInitialized() || azureModule.hasAzureDependencies());
7071
if (!forceHide && (forceShow || defaultShow)) {
7172
addListener(parent.getProject());
72-
final AbstractProjectViewPane viewPane = ProjectView.getInstance(parent.getProject()).getCurrentProjectViewPane();
7373
final AbstractTreeNode<?> dotAzureDir = children.stream()
7474
.filter(n -> n instanceof PsiDirectoryNode)
7575
.map(n -> ((PsiDirectoryNode) n))
@@ -110,18 +110,15 @@ private Module toModule(final AbstractTreeNode<?> node) {
110110

111111
@RequiredArgsConstructor
112112
static class AzureProjectExplorerMouseListener extends MouseAdapter {
113-
private static final Separator SEPARATOR = new Separator();
114113
private final JTree tree;
115-
private final Project project;
116114

117115
private IAzureFacetNode currentNode;
118116
private List<AnAction> backupActions;
119117

120118
@Override
121119
public void mousePressed(MouseEvent e) {
122120
final AbstractTreeNode<?> currentTreeNode = getCurrentTreeNode(e);
123-
if (SwingUtilities.isLeftMouseButton(e) && currentTreeNode instanceof IAzureFacetNode) {
124-
final IAzureFacetNode node = (IAzureFacetNode) currentTreeNode;
121+
if (SwingUtilities.isLeftMouseButton(e) && currentTreeNode instanceof IAzureFacetNode node) {
125122
final DataContext context = DataManager.getInstance().getDataContext(tree);
126123
final AnActionEvent event = AnActionEvent.createFromAnAction(new EmptyAction(), e, ActionPlaces.PROJECT_VIEW_POPUP + ".click", context);
127124
if (e.getClickCount() == 1) {
@@ -146,14 +143,13 @@ public void mouseExited(MouseEvent e) {
146143

147144
private void modifyPopupActions(MouseEvent e) {
148145
final AbstractTreeNode<?> node = getCurrentTreeNode(e);
149-
if (!(node instanceof IAzureFacetNode)) {
146+
if (!(node instanceof IAzureFacetNode newNode)) {
150147
if (Objects.nonNull(currentNode)) {
151148
// clean up popup menu actions
152149
resetPopupMenuActions();
153150
}
154151
return;
155152
}
156-
final IAzureFacetNode newNode = (IAzureFacetNode) node;
157153
if (!Objects.equals(newNode, currentNode)) {
158154
// update popup menu actions for new node
159155
updatePopupMenuActions(newNode);
@@ -163,8 +159,6 @@ private void modifyPopupActions(MouseEvent e) {
163159

164160
private AbstractTreeNode<?> getCurrentTreeNode(MouseEvent e) {
165161
final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
166-
// final int rowForLocation = tree.getRowForLocation(e.getX(), e.getY());
167-
// final TreePath pathForRow = tree.getPathForRow(rowForLocation);
168162
return TreeUtil.getAbstractTreeNode(path);
169163
}
170164

@@ -201,7 +195,7 @@ private void addListener(@Nonnull final Project project) {
201195
if (!exists) {
202196
final MouseListener[] mouseListeners = tree.getMouseListeners();
203197
Arrays.stream(mouseListeners).forEach(tree::removeMouseListener);
204-
tree.addMouseListener(new AzureProjectExplorerMouseListener(tree, project));
198+
tree.addMouseListener(new AzureProjectExplorerMouseListener(tree));
205199
Arrays.stream(mouseListeners).forEach(tree::addMouseListener);
206200
}
207201
}

0 commit comments

Comments
 (0)