Changed try/catch to check file existence

This commit is contained in:
Maksim Pozdeev 2022-08-04 15:12:34 +04:00
parent 0014ddbc0c
commit 71765283c1
1 changed files with 23 additions and 21 deletions

View File

@ -9,32 +9,34 @@ import static_analysis.errors.StaticAnalysisError
import static_analysis.plugins.StaticAnalysisExtension
import static_analysis.utils.typedChildren
import static_analysis.utils.xmlParser
import java.io.FileNotFoundException
class AndroidLinter : Linter {
override val name: String = "Android lint"
override fun getErrors(project: Project): List<StaticAnalysisError> = try {
xmlParser(project.getLintReportFile())
.typedChildren()
.filter { it.name() == "issue" && (it.attribute("severity") as String) == "Error" }
.map { errorNode ->
errorNode
.typedChildren()
.filter { it.name() == "location" }
.map { locationNode ->
AndroidLintError(
filePath = locationNode.attribute("file") as String,
fileLine = locationNode.attribute("line") as String?,
errorId = errorNode.attribute("id") as String,
description = errorNode.attribute("message") as String
)
}
}
.flatten()
} catch (ex: FileNotFoundException) {
listOf()
override fun getErrors(project: Project): List<StaticAnalysisError> {
val lintRepostFile = project.getLintReportFile()
return if (lintRepostFile.exists()) {
xmlParser(project.getLintReportFile())
.typedChildren()
.filter { it.name() == "issue" && (it.attribute("severity") as String) == "Error" }
.map { errorNode ->
errorNode
.typedChildren()
.filter { it.name() == "location" }
.map { locationNode ->
AndroidLintError(
filePath = locationNode.attribute("file") as String,
fileLine = locationNode.attribute("line") as String?,
errorId = errorNode.attribute("id") as String,
description = errorNode.attribute("message") as String
)
}
}
.flatten()
} else {
listOf()
}
}
override fun setupForProject(project: Project, extension: StaticAnalysisExtension) {