From 846e27fd701211f0711f2925e6eae52010abcd65 Mon Sep 17 00:00:00 2001 From: Shalom Ben Zvi Kazaz Date: Wed, 18 Dec 2024 11:24:46 +0200 Subject: [PATCH] logging --- .../analytics/ConnectionTestResult.java | 35 ----------- .../intellij/plugin/updates/UpdatesService.kt | 60 +++++++++++-------- .../plugin/updates/ui/UIVersioningService.kt | 6 +- .../RecentActivityMessagesUtils.kt | 16 ----- .../model/ConnectionTestResultMessage.kt | 5 -- 5 files changed, 39 insertions(+), 83 deletions(-) delete mode 100644 ide-common/src/main/java/org/digma/intellij/plugin/analytics/ConnectionTestResult.java delete mode 100644 src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/RecentActivityMessagesUtils.kt delete mode 100644 src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/model/ConnectionTestResultMessage.kt diff --git a/ide-common/src/main/java/org/digma/intellij/plugin/analytics/ConnectionTestResult.java b/ide-common/src/main/java/org/digma/intellij/plugin/analytics/ConnectionTestResult.java deleted file mode 100644 index 8262b4a6e..000000000 --- a/ide-common/src/main/java/org/digma/intellij/plugin/analytics/ConnectionTestResult.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.digma.intellij.plugin.analytics; - -public class ConnectionTestResult { - private String result; - private String error; - - public ConnectionTestResult(String result, String error) { - this.result = result; - this.error = error; - } - - public String getResult() { - return result; - } - - public void setResult(String result) { - this.result = result; - } - - public String getError() { - return error; - } - - public void setError(String error) { - this.error = error; - } - - public static ConnectionTestResult success() { - return new ConnectionTestResult("success", null); - } - - public static ConnectionTestResult failure(String errorMessage) { - return new ConnectionTestResult("failure", errorMessage); - } -} \ No newline at end of file diff --git a/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/UpdatesService.kt b/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/UpdatesService.kt index 0533aa1f8..66f551f04 100644 --- a/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/UpdatesService.kt +++ b/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/UpdatesService.kt @@ -27,6 +27,8 @@ import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel import org.digma.intellij.plugin.updates.ui.NewUIVersionAvailableEvent import org.digma.intellij.plugin.updates.ui.UIVersioningService import java.util.concurrent.TimeUnit +import java.util.concurrent.locks.ReentrantLock +import kotlin.concurrent.withLock import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -35,6 +37,8 @@ class UpdatesService(private val project: Project) : Disposable { private val logger = Logger.getInstance(UpdatesService::class.java) + private val checkLock = ReentrantLock(true) + companion object { @JvmStatic fun getInstance(project: Project): UpdatesService { @@ -143,40 +147,44 @@ class UpdatesService(private val project: Project) : Disposable { //this method may throw exception, always catch and report private fun checkForNewerVersions() { - Log.log(logger::trace, "checking for new versions") - val versionsResp: VersionResponse = AnalyticsService.getInstance(project).getVersions(buildVersionRequest()) - Log.log(logger::debug, "got version response {}", versionsResp) + checkLock.withLock { + + Log.log(logger::trace, "checking for new versions") + val versionsResp: VersionResponse = AnalyticsService.getInstance(project).getVersions(buildVersionRequest()) + Log.log(logger::debug, "got version response {}", versionsResp) - if (versionsResp.errors.isNotEmpty()) { - val currErrors = versionsResp.errors.toList() + if (versionsResp.errors.isNotEmpty()) { + val currErrors = versionsResp.errors.toList() - if (currErrors != prevBackendErrorsList) { - currErrors.forEach { - ErrorReporter.getInstance().reportBackendError(project, "UpdatesService.checkForNewerVersions", it) + if (currErrors != prevBackendErrorsList) { + currErrors.forEach { + ErrorReporter.getInstance().reportBackendError(project, "UpdatesService.checkForNewerVersions", it) + } } + + prevBackendErrorsList = currErrors + return } - prevBackendErrorsList = currErrors - return - } + stateBackendVersion = versionsResp.backend + statePluginVersion.latestVersion = versionsResp.plugin.latestVersion + + //the panel is going to show the update button if shouldUpdatePlugin is true. + //when user clicks the button we will open the intellij plugins settings. + //sometimes the plugin list is not refreshed and user will not be able to update the plugin, + // so we refresh plugins metadata before showing the button. waiting maximum 10 seconds for + // the refresh to complete, and show the button anyway. + if (shouldUpdatePlugin()) { + //refreshPluginsMetadata returns a future that doesn't throw exception from get. + val future = refreshPluginsMetadata() + future.get(10, TimeUnit.SECONDS) + } - stateBackendVersion = versionsResp.backend - statePluginVersion.latestVersion = versionsResp.plugin.latestVersion - - //the panel is going to show the update button if shouldUpdatePlugin is true. - //when user clicks the button we will open the intellij plugins settings. - //sometimes the plugin list is not refreshed and user will not be able to update the plugin, - // so we refresh plugins metadata before showing the button. waiting maximum 10 seconds for - // the refresh to complete, and show the button anyway. - if (shouldUpdatePlugin()) { - //refreshPluginsMetadata returns a future that doesn't throw exception from get. - val future = refreshPluginsMetadata() - future.get(10, TimeUnit.SECONDS) + EDT.ensureEDT { + affectedPanel?.reset() + } } - EDT.ensureEDT { - affectedPanel?.reset() - } } diff --git a/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/ui/UIVersioningService.kt b/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/ui/UIVersioningService.kt index 3bcb775bc..114c03b74 100644 --- a/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/ui/UIVersioningService.kt +++ b/ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/ui/UIVersioningService.kt @@ -155,10 +155,14 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor { if (latestDownloadedUiVersion != null) { Log.log( logger::info, - "updating ui to latest downloaded version {}", latestDownloadedUiVersion + "got latest downloaded ui version on startup {}, trying to update..", latestDownloadedUiVersion ) val latestDownloadedUi = buildUiBundleLocalFile(latestDownloadedUiVersion) if (latestDownloadedUi.exists()) { + Log.log( + logger::info, + "updating ui to latest downloaded version on startup {}", latestDownloadedUiVersion + ) deleteUiBundle(getCurrentUiVersion()) setCurrentUiVersion(latestDownloadedUiVersion) setLatestDownloadedVersion(null) diff --git a/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/RecentActivityMessagesUtils.kt b/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/RecentActivityMessagesUtils.kt deleted file mode 100644 index cc8bbe0e7..000000000 --- a/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/RecentActivityMessagesUtils.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.digma.intellij.plugin.ui.recentactivity - -import org.cef.browser.CefBrowser -import org.digma.intellij.plugin.analytics.ConnectionTestResult -import org.digma.intellij.plugin.ui.jcef.JCEFGlobalConstants -import org.digma.intellij.plugin.ui.jcef.serializeAndExecuteWindowPostMessageJavaScript -import org.digma.intellij.plugin.ui.recentactivity.model.ConnectionTestResultMessage - - -fun sendRemoteConnectionCheckResult(browser: CefBrowser, connectionTestResult: ConnectionTestResult) { - val connectionTestResultMessage = ConnectionTestResultMessage( - JCEFGlobalConstants.REQUEST_MESSAGE_TYPE, - "RECENT_ACTIVITY/SET_REMOTE_ENVIRONMENT_CONNECTION_CHECK_RESULT", connectionTestResult - ) - serializeAndExecuteWindowPostMessageJavaScript(browser, connectionTestResultMessage) -} \ No newline at end of file diff --git a/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/model/ConnectionTestResultMessage.kt b/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/model/ConnectionTestResultMessage.kt deleted file mode 100644 index e532f5ffa..000000000 --- a/src/main/kotlin/org/digma/intellij/plugin/ui/recentactivity/model/ConnectionTestResultMessage.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.digma.intellij.plugin.ui.recentactivity.model - -import org.digma.intellij.plugin.analytics.ConnectionTestResult - -data class ConnectionTestResultMessage(val type: String, val action: String, val payload: ConnectionTestResult) \ No newline at end of file