Skip to content

Commit e2a1bce

Browse files
authored
Merge pull request #156 from PatilShreyas/139
#139: Refactor ReportAndMetricsFileFinder: collect all files inside nested directories
2 parents e3dd265 + 26175fd commit e2a1bce

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/file/ReportAndMetricsFileFinder.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package dev.shreyaspatil.composeCompilerMetricsGenerator.core.file
2525

2626
import java.io.File
27+
import java.nio.file.Files
2728

2829
/**
2930
* Finds reports and metrics files generated by Compose compiler
@@ -33,11 +34,7 @@ import java.io.File
3334
class ReportAndMetricsFileFinder(
3435
directory: File,
3536
) {
36-
private val allFiles =
37-
directory
38-
.listFiles()
39-
?.filterNotNull()
40-
?: emptyList()
37+
private val allFiles = directory.listAllFiles()
4138

4239
fun findBriefStatisticsJsonFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.MODULE_REPORT_JSON) }
4340

@@ -47,6 +44,21 @@ class ReportAndMetricsFileFinder(
4744

4845
fun findClassesReportTxtFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.CLASSES_REPORT_TXT) }
4946

47+
private fun File.listAllFiles(): List<File> =
48+
buildList {
49+
val currentPath = toPath()
50+
Files.newDirectoryStream(currentPath).use { directoryStream ->
51+
for (entry in directoryStream) {
52+
val file = entry.toFile() ?: continue
53+
if (Files.isDirectory(entry)) {
54+
addAll(file.listAllFiles())
55+
} else {
56+
add(file)
57+
}
58+
}
59+
}
60+
}
61+
5062
object FileSuffixes {
5163
const val CLASSES_REPORT_TXT = "-classes.txt"
5264
const val COMPOSABLES_REPORT_TXT = "-composables.txt"

0 commit comments

Comments
 (0)