Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-32472 - Fix CLI upgrading when the cache of remote checksums is not expired #46

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

## [Unreleased]

## [1.3.0] - 2024-02-12
## [1.3.1] - 2024-02-13

- Fix CLI upgrading when the cache of remote checksums is not expired

## [1.3.0] - 2024-02-13

- Add new SCA flow which decreases execution time

Expand Down Expand Up @@ -47,6 +51,8 @@

The first public release of the plugin.

[1.3.1]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.3.1

[1.3.0]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.3.0

[1.2.0]: https://github.com/cycodehq/intellij-platform-plugin/releases/tag/v1.2.0
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.cycode.plugin
pluginName = Cycode
pluginRepositoryUrl = https://github.com/cycodehq/intellij-platform-plugin
# SemVer format -> https://semver.org
pluginVersion = 1.3.0
pluginVersion = 1.3.1

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 211.1
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/cycode/plugin/Consts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ class Consts {
companion object {
val PLUGIN_PATH = PathManager.getPluginsPath() + "/cycode-intellij-platform-plugin"
val DEFAULT_CLI_PATH = getDefaultCliPath()
const val REQUIRED_CLI_VERSION = "1.9.0"

const val CLI_GITHUB_ORG = "cycodehq"
const val CLI_GITHUB_REPO = "cycode-cli"
const val CLI_GITHUB_TAG = "v1.9.0"
const val CLI_GITHUB_TAG = "v$REQUIRED_CLI_VERSION"
const val CLI_CHECK_NEW_VERSION_EVERY_SEC = 24 * 60 * 60 // 24 hours

const val PLUGIN_AUTO_SAVE_FLUSH_INITIAL_DELAY_SEC = 0L
const val PLUGIN_AUTO_SAVE_FLUSH_DELAY_SEC = 5L
}
Expand Down
31 changes: 18 additions & 13 deletions src/main/kotlin/com/cycode/plugin/services/CliDownloadService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ class CliDownloadService {

private var githubReleaseInfo: GitHubRelease? = null

private val initCliLock = Any()
// shared lock for the entire application (all projects)
// used with calling of initCli() method
val initCliLock = Any()

fun initCli() {
synchronized(initCliLock) {
// if the CLI path is not overriden and executable is auto managed, and need to download - download it.
if (
pluginSettings.cliPath == Consts.DEFAULT_CLI_PATH &&
pluginSettings.cliAutoManaged &&
shouldDownloadCli()
) {
downloadCli()
thisLogger().info("CLI was successfully downloaded/updated")
}
// if the CLI path is not overriden and executable is auto managed, and need to download - download it.
if (
pluginSettings.cliPath == Consts.DEFAULT_CLI_PATH &&
pluginSettings.cliAutoManaged &&
shouldDownloadCli()
) {
downloadCli()
thisLogger().info("CLI was successfully downloaded/updated")
}
}

Expand Down Expand Up @@ -87,6 +87,11 @@ class CliDownloadService {
}

private fun shouldDownloadNewRemoteCli(localPath: String, isDir: Boolean): Boolean {
if (pluginState.cliVer != Consts.REQUIRED_CLI_VERSION) {
thisLogger().warn("Should download CLI because version missmatch")
return true
}

val timeNow = System.currentTimeMillis()

if (pluginState.cliLastUpdateCheckedAt == null) {
Expand Down Expand Up @@ -148,7 +153,7 @@ class CliDownloadService {
return true
}

if (shouldDownloadNewRemoteCli(Consts.DEFAULT_CLI_PATH, false)) {
if (shouldDownloadNewRemoteCli(Consts.DEFAULT_CLI_PATH, isDir=false)) {
return true
}

Expand All @@ -167,7 +172,7 @@ class CliDownloadService {
return true
}

if (shouldDownloadNewRemoteCli(Consts.PLUGIN_PATH, true)) {
if (shouldDownloadNewRemoteCli(Consts.PLUGIN_PATH, isDir=true)) {
return true
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/kotlin/com/cycode/plugin/services/CycodeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ class CycodeService(val project: Project) {
fun installCliIfNeededAndCheckAuthentication() {
object : Task.Backgroundable(project, CycodeBundle.message("pluginLoading"), false) {
override fun run(indicator: ProgressIndicator) {
cliDownloadService.initCli()
// we are using lock of download service because it shared per application
// the current service is per project so, we can't create a lock here
synchronized(cliDownloadService.initCliLock) {
cliDownloadService.initCli()

// required to know CLI version.
// unfortunately, we don't have a universal command that will cover the auth state and CLI version yet
cliService.healthCheck()
// required to know CLI version.
// we don't have a universal command that will cover the auth state and CLI version yet
cliService.healthCheck()

cliService.checkAuth()
updateToolWindowState(project)
cliService.checkAuth()
updateToolWindowState(project)
}
}
}.queue()
}
Expand Down
Loading