Skip to content

Commit

Permalink
Report scanner progress using ProgressReport from zpa-core
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 23, 2019
1 parent 0ab0fa7 commit 7e3edd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/br/com/felipezorzo/zpa/cli/InputFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package br.com.felipezorzo.zpa.cli
import org.sonar.plugins.plsqlopen.api.PlSqlFile
import java.io.File
import java.nio.charset.Charset
import java.nio.file.Path
import java.nio.file.Paths

class InputFile(private val file: File, private val charset: Charset) : PlSqlFile {
class InputFile(private val baseDirPath: Path, private val file: File, private val charset: Charset) : PlSqlFile {

override fun contents(): String =
file.inputStream().use {
Expand All @@ -13,6 +15,6 @@ class InputFile(private val file: File, private val charset: Charset) : PlSqlFil

override fun fileName(): String = file.name

val absolutePath: String = file.absolutePath
val pathRelativeToBase: String = baseDirPath.relativize(Paths.get(file.absolutePath)).toString()

}
19 changes: 9 additions & 10 deletions src/main/kotlin/br/com/felipezorzo/zpa/cli/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import org.sonar.plsqlopen.rules.ZpaRule
import org.sonar.plsqlopen.rules.ZpaRuleKey
import org.sonar.plsqlopen.squid.PlSqlAstWalker
import org.sonar.plsqlopen.squid.PlSqlConfiguration
import org.sonar.plsqlopen.squid.ProgressReport
import org.sonar.plsqlopen.symbols.DefaultTypeSolver
import org.sonar.plsqlopen.symbols.SymbolVisitor
import org.sonar.plugins.plsqlopen.api.PlSqlVisitorContext
import org.sonar.plugins.plsqlopen.api.checks.PlSqlCheck
import org.sonar.plugins.plsqlopen.api.checks.PlSqlVisitor
import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import br.com.felipezorzo.zpa.cli.sqissue.Issue as GenericIssue

class Main : CliktCommand(name = "zpa-cli") {
Expand Down Expand Up @@ -61,7 +62,7 @@ class Main : CliktCommand(name = "zpa-cli") {
val files = baseDir
.walkTopDown()
.filter { it.isFile && extensions.contains(it.extension.toLowerCase()) }
.map { InputFile(it, StandardCharsets.UTF_8) }
.map { InputFile(baseDirPath, it, StandardCharsets.UTF_8) }
.toList()

val parser = PlSqlParser.create(PlSqlConfiguration(StandardCharsets.UTF_8))
Expand All @@ -71,10 +72,11 @@ class Main : CliktCommand(name = "zpa-cli") {

val genericIssues = mutableListOf<GenericIssue>()

for (file in files) {
val relativeFilePath = baseDirPath.relativize(Paths.get(file.absolutePath))
val progressReport = ProgressReport("Report about progress of code analyzer", TimeUnit.SECONDS.toMillis(10))
progressReport.start(files.map { it.pathRelativeToBase }.toList())

val relativeFilePathStr = relativeFilePath.toString().replace('\\', '/')
for (file in files) {
val relativeFilePathStr = file.pathRelativeToBase.replace('\\', '/')

val visitorContext = try {
val tree = getSemanticNode(parser.parse(file.contents()))
Expand All @@ -83,11 +85,6 @@ class Main : CliktCommand(name = "zpa-cli") {
PlSqlVisitorContext(file, e, metadata)
}

/*val defaultChecks = CheckList.checks
.map { it.getConstructor().newInstance() as PlSqlCheck }
.filter { metadata != null || it !is FormsMetadataAwareCheck }
.toTypedArray()*/

val visitors = listOf(
SymbolVisitor(DefaultTypeSolver()),
*checks.all().toTypedArray())
Expand Down Expand Up @@ -136,7 +133,9 @@ class Main : CliktCommand(name = "zpa-cli") {
)
}
}
progressReport.nextFile()
}
progressReport.stop()

val genericReport = GenericIssueData(genericIssues)

Expand Down

0 comments on commit 7e3edd3

Please sign in to comment.