Skip to content

Commit

Permalink
feat: Add debug logging on the test and coverage importers
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 24, 2024
1 parent b5918c0 commit 4ef718b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.sonar.plsqlopen.utils.log.Loggers
import java.io.File

abstract class AbstractReportImporter(private val analysisWarnings: AnalysisWarnings) {

private val logger: Logger = Loggers.getLogger(AbstractReportImporter::class.java)

abstract val reportType: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ import org.simpleframework.xml.core.Persister
import org.sonar.api.batch.sensor.SensorContext
import org.sonar.api.notifications.AnalysisWarnings
import org.sonar.plsqlopen.symbols.ObjectLocator
import org.sonar.plsqlopen.utils.log.Loggers
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import java.io.File


class CoverageResultImporter(private val objectLocator: ObjectLocator,
analysisWarnings: AnalysisWarnings) : AbstractReportImporter(analysisWarnings) {

private val logger = Loggers.getLogger(CoverageResultImporter::class.java)
override val reportType = "coverage"
override val reportKey = UtPlSqlSensor.COVERAGE_REPORT_PATH_KEY

Expand Down Expand Up @@ -63,6 +65,7 @@ class CoverageResultImporter(private val objectLocator: ObjectLocator,
}

if (inputFile != null) {
logger.debug("The path ${file.path} was mapped to ${inputFile}")
val newCoverage = context.newCoverage().onFile(inputFile)

file.linesToCover?.forEach { line ->
Expand All @@ -82,6 +85,8 @@ class CoverageResultImporter(private val objectLocator: ObjectLocator,
}

newCoverage.save()
} else {
logger.warn("The path ${file.path} was not found in the project")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import org.sonar.api.batch.sensor.SensorContext
import org.sonar.api.measures.CoreMetrics
import org.sonar.api.notifications.AnalysisWarnings
import org.sonar.plsqlopen.symbols.ObjectLocator
import org.sonar.plsqlopen.utils.log.Loggers
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import java.io.File
import java.io.Serializable

class TestResultImporter(private val objectLocator: ObjectLocator,
analysisWarnings: AnalysisWarnings) : AbstractReportImporter(analysisWarnings) {

private val logger = Loggers.getLogger(TestResultImporter::class.java)
override val reportType = "test"
override val reportKey = UtPlSqlSensor.TEST_REPORT_PATH_KEY

Expand All @@ -47,6 +49,7 @@ class TestResultImporter(private val objectLocator: ObjectLocator,
.inputFile(context.fileSystem().predicates().hasPath(file.path))

if (inputFile != null) {
logger.debug("The path ${file.path} was mapped to ${inputFile}")
file.testCases?.let { testCase ->
val testCount = testCase.count { it.status != TestCaseStatus.SKIPPED }
val failureCount = testCase.count { it.status == TestCaseStatus.FAILED }
Expand All @@ -60,6 +63,8 @@ class TestResultImporter(private val objectLocator: ObjectLocator,
saveMetricOnFile(context, inputFile, CoreMetrics.SKIPPED_TESTS, skippedCount)
saveMetricOnFile(context, inputFile, CoreMetrics.TEST_EXECUTION_TIME, duration)
}
} else {
logger.warn("The path ${file.path} was not found in the project")
}
}
}
Expand Down

0 comments on commit 4ef718b

Please sign in to comment.