diff --git a/.gitignore b/.gitignore
index 2f23d24..28c295f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,5 +16,3 @@ build/
*.iws
.java-version
-# Documentation folder - contains drafts, AI-generated content, and other private content not intended for public repo
-docs/
diff --git a/app-sizer/src/main/kotlin/com/grab/sizer/parser/ProguardFileParser.kt b/app-sizer/src/main/kotlin/com/grab/sizer/parser/ProguardFileParser.kt
index c86a928..2baa724 100644
--- a/app-sizer/src/main/kotlin/com/grab/sizer/parser/ProguardFileParser.kt
+++ b/app-sizer/src/main/kotlin/com/grab/sizer/parser/ProguardFileParser.kt
@@ -58,9 +58,9 @@ class DefaultProguardFileParser @Inject constructor(
readFromReader(InputStreamReader(it, Charsets.UTF_8))
}
} catch (e: IOException) {
- logger.log(e)
+ logger.log("Parse mapping file failure", e)
} catch (e: ParseException) {
- logger.log(e)
+ logger.log("Parse mapping file failure", e)
}
}
}
\ No newline at end of file
diff --git a/app-sizer/src/main/kotlin/com/grab/sizer/utils/Logger.kt b/app-sizer/src/main/kotlin/com/grab/sizer/utils/Logger.kt
index b97f943..f5823cb 100644
--- a/app-sizer/src/main/kotlin/com/grab/sizer/utils/Logger.kt
+++ b/app-sizer/src/main/kotlin/com/grab/sizer/utils/Logger.kt
@@ -32,17 +32,13 @@ const val DEFAULT_TAG = "AppSize"
interface Logger {
fun log(tag: String, message: String)
- fun log(tag: String, e: Exception)
- fun logDebug(tag: String, message: String)
+ fun log(tag: String, message: String, e: Exception)
}
-fun Logger.logDebug(message: String) {
- logDebug(DEFAULT_TAG, message)
-}
fun Logger.log(message: String) {
log(DEFAULT_TAG, message)
}
-fun Logger.log(e: Exception) {
- log(DEFAULT_TAG, e)
+fun Logger.log(message: String, e: Exception) {
+ log(DEFAULT_TAG, message, e)
}
diff --git a/cli/src/main/kotlin/com/grab/sizer/utils/CliLogger.kt b/cli/src/main/kotlin/com/grab/sizer/utils/CliLogger.kt
index 3e2d9dc..d2895e4 100644
--- a/cli/src/main/kotlin/com/grab/sizer/utils/CliLogger.kt
+++ b/cli/src/main/kotlin/com/grab/sizer/utils/CliLogger.kt
@@ -32,12 +32,8 @@ class CliLogger : Logger {
println("$tag : $message")
}
- override fun log(tag: String, e: Exception) {
- println("$tag :")
- e.printStackTrace()
- }
-
- override fun logDebug(tag: String, message: String) {
+ override fun log(tag: String, message: String, e: Exception) {
println("$tag : $message")
+ e.printStackTrace()
}
}
\ No newline at end of file
diff --git a/docs/plugin.md b/docs/plugin.md
index d6185aa..4b25c97 100644
--- a/docs/plugin.md
+++ b/docs/plugin.md
@@ -231,14 +231,76 @@ appSizer {
+## Known Limitations
+
+### Variant Matching and Module Skipping
+
+The App Sizer plugin uses sophisticated variant matching to analyze dependencies across different project types. However, some scenarios may result in modules being skipped during analysis, which can impact the accuracy of the final results.
+
+#### When Modules Are Skipped
+
+The plugin may skip modules in the following scenarios:
+
+1. **Unsupported Project Types**: Projects that don't match any supported type (Android app/library, Java/Kotlin JVM, Kotlin Multiplatform)
+2. **Missing Build Variants**: Android library modules that lack variants matching the main app's flavor/buildType configuration
+4. **Custom Build Logic**: Modules using non-standard build configurations that the plugin cannot interpret
+
+
+#### Error Handling Behavior
+
+The plugin uses defensive error handling to maintain build stability while logging informative warnings:
+
+```
+AppSize: Skipping project module-name - variant extraction failed: Cannot find matching variant for module-name
+AppSize: Skipping dependency project library-name - unsupported type: Project type not supported: library-name
+AppSize: Could not find matching variant for Android library project module-name: Cannot find matching variant for module-name
+AppSize: Unsupported project type for Android library project module-name: Project type not supported: module-name
+```
+
+When debug logging is enabled (`--debug` flag), full stack traces are available for detailed troubleshooting:
+
+```
+AppSize: Full stack trace for variant extraction failure:
+java.lang.IllegalStateException: Cannot find matching variant for module-name
+ at com.grab.plugin.sizer.dependencies.DefaultVariantExtractor.extractVariant(VariantExtractor.kt:284)
+ at com.grab.plugin.sizer.dependencies.DefaultVariantExtractor.defaultFindMatchVariant(VariantExtractor.kt:132)
+ [... full stack trace ...]
+```
+
+#### Impact on Analysis Results
+
+All classes and resources belonging to skipped modules will be automatically attributed to the app module during analysis, which may impact the accuracy of module-wise and team-based size breakdowns.
+
+
## Troubleshooting
+### Common Variant Matching Issues
+
+1. **"Cannot find matching variant for [module-name]"**
+ - **Cause**: Library module lacks a variant matching the app's configuration
+ - **Solution**: Add `matchingFallbacks` to the library module or ensure consistent flavor/buildType naming
+
+2. **"Unsupported project type: [project-name]"**
+ - **Cause**: Project doesn't use a supported plugin type
+ - **Solution**: Verify the project applies Android, Java, or Kotlin plugin correctly
+
+3. **"Skipping dependency project [library-name]"**
+ - **Cause**: External or internal dependency has configuration issues
+ - **Solution**: Check dependency's build configuration and ensure it's compatible
+
### Resource Verification Failures
If you encounter issues with the `verifyResourceRelease` task, try these solutions:
- Check that your resource files are properly formatted and located
- Verify that resource names follow Android naming conventions
- Enable the `enableMatchDebugVariant` flag in your configuration
+### Missing Analysis Data
+
+If modules appear to be missing from your analysis reports:
+
+1. **Check Warning Logs**: Look for "Skipping project" messages in build output
+2. **Enable Debug Mode**: Run with `--debug` to get detailed variant matching information
+
### Dagger NoSuchMethodError
If you encounter this exception:
```java
@@ -252,6 +314,16 @@ This error typically occurs due to a version conflict between the Android build
classpath "com.google.dagger:dagger:2.47"
```
+### Debug Mode Analysis
+
+Run with debug logging to get detailed information about module processing, variant matching, and potential issues:
+
+```bash
+./gradlew appSizeAnalysisRelease --debug 2>&1 | grep -E "(Skipping|variant|extraction)"
+```
+
+This will filter the output to show only variant matching and module processing information.
+
## Resources
- [Bundletool GitHub Repository](https://github.com/google/bundletool)
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/AppSizerPlugin.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/AppSizerPlugin.kt
index 143ebeb..a61bc21 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/AppSizerPlugin.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/AppSizerPlugin.kt
@@ -27,6 +27,7 @@
package com.grab.plugin.sizer
+import com.grab.plugin.sizer.utils.DefaultPluginLogger
import org.gradle.api.Plugin
import org.gradle.api.Project
@@ -36,6 +37,7 @@ class AppSizerPlugin : Plugin {
override fun apply(project: Project) =
TaskManager(
project,
- project.extensions.create(PLUGIN_EXTENSION, AppSizePluginExtension::class.java)
+ project.extensions.create(PLUGIN_EXTENSION, AppSizePluginExtension::class.java),
+ DefaultPluginLogger(project)
).configTasks()
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/TaskManager.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/TaskManager.kt
index fcf0d4e..68e1e96 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/TaskManager.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/TaskManager.kt
@@ -37,11 +37,7 @@ import com.grab.plugin.sizer.dependencies.*
import com.grab.plugin.sizer.tasks.AppSizeAnalysisTask
import com.grab.plugin.sizer.tasks.GenerateApkTask
import com.grab.plugin.sizer.tasks.GenerateArchivesListTask
-import com.grab.plugin.sizer.utils.isAndroidApplication
-import com.grab.plugin.sizer.utils.isAndroidLibrary
-import com.grab.plugin.sizer.utils.isJava
-import com.grab.plugin.sizer.utils.isKotlinJvm
-import com.grab.plugin.sizer.utils.isKotlinMultiplatform
+import com.grab.plugin.sizer.utils.*
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.ProjectDependency
@@ -57,7 +53,8 @@ import org.gradle.kotlin.dsl.the
*/
internal class TaskManager(
private val project: Project,
- private val pluginExtension: AppSizePluginExtension
+ private val pluginExtension: AppSizePluginExtension,
+ private val logger: PluginLogger
) {
fun configTasks() {
project.rootProject.gradle.projectsEvaluated {
@@ -147,8 +144,12 @@ internal class TaskManager(
if (variant is AndroidAppSizeVariant) {
task.dependsOn(variant.baseVariant.assembleProvider)
}
- } catch (e: RuntimeException) {
- project.logger.warn("Could not find matching variant for Android library project ${project.name}: ${e.message}")
+ } catch (e: UnsupportedOperationException) {
+ logger.warn("Unsupported project type for Android library project ${project.name}: ${e.message}")
+ logger.debug("Full stack trace for variant extraction failure:", e)
+ } catch (e: IllegalStateException) {
+ logger.warn("Could not find matching variant for Android library project ${project.name}: ${e.message}")
+ logger.debug("Full stack trace for variant extraction failure:", e)
}
}
@@ -163,10 +164,10 @@ internal class TaskManager(
project.isKotlinMultiplatform -> {
task.dependsOn(project.tasks.named(KMP_JAR_TASK))
}
-
+
else -> {
// Skip unsupported project types to avoid variant extraction errors
- project.logger.debug("Skipping variant extraction for unsupported project type: ${project.name}")
+ logger.warn("Skipping variant extraction for unsupported project type: ${project.name}")
}
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/ArchiveExtractor.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/ArchiveExtractor.kt
index ab697cf..7d169f8 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/ArchiveExtractor.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/ArchiveExtractor.kt
@@ -36,6 +36,15 @@ import org.gradle.api.Project
import javax.inject.Inject
interface ArchiveExtractor {
+ /**
+ * Extracts archive dependency from a project.
+ *
+ * @param project The project to extract archive dependency from
+ * @return ArchiveDependency representing the project's binary output
+ * @throws UnsupportedOperationException if the project type is unsupported
+ * @throws IllegalStateException if variant extraction fails
+ */
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
fun extract(project: Project): ArchiveDependency
}
@@ -43,6 +52,7 @@ interface ArchiveExtractor {
internal class DefaultArchiveExtractor @Inject constructor(
private val variantExtractor: VariantExtractor
) : ArchiveExtractor {
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
override fun extract(project: Project): ArchiveDependency {
val matchVariant = variantExtractor.findMatchVariant(project)
return when {
@@ -61,7 +71,7 @@ internal class DefaultArchiveExtractor @Inject constructor(
pathToArtifact = matchVariant.binaryOutPut.path
)
- else -> throw IllegalArgumentException("The ${project.name} is not an Android/Kotlin/Java module")
+ else -> throw UnsupportedOperationException("Unsupported project type: ${project.name}")
}
}
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DefaultConfigurationExtractor.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DefaultConfigurationExtractor.kt
index 7bb9b92..c30a45c 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DefaultConfigurationExtractor.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DefaultConfigurationExtractor.kt
@@ -27,6 +27,9 @@
package com.grab.plugin.sizer.dependencies
+import com.grab.plugin.sizer.utils.PluginLogger
+import com.grab.plugin.sizer.utils.debug
+import com.grab.plugin.sizer.utils.warn
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import javax.inject.Inject
@@ -37,14 +40,22 @@ interface ConfigurationExtractor {
@DependenciesScope
internal class DefaultConfigurationExtractor @Inject constructor(
- private val variantExtractor: VariantExtractor
+ private val variantExtractor: VariantExtractor,
+ private val logger: PluginLogger
) : ConfigurationExtractor {
override fun runtimeConfigurations(project: Project): Sequence {
- val variant = variantExtractor.findMatchVariant(project)
- return project.configurations.asSequence()
- .filter {
- variant.runtimeConfiguration.hierarchy.contains(it)
- }
+ return try {
+ val variant = variantExtractor.findMatchVariant(project)
+ project.configurations.asSequence()
+ .filter {
+ variant.runtimeConfiguration.hierarchy.contains(it)
+ }
+ } catch (e: RuntimeException) {
+ logger.warn("Could not find matching variant for project ${project.name}: ${e.message}")
+ logger.debug("Full stack trace for variant extraction failure:", e)
+ // Return empty sequence if variant extraction fails
+ emptySequence()
+ }
}
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependenciesComponent.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependenciesComponent.kt
index 1d5ccaf..0d57419 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependenciesComponent.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependenciesComponent.kt
@@ -27,6 +27,7 @@
package com.grab.plugin.sizer.dependencies
+import com.grab.plugin.sizer.utils.DefaultPluginLogger
import com.grab.plugin.sizer.utils.PluginLogger
import com.grab.sizer.utils.Logger
import dagger.Binds
@@ -50,8 +51,6 @@ internal interface DependenciesComponent {
fun configurationExtractor(): ConfigurationExtractor
fun variantExtractor(): VariantExtractor
- fun logger(): Logger
-
@Component.Factory
interface Factory {
fun create(
@@ -79,5 +78,5 @@ internal interface DependenciesModule {
fun bindVariantExtractor(extractor: DefaultVariantExtractor): VariantExtractor
@Binds
- fun bindLogger(logger: PluginLogger): Logger
+ fun bindLogger(logger: DefaultPluginLogger): PluginLogger
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependencyExtractor.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependencyExtractor.kt
index 24ff36a..46230df 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependencyExtractor.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/DependencyExtractor.kt
@@ -27,14 +27,14 @@
package com.grab.plugin.sizer.dependencies
-import com.grab.sizer.utils.Logger
-import com.grab.sizer.utils.log
+import com.grab.plugin.sizer.utils.PluginLogger
+import com.grab.plugin.sizer.utils.debug
+import com.grab.plugin.sizer.utils.warn
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolveException
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.ResolvedDependency
-import org.gradle.api.internal.artifacts.DefaultResolvedDependency
import org.gradle.internal.component.AmbiguousVariantSelectionException
import java.util.*
import javax.inject.Inject
@@ -53,7 +53,7 @@ class DefaultDependencyExtractor @Inject constructor(
private val appProject: Project,
private val configurationExtractor: ConfigurationExtractor,
private val archiveExtractor: ArchiveExtractor,
- private val logger: Logger
+ private val logger: PluginLogger
) : DependencyExtractor {
override fun extract(): ArchiveDependencyStore {
return ArchiveDependencyStore().apply {
@@ -62,8 +62,16 @@ class DefaultDependencyExtractor @Inject constructor(
while (queue.isNotEmpty()) {
val project = queue.poll()
- val projectArchive = archiveExtractor.extract(project)
- add(projectArchive)
+ try {
+ val projectArchive = archiveExtractor.extract(project)
+ add(projectArchive)
+ } catch (e: UnsupportedOperationException) {
+ logger.warn("Skipping project ${project.name} - unsupported type: ${e.message}")
+ logger.debug("Full stack trace for archive extraction failure:", e)
+ } catch (e: IllegalStateException) {
+ logger.warn("Skipping project ${project.name} - variant extraction failed: ${e.message}")
+ logger.debug("Full stack trace for archive extraction failure:", e)
+ }
fetchInternalDependency(project, this, checkedProjects, queue)
fetchExternalDependency(project, this)
}
@@ -81,9 +89,17 @@ class DefaultDependencyExtractor @Inject constructor(
.filterIsInstance()
.map { it.dependencyProject }
.forEach { dependencyProject ->
- archiveDependencyStore.add(
- archiveExtractor.extract(dependencyProject)
- )
+ try {
+ archiveDependencyStore.add(
+ archiveExtractor.extract(dependencyProject)
+ )
+ } catch (e: UnsupportedOperationException) {
+ logger.warn("Skipping dependency project ${dependencyProject.name} - unsupported type: ${e.message}")
+ logger.debug("Full stack trace for dependency archive extraction failure:", e)
+ } catch (e: IllegalStateException) {
+ logger.warn("Skipping dependency project ${dependencyProject.name} - variant extraction failed: ${e.message}")
+ logger.debug("Full stack trace for dependency archive extraction failure:", e)
+ }
if (!checkedProjects.contains(dependencyProject.path)) {
queue.add(dependencyProject)
checkedProjects.add(dependencyProject.path)
@@ -102,7 +118,7 @@ class DefaultDependencyExtractor @Inject constructor(
try {
it.firstLevelModuleDependencies
} catch (e: ResolveException) {
- logger.log("Fetching firstLevelModuleDependencies having issue with $it for ${project.name}")
+ logger.warn("Fetching firstLevelModuleDependencies having issue with $it for ${project.name}")
emptySet()
}
}
@@ -118,7 +134,7 @@ class DefaultDependencyExtractor @Inject constructor(
archiveDependencyStore.add(artifact.toArchiveDependency())
}
} catch (e: AmbiguousVariantSelectionException) {
- logger.log("Fetching allModuleArtifacts having issue with ${resolvedDep.name}")
+ logger.warn("Fetching allModuleArtifacts having issue with ${resolvedDep.name}")
}
}
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/VariantExtractor.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/VariantExtractor.kt
index df3a8e7..39d5b5c 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/VariantExtractor.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/dependencies/VariantExtractor.kt
@@ -30,11 +30,7 @@ package com.grab.plugin.sizer.dependencies
import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
-import com.grab.plugin.sizer.utils.isAndroidApplication
-import com.grab.plugin.sizer.utils.isAndroidLibrary
-import com.grab.plugin.sizer.utils.isJava
-import com.grab.plugin.sizer.utils.isKotlinJvm
-import com.grab.plugin.sizer.utils.isKotlinMultiplatform
+import com.grab.plugin.sizer.utils.*
import org.gradle.api.DomainObjectSet
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
@@ -60,8 +56,10 @@ internal interface VariantExtractor {
*
* @param project The project for which to locate the matching variant.
* @return AppSizeVariant that is the extracted variant for the given project type.
- * @throws IllegalArgumentException if the project type is not supported.
+ * @throws UnsupportedOperationException if the project type is not supported.
+ * @throws IllegalStateException if no matching variant can be found.
*/
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
fun findMatchVariant(project: Project): AppSizeVariant
}
@@ -109,8 +107,9 @@ internal class DefaultVariantExtractor @Inject constructor(
private val enableMatchDebugVariant: Boolean,
) : VariantExtractor {
- override fun findMatchVariant(project: Project): AppSizeVariant{
- return when{
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
+ override fun findMatchVariant(project: Project): AppSizeVariant {
+ return when {
enableMatchDebugVariant -> findMatchDebugVariant(project)
else -> defaultFindMatchVariant(project)
}
@@ -122,8 +121,10 @@ internal class DefaultVariantExtractor @Inject constructor(
*
* @param project The project for which to locate the matching variant.
* @return AppSizeVariant that is the extracted variant for the given project type.
- * @throws IllegalArgumentException if the project type is not supported.
+ * @throws UnsupportedOperationException if the project type is not supported.
+ * @throws IllegalStateException if no matching variant can be found.
*/
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
private fun defaultFindMatchVariant(project: Project): AppSizeVariant {
return when {
project.isAndroidApplication -> AndroidAppSizeVariant(
@@ -139,7 +140,7 @@ internal class DefaultVariantExtractor @Inject constructor(
project.isKotlinMultiplatform -> KmpJarAppSizeVariant(project)
else -> {
- throw IllegalArgumentException("${project.name} is not supported")
+ throw UnsupportedOperationException("Project type not supported: ${project.name}")
}
}
}
@@ -150,8 +151,10 @@ internal class DefaultVariantExtractor @Inject constructor(
*
* @param project The project for which to locate the debug variant.
* @return AppSizeVariant that is the debug variant for the given project type.
- * @throws IllegalArgumentException if the project type is not supported.
+ * @throws UnsupportedOperationException if the project type is not supported.
+ * @throws IllegalStateException if no matching debug variant can be found.
*/
+ @Throws(UnsupportedOperationException::class, IllegalStateException::class)
private fun findMatchDebugVariant(project: Project): AppSizeVariant {
return when {
project.isAndroidApplication -> AndroidAppSizeVariant(
@@ -167,7 +170,7 @@ internal class DefaultVariantExtractor @Inject constructor(
project.isKotlinMultiplatform -> KmpJarAppSizeVariant(project)
else -> {
- throw IllegalArgumentException("${project.name} is not supported")
+ throw UnsupportedOperationException("Project type not supported: ${project.name}")
}
}
}
@@ -177,8 +180,9 @@ internal class DefaultVariantExtractor @Inject constructor(
*
* @param variants DomainObjectSet of BaseVariants that should be searched.
* @return BaseVariant that is the debug variant matching the flavor of the base variant.
- * @throws RuntimeException if no matching debug variant can be found.
+ * @throws IllegalStateException if no matching debug variant can be found.
*/
+ @Throws(IllegalStateException::class)
private fun findDebugVariant(variants: DomainObjectSet): BaseVariant {
// Filter out the debug variants from the provided set of variants.
val debugVariants = variants.filter { variant ->
@@ -205,7 +209,7 @@ internal class DefaultVariantExtractor @Inject constructor(
}
}
// If no match was found, throw an exception.
- throw RuntimeException("Can not find the matching debug variant")
+ throw IllegalStateException("Cannot find matching debug variant")
}
@@ -214,8 +218,9 @@ internal class DefaultVariantExtractor @Inject constructor(
*
* @receiver Project The project from which to extract the variant.
* @return BaseVariant that is the variant matching the flavor and build type of the base variant.
- * @throws RuntimeException if no matching variant can be found.
+ * @throws IllegalStateException if no matching variant can be found.
*/
+ @Throws(IllegalStateException::class)
private fun Project.extractVariant(variants: DomainObjectSet): BaseVariant {
// Try to find a variant that fully matches the base variant
@@ -278,7 +283,7 @@ internal class DefaultVariantExtractor @Inject constructor(
}
}
// When no match found, throw exception
- throw RuntimeException("Can not find the matching variant for ${project.name}")
+ throw IllegalStateException("Cannot find matching variant for ${project.name}")
}
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/tasks/AppSizeAnalysisTask.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/tasks/AppSizeAnalysisTask.kt
index 351809c..504b2db 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/tasks/AppSizeAnalysisTask.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/tasks/AppSizeAnalysisTask.kt
@@ -37,8 +37,8 @@ import com.grab.plugin.sizer.dependencies.ArchiveDependencyStore
import com.grab.plugin.sizer.dependencies.VariantInput
import com.grab.plugin.sizer.dependencies.toVariantInput
import com.grab.plugin.sizer.params
+import com.grab.plugin.sizer.utils.DefaultPluginLogger
import com.grab.plugin.sizer.utils.PluginInputProvider
-import com.grab.plugin.sizer.utils.PluginLogger
import com.grab.plugin.sizer.utils.PluginOutputProvider
import com.grab.sizer.AnalyticsOption
import com.grab.sizer.AppSizer
@@ -123,7 +123,7 @@ internal abstract class AppSizeAnalysisTask : DefaultTask() {
inputProvider = createInputProvider(archiveDependencyStore, apkDirectory),
outputProvider = createOutputProvider(projectInfo),
libName = libName.orNull,
- logger = PluginLogger(project),
+ logger = DefaultPluginLogger(project),
).process(option.get())
}
@@ -181,7 +181,7 @@ internal abstract class AppSizeAnalysisTask : DefaultTask() {
this.outputDirectory.set(project.layout.buildDirectory.dir("sizer/reports/${variant.name}"))
}
- if(pluginExtension.input.teamMappingFile.isPresent){
+ if (pluginExtension.input.teamMappingFile.isPresent) {
this.teamMappingFile.set(pluginExtension.input.teamMappingFile)
}
diff --git a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/utils/Logger.kt b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/utils/Logger.kt
index 1be1ba4..adbdad0 100644
--- a/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/utils/Logger.kt
+++ b/sizer-gradle-plugin/src/main/kotlin/com/grab/plugin/sizer/utils/Logger.kt
@@ -28,15 +28,48 @@
package com.grab.plugin.sizer.utils
import com.grab.plugin.sizer.dependencies.DependenciesScope
+import com.grab.sizer.utils.DEFAULT_TAG
import com.grab.sizer.utils.Logger
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import javax.inject.Inject
+
+interface PluginLogger : Logger {
+ fun warn(tag: String, message: String)
+ fun warn(tag: String, message: String, e: Exception)
+
+ fun debug(tag: String, message: String)
+ fun debug(tag: String, message: String, e: Exception)
+}
+
+fun PluginLogger.warn(message: String) {
+ warn(DEFAULT_TAG, message)
+}
+
+fun PluginLogger.warn(message: String, e: Exception) {
+ warn(DEFAULT_TAG, message, e)
+}
+
+fun PluginLogger.debug(message: String) {
+ debug(DEFAULT_TAG, message)
+}
+
+fun PluginLogger.debug(message: String, e: Exception) {
+ debug(DEFAULT_TAG, message, e)
+}
+
+
@DependenciesScope
-class PluginLogger @Inject constructor(private val project: Project) : Logger {
+class DefaultPluginLogger @Inject constructor(private val project: Project) : PluginLogger {
override fun log(tag: String, message: String) = project.logger.log(LogLevel.QUIET, "$tag: $message")
+ override fun log(tag: String, message: String, e: Exception) =
+ project.logger.log(LogLevel.DEBUG, "$tag: $message", e)
+
+ override fun warn(tag: String, message: String) = project.logger.warn("$tag: $message")
+
+ override fun warn(tag: String, message: String, e: Exception) = project.logger.warn("$tag: $message", e)
- override fun logDebug(tag: String, message: String) = project.logger.log(LogLevel.DEBUG, "$tag: $message")
- override fun log(tag: String, e: Exception) = project.logger.log(LogLevel.DEBUG, tag, e)
+ override fun debug(tag: String, message: String) = project.logger.debug("$tag: $message")
+ override fun debug(tag: String, message: String, e: Exception) = project.logger.debug("$tag: $message", e)
}
diff --git a/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/dependencies/DefaultVariantExtractorTest.kt b/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/dependencies/DefaultVariantExtractorTest.kt
index 2a0606d..3d204cd 100644
--- a/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/dependencies/DefaultVariantExtractorTest.kt
+++ b/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/dependencies/DefaultVariantExtractorTest.kt
@@ -81,7 +81,7 @@ class DefaultVariantExtractorTest {
val project = ProjectBuilder.builder().withParent(rootProject).build()
project.doEvaluate()
- assertThrows("${project.name} is not supported") {
+ assertThrows("Project type not supported: ${project.name}") {
extractor.findMatchVariant(project)
}
}
diff --git a/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/fake/MockLogger.kt b/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/fake/MockLogger.kt
index baf71fa..699d0f2 100644
--- a/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/fake/MockLogger.kt
+++ b/sizer-gradle-plugin/src/test/kotlin/com/grab/plugin/sizer/fake/MockLogger.kt
@@ -27,20 +27,32 @@
package com.grab.plugin.sizer.fake
-import com.grab.sizer.utils.Logger
+import com.grab.plugin.sizer.utils.PluginLogger
-class MockLogger : Logger {
+class MockLogger : PluginLogger {
val loggedMessages = mutableListOf()
override fun log(tag: String, message: String) {
loggedMessages.add("$tag: $message")
}
- override fun log(tag: String, e: Exception) {
- loggedMessages.add("$tag: ${e.message}")
+ override fun log(tag: String, message: String, e: Exception) {
+ loggedMessages.add("$tag: $message ${e.message}")
}
- override fun logDebug(tag: String, message: String) {
+ override fun warn(tag: String, message: String) {
+ loggedMessages.add("$tag: $message")
+ }
+
+ override fun warn(tag: String, message: String, e: Exception) {
+ loggedMessages.add("$tag: $message ${e.message}")
+ }
+
+ override fun debug(tag: String, message: String) {
loggedMessages.add("DEBUG - $tag: $message")
}
+
+ override fun debug(tag: String, message: String, e: Exception) {
+ loggedMessages.add("DEBUG - $tag: $message ${e.message}")
+ }
}
\ No newline at end of file