jk1/Gradle-License-Report

Information about configurations in inventory report

Vampire opened this issue · 1 comments

It would be nice to have information about the configurations a dependency is coming from in the inventory report.
If you for example enable ALL configurations, it is important to see whether a dependency is a production dependency, a test dependency, a tool dependency, ...

Here a way to add this information by customization using Kotlin, writing configurations with "test" in their name in dark grey:

class EnhancedInventoryHtmlReportRenderer : InventoryHtmlReportRenderer() {
    lateinit var configurations: Set<ConfigurationData>

    override fun render(data: ProjectData) {
        configurations = data.configurations
        super.render(data)
    }

    override fun printDependencyMetaInformation(group: String, name: String, version: String) {
        super.printDependencyMetaInformation(group, name, version)

        val configurationNames = configurations
            .filter { configuration ->
                configuration
                    .dependencies
                    .any { (it.group == group) && (it.name == name) && (it.version == version) }
            }
            .map { it.name }
            .sorted()
            .joinToString(
                separator = "",
                prefix = "<ul>",
                postfix = "</ul>"
            ) {
                if (it.contains("test", ignoreCase = true)) {
                    "<li style='color: darkGrey'>$it</li>"
                } else {
                    "<li>$it</li>"
                }
            }

        output.appendText(section("Configurations", configurationNames))
    }

    fun section(label: String, value: String) = """
        <label>$label</label>
        <div class='dependency-value'>$value</div>
    """.trimIndent()

    fun link(name: String, url: String) = "<a href='$url'>$name</a>"
}