Skip to content

Commit

Permalink
refactor: remove unused var, introduce listener object
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Nov 8, 2023
1 parent 20bc30c commit b4b0798
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
124 changes: 63 additions & 61 deletions src/main/kotlin/io/snyk/plugin/analytics/AnalyticsScanListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,80 +47,82 @@ class AnalyticsScanListener(val project: Project) {
)
}

fun initScanListener() = project.messageBus.connect().subscribe(
SnykScanListener.SNYK_SCAN_TOPIC,
object : SnykScanListener {
var start: Long = 0
private val snykScanListener = object : SnykScanListener {
var start: Long = 0

override fun scanningStarted() {
start = System.currentTimeMillis()
}
override fun scanningStarted() {
start = System.currentTimeMillis()
}

override fun scanningOssFinished(ossResult: OssResult) {
override fun scanningOssFinished(ossResult: OssResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Open Source",
ossResult.criticalSeveritiesCount(),
ossResult.highSeveritiesCount(),
ossResult.mediumSeveritiesCount(),
ossResult.lowSeveritiesCount()
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningSnykCodeFinished(snykCodeResults: SnykCodeResults?) {
snykCodeResults?.let {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Open Source",
ossResult.criticalSeveritiesCount(),
ossResult.highSeveritiesCount(),
ossResult.mediumSeveritiesCount(),
ossResult.lowSeveritiesCount()
"Snyk Code",
snykCodeResults.totalCriticalCount,
snykCodeResults.totalErrorsCount,
snykCodeResults.totalWarnsCount,
snykCodeResults.totalInfosCount,
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}
}

override fun scanningSnykCodeFinished(snykCodeResults: SnykCodeResults?) {
snykCodeResults?.let {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Code",
snykCodeResults.totalCriticalCount,
snykCodeResults.totalErrorsCount,
snykCodeResults.totalWarnsCount,
snykCodeResults.totalInfosCount,
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}
}
override fun scanningIacFinished(iacResult: IacResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk IaC",
iacResult.criticalSeveritiesCount(),
iacResult.highSeveritiesCount(),
iacResult.mediumSeveritiesCount(),
iacResult.lowSeveritiesCount()
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningIacFinished(iacResult: IacResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk IaC",
iacResult.criticalSeveritiesCount(),
iacResult.highSeveritiesCount(),
iacResult.mediumSeveritiesCount(),
iacResult.lowSeveritiesCount()
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}
override fun scanningOssError(snykError: SnykError) {
// do nothing
}

override fun scanningOssError(snykError: SnykError) {
// do nothing
}
override fun scanningIacError(snykError: SnykError) {
// do nothing
}

override fun scanningIacError(snykError: SnykError) {
// do nothing
}
override fun scanningSnykCodeError(snykError: SnykError) {
// do nothing
}

override fun scanningSnykCodeError(snykError: SnykError) {
// do nothing
}
override fun scanningContainerFinished(containerResult: ContainerResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Container",
containerResult.criticalSeveritiesCount(),
containerResult.highSeveritiesCount(),
containerResult.mediumSeveritiesCount(),
containerResult.lowSeveritiesCount()
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}

override fun scanningContainerFinished(containerResult: ContainerResult) {
val scanDoneEvent = getScanDoneEvent(
System.currentTimeMillis() - start,
"Snyk Container",
containerResult.criticalSeveritiesCount(),
containerResult.highSeveritiesCount(),
containerResult.mediumSeveritiesCount(),
containerResult.lowSeveritiesCount()
)
getSnykTaskQueueService(project)?.ls?.sendReportAnalyticsCommand(scanDoneEvent)
}
override fun scanningContainerError(snykError: SnykError) {
// do nothing
}
}

override fun scanningContainerError(snykError: SnykError) {
// do nothing
}
},
fun initScanListener() = project.messageBus.connect().subscribe(
SnykScanListener.SNYK_SCAN_TOPIC,
snykScanListener,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class SnykTaskQueueService(val project: Project) {
settings.localCodeEngineEnabled = sastCliConfigSettings?.localCodeEngine?.enabled
settings.localCodeEngineUrl = sastCliConfigSettings?.localCodeEngine?.url
settings.reportFalsePositivesEnabled = sastCliConfigSettings?.reportFalsePositivesEnabled
val start = System.currentTimeMillis()
when (settings.sastOnServerEnabled) {
true -> {
getSnykCode(project)?.scan()
Expand Down

0 comments on commit b4b0798

Please sign in to comment.