Skip to content

Commit 3b04f7a

Browse files
committed
Merge branch 'main' of github.com:PatilShreyas/compose-report-to-html
2 parents 7349e55 + e2a1bce commit 3b04f7a

File tree

21 files changed

+171
-133
lines changed

21 files changed

+171
-133
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,15 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v1
10+
- name: Checkout branch
11+
uses: actions/checkout@v3.5.3
1112

12-
- name: Set up JDK 11
13-
uses: actions/setup-java@v1
13+
- name: Set up JDK 17
14+
uses: actions/setup-java@v3
1415
with:
15-
java-version: 11
16-
17-
- name: Cache Gradle and wrapper
18-
uses: actions/cache@v2
19-
with:
20-
path: |
21-
~/.gradle/caches
22-
~/.gradle/wrapper
23-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
24-
restore-keys: |
25-
${{ runner.os }}-gradle-
16+
java-version: 17
17+
distribution: temurin
18+
cache: gradle
2619

2720
- name: Grant Permission to Execute
2821
run: chmod +x gradlew

.github/workflows/publish-docs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- name: Checkout branch
15+
uses: actions/checkout@v3.5.3
1516

16-
- name: set up JDK
17-
uses: actions/setup-java@v1
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v3
1819
with:
19-
java-version: 11
20+
java-version: 17
21+
distribution: temurin
22+
cache: gradle
2023

2124
- name: Setup Python
2225
uses: actions/setup-python@v2

.github/workflows/release.yml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,15 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v1
13+
- name: Checkout branch
14+
uses: actions/checkout@v3.5.3
1415

15-
- name: Set up JDK 11
16-
uses: actions/setup-java@v1
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v3
1718
with:
18-
java-version: 11
19-
20-
- name: Cache Gradle and wrapper
21-
uses: actions/cache@v2
22-
with:
23-
path: |
24-
~/.gradle/caches
25-
~/.gradle/wrapper
26-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
27-
restore-keys: |
28-
${{ runner.os }}-gradle-
19+
java-version: 17
20+
distribution: temurin
21+
cache: gradle
2922

3023
- name: Set up NPM
3124
uses: actions/setup-node@v3

cli/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/cli/Main.kt

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ fun saveReportAsHtml(
9898
/**
9999
* Parses and validates CLI arguments
100100
*/
101-
class CliArguments(args: Array<String>, private val path: Path) {
101+
class CliArguments(
102+
args: Array<String>,
103+
private val path: Path,
104+
) {
102105
private val parser = ArgParser("Compose Compiler Report to HTML Generator ~ ${Constants.VERSION}")
103106

104-
val applicationName by parser.option(
105-
ArgType.String,
106-
shortName = "app",
107-
description = "Application name (To be displayed in the report)",
108-
).required()
107+
val applicationName by parser
108+
.option(
109+
ArgType.String,
110+
shortName = "app",
111+
description = "Application name (To be displayed in the report)",
112+
).required()
109113

110114
val inputDirectory by parser.option(
111115
ArgType.String,
@@ -137,31 +141,36 @@ class CliArguments(args: Array<String>, private val path: Path) {
137141
description = "Class Metrics TXT files (separated by commas)",
138142
)
139143

140-
val outputDirectory by parser.option(
141-
ArgType.String,
142-
shortName = "o",
143-
description = "Output directory name",
144-
).default(path.toAbsolutePath().toString())
145-
146-
val includeStableComposables by parser.option(
147-
ArgType.Boolean,
148-
description = "Whether to include stable Composable functions in the report",
149-
).default(true)
150-
151-
val includeStableClasses by parser.option(
152-
ArgType.Boolean,
153-
description = "Whether to include stable classes in the report",
154-
).default(true)
155-
156-
val includeClasses by parser.option(
157-
ArgType.Boolean,
158-
description = "Whether to include all the classes in the report",
159-
).default(true)
160-
161-
val showOnlyUnstableComposables by parser.option(
162-
ArgType.Boolean,
163-
description = "Whether to ONLY include unstable composables in the report",
164-
).default(false)
144+
val outputDirectory by parser
145+
.option(
146+
ArgType.String,
147+
shortName = "o",
148+
description = "Output directory name",
149+
).default(path.toAbsolutePath().toString())
150+
151+
val includeStableComposables by parser
152+
.option(
153+
ArgType.Boolean,
154+
description = "Whether to include stable Composable functions in the report",
155+
).default(true)
156+
157+
val includeStableClasses by parser
158+
.option(
159+
ArgType.Boolean,
160+
description = "Whether to include stable classes in the report",
161+
).default(true)
162+
163+
val includeClasses by parser
164+
.option(
165+
ArgType.Boolean,
166+
description = "Whether to include all the classes in the report",
167+
).default(true)
168+
169+
val showOnlyUnstableComposables by parser
170+
.option(
171+
ArgType.Boolean,
172+
description = "Whether to ONLY include unstable composables in the report",
173+
).default(false)
165174

166175
init {
167176
parser.parse(args)
@@ -195,22 +204,18 @@ class CliArguments(args: Array<String>, private val path: Path) {
195204
}
196205
}
197206

198-
private fun getRawReportProviderFromIndividualFiles(): ComposeCompilerRawReportProvider {
199-
return ComposeCompilerRawReportProvider.FromIndividualFiles(
207+
private fun getRawReportProviderFromIndividualFiles(): ComposeCompilerRawReportProvider =
208+
ComposeCompilerRawReportProvider.FromIndividualFiles(
200209
briefStatisticsJsonFiles = files(overallStatsFile!!),
201210
detailedStatisticsCsvFiles = files(detailedStatsFile!!),
202211
composableReportFiles = files(composableMetricsFile!!),
203212
classesReportFiles = files(classMetricsFile!!),
204213
)
205-
}
206214

207-
private fun getRawReportProviderFromDirectory(directory: String): ComposeCompilerRawReportProvider.FromDirectory {
208-
return ComposeCompilerRawReportProvider.FromDirectory(File(Paths.get(directory).toAbsolutePath().toString()))
209-
}
215+
private fun getRawReportProviderFromDirectory(directory: String): ComposeCompilerRawReportProvider.FromDirectory =
216+
ComposeCompilerRawReportProvider.FromDirectory(File(Paths.get(directory).toAbsolutePath().toString()))
210217

211-
private fun files(filenames: String): List<File> {
212-
return filenames.split(",").map { ensureFileExists(it) { "File not exist: $it" } }
213-
}
218+
private fun files(filenames: String): List<File> = filenames.split(",").map { ensureFileExists(it) { "File not exist: $it" } }
214219
}
215220

216221
fun printHeader(header: String) =

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/ComposeCompilerMetricsProvider.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private class DefaultComposeCompilerMetricsProvider(
101101
if (csv.size > 1) {
102102
val headers = splitWithCsvSeparator(csv.first())
103103

104-
csv.subList(1, csv.size)
104+
csv
105+
.subList(1, csv.size)
105106
.map { splitWithCsvSeparator(it) }
106107
.map { items -> RowItems(items.mapIndexed { index, value -> Item(headers[index], value) }) }
107108
} else {
@@ -111,13 +112,9 @@ private class DefaultComposeCompilerMetricsProvider(
111112
return DetailedStatistics(metrics)
112113
}
113114

114-
override fun getComposablesReport(): ComposablesReport {
115-
return ComposableReportParser.parse(contentProvider.composablesReportContents)
116-
}
115+
override fun getComposablesReport(): ComposablesReport = ComposableReportParser.parse(contentProvider.composablesReportContents)
117116

118-
override fun getClassesReport(): ClassesReport {
119-
return ClassReportParser.parse(contentProvider.classesReportContents)
120-
}
117+
override fun getClassesReport(): ClassesReport = ClassReportParser.parse(contentProvider.classesReportContents)
121118

122119
private fun splitWithCsvSeparator(content: String) = content.split(",").filter { it.isNotBlank() }
123120
}

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/ComposeCompilerRawReportProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ sealed interface ComposeCompilerRawReportProvider {
5454
/**
5555
* Searches for files in the given [directory] and provides report and metric files found in that directory.
5656
*/
57-
class FromDirectory(directory: File) : ComposeCompilerRawReportProvider {
57+
class FromDirectory(
58+
directory: File,
59+
) : ComposeCompilerRawReportProvider {
5860
private val finder = ReportAndMetricsFileFinder(directory)
5961

6062
override val briefStatisticsJsonFiles: List<File> = finder.findBriefStatisticsJsonFile()

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/ComposeMetricsContentProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ package dev.shreyaspatil.composeCompilerMetricsGenerator.core
2626
/**
2727
* Provides content of a composable report and metrics
2828
*/
29-
class ComposeMetricsContentProvider(private val fileProvider: ComposeCompilerRawReportProvider) {
29+
class ComposeMetricsContentProvider(
30+
private val fileProvider: ComposeCompilerRawReportProvider,
31+
) {
3032
val briefStatisticsContents: List<String> get() = fileProvider.briefStatisticsJsonFiles.map { it.readText() }
3133
val detailedStatisticsCsvRows: List<String> get() = fileProvider.detailedStatisticsCsvFiles.flatMap { it.readLines() }
3234
val composablesReportContents: String get() = fileProvider.composableReportFiles.joinToString(separator = "\n") { it.readText() }

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

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,40 @@
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
3031
*
3132
* @param directory The directory in which files will be searched
3233
*/
33-
class ReportAndMetricsFileFinder(directory: File) {
34-
private val allFiles =
35-
directory
36-
.listFiles()
37-
?.filterNotNull()
38-
?: emptyList()
39-
40-
fun findBriefStatisticsJsonFile(): List<File> {
41-
return allFiles.filter { it.name.endsWith(FileSuffixes.MODULE_REPORT_JSON) }
42-
}
34+
class ReportAndMetricsFileFinder(
35+
directory: File,
36+
) {
37+
private val allFiles = directory.listAllFiles()
4338

44-
fun findDetailsStatisticsCsvFile(): List<File> {
45-
return allFiles.filter { it.name.endsWith(FileSuffixes.COMPOSABLES_STATS_METRICS_CSV) }
46-
}
39+
fun findBriefStatisticsJsonFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.MODULE_REPORT_JSON) }
4740

48-
fun findComposablesReportTxtFile(): List<File> {
49-
return allFiles.filter { it.name.endsWith(FileSuffixes.COMPOSABLES_REPORT_TXT) }
50-
}
41+
fun findDetailsStatisticsCsvFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.COMPOSABLES_STATS_METRICS_CSV) }
5142

52-
fun findClassesReportTxtFile(): List<File> {
53-
return allFiles.filter { it.name.endsWith(FileSuffixes.CLASSES_REPORT_TXT) }
54-
}
43+
fun findComposablesReportTxtFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.COMPOSABLES_REPORT_TXT) }
44+
45+
fun findClassesReportTxtFile(): List<File> = allFiles.filter { it.name.endsWith(FileSuffixes.CLASSES_REPORT_TXT) }
46+
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+
}
5561

5662
object FileSuffixes {
5763
const val CLASSES_REPORT_TXT = "-classes.txt"

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/model/DetailedStatistics.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ package dev.shreyaspatil.composeCompilerMetricsGenerator.core.model
2828
*
2929
* @property items List of detailed items
3030
*/
31-
data class DetailedStatistics(val items: List<RowItems>) {
31+
data class DetailedStatistics(
32+
val items: List<RowItems>,
33+
) {
3234
/**
3335
* Headers of a report
3436
*/
@@ -38,9 +40,14 @@ data class DetailedStatistics(val items: List<RowItems>) {
3840
/**
3941
* Model for holding list of name and value pairs i.e. item details
4042
*/
41-
data class RowItems(val item: List<Item>)
43+
data class RowItems(
44+
val item: List<Item>,
45+
)
4246

4347
/**
4448
* Model representing name-value pairs
4549
*/
46-
data class Item(val name: String, val value: String)
50+
data class Item(
51+
val name: String,
52+
val value: String,
53+
)

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/model/RawContent.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ package dev.shreyaspatil.composeCompilerMetricsGenerator.core.model
2727
* Represents raw data provided by Compose compiler.
2828
* Example: Composable function metric generated by compiler extracted from `-composables.txt` file
2929
*/
30-
data class RawContent(val content: String)
30+
data class RawContent(
31+
val content: String,
32+
)

0 commit comments

Comments
 (0)