com.jetbrains.pluginverifier.response.sarif.SarifFormatConverter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of verifier-intellij Show documentation
Show all versions of verifier-intellij Show documentation
JetBrains Plugin Verifier Classes for IntelliJ Platform integration with API usage detection and reporting.
package com.jetbrains.pluginverifier.response.sarif
import com.jetbrains.pluginverifier.PluginVerificationResult
import com.jetbrains.pluginverifier.PluginVerificationTarget
import com.jetbrains.pluginverifier.response.VerificationResultTypeDto
import com.jetbrains.pluginverifier.response.convert
import com.jetbrains.pluginverifier.response.convertResultType
fun PluginVerificationResult.toSarif(): PluginVerificationResultSARIF {
return when (this) {
is PluginVerificationResult.Verified -> generateReport(
rules = buildRules(),
invocations = buildVerifiedInspections(),
)
is PluginVerificationResult.InvalidPlugin -> generateReport(
rules = buildPluginStructureRules(),
invocations = buildPluginStructureInspections(),
)
else -> generateReport(
rules = buildSingleRule(),
invocations = buildSingleInvocation(),
)
}
}
private fun PluginVerificationResult.generateReport(
rules: List,
invocations: List
): PluginVerificationResultSARIF {
return PluginVerificationResultSARIF(
runs = listOf(
Runner(
properties = toPluginVerifierPropertiesBag(),
automationDetails = toAutomationDetails(),
versionControlProvenance = toVersionControlProvenance(),
invocations = toInvocationStatus(),
tool = toToolWithRules(rules),
results = invocations
)
)
)
}
private fun PluginVerificationResult.toInvocationStatus(): List {
val code = when (this) {
is PluginVerificationResult.NotFound, is PluginVerificationResult.FailedToDownload -> 127
is PluginVerificationResult.InvalidPlugin -> 1
is PluginVerificationResult.Verified -> 0
}
val executionSuccessful = if (this is PluginVerificationResult.Verified) {
this.convertResultType() != VerificationResultTypeDto.PROBLEMS
} else false
return listOf(
InvocationStatus(
exitCode = code,
executionSuccessful = executionSuccessful,
exitCodeDescription = this.verificationVerdict
)
)
}
private fun PluginVerificationResult.toAutomationDetails(): AutomationDetails {
val plugin = this.plugin
return AutomationDetails(id = plugin.presentableName + " " + plugin.presentableSinceUntilRange)
}
private fun PluginVerificationResult.toPluginVerifierPropertiesBag(): PluginVerifierPropertiesBag {
val dependenciesGraph = if (this is PluginVerificationResult.Verified) dependenciesGraph.convert() else null
val dynamicPluginStatus = if (this is PluginVerificationResult.Verified) dynamicPluginStatus?.convert() else null
val ideVersion = verificationTarget as PluginVerificationTarget.IDE
val type = when (this) {
is PluginVerificationResult.Verified -> this.convertResultType()
is PluginVerificationResult.NotFound, is PluginVerificationResult.FailedToDownload -> VerificationResultTypeDto.NON_DOWNLOADABLE
is PluginVerificationResult.InvalidPlugin -> VerificationResultTypeDto.INVALID_PLUGIN
}
return PluginVerifierPropertiesBag(
ideVersion = ideVersion.ideVersion.asString(),
javaVersion = ideVersion.jdkVersion.javaVersion,
resultType = type,
verdict = this.verificationVerdict,
dependenciesGraph = dependenciesGraph,
dynamicPluginStatus = dynamicPluginStatus,
)
}
private fun toVersionControlProvenance(): List {
return listOf(
VersionControlProvenance(
repositoryUri = "TODO()" // TODO()
)
)
}
private fun toToolWithRules(rules: List): Tool {
return Tool(Driver(rules = rules))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy