@@ -26,6 +26,7 @@ import com.saveourtool.save.plugin.warn.sarif.toWarnings
26
26
import com.saveourtool.save.plugin.warn.utils.CmdExecutorWarn
27
27
import com.saveourtool.save.plugin.warn.utils.ResultsChecker
28
28
import com.saveourtool.save.plugin.warn.utils.Warning
29
+ import com.saveourtool.save.plugin.warn.utils.collectWarningsFromPlain
29
30
import com.saveourtool.save.plugin.warn.utils.collectWarningsFromSarif
30
31
import com.saveourtool.save.plugin.warn.utils.collectionMultilineWarnings
31
32
import com.saveourtool.save.plugin.warn.utils.collectionSingleWarnings
@@ -37,7 +38,6 @@ import okio.FileSystem
37
38
import okio.Path
38
39
39
40
import kotlin.random.Random
40
- import kotlinx.serialization.decodeFromString
41
41
import kotlinx.serialization.json.Json
42
42
43
43
private typealias WarningMap = Map <String , List <Warning >>
@@ -258,30 +258,52 @@ class WarnPlugin(
258
258
)
259
259
}.asSequence()
260
260
261
- @Suppress(" TooGenericExceptionCaught" , " SwallowedException" )
261
+ @Suppress(
262
+ " TooGenericExceptionCaught" ,
263
+ " SwallowedException" ,
264
+ " TOO_LONG_FUNCTION"
265
+ )
262
266
private fun collectExpectedWarnings (
263
267
generalConfig : GeneralConfig ,
264
268
warnPluginConfig : WarnPluginConfig ,
265
269
originalPaths : List <Path >,
266
270
copyPaths : List <Path >,
267
271
workingDirectory : Path ,
268
- ): WarningMap = if (warnPluginConfig.expectedWarningsFormat == ExpectedWarningsFormat .SARIF ) {
269
- val warningsFromSarif = try {
270
- collectWarningsFromSarif(warnPluginConfig, originalPaths, fs, workingDirectory)
271
- } catch (e: Exception ) {
272
- throw SarifParsingException (" We failed to parse sarif. Check the your tool generation of sarif report, cause: ${e.message} " , e.cause)
273
- }
274
- copyPaths.associate { copyPath ->
275
- copyPath.name to warningsFromSarif.filter { it.fileName == copyPath.name }
272
+ ): WarningMap {
273
+ val expectedWarningsFileName: String by lazy {
274
+ warnPluginConfig.expectedWarningsFileName
275
+ ? : throw IllegalArgumentException (" <expectedWarningsFileName> is not provided for expectedWarningsFormat=${warnPluginConfig.expectedWarningsFormat} " )
276
276
}
277
- } else {
278
- copyPaths.associate { copyPath ->
279
- val warningsForCurrentPath =
280
- copyPath .collectExpectedWarningsWithLineNumbers(
277
+ return when (warnPluginConfig.expectedWarningsFormat) {
278
+ ExpectedWarningsFormat . PLAIN -> {
279
+ val warningsFromPlain = collectWarningsFromPlain(expectedWarningsFileName, originalPaths, fs) { plainFile ->
280
+ plainFile .collectExpectedWarningsWithLineNumbers(
281
281
warnPluginConfig,
282
282
generalConfig
283
283
)
284
- copyPath.name to warningsForCurrentPath
284
+ }
285
+ copyPaths.associate { copyPath ->
286
+ copyPath.name to warningsFromPlain.filter { it.fileName == copyPath.name }
287
+ }
288
+ }
289
+ ExpectedWarningsFormat .SARIF -> {
290
+ val warningsFromSarif = try {
291
+ collectWarningsFromSarif(expectedWarningsFileName, originalPaths, fs, workingDirectory)
292
+ } catch (e: Exception ) {
293
+ throw SarifParsingException (" We failed to parse sarif. Check the your tool generation of sarif report, cause: ${e.message} " , e.cause)
294
+ }
295
+ copyPaths.associate { copyPath ->
296
+ copyPath.name to warningsFromSarif.filter { it.fileName == copyPath.name }
297
+ }
298
+ }
299
+ else -> copyPaths.associate { copyPath ->
300
+ val warningsForCurrentPath =
301
+ copyPath.collectExpectedWarningsWithLineNumbers(
302
+ warnPluginConfig,
303
+ generalConfig
304
+ )
305
+ copyPath.name to warningsForCurrentPath
306
+ }
285
307
}
286
308
}
287
309
0 commit comments