Skip to content

Commit

Permalink
Ban Gson (#4139)
Browse files Browse the repository at this point in the history
Gson is currently on the classpath, but the rest of the repo uses Jackson ObjectMapper.
Gson is also in maintenance mode.
  • Loading branch information
rli authored Feb 20, 2024
1 parent a990210 commit 6b5f024
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ class BannedImportsRule : Rule() {
)
)
}

if (importedFqName == "com.google.gson.Gson") {
report(
CodeSmell(
issue,
Entity.from(element),
message = "Use jacksonObjectMapper() insted of Gson"
)
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class BannedImportsRuleTest {
.matches { it.id == "BannedImports" && it.message == "Use AssertJ instead of Hamcrest assertions" }
}

@Test
fun `Importing Gson fails`() {
assertThat(rule.lint("import com.google.gson.Gson"))
.singleElement()
.matches { it.id == "BannedImports" && it.message == "Use jacksonObjectMapper() insted of Gson" }
}

@Test
fun `Importing Kotlin test assert fails`() {
assertThat(rule.lint("import kotlin.test.assertTrue"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package software.aws.toolkits.jetbrains.services.codewhisperer

import com.google.gson.Gson
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.editor.Editor
Expand Down Expand Up @@ -379,14 +379,15 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
fun `test user Decision events record CodeWhisperer reference info`() {
val userGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup()
withCodeWhispererServiceInvokedAndWait {}
val mapper = jacksonObjectMapper()
argumentCaptor<MetricEvent>().apply {
verify(batcher, atLeastOnce()).enqueue(capture())
pythonResponse.completions().forEach {
assertEventsContainsFieldsAndCount(
allValues,
userDecision,
1,
"codewhispererSuggestionReferences" to Gson().toJson(it.references().map { ref -> ref.licenseName() }.toSet()),
"codewhispererSuggestionReferences" to mapper.writeValueAsString(it.references().map { ref -> ref.licenseName() }.toSet()),
"codewhispererSuggestionReferenceCount" to it.references().size.toString(),
"codewhispererUserGroup" to userGroup.name,
atLeast = true
Expand Down

0 comments on commit 6b5f024

Please sign in to comment.