Skip to content

Commit

Permalink
ui versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Dec 11, 2024
1 parent 2211ec0 commit 081400e
Show file tree
Hide file tree
Showing 108 changed files with 861 additions and 18,123 deletions.
34 changes: 30 additions & 4 deletions ide-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {

tasks {

val downloadComposeFile = register("downloadComposeFile", Download::class.java) {
val downloadComposeFile by registering(Download::class) {
src(
listOf(
"https://get.digma.ai/"
Expand All @@ -64,11 +64,37 @@ tasks {

val dir = File(project.sourceSets.main.get().output.resourcesDir, "docker-compose")
dest(File(dir, "docker-compose.yml"))
overwrite(false)
onlyIfModified(true)
retries(3)
}


val uiVersionFile = project.rootProject.file("ui-version")
val uiVersion = uiVersionFile.readText()
//the directory inside the jar to package to
val uiBundleDir = File(project.sourceSets.main.get().output.resourcesDir, "ui-bundle")
val uiBundleFile = File(uiBundleDir, "digma-ui-$uiVersion.zip")

val downloadUiBundle by registering(Download::class) {

inputs.files(uiVersionFile)
outputs.files(uiBundleFile)

src(
listOf(
"https://github.com/digma-ai/digma-ui/releases/download/v$uiVersion/dist-jetbrains-v$uiVersion.zip"
)
)
dest(uiBundleFile)
retries(3)
}

val createUiBundleVersionFile by registering(Copy::class) {
from(uiVersionFile)
into(uiBundleDir)
}


processResources {
dependsOn(downloadComposeFile)
dependsOn(downloadComposeFile, downloadUiBundle, createUiBundleVersionFile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.digma.intellij.plugin.auth.account.*;
import org.digma.intellij.plugin.common.*;
import org.digma.intellij.plugin.errorreporting.ErrorReporter;
import org.digma.intellij.plugin.updates.ui.UIVersioningService;
import org.jetbrains.annotations.*;

import javax.swing.*;
Expand Down Expand Up @@ -167,6 +168,8 @@ public boolean verify(JComponent input) {

var backendVersionLabel = createBackendVersionLabel();

var uiVersionLabel = createUiVersionLabel();

var importExportPanel = createImportExportPanel();

var resetPluginButton = createResetPluginButton();
Expand All @@ -186,6 +189,7 @@ public boolean verify(JComponent input) {
.addComponent(resetToDefaultsButton)
.addLabeledComponent(new JBLabel("User id"), userIdLabel)
.addLabeledComponent(new JBLabel("Backend version"), backendVersionLabel)
.addLabeledComponent(new JBLabel("UI version"), uiVersionLabel)
.addComponent(importExportPanel)
.addComponent(resetPluginButton)
.addComponent(pluginResetWarning)
Expand Down Expand Up @@ -384,6 +388,11 @@ private static JBLabel createBackendVersionLabel() {
return backendVersionLabel;
}

@NotNull
private static JBLabel createUiVersionLabel() {
return new JBLabel(UIVersioningService.getInstance().getCurrentUiVersion()+" ("+UIVersioningService.getInstance().getCurrentUiBundlePath()+")");
}


private JPanel createImportExportPanel() {
//noinspection ExtractMethodRecommender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ public void initComponents(@NotNull ToolWindow toolWindow,

public void updateStateChanged(@NotNull PublicUpdateState updateState) {
if (updateState.getUpdateState() == CurrentUpdateState.OK) {
closeUpdateBackendPanel();
closeAggressiveUpdatePanel();
} else {
showUpdateBackendPanel();
showAggressiveUpdatePanel();
}
}

Expand Down Expand Up @@ -296,25 +296,25 @@ public void showMainPanel() {
}
}

private void showUpdateBackendPanel() {
private void showAggressiveUpdatePanel() {

Log.log(LOGGER::debug, "showUpdateBackendPanel called");
Log.log(LOGGER::debug, "showAggressiveUpdatePanel called");

//replace the card even if wizard is on. it will not show until wizard content is removed.

//this may happen on startup,showMainPanel is called from the tool window factory,
// but there may be a connection lost before the content was built and before this controller was initialized
if (isConnectionLost.get()) {
Log.log(LOGGER::debug, "Not showing MainPanel because connection lost, showing NoConnection");
Log.log(LOGGER::debug, "Not showing AggressiveUpdatePanel because connection lost, showing NoConnection");
showNoConnection();
} else {
EDT.ensureEDT(() -> showCard(MainWindowCard.UPDATE_MODE));
}
}

private void closeUpdateBackendPanel() {
private void closeAggressiveUpdatePanel() {

Log.log(LOGGER::debug, "closeUpdateBackendPanel called");
Log.log(LOGGER::debug, "closeAggressiveUpdatePanel called");


//replace the card even if wizard is on. it will not show until wizard content is removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class RecentActivityToolWindowCardsController(private val project: Project) {

fun updateStateChanged(updateState: PublicUpdateState) {
if (updateState.updateState == CurrentUpdateState.OK) {
closeUpdateBackendPanel()
closeAggressiveUpdatePanel()
} else {
showUpdateBackendPanel()
showAggressiveUpdatePanel()
}
}

Expand All @@ -112,19 +112,19 @@ class RecentActivityToolWindowCardsController(private val project: Project) {
}
}

private fun showUpdateBackendPanel() {
Log.log(logger::debug, "showUpdateBackendPanel called")
private fun showAggressiveUpdatePanel() {
Log.log(logger::debug, "showAggressiveUpdatePanel called")

if (isConnectionLost.get()) {
Log.log(logger::debug, "Not showing MainPanel because connection lost, showing NoConnection")
Log.log(logger::debug, "Not showing AggressiveUpdatePanel because connection lost, showing NoConnection")
showNoConnection()
} else {
EDT.ensureEDT { showCard(RecentActivityWindowCard.UPDATE_MODE) }
}
}

private fun closeUpdateBackendPanel() {
Log.log(logger::debug, "closeUpdateBackendPanel called")
private fun closeAggressiveUpdatePanel() {
Log.log(logger::debug, "closeAggressiveUpdatePanel called")

//this may happen on startup,showMainPanel is called from the tool window factory,
// but there may be a connection lost before the content was built and before this controller was initialized
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.digma.intellij.plugin.common

import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.components.service
import org.digma.intellij.plugin.model.rest.version.VersionRequest
import org.digma.intellij.plugin.semanticversion.SemanticVersionUtil
import org.digma.intellij.plugin.updates.ui.UIVersioningService


// returns one of:
Expand All @@ -23,9 +25,15 @@ fun getPluginVersion(defaultIfNotFound: String = "0.0.0"): String {
return SemanticVersionUtil.getPluginVersionWithoutBuildNumberAndPreRelease(defaultIfNotFound)
}

fun getUiVersion(): String {
return service<UIVersioningService>().getUiVersionForVersionRequest()
}




fun buildVersionRequest(): VersionRequest {
return VersionRequest(
getPluginVersion(), getPlatformType(), getPlatformVersion()
getPluginVersion(), getPlatformType(), getPlatformVersion(), getUiVersion()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ class Downloader {
return
}

val outputStream = FileOutputStream(composeFile)
Log.log(logger::info, "unpacking {} to {}", COMPOSE_FILE_NAME, composeFile)
com.intellij.openapi.util.io.StreamUtil.copy(inputStream, outputStream)
FileOutputStream(composeFile).use {
Log.log(logger::info, "unpacking {} to {}", COMPOSE_FILE_NAME, composeFile)
com.intellij.openapi.util.io.StreamUtil.copy(inputStream, it)
}

}


Expand Down Expand Up @@ -103,6 +105,7 @@ class Downloader {
"download from $url",
mapOf("responseCode" to responseCode.toString())
)
throw RuntimeException("could not download file from $url")
} else {
connection.inputStream.use {
Files.copy(it, tempFile, StandardCopyOption.REPLACE_EXISTING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.digma.intellij.plugin.paths

import com.intellij.openapi.application.ApplicationNamesInfo
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.SystemInfo
import org.digma.intellij.plugin.errorreporting.ErrorReporter
import java.io.File

const val DIGMA_DIR = "digma-intellij-plugin"

class DigmaPathManager {


companion object {

fun getLocalFilesDirectoryPath(): String {
val ideFullName = ApplicationNamesInfo.getInstance().fullProductNameWithEdition
val ideHomeDir = PathManager.getHomePath().substringAfterLast("/")
val ideName = "$ideFullName-$ideHomeDir".replace(" ", "-").replace(".","-")
return try {
val baseDir = getBaseDirectory()
val ideDir = File(baseDir,ideName)
ideDir.mkdirs()
ideDir.absolutePath
}catch (e:Throwable){
ErrorReporter.getInstance().reportError("DigmaPathManager.getLocalFilesDirectoryPath", e)
val fallback = File(System.getProperty("java.io.tmpdir"), "$DIGMA_DIR/$ideName")
fallback.mkdirs()
fallback.absolutePath
}
}


private fun getUserHome(): String {
//user.home should never be null, but just in case,use temp dir
return System.getProperty("user.home") ?: System.getProperty("java.io.tmpdir")
}


private fun getBaseDirectory(): File {

return try {
if (SystemInfo.isMac) {
val userHome = getUserHome()
val digmaDir = File(userHome, "Library/Application Support/$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
} else if (SystemInfo.isWindows) {
val userHome = System.getenv("LOCALAPPDATA") ?: getUserHome()
val digmaDir = File(userHome, DIGMA_DIR)
digmaDir.mkdirs()
digmaDir
} else {
//for linux or any other os
val userHome = getUserHome()
val digmaDir = File(userHome, ".$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
}

} catch (e: Throwable) {
ErrorReporter.getInstance().reportError("DigmaPathManager.getBaseDirectory", e)
val userHome = getUserHome()
val digmaDir = File(userHome, ".$DIGMA_DIR")
digmaDir.mkdirs()
digmaDir
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ internal data class PersistenceData(

var detectedFrameworks: String? = null,

var engagementScorePersistenceFileFixed: Boolean = false
var engagementScorePersistenceFileFixed: Boolean = false,

var currentUiVersion: String? = null,
var latestDownloadedUiVersion: String? = null

)
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,20 @@ class PersistenceService {
state.engagementScorePersistenceFileFixed = true
}

fun getCurrentUiVersion(): String? {
return state.currentUiVersion
}

fun setCurrentUiVersion(uiVersion: String) {
state.currentUiVersion = uiVersion
}

fun getLatestDownloadedUiVersion(): String? {
return state.latestDownloadedUiVersion
}

fun setLatestDownloadedUiVersion(uiVersion: String?) {
state.latestDownloadedUiVersion = uiVersion
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.digma.intellij.plugin.reload

enum class ReloadSource {
RELOAD_ACTION,RELOAD_OBSERVER
RELOAD_ACTION,RELOAD_OBSERVER,UI_UPDATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ data class UpdateState(
val backendDeploymentType: BackendDeploymentType,
val shouldUpdateBackend: Boolean,
val shouldUpdatePlugin: Boolean,
val shouldUpdateUi: Boolean,
) {

fun shouldUpdateAny(): Boolean {
return shouldUpdateBackend || shouldUpdatePlugin
return shouldUpdateBackend || shouldUpdatePlugin || shouldUpdateUi
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.digma.intellij.plugin.scheduling.disposingPeriodicTask
import org.digma.intellij.plugin.scheduling.oneShotTask
import org.digma.intellij.plugin.settings.InternalFileSettings
import org.digma.intellij.plugin.ui.panels.DigmaResettablePanel
import org.digma.intellij.plugin.updates.ui.UIVersioningService
import java.util.concurrent.TimeUnit
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -174,6 +175,7 @@ class UpdatesService(private val project: Project) : Disposable {
stateBackendVersion.deploymentType,
shouldUpdateBackend(),
shouldUpdatePlugin(),
UIVersioningService.getInstance().isNewUIBundleAvailable()
)
Log.log(logger::debug, "current state is {}", state)
return state
Expand Down
Loading

0 comments on commit 081400e

Please sign in to comment.