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

Use the same logic for classify and remapping #1163

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 remap again`() {
novotnyr marked this conversation as resolved.
Show resolved Hide resolved
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
Loading