Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information about configurations in inventory report #295

Open
Vampire opened this issue Apr 16, 2024 · 1 comment
Open

Information about configurations in inventory report #295

Vampire opened this issue Apr 16, 2024 · 1 comment

Comments

@Vampire
Copy link
Contributor

Vampire commented Apr 16, 2024

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, ...

@Vampire
Copy link
Contributor Author

Vampire commented Apr 25, 2024

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>"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant