Skip to content

Commit 99141bc

Browse files
committed
support plugin downgrade in ui versioning
1 parent 21ae956 commit 99141bc

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceData.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ internal data class PersistenceData(
101101
var latestDownloadedUiVersion: String? = null,
102102
var isFirstRunAfterPersistDockerCompose: Boolean = true,
103103
var lastUnpackedOtelJarsPluginVersion: String? = null,
104+
var lastUiUpdatePluginVersion: String? = null,
104105
var aboutAsJson: String? = null
105106

106107
)

ide-common/src/main/kotlin/org/digma/intellij/plugin/persistence/PersistenceService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,14 @@ class PersistenceService {
459459
state.lastUnpackedOtelJarsPluginVersion = pluginVersion
460460
}
461461

462+
fun getLastUiUpdatePluginVersion(): String? {
463+
return state.lastUiUpdatePluginVersion
464+
}
465+
466+
fun setLastUiUpdatePluginVersion(pluginVersion: String) {
467+
state.lastUiUpdatePluginVersion = pluginVersion
468+
}
469+
462470
fun saveAboutAsJson(aboutAsJson: String) {
463471
state.aboutAsJson = aboutAsJson
464472
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/updates/ui/UIVersioningService.kt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.digma.intellij.plugin.common.Retries
1313
import org.digma.intellij.plugin.common.buildVersionRequest
1414
import org.digma.intellij.plugin.common.findActiveProject
1515
import org.digma.intellij.plugin.common.newerThan
16+
import org.digma.intellij.plugin.common.olderThan
1617
import org.digma.intellij.plugin.errorreporting.ErrorReporter
1718
import org.digma.intellij.plugin.log.Log
1819
import org.digma.intellij.plugin.paths.DigmaPathManager
@@ -21,6 +22,7 @@ import org.digma.intellij.plugin.posthog.ActivityMonitor
2122
import org.digma.intellij.plugin.reload.ReloadService
2223
import org.digma.intellij.plugin.reload.ReloadSource
2324
import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
25+
import org.digma.intellij.plugin.semanticversion.SemanticVersionUtil
2426
import org.digma.intellij.plugin.settings.InternalFileSettings
2527
import java.io.File
2628
import java.net.HttpURLConnection
@@ -114,6 +116,9 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor {
114116
}
115117

116118
private fun setCurrentUiVersion(uiVersion: String) {
119+
//on every change to current version keep also the plugin version it will help to identify a plugin downgrade
120+
val currentPluginVersion = SemanticVersionUtil.getPluginVersionWithoutBuildNumberAndPreRelease("unknown")
121+
PersistenceService.getInstance().setLastUiUpdatePluginVersion(currentPluginVersion)
117122
return PersistenceService.getInstance().setCurrentUiVersion(uiVersion)
118123
}
119124

@@ -146,6 +151,36 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor {
146151
setCurrentUiVersion(bundledUiVersion)
147152
}
148153

154+
//first check if there was a plugin downgrade since the last time the current ui version was updated if yes
155+
// switch to the bundled UI
156+
val needToUnpackAfterPluginDowngrade = PersistenceService.getInstance().getLastUiUpdatePluginVersion()?.let { lastUiUpdatePluginVersion ->
157+
val currentPluginVersion = SemanticVersionUtil.getPluginVersionWithoutBuildNumberAndPreRelease("unknown")
158+
ComparableVersion(currentPluginVersion).olderThan(ComparableVersion(lastUiUpdatePluginVersion))
159+
} ?: false
160+
if (needToUnpackAfterPluginDowngrade) {
161+
Log.log(
162+
logger::info,
163+
"there was a plugin downgrade, using bundled ui. current version: {}, bundled version: {}",
164+
getCurrentUiVersion(),
165+
bundledUiVersion
166+
)
167+
if (unpackUiBundle()) {
168+
deleteUiBundle(getCurrentUiVersion())
169+
getLatestDownloadedVersion()?.let {
170+
deleteUiBundle(it)
171+
setLatestDownloadedVersion(null)
172+
}
173+
setCurrentUiVersion(bundledUiVersion)
174+
findActiveProject()?.let {
175+
ActivityMonitor.getInstance(it).setUIVersion(getCurrentUiVersion())
176+
}
177+
} else {
178+
Log.log(logger::warn, "could not unpack bundled ui version {}", bundledUiVersion)
179+
}
180+
return
181+
}
182+
183+
149184
//Note:always use the methods getCurrentUiVersion() and getLatestDownloadedVersion() and don't assign to local variables
150185
// because values may change concurrently
151186

@@ -160,7 +195,9 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor {
160195

161196
//if we have the latest downloaded file, switch to use it and delete the old version
162197
val latestDownloadedUiVersion = getLatestDownloadedVersion()
163-
if (latestDownloadedUiVersion != null) {
198+
if (latestDownloadedUiVersion != null &&
199+
ComparableVersion(latestDownloadedUiVersion).newerThan(ComparableVersion(getCurrentUiVersion()))
200+
) {
164201
Log.log(
165202
logger::info,
166203
"got latest downloaded ui version on startup {}, trying to update..", latestDownloadedUiVersion
@@ -207,13 +244,19 @@ class UIVersioningService(val cs: CoroutineScope) : DisposableAdaptor {
207244
"latestDownloadedUiVersion property exists but file does not exist, not updating"
208245
)
209246

247+
setLatestDownloadedVersion(null)
248+
}
249+
} else {
250+
//in any case if we didn't use latest downloaded reset it if it exists
251+
getLatestDownloadedVersion()?.let {
252+
deleteUiBundle(it)
210253
setLatestDownloadedVersion(null)
211254
}
212255
}
213256

214257

215-
//maybe user updated the plugin, and the bundled ui is newer then the current ui version.
216-
//this is a valid check even if we had a latestDownloadedVersion and we switched to it above
258+
//this is support for plugin update that have a newer ui bundled with it.
259+
//this is a valid check even if we had a latestDownloadedVersion and we switched to it above.
217260
if (ComparableVersion(bundledUiVersion).newerThan(ComparableVersion(getCurrentUiVersion()))) {
218261
Log.log(
219262
logger::info,

0 commit comments

Comments
 (0)