Skip to content

Commit

Permalink
Use the same logic for classify and remapping (#1163)
Browse files Browse the repository at this point in the history
Use the same logic for classify and remapping
  • Loading branch information
LChernigovskaya authored Sep 24, 2024
1 parent 96364e9 commit 1e01d56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,22 @@ class LevelRemappingPluginCreationResultResolver(private val delegatedResolver:
}

private fun remapPluginProblemLevel(pluginProblem: PluginProblem): PluginProblem? {
return remapPluginProblemLevel(pluginProblem, unwrapRemappedProblems)
}

private fun remapPluginProblemLevel(pluginProblem: PluginProblem, unwrapRemappedProblems: Boolean): PluginProblem? {
val problem = if (unwrapRemappedProblems) {
pluginProblem.unwrapped
} else {
pluginProblem
}

return when (val remappedLevel = remappedLevel[problem::class]) {
is StandardLevel -> ReclassifiedPluginProblem(remappedLevel.originalLevel, pluginProblem)
is IgnoredLevel -> null
null -> pluginProblem
}
return classify(pluginProblem)
}

override fun classify(plugin: IdePlugin, problems: List<PluginProblem>): List<PluginProblem> {
return delegatedResolver.classify(plugin, problems).mapNotNull {
classify(it.unwrapped)
classify(it)
}
}

private fun classify(pluginProblem: PluginProblem): PluginProblem? {
return when (val remappedLevel = remappedLevel[pluginProblem::class]) {
val problem = if (unwrapRemappedProblems) {
pluginProblem.unwrapped
} else {
pluginProblem
}
return when (val remappedLevel = remappedLevel[problem::class]) {
is StandardLevel -> ReclassifiedPluginProblem(remappedLevel.originalLevel, pluginProblem)
is IgnoredLevel -> null
null -> pluginProblem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.jetbrains.pluginverifier.tests

import com.jetbrains.plugin.structure.base.problems.PluginProblem
import com.jetbrains.plugin.structure.intellij.plugin.IdePluginImpl
import com.jetbrains.plugin.structure.intellij.problems.LevelRemappingPluginCreationResultResolver
import com.jetbrains.plugin.structure.intellij.problems.ReleaseVersionAndPluginVersionMismatch
import com.jetbrains.plugin.structure.intellij.problems.ignore
import com.jetbrains.plugin.structure.intellij.problems.*
import com.jetbrains.plugin.structure.intellij.problems.remapping.JsonUrlProblemLevelRemappingManager
import com.jetbrains.plugin.structure.intellij.problems.remapping.RemappingSet
import com.jetbrains.plugin.structure.intellij.version.ProductReleaseVersion
Expand All @@ -28,6 +26,21 @@ class LevelRemappingTest {
assertEmpty(remappedProblems)
}

@Test
fun `problem is remapped according to JSON rules and not remapped again`() {
val existingPluginResolver = JsonUrlProblemLevelRemappingManager
.fromClassPathJson()
.newDefaultResolver(RemappingSet.EXISTING_PLUGIN_REMAPPING_SET)
val ignoringProblemResolver = LevelRemappingPluginCreationResultResolver(existingPluginResolver, ignore<ReleaseDateInFuture>())

val problems = listOf(
ReleaseVersionWrongFormat(PLUGIN_XML, "1")
)

val remappedProblems = ignoringProblemResolver.classify(IdePluginImpl(), problems).filter { it.level == PluginProblem.Level.ERROR }
assertEmpty(remappedProblems)
}

private fun assertEmpty(problems: List<PluginProblem>) {
if (problems.isNotEmpty()) {
fail("No problems were expected, but found ${problems.size}: " + problems.joinToString { it.message })
Expand Down

0 comments on commit 1e01d56

Please sign in to comment.