-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #276 use java nio to scan for reports
- Loading branch information
Showing
6 changed files
with
58 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
.../src/main/kotlin/org/camunda/community/process_test_coverage/sonar/ReportPathsProvider.kt
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...ugin/src/main/kotlin/org/camunda/community/process_test_coverage/sonar/ReportsProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.camunda.community.process_test_coverage.sonar | ||
|
||
import org.sonar.api.batch.sensor.SensorContext | ||
import org.sonar.api.utils.log.Logger | ||
import org.sonar.api.utils.log.Loggers | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import kotlin.streams.toList as streamToList | ||
|
||
|
||
class ReportsProvider( | ||
private val context: SensorContext | ||
) { | ||
|
||
companion object { | ||
private val LOG: Logger = Loggers.get(ReportsProvider::class.java) | ||
private val DEFAULT_PATHS = arrayOf("target/process-test-coverage/**/report.json") | ||
const val REPORT_PATHS_PROPERTY_KEY = "sonar.process-test-coverage.jsonReportPaths" | ||
} | ||
|
||
fun getProjectReports(): Collection<Path> { | ||
val pathPattern = getPathPattern("**/") | ||
val matcher = FileSystems.getDefault().getPathMatcher("glob:$pathPattern") | ||
return Files.find(context.fileSystem().baseDir().toPath(), Int.MAX_VALUE, { path, _ -> | ||
matcher.matches(path) | ||
}).streamToList() | ||
} | ||
|
||
fun getModuleReports(): Collection<Path> { | ||
val pathPattern = getPathPattern("") | ||
val matcher = FileSystems.getDefault().getPathMatcher("glob:$pathPattern") | ||
return Files.find(context.fileSystem().baseDir().toPath(), Int.MAX_VALUE, { path, _ -> | ||
val relativePath = context.fileSystem().baseDir().toPath().relativize(path) | ||
matcher.matches(relativePath) | ||
}).streamToList() | ||
} | ||
|
||
private fun getPathPattern(prefix: String): String { | ||
val paths = context.config().getStringArray(REPORT_PATHS_PROPERTY_KEY) | ||
.filter { it.isNotEmpty() } | ||
.plus(DEFAULT_PATHS) | ||
LOG.info("Configured paths are $paths") | ||
val pattern = paths.joinToString(prefix = "{", postfix = "}", separator = ",") { "$prefix$it" } | ||
LOG.info("Using pattern $pattern for reports") | ||
return pattern | ||
} | ||
|
||
} |
98 changes: 0 additions & 98 deletions
98
...in/kotlin/org/camunda/community/process_test_coverage/sonar/WildcardPatternFileScanner.kt
This file was deleted.
Oops, something went wrong.