Skip to content

Commit d13692d

Browse files
committed
Fix maven report background thread exception and update logs
1 parent 49d50c6 commit d13692d

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-azuremcp/src/main/java/com/microsoft/azure/toolkit/intellij/azuremcp/AzureMcpPackageManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public synchronized File getAzureMcpExecutable() {
7777
}
7878
}
7979
} catch (final IOException e) {
80-
System.err.println("Error reading Azure MCP Server version: " + e.getMessage());
80+
log.error("Error getting Azure MCP executable: " + e.getMessage());
81+
AzureMcpUtils.logErrorTelemetryEvent("azmcp-get-executable", e);
8182
}
8283
return null;
8384
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.microsoft.azure.toolkit.intellij.azuremcp;
2+
3+
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
4+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
5+
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
6+
import org.apache.commons.lang3.exception.ExceptionUtils;
7+
8+
import java.util.Map;
9+
10+
public final class AzureMcpUtils {
11+
12+
private static final String GHCP_MCP_INITIALIZER = "GHCP_MCP_INITIALIZER";
13+
14+
private AzureMcpUtils() {
15+
}
16+
17+
public static void logTelemetryEvent(String eventName) {
18+
Map<String, String> properties = Map.of(
19+
AzureTelemeter.OP_NAME, eventName,
20+
AzureTelemeter.OP_PARENT_ID, GHCP_MCP_INITIALIZER,
21+
AzureTelemeter.OPERATION_NAME, eventName, // what's the difference between OP_NAME and OPERATION_NAME?
22+
AzureTelemeter.SERVICE_NAME, GHCP_MCP_INITIALIZER
23+
);
24+
AzureTaskManager.getInstance().runLater(() -> {
25+
AzureTelemeter.log(AzureTelemetry.Type.INFO, properties);
26+
});
27+
}
28+
29+
public static void logErrorTelemetryEvent(String eventName, Exception ex) {
30+
Map<String, String> properties = Map.of(
31+
AzureTelemeter.OP_NAME, eventName,
32+
AzureTelemeter.OP_PARENT_ID, GHCP_MCP_INITIALIZER,
33+
AzureTelemeter.OPERATION_NAME, eventName, // what's the difference between OP_NAME and OPERATION_NAME?
34+
AzureTelemeter.SERVICE_NAME, GHCP_MCP_INITIALIZER,
35+
AzureTelemeter.ERROR_STACKTRACE, ExceptionUtils.getStackTrace(ex)
36+
);
37+
AzureTaskManager.getInstance().runLater(() -> {
38+
AzureTelemeter.log(AzureTelemetry.Type.ERROR, properties);
39+
});
40+
}
41+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-azuremcp/src/main/java/com/microsoft/azure/toolkit/intellij/azuremcp/GithubCopilotMcpInitializer.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313
import com.intellij.openapi.startup.ProjectActivity;
1414
import com.intellij.openapi.util.SystemInfo;
1515
import com.intellij.openapi.util.registry.Registry;
16-
import com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager;
17-
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter;
18-
import com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry;
1916
import kotlin.Unit;
2017
import kotlin.coroutines.Continuation;
2118
import lombok.extern.slf4j.Slf4j;
22-
import org.apache.commons.lang3.exception.ExceptionUtils;
2319
import org.apache.maven.artifact.versioning.ComparableVersion;
2420
import org.jetbrains.annotations.NotNull;
2521

@@ -30,6 +26,9 @@
3026
import java.util.HashMap;
3127
import java.util.Map;
3228

29+
import static com.microsoft.azure.toolkit.intellij.azuremcp.AzureMcpUtils.logErrorTelemetryEvent;
30+
import static com.microsoft.azure.toolkit.intellij.azuremcp.AzureMcpUtils.logTelemetryEvent;
31+
3332
@Slf4j
3433
public class GithubCopilotMcpInitializer implements ProjectActivity, DumbAware, ProjectManagerListener {
3534
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
@@ -39,7 +38,6 @@ public class GithubCopilotMcpInitializer implements ProjectActivity, DumbAware,
3938
.enable(SerializationFeature.INDENT_OUTPUT);
4039

4140
private static final ComparableVersion LOWEST_SUPPORTED_COPILOT_VERSION = new ComparableVersion("1.5.50");
42-
private static final String GHCP_MCP_INITIALIZER = "GitHubCopilotMcpInitializer";
4341
private static final String COPILOT_PLUGIN_ID = "com.github.copilot";
4442
private final AzureMcpPackageManager azureMcpPackageManager;
4543

@@ -71,7 +69,7 @@ public Object execute(@NotNull Project project, @NotNull Continuation<? super Un
7169
private boolean isCopilotMcpSupported() {
7270
// Get all installed plugins
7371
final IdeaPluginDescriptor[] installedPlugins = PluginManagerCore.getPlugins();
74-
boolean copilotMcpSupported = Arrays.stream(installedPlugins)
72+
final boolean copilotMcpSupported = Arrays.stream(installedPlugins)
7573
.anyMatch(plugin -> {
7674
final boolean copilotPluginInstalled = COPILOT_PLUGIN_ID.equals(plugin.getPluginId().getIdString());
7775
return copilotPluginInstalled && isMcpSupported(plugin.getVersion());
@@ -156,29 +154,4 @@ private File getConfigPath() {
156154
}
157155
return configPath;
158156
}
159-
160-
public static void logTelemetryEvent(String eventName) {
161-
Map<String, String> properties = Map.of(
162-
AzureTelemeter.OP_NAME, eventName,
163-
AzureTelemeter.OP_PARENT_ID, GHCP_MCP_INITIALIZER,
164-
AzureTelemeter.OPERATION_NAME, eventName, // what's the difference between OP_NAME and OPERATION_NAME?
165-
AzureTelemeter.SERVICE_NAME, GHCP_MCP_INITIALIZER
166-
);
167-
AzureTaskManager.getInstance().runLater(() -> {
168-
AzureTelemeter.log(AzureTelemetry.Type.INFO, properties);
169-
});
170-
}
171-
172-
public static void logErrorTelemetryEvent(String eventName, Exception ex) {
173-
Map<String, String> properties = Map.of(
174-
AzureTelemeter.OP_NAME, eventName,
175-
AzureTelemeter.OP_PARENT_ID, GHCP_MCP_INITIALIZER,
176-
AzureTelemeter.OPERATION_NAME, eventName, // what's the difference between OP_NAME and OPERATION_NAME?
177-
AzureTelemeter.SERVICE_NAME, GHCP_MCP_INITIALIZER,
178-
AzureTelemeter.ERROR_STACKTRACE, ExceptionUtils.getStackTrace(ex)
179-
);
180-
AzureTaskManager.getInstance().runLater(() -> {
181-
AzureTelemeter.log(AzureTelemetry.Type.ERROR, properties);
182-
});
183-
}
184157
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-java-sdk/src/main/java/com/microsoft/azure/toolkit/intellij/java/sdk/MavenProjectReportGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public MavenProjectReportGenerator() {
8383
@Nullable
8484
@Override
8585
public Object execute(@Nonnull Project project, @Nonnull Continuation<? super Unit> continuation) {
86-
scheduledExecutor.schedule(() -> generateReport(project), INITIAL_DELAY_IN_MINUTES, TimeUnit.MINUTES);
86+
scheduledExecutor.schedule(() -> ApplicationManager.getApplication().runReadAction(() -> generateReport(project)),
87+
INITIAL_DELAY_IN_MINUTES, TimeUnit.MINUTES);
8788
return null;
8889
}
8990

0 commit comments

Comments
 (0)