Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ internal class ProgressPrinter(
files.forEachIndexed { index, file ->
val modIndex = (index + 1).toString().padStart(padStart)
val module = file.module
builder.append("$modIndex. :${module.name} (${module.buildVariant}) \n")
val variant = module.buildVariant
.takeIf { name -> name.isNullOrEmpty().not() }
?.let { name -> "($name)" } ?: ""
builder.append("$modIndex. :${module.name} $variant\n")
}
return builder.toString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ internal val Module.id: String
get() = "${name}_$buildVariant"

internal val Module.displayName: String
get() = "$name ($buildVariant)"
get() {
val variant = buildVariant
.takeIf { name -> name.isNullOrEmpty().not() }
?.let { name -> "($name)" } ?: ""
return "$name $variant"
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ private fun BODY.ModuleOverviews(

span("module-overview-title") { +":${module.module.name}\n" }
br {
span("module-overview-details") {
setStyle(fontSize = "18px")
+"(${module.module.buildVariant})"
if (module.module.buildVariant.isNullOrEmpty().not()) {
span("module-overview-details") {
setStyle(fontSize = "18px")
+"(${module.module.buildVariant})"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.jayasuryat.mendable.MendableReportGeneratorRequest.ExportType
import com.jayasuryat.mendable.MendableReportGeneratorRequest.IncludeModules
import com.jayasuryat.mendable.metricsfile.Module
import com.jayasuryat.mendable.model.ComposeCompilerMetricsExportModel
import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.matchers.file.shouldBeAFile
import io.kotest.matchers.file.shouldExist
import io.kotest.matchers.ints.shouldBeGreaterThan
Expand Down Expand Up @@ -324,4 +325,40 @@ internal class MendableReportGeneratorTest {
outputModel.totalModulesReported shouldBe 1
outputModel.totalModulesFiltered shouldBe 1
}

@Test
fun `should not throw exception for null build variant`() = runTest {

val path = this::class.java.classLoader?.getResource("app_release-composables.txt")?.path
require(!path.isNullOrEmpty())

val resourceRoot = File(path).parent

val request = MendableReportGeneratorRequest(
scanPaths = listOf(resourceRoot),
outputPath = temporaryFolder.root.path,
scanRecursively = false,
outputFileName = "report",
exportType = ExportType.HTML,
includeModules = IncludeModules.ALL,
moduleProducer = {
Module(
name = "resources",
buildVariant = null,
)
},
)

shouldNotThrow<Throwable> {

var filesFound: Progress.MetricsFilesFound? = null
generator.generate(request = request) { progress ->
if (progress is Progress.MetricsFilesFound) filesFound = progress
}

val metricsFiles = filesFound?.files
metricsFiles.shouldNotBeNull()
metricsFiles.size shouldBeGreaterThan 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import dev.drewhamilton.poko.Poko
@Poko
public class Module(
public val name: String,
public val buildVariant: String,
public val buildVariant: String?,
) {

public companion object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ public fun interface ModuleFactory {
}

/**
* A default implementation of [ModuleFactory]. Parses [Module] using underscore and hyphens ('_' & '-') as delimiters.
* For example: For "app_qaRelease-composables.txt", a [Module] with "app" as [Module.name] and "qaRelease" as
* [Module.buildVariant] would be produced.
* Default implementation of [ModuleFactory].
*
* Note : While this implementation should work for most of the cases, this will not generate expected outputs for files
* whose original module's build variants' name have underscores in them.
* For example: "feature_a_build_variant-composables.txt"; here expectation is "feature_a" should be the [Module.name]
* and "build_variant" should be [Module.buildVariant]. But due to the nature of this implementation, "feature_a_build"
* and "variant" would be [Module.name] and [Module.buildVariant] respectively for this case.
* This implementation parses a [Module] from a file name using underscores ('_') and hyphens ('-')
* as delimiters. It assumes a convention where:
* - The file name is structured as "<module_name>_<build_variant>-<suffix>.<extension>".
* - The [Module.name] is derived from the part of the file name before the last underscore ('_').
* - The [Module.buildVariant] is derived from the part of the file name between the last underscore
* ('_') and the last hyphen ('-'). Build variant is considered optional, if build variant is
* missing in the file name, the resulting [Module] will have [Module.buildVariant] as `null`.
*
* ### Example
* For a file named `app_qaRelease-composables.txt`:
* - [Module.name] would be `"app"`
* - [Module.buildVariant] would be `"qaRelease"`
*
* ### Limitations
* This implementation may produce unexpected results for file names where the build variant or the
* module name contains hyphens or underscores.
*/
public class DefaultModuleFactory : ModuleFactory {

Expand All @@ -48,8 +57,18 @@ public class DefaultModuleFactory : ModuleFactory {
val fileName = file.name
val partialFileName = fileName.take(fileName.lastIndexOf('-'))
val separatorIndex: Int = partialFileName.lastIndexOf('_')
val moduleName: String = partialFileName.take(separatorIndex)
val buildVariant: String = partialFileName.removePrefix(moduleName).drop(1)

val hasBuildVariant = separatorIndex != -1
val moduleName: String
val buildVariant: String?
if (hasBuildVariant) {
moduleName = partialFileName.take(separatorIndex)
buildVariant = partialFileName.removePrefix(moduleName).drop(1)
} else {
moduleName = partialFileName
buildVariant = null
}

return Module(
name = moduleName,
buildVariant = buildVariant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,16 @@ internal class DefaultModuleFactoryTest {
}
}
}

@Test
fun `should parse correctly for file name without build variant`() {

val file = File("resources-composables.txt")
val module: Module = factory.parseModule(
file = file,
)

module.name shouldBe "resources"
module.buildVariant shouldBe null
}
}