All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.didiglobal.booster.task.analyser.reference.ReferencePageRenderer.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0-alpha3
Show newest version
package com.didiglobal.booster.task.analyser.reference

import com.android.build.gradle.api.BaseVariant
import com.didiglobal.booster.cha.asm.Reference
import com.didiglobal.booster.graph.Graph
import org.gradle.api.Project
import org.gradle.internal.html.SimpleHtmlWriter
import org.gradle.reporting.ReportRenderer
import org.gradle.reporting.TabbedPageRenderer
import java.net.URL

class ReferencePageRenderer(
        private val project: Project,
        private val variant: BaseVariant?
) : TabbedPageRenderer>() {

    private val _title: String by lazy {
        if (variant == null) project.name else "${project.name}:${variant.name}"
    }

    override fun getTitle(): String = _title

    override fun getHeaderRenderer(): ReportRenderer, SimpleHtmlWriter> = object : ReportRenderer, SimpleHtmlWriter>() {
        override fun render(model: Graph, output: SimpleHtmlWriter) {
            output.startElement("p").attribute("class", "subtitle").characters(project.description ?: "").endElement()
        }
    }

    override fun getContentRenderer(): ReportRenderer, SimpleHtmlWriter> = object : ReportRenderer, SimpleHtmlWriter>() {
        override fun render(model: Graph, output: SimpleHtmlWriter) {
            output.run {
                model.groupBy {
                    it.to.groupBy()
                }.toSortedMap(Reference.COMPONENT_COMPARATOR).map { (group, edges) ->
                    group to edges.groupBy({ it.to.klass }) { it.from.klass }
                }.forEach { (title, references) ->
                    startElement("h2").characters(title).endElement()
                    startElement("ul").attribute("class", "refs")
                    references.forEach { (ref, sources) ->
                        startElement("li")
                        startElement("div").characters(ref).endElement()
                        startElement("ul")
                        sources.forEach {
                            startElement("li").characters(it).endElement()
                        }
                        endElement()
                        endElement()
                    }
                    endElement()
                }
            }
        }

    }

    override fun getStyleUrl(): URL = ReferencePageRenderer::class.java.getResource("/style.css")

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy