Skip to content

Commit 79890ee

Browse files
authored
Merge pull request #29 from PatilShreyas/v1.0.0-beta02
Release v1.0.0-beta02
2 parents ab79b43 + 90ee389 commit 79890ee

File tree

11 files changed

+98
-24
lines changed

11 files changed

+98
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ fun printHeader(header: String) = println(
185185
)
186186

187187
object Constants {
188-
const val VERSION = "v1.0.0-beta01"
188+
const val VERSION = "v1.0.0-beta02"
189189
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 Shreyas Patil
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package dev.shreyaspatil.composeCompilerMetricsGenerator.core.model
25+
26+
/**
27+
* Represents raw data provided by Compose compiler.
28+
* Example: Composable function metric generated by compiler extracted from `-composables.txt` file
29+
*/
30+
data class RawContent(val content: String)

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/model/classes/ClassDetail.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.classes
2525

2626
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.Condition
27+
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.RawContent
2728

2829
/**
2930
* Model for holding class details
@@ -37,7 +38,8 @@ data class ClassDetail(
3738
val className: String,
3839
val stability: Condition,
3940
val runtimeStability: Condition?,
40-
val fields: List<Field>
41+
val fields: List<Field>,
42+
val rawContent: RawContent,
4143
) {
4244
/**
4345
* Model for holding field details of a class

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/model/composables/ComposableDetail.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.composables
2525

2626
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.Condition
27+
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.RawContent
2728

2829
/**
2930
* Model for holding Detail of a composable function
@@ -39,7 +40,8 @@ data class ComposableDetail(
3940
val isRestartable: Boolean,
4041
val isSkippable: Boolean,
4142
val isInline: Boolean,
42-
val params: List<Parameter>
43+
val params: List<Parameter>,
44+
val rawContent: RawContent,
4345
) {
4446
/**
4547
* Model for holding details of a parameter of a function

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/parser/ClassReportParser.kt

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

2626
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.exception.ParsingException
2727
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.mapper.ConditionMapper
28+
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.RawContent
2829
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.classes.ClassDetail
2930
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.classes.ClassesReport
3031

@@ -33,17 +34,16 @@ import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.classes.Class
3334
*/
3435
object ClassReportParser : Parser<String, ClassesReport> {
3536
private val REGEX_RUNTIME_STABILITY = "<runtime stability> = (\\w+)".toRegex()
36-
private val REGEX_CLASS_NAME = "(stable|unstable) class (\\w*)".toRegex()
37+
private val REGEX_CLASS_NAME = "(stable|unstable|runtime) class (\\w*)".toRegex()
3738
private val REGEX_CLASS_FIELDS = "((\\w*) ((?:val|var) .*))".toRegex()
38-
private val REGEX_ALL_CLASSES = "((?:stable|unstable) class \\w+ \\{\\s*(?:[^{}\\r\\n]|\\n|)*})".toRegex()
3939

4040
/**
4141
* Parses all classes
4242
*/
4343
override fun parse(content: String): ClassesReport {
4444
val errors = mutableListOf<ParsingException>()
45-
val classes = REGEX_ALL_CLASSES.findAll(content)
46-
.map { it.value }
45+
46+
val classes = getClasses(content)
4747
.mapNotNull { classBody ->
4848
runCatching {
4949
parseClassDetail(classBody)
@@ -55,6 +55,22 @@ object ClassReportParser : Parser<String, ClassesReport> {
5555
return ClassesReport(classes, errors.toList())
5656
}
5757

58+
internal fun getClasses(content: String): List<String> {
59+
val lines = content.split("\n").filter { it.isNotBlank() }
60+
61+
val classIndexes = lines.mapIndexedNotNull { index, s ->
62+
if (REGEX_CLASS_NAME.containsMatchIn(s)) {
63+
index
64+
} else {
65+
null
66+
}
67+
}
68+
69+
return classIndexes.mapIndexed { index: Int, item: Int ->
70+
lines.subList(item, classIndexes.getOrElse(index + 1) { lines.size }).joinToString(separator = "\n")
71+
}
72+
}
73+
5874
/**
5975
* Parses unit class
6076
*/
@@ -70,6 +86,12 @@ object ClassReportParser : Parser<String, ClassesReport> {
7086
val fields = REGEX_CLASS_FIELDS.findAll(classBody).map { it.groupValues }.filter { it.isNotEmpty() }
7187
.map { ClassDetail.Field(it[2], it[3]) }.toList()
7288

73-
return ClassDetail(className, stability, runtimeStability, fields = fields)
89+
return ClassDetail(
90+
className = className,
91+
stability = stability,
92+
runtimeStability = runtimeStability,
93+
fields = fields,
94+
rawContent = RawContent(classBody)
95+
)
7496
}
7597
}

core/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/core/parser/ComposableReportParser.kt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ package dev.shreyaspatil.composeCompilerMetricsGenerator.core.parser
2525

2626
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.exception.ParsingException
2727
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.mapper.ConditionMapper
28+
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.RawContent
2829
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.composables.ComposableDetail
2930
import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.composables.ComposablesReport
3031

3132
/**
3233
* Parses [ComposablesReport] from the [String] content.
3334
*/
3435
object ComposableReportParser : Parser<String, ComposablesReport> {
35-
private val REGEX_ALL_COMPOSABLES_FUNCTIONS =
36-
"(.*(\\s|\\S)fun \\w*\\([\\s\\S]*?^\\))".toRegex(RegexOption.MULTILINE)
37-
3836
private val REGEX_COMPOSABLE_FUNCTION = "(?:(.*))fun (\\w*)".toRegex()
3937
private val REGEX_COMPOSABLE_PARAMETERS = "(?:(stable|unstable|) (\\w*:\\s.*))".toRegex()
4038

@@ -43,8 +41,8 @@ object ComposableReportParser : Parser<String, ComposablesReport> {
4341
*/
4442
override fun parse(content: String): ComposablesReport {
4543
val errors = mutableListOf<ParsingException>()
46-
val composables = REGEX_ALL_COMPOSABLES_FUNCTIONS.findAll(content)
47-
.map { it.value }
44+
45+
val composables = getComposableFunctions(content)
4846
.mapNotNull { function ->
4947
runCatching {
5048
parseComposableDetail(function)
@@ -57,6 +55,22 @@ object ComposableReportParser : Parser<String, ComposablesReport> {
5755
return ComposablesReport(composables, errors.toList())
5856
}
5957

58+
internal fun getComposableFunctions(content: String): List<String> {
59+
val lines = content.split("\n").filter { it.isNotBlank() }
60+
61+
val composableFunIndexes = lines.mapIndexedNotNull { index, s ->
62+
if (REGEX_COMPOSABLE_FUNCTION.containsMatchIn(s)) {
63+
index
64+
} else {
65+
null
66+
}
67+
}
68+
69+
return composableFunIndexes.mapIndexed { index: Int, item: Int ->
70+
lines.subList(item, composableFunIndexes.getOrElse(index + 1) { lines.size }).joinToString(separator = "\n")
71+
}
72+
}
73+
6074
/**
6175
* Parses unit composable
6276
*/
@@ -73,6 +87,13 @@ object ComposableReportParser : Parser<String, ComposablesReport> {
7387
val params = REGEX_COMPOSABLE_PARAMETERS.findAll(function).map { it.groupValues }.filter { it.isNotEmpty() }
7488
.map { ComposableDetail.Parameter(ConditionMapper.from(it[1]), it[2]) }.toList()
7589

76-
return ComposableDetail(functionName, isRestartable, isSkippable, isInline, params)
90+
return ComposableDetail(
91+
functionName = functionName,
92+
isRestartable = isRestartable,
93+
isSkippable = isSkippable,
94+
isInline = isInline,
95+
params = params,
96+
rawContent = RawContent(function)
97+
)
7798
}
7899
}

docs/use/using-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Run the command to know the usage of CLI
5656
!!! success "▶️Output"
5757

5858
```shell
59-
Usage: Compose Compiler Report to HTML Generator ~ v1.0.0-beta01 options_list
59+
Usage: Compose Compiler Report to HTML Generator ~ v1.0.0-beta02 options_list
6060
Options:
6161
--applicationName, -app -> Application name (To be displayed in the report) (always required) { String }
6262
--inputDirectory, -i -> Input directory where composable report and metrics are available { String }

docs/use/using-gradle-plugin.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Apply the plugin to the module in which _**compose is enabled**_.
1919

2020
```groovy title="build.gradle"
2121
plugins {
22-
id "dev.shreyaspatil.compose-compiler-report-generator" version "1.0.0-beta01"
22+
id "dev.shreyaspatil.compose-compiler-report-generator" version "1.0.0-beta02"
2323
}
2424
```
2525

2626
=== "Kotlin"
2727

2828
```kotlin title="build.gradle.kts"
2929
plugins {
30-
id("dev.shreyaspatil.compose-compiler-report-generator") version "1.0.0-beta01"
30+
id("dev.shreyaspatil.compose-compiler-report-generator") version "1.0.0-beta02"
3131
}
3232
```
3333

@@ -45,7 +45,7 @@ Add this to top project level `build.gradle`
4545
}
4646
}
4747
dependencies {
48-
classpath "dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.0.0-beta01"
48+
classpath "dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.0.0-beta02"
4949
}
5050
}
5151
```
@@ -66,7 +66,7 @@ Add this to top project level `build.gradle`
6666
}
6767
}
6868
dependencies {
69-
classpath("dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.0.0-beta01")
69+
classpath("dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.0.0-beta02")
7070
}
7171
}
7272
```

gradle-plugin/src/main/kotlin/dev/shreyaspatil/composeCompilerMetricsGenerator/plugin/task/ComposeCompilerReportGenerateTask.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ fun Project.createComposeCompilerReportGenTaskForVariant(
5151
// and again runs this task then compose metrics won't be generated by compiler again
5252
startParameter.isRerunTasks = true
5353

54-
// For the same reason as above, disable caching for this task.
55-
startParameter.isBuildCacheEnabled = false
56-
5754
tasks = listOf("compile${variant.name.capitalized()}Kotlin")
5855

5956
doFirst {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
kotlin.code.style=official
22

33
GROUP=dev.shreyaspatil.compose-compiler-report-generator
4-
VERSION_NAME=1.0.0-beta01
4+
VERSION_NAME=1.0.0-beta02
55

66
# Library configuration
77
SONATYPE_HOST=DEFAULT

0 commit comments

Comments
 (0)