Skip to content

Commit

Permalink
refactor: first batch of deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Mar 6, 2024
1 parent 3105eff commit f642ca3
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 208 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginName=Snyk Security - Code, Open Source, Container, IaC Configurations
# for insight into build numbers and IntelliJ Platform versions
# see https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=233
pluginUntilBuild=233.*
pluginUntilBuild=241.*
platformVersion=2023.3
platformDownloadSources=true

Expand All @@ -13,7 +13,7 @@ platformDownloadSources=true
# see https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
platformPlugins=org.intellij.plugins.hcl:233.11799.172,org.jetbrains.plugins.yaml,org.jetbrains.kotlin,com.intellij.java,org.intellij.groovy
# list of versions for which to check the plugin for api compatibility
pluginVerifierIdeVersions=2023.3
pluginVerifierIdeVersions=2023.3,2024.1
localIdeDirectory=
# opt-out flag for bundling Kotlin standard library
# see https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
Expand Down
57 changes: 36 additions & 21 deletions src/main/kotlin/io/snyk/plugin/ui/SnykSettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import com.intellij.ui.ContextHelpLabel
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.IdeBorderFactory
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBTextField
import com.intellij.ui.components.fields.ExpandableTextField
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.panel
import com.intellij.uiDesigner.core.Spacer
import com.intellij.util.Alarm
import com.intellij.util.FontUtil
import com.intellij.util.ui.GridBag
import com.intellij.util.ui.UI
import io.snyk.plugin.events.SnykCliDownloadListener
import io.snyk.plugin.getCliFile
import io.snyk.plugin.getSnykCliAuthenticationService
Expand Down Expand Up @@ -80,7 +82,7 @@ class SnykSettingsDialog(

private val manageBinariesAutomatically: JCheckBox = JCheckBox()
private val cliPathTextBoxWithFileBrowser = TextFieldWithBrowseButton()
private val cliBaseDownloadUrlTextField = JTextField()
private val cliBaseDownloadUrlTextField = JBTextField()

private val logger = Logger.getInstance(this::class.java)

Expand Down Expand Up @@ -482,33 +484,44 @@ class SnykSettingsDialog(

cliBaseDownloadUrlTextField.toolTipText = "The default URL is https://static.snyk.io. " +
"for FIPS-enabled CLIs (only available for Windows and Linux), please use https://static.snyk.io/fips"
executableSettingsPanel.add(
UI.PanelFactory
.panel(cliBaseDownloadUrlTextField)
.withLabel("Base URL to download the CLI: ").createPanel(),
gb.nextLine()
)
val cliBaseDownloadPanel = panel {
row {
label("Base URL to download the CLI: ")
cell(cliBaseDownloadUrlTextField).align(AlignX.FILL)
}
}
executableSettingsPanel.add(cliBaseDownloadPanel, gb.nextLine())

cliPathTextBoxWithFileBrowser.toolTipText = "The default path is ${getCliFile().canonicalPath}."
val descriptor = FileChooserDescriptor(true, false, false, false, false, false)
cliPathTextBoxWithFileBrowser.addBrowseFolderListener(
"", "Please choose the Snyk CLI you want to use:", null,
"",
"Please choose the Snyk CLI you want to use:",
null,
descriptor,
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT
)

executableSettingsPanel.add(
UI.PanelFactory
.panel(cliPathTextBoxWithFileBrowser)
.withLabel("Path to Snyk CLI: ").createPanel(),
panel {
row {
label("Path to Snyk CLI: ")
cell(cliPathTextBoxWithFileBrowser).align(AlignX.FILL)
}
},
gb.nextLine()
)

manageBinariesAutomatically.text = "Automatically manage needed binaries"
executableSettingsPanel.add(
manageBinariesAutomatically,
panel {
row {
label("Automatically manage needed binaries: ")
cell(manageBinariesAutomatically).align(AlignX.FILL)
}
},
gb.nextLine()
)

val descriptionLabelManageBinaries =
JLabel(
"<html>These options allow you to customize the handling, where and how plugin " +
Expand Down Expand Up @@ -558,14 +571,16 @@ class SnykSettingsDialog(
}

private fun setupValidation(textField: JTextField, message: String, isValidText: (sourceStr: String?) -> Boolean) {
ComponentValidator(rootPanel).withValidator(Supplier<ValidationInfo?> {
val validationInfo: ValidationInfo = if (!isValidText(textField.text)) {
ValidationInfo(message, textField)
} else {
ValidationInfo("")
ComponentValidator(rootPanel).withValidator(
Supplier<ValidationInfo?> {
val validationInfo: ValidationInfo = if (!isValidText(textField.text)) {
ValidationInfo(message, textField)
} else {
ValidationInfo("")
}
validationInfo
}
validationInfo
}).installOn(textField)
).installOn(textField)

textField.document.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(event: DocumentEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.snyk.plugin.ui.settings

import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.layout.panel
import com.intellij.ui.dsl.builder.panel
import com.intellij.util.ui.JBUI
import io.snyk.plugin.Severity
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.ui.SnykBalloonNotificationHelper
import java.awt.event.ItemEvent

class SeveritiesEnablementPanel {
private val settings
Expand All @@ -18,62 +19,42 @@ class SeveritiesEnablementPanel {

val panel = panel {
row {
cell {
checkBox(
text = Severity.CRITICAL.toPresentableString(),
getter = { settings.criticalSeverityEnabled },
setter = { settings.criticalSeverityEnabled = it }
).component.apply {
this.addItemListener {
isLastSeverityDisabling(this, currentCriticalSeverityEnabled)
currentCriticalSeverityEnabled = this.isSelected
}
name = Severity.CRITICAL.toPresentableString()
checkBox(Severity.CRITICAL.toPresentableString()).applyToComponent {
name = text
isSelected = settings.criticalSeverityEnabled
this.addItemListener {
correctLastSeverityDisabled(it)
settings.criticalSeverityEnabled = this.isSelected
}
}
}
row {
cell {
checkBox(
text = Severity.HIGH.toPresentableString(),
getter = { settings.highSeverityEnabled },
setter = { settings.highSeverityEnabled = it }
).component.apply {
this.addItemListener {
isLastSeverityDisabling(this, currentHighSeverityEnabled)
currentHighSeverityEnabled = this.isSelected
}
name = Severity.HIGH.toPresentableString()
checkBox(Severity.HIGH.toPresentableString()).applyToComponent {
name = text
isSelected = settings.highSeverityEnabled
this.addItemListener {
correctLastSeverityDisabled(it)
settings.highSeverityEnabled = this.isSelected
}
}
}
row {
cell {
checkBox(
text = Severity.MEDIUM.toPresentableString(),
getter = { settings.mediumSeverityEnabled },
setter = { settings.mediumSeverityEnabled = it }
).component.apply {
this.addItemListener {
isLastSeverityDisabling(this, currentMediumSeverityEnabled)
currentMediumSeverityEnabled = this.isSelected
}
name = Severity.MEDIUM.toPresentableString()
checkBox(Severity.MEDIUM.toPresentableString()).applyToComponent {
name = text
isSelected = settings.mediumSeverityEnabled
this.addItemListener {
correctLastSeverityDisabled(it)
settings.mediumSeverityEnabled = this.isSelected
}
}
}
row {
cell {
checkBox(
text = Severity.LOW.toPresentableString(),
getter = { settings.lowSeverityEnabled },
setter = { settings.lowSeverityEnabled = it }
).component.apply {
this.addItemListener {
isLastSeverityDisabling(this, currentLowSeverityEnabled)
currentLowSeverityEnabled = this.isSelected
}
name = Severity.LOW.toPresentableString()
checkBox(Severity.LOW.toPresentableString()).applyToComponent {
name = text
isSelected = settings.lowSeverityEnabled
this.addItemListener {
correctLastSeverityDisabled(it)
settings.lowSeverityEnabled = this.isSelected
}
}
}
Expand All @@ -82,6 +63,11 @@ class SeveritiesEnablementPanel {
border = JBUI.Borders.empty(2)
}

private fun JBCheckBox.correctLastSeverityDisabled(it: ItemEvent) {
val deselected = it.stateChange == ItemEvent.DESELECTED
isLastSeverityDisabling(this, deselected)
}

private fun isLastSeverityDisabling(component: JBCheckBox, wasEnabled: Boolean): Boolean {
val onlyOneEnabled = arrayOf(
currentCriticalSeverityEnabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.snyk.plugin.net

import com.intellij.util.Base64
import com.intellij.util.net.HttpConfigurable
import io.mockk.every
import io.mockk.mockk
Expand All @@ -11,6 +10,7 @@ import okhttp3.Response
import okhttp3.Route
import org.junit.Test
import java.net.PasswordAuthentication
import java.util.Base64

class RetrofitAuthenticatorTest {

Expand All @@ -37,7 +37,7 @@ class RetrofitAuthenticatorTest {
val authHeader = request.headers[PROXY_AUTHORIZATION_HEADER_NAME]
assertNotNull(authHeader)
assertEquals("Basic dXNlcm5hbWU6cHc=", authHeader)
assertEquals("dXNlcm5hbWU6cHc=", Base64.encode("username:pw".toByteArray()))
assertEquals("dXNlcm5hbWU6cHc=", Base64.getEncoder().encode("username:pw".toByteArray()))
}

@Test
Expand All @@ -56,7 +56,7 @@ class RetrofitAuthenticatorTest {

val request = cut.authenticate(route, response)

val authHeader = request!!.headers[PROXY_AUTHORIZATION_HEADER_NAME]
val authHeader = request.headers[PROXY_AUTHORIZATION_HEADER_NAME]
assertNull(authHeader)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CliDownloaderTest {

@Test
fun `should not delete file if checksum verification fails`() {
val testFile = createTempFile()
val testFile = Files.createTempFile("test", "test").toFile()
testFile.deleteOnExit()
val dummyContent = "test test test".toByteArray()
Files.write(testFile.toPath(), dummyContent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("UNCHECKED_CAST")

package io.snyk.plugin.ui.toolwindow

import ai.deepcode.javaclient.core.SuggestionForFile
Expand Down Expand Up @@ -889,7 +891,7 @@ class SnykToolWindowPanelIntegTest : HeavyPlatformTestCase() {
val rootContainerNode = toolWindowPanel.getRootContainerIssuesTreeNode()

val expectedIssuesCount = containerResult.issuesCount
val actualIssueNodesCount = rootContainerNode.children().asSequence().sumBy {
val actualIssueNodesCount = rootContainerNode.children().asSequence().sumOf {
(it as TreeNode).childCount
}
assertEquals(expectedIssuesCount, actualIssueNodesCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okio.buffer
import okio.source
import org.hamcrest.collection.IsMapWithSize.aMapWithSize
import org.hamcrest.collection.IsMapWithSize.anEmptyMap
import org.hamcrest.core.IsEqual.equalTo
import org.hamcrest.core.IsNull.notNullValue
import org.junit.After
import org.junit.Assert.assertThat
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -64,21 +62,21 @@ class AmplitudeExperimentApiClientTest {
val response = amplitudeVariantService.sdkVardata(ExperimentUser("random-user-id")).execute()

// asserts
assertThat(response.code(), equalTo(200))
assertEquals(200, response.code())

val variants = response.body()
assertThat(variants, notNullValue())
assertThat(variants, aMapWithSize(2))
assertNotNull(variants)
assertEquals(2, variants?.size)

val expectedFirstVariant = Variant(value = "on", payload = mapOf("message" to "random message"))
val actualFirstVariant = variants?.entries?.first()
assertThat(actualFirstVariant?.key, equalTo("first-experiment"))
assertThat(actualFirstVariant?.value, equalTo(expectedFirstVariant))
assertEquals("first-experiment", actualFirstVariant?.key)
assertEquals(expectedFirstVariant, actualFirstVariant?.value)

val expectedLastVariant = Variant(value = "off")
val actualLastVariant = variants?.entries?.last()
assertThat(actualLastVariant?.key, equalTo("second-experiment"))
assertThat(actualLastVariant?.value, equalTo(expectedLastVariant))
assertEquals("second-experiment", actualLastVariant?.key)
assertEquals(expectedLastVariant, actualLastVariant?.value)
}

@Test
Expand All @@ -90,7 +88,7 @@ class AmplitudeExperimentApiClientTest {

val response = amplitudeVariantService.sdkVardata(ExperimentUser("")).execute()

assertThat(response.code(), equalTo(200))
assertEquals(200, response.code())
}

@Test
Expand All @@ -101,8 +99,8 @@ class AmplitudeExperimentApiClientTest {

val actualVariants = clientUnderTest.allVariants(ExperimentUser("random-user-id"))

assertThat(actualVariants, notNullValue())
assertThat(actualVariants, aMapWithSize(2))
assertNotNull(actualVariants)
assertEquals(2, actualVariants.size)
}

@Test
Expand All @@ -111,7 +109,7 @@ class AmplitudeExperimentApiClientTest {

val variants = clientUnderTest.allVariants(ExperimentUser(""))

assertThat(variants, anEmptyMap())
assertTrue(variants.isEmpty())
}
}

Expand Down
Loading

0 comments on commit f642ca3

Please sign in to comment.