Skip to content

Commit 70e838a

Browse files
committed
Merge branch 'main' of github.com:PatilShreyas/compose-report-to-html
2 parents 98b7da2 + 3bccc64 commit 70e838a

File tree

18 files changed

+342
-79
lines changed

18 files changed

+342
-79
lines changed

build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ plugins {
1212
group = GROUP
1313
version = VERSION_NAME
1414

15-
repositories {
16-
mavenCentral()
17-
}
18-
1915
tasks.withType<KotlinCompile> {
2016
kotlinOptions.jvmTarget = "1.8"
2117
}
@@ -32,4 +28,4 @@ subprojects {
3228
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
3329
}
3430
}
35-
}
31+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,5 @@ fun printHeader(header: String) =
222222
)
223223

224224
object Constants {
225-
const val VERSION = "v1.3.1"
225+
const val VERSION = "v1.4.0"
226226
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import dev.shreyaspatil.composeCompilerMetricsGenerator.core.model.composables.C
3434
*/
3535
object ComposableReportParser : Parser<String, ComposablesReport> {
3636
private val REGEX_COMPOSABLE_FUNCTION = "(?:(.*))fun (\\w*)".toRegex()
37-
private val REGEX_COMPOSABLE_PARAMETERS = "(?:(stable|unstable|) (\\w*:\\s.*))".toRegex()
37+
private val REGEX_COMPOSABLE_PARAMETERS = "(?:(stable|unstable|\\w+) (\\w*:\\s.*))".toRegex()
3838

3939
/**
4040
* Parses all composable functions
123 KB
Loading

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.3.1 options_list
59+
Usage: Compose Compiler Report to HTML Generator ~ v1.4.0 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: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Using the Gradle Plugin, you can fully automate the process of generating the re
44
This Gradle plugin takes care of generating raw compose metrics and report from the Compose compiler and then
55
generates the beautified report from them.
66

7+
**This plugin has support for Android projects and Kotlin Multiplatform projects.**
8+
79
## ✅ Apply the plugin
810

911
Apply the plugin to the module in which _**compose is enabled**_.
@@ -19,15 +21,15 @@ Apply the plugin to the module in which _**compose is enabled**_.
1921

2022
```groovy title="build.gradle"
2123
plugins {
22-
id "dev.shreyaspatil.compose-compiler-report-generator" version "1.3.1"
24+
id "dev.shreyaspatil.compose-compiler-report-generator" version "1.4.0"
2325
}
2426
```
2527

2628
=== "Kotlin"
2729

2830
```kotlin title="build.gradle.kts"
2931
plugins {
30-
id("dev.shreyaspatil.compose-compiler-report-generator") version "1.3.1"
32+
id("dev.shreyaspatil.compose-compiler-report-generator") version "1.4.0"
3133
}
3234
```
3335

@@ -45,7 +47,7 @@ Add this to top project level `build.gradle`
4547
}
4648
}
4749
dependencies {
48-
classpath "dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.3.1"
50+
classpath "dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.4.0"
4951
}
5052
}
5153
```
@@ -66,7 +68,7 @@ Add this to top project level `build.gradle`
6668
}
6769
}
6870
dependencies {
69-
classpath("dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.3.1")
71+
classpath("dev.shreyaspatil.compose-compiler-report-generator:gradle-plugin:1.4.0")
7072
}
7173
}
7274
```
@@ -79,12 +81,22 @@ Add this to top project level `build.gradle`
7981

8082
## 💫 Sync the project
8183

82-
Once plugin is applied, sync the project. After the project is synced, tasks for generating compose report will be
83-
generated for the variants and flavors used in the project.
84+
Once plugin is applied, sync the project. After the project is synced, tasks for generating compose
85+
report will be generated for the variants and flavors used in the project.
8486

8587
!!! example
88+
89+
=== "Android Project"
90+
91+
![](../images/gradle-plugin-example-android.png){ height="150" }
92+
93+
=== "Multiplatform Project"
94+
For Kotlin Multiplatform project, tasks will be generated for the platform modules
95+
and build types.
96+
97+
![](../images/gradle-plugin-example-kmp.png){ height="120" }
98+
8699

87-
![](../images/gradle-plugin-example.png){ height="150" }
88100

89101
## 🪄 Generate report
90102

@@ -139,7 +151,7 @@ If you have to configure plugin parameters manually (which is completely optiona
139151
}
140152
```
141153

142-
=== "Kotlin"
154+
=== "Kotlin (JVM / Android / Multiplatform)"
143155

144156
```kotlin title="build.gradle.kts"
145157
htmlComposeCompilerReport {

gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ plugins {
99
alias(libs.plugins.gradle.plugin.publish)
1010
}
1111

12-
repositories {
13-
mavenCentral()
14-
google()
15-
gradlePluginPortal()
16-
maven(url = "https://plugins.gradle.org/m2/")
17-
}
18-
1912
group = GROUP
2013
version = VERSION_NAME
2114

@@ -24,6 +17,7 @@ dependencies {
2417
compileOnly(kotlin("stdlib"))
2518
compileOnly(libs.kotlin.gradle.plugin)
2619
compileOnly(libs.android.gradle.plugin)
20+
compileOnly(libs.compose.multiplatform.gradle.plugin)
2721

2822
implementation(project(":core"))
2923
implementation(project(":report-generator"))

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

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,73 +23,73 @@
2323
*/
2424
package dev.shreyaspatil.composeCompilerMetricsGenerator.plugin
2525

26-
import com.android.build.api.dsl.CommonExtension
2726
import com.android.build.api.variant.AndroidComponentsExtension
28-
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.task.executingComposeCompilerReportGenerationGradleTask
29-
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.task.registerComposeCompilerReportGenTaskForVariant
27+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.multiplatform.android.configureKotlinAndroidComposeCompilerReports
28+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.multiplatform.configureKotlinMultiplatformComposeCompilerReports
29+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.multiplatform.jvm.configureKotlinJvmComposeCompilerReports
3030
import org.gradle.api.Plugin
3131
import org.gradle.api.Project
3232
import org.gradle.kotlin.dsl.getByType
33-
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
34-
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
33+
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions
34+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
35+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
3536

3637
@Suppress("UnstableApiUsage")
3738
class ReportGenPlugin : Plugin<Project> {
3839
override fun apply(target: Project) {
3940
val reportExt = ComposeCompilerReportExtension.create(target)
41+
var isAppliedForKmp = false
4042

41-
val android =
42-
runCatching {
43-
target.extensions.getByType(AndroidComponentsExtension::class.java)
44-
}.getOrElse { error("This plugin is only applicable for Android modules") }
45-
46-
val commonExtension = runCatching { target.extensions.getByType(CommonExtension::class.java) }.getOrNull()
47-
48-
android.onVariants { variant ->
49-
// Create gradle tasks for generating report
50-
target.registerComposeCompilerReportGenTaskForVariant(variant)
51-
}
52-
53-
target.afterEvaluate {
54-
val isComposeEnabled = commonExtension?.buildFeatures?.compose
55-
56-
if (isComposeEnabled != true) {
57-
error("Jetpack Compose is not found enabled in this module '$name'")
43+
with(target) {
44+
pluginManager.withPlugin("org.jetbrains.compose") {
45+
isAppliedForKmp = true
46+
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { // if kotlin jvm is applied
47+
val jvm = extensions.getByType(KotlinJvmProjectExtension::class.java)
48+
configureKotlinJvmComposeCompilerReports(jvm)
49+
}
50+
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { // if kotlin multiplatform is applied
51+
val multiplatform = extensions.getByType(KotlinMultiplatformExtension::class.java)
52+
configureKotlinMultiplatformComposeCompilerReports(multiplatform)
53+
}
54+
pluginManager.withPlugin("org.jetbrains.kotlin.android") { // if kotlin android is applied
55+
val android = extensions.getByType(AndroidComponentsExtension::class.java)
56+
configureKotlinAndroidComposeCompilerReports(android)
57+
}
5858
}
59-
60-
// When this method returns true it means gradle task for generating report is executing otherwise
61-
// normal compilation task is executing.
62-
val isFromReportGenGradleTask = target.executingComposeCompilerReportGenerationGradleTask()
63-
if (isFromReportGenGradleTask) {
64-
val kotlinAndroidExt = extensions.getByType<KotlinAndroidProjectExtension>()
65-
kotlinAndroidExt.target {
66-
// Exclude for test variants, no use!
67-
compilations.filter { !it.name.endsWith("Test") }.forEach {
68-
it.kotlinOptions {
69-
configureKotlinOptionsForComposeCompilerReport(this@afterEvaluate)
70-
}
71-
}
59+
var isAppliedForAndroid = false
60+
if (!isAppliedForKmp) {
61+
val android = extensions.getByType(AndroidComponentsExtension::class.java)
62+
pluginManager.withPlugin("com.android.application") {
63+
configureKotlinAndroidComposeCompilerReports(android)
64+
isAppliedForAndroid = true
65+
}
66+
pluginManager.withPlugin("com.android.library") {
67+
configureKotlinAndroidComposeCompilerReports(android)
68+
isAppliedForAndroid = true
7269
}
7370
}
71+
if (!isAppliedForAndroid && !isAppliedForKmp) {
72+
error("Jetpack Compose is not found enabled in this module '$name'")
73+
}
7474
}
7575
}
76+
}
7677

77-
private fun KotlinJvmOptions.configureKotlinOptionsForComposeCompilerReport(project: Project) {
78-
val reportExtension = project.extensions.getByType<ComposeCompilerReportExtension>()
79-
val outputPath = reportExtension.composeRawMetricsOutputDirectory.absolutePath
80-
if (reportExtension.enableReport.get()) {
81-
freeCompilerArgs +=
82-
listOf(
83-
"-P",
84-
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$outputPath",
85-
)
86-
}
87-
if (reportExtension.enableMetrics.get()) {
88-
freeCompilerArgs +=
89-
listOf(
90-
"-P",
91-
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$outputPath",
92-
)
93-
}
78+
fun KotlinCommonToolOptions.configureKotlinOptionsForComposeCompilerReport(project: Project) {
79+
val reportExtension = project.extensions.getByType<ComposeCompilerReportExtension>()
80+
val outputPath = reportExtension.composeRawMetricsOutputDirectory.absolutePath
81+
if (reportExtension.enableReport.get()) {
82+
freeCompilerArgs +=
83+
listOf(
84+
"-P",
85+
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$outputPath",
86+
)
87+
}
88+
if (reportExtension.enableMetrics.get()) {
89+
freeCompilerArgs +=
90+
listOf(
91+
"-P",
92+
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$outputPath",
93+
)
9494
}
9595
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
@file:Suppress("ktlint:standard:filename")
25+
26+
package dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.multiplatform.android
27+
28+
import com.android.build.api.dsl.CommonExtension
29+
import com.android.build.api.variant.AndroidComponentsExtension
30+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.multiplatform.configureKotlinOptionsForComposeCompilerReport
31+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.task.executingComposeCompilerReportGenerationGradleTask
32+
import dev.shreyaspatil.composeCompilerMetricsGenerator.plugin.task.registerComposeCompilerReportGenTaskForVariant
33+
import org.gradle.api.Project
34+
import org.gradle.kotlin.dsl.getByType
35+
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
36+
37+
fun Project.configureKotlinAndroidComposeCompilerReports(android: AndroidComponentsExtension<*, *, *>) {
38+
val commonExtension =
39+
runCatching { extensions.getByType(CommonExtension::class.java) }.getOrNull()
40+
41+
android.onVariants { variant ->
42+
// Create gradle tasks for generating report
43+
registerComposeCompilerReportGenTaskForVariant(variant)
44+
}
45+
46+
afterEvaluate {
47+
val isComposeEnabled = commonExtension?.buildFeatures?.compose
48+
49+
if (isComposeEnabled != true) {
50+
error("Jetpack Compose is not found enabled in this module '$name'")
51+
}
52+
53+
// When this method returns true it means gradle task for generating report is executing otherwise
54+
// normal compilation task is executing.
55+
val isFromReportGenGradleTask = executingComposeCompilerReportGenerationGradleTask()
56+
if (isFromReportGenGradleTask) {
57+
val kotlinAndroidExt = extensions.getByType<KotlinAndroidProjectExtension>()
58+
kotlinAndroidExt.target {
59+
// Exclude for test variants, no use!
60+
configureKotlinOptionsForComposeCompilerReport(compilations)
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)