|
| 1 | +package com.jakewharton.diffuse.report.html |
| 2 | + |
| 3 | +import com.jakewharton.diffuse.diff.AarDiff |
| 4 | +import com.jakewharton.diffuse.diff.toDetailReport |
| 5 | +import com.jakewharton.diffuse.diff.toHtmlSummary |
| 6 | +import com.jakewharton.diffuse.diff.toSummaryTable |
| 7 | +import com.jakewharton.diffuse.format.ArchiveFile.Type |
| 8 | +import com.jakewharton.diffuse.report.Report |
| 9 | +import kotlinx.html.body |
| 10 | +import kotlinx.html.br |
| 11 | +import kotlinx.html.details |
| 12 | +import kotlinx.html.h2 |
| 13 | +import kotlinx.html.head |
| 14 | +import kotlinx.html.html |
| 15 | +import kotlinx.html.span |
| 16 | +import kotlinx.html.stream.appendHTML |
| 17 | +import kotlinx.html.style |
| 18 | +import kotlinx.html.summary |
| 19 | +import kotlinx.html.unsafe |
| 20 | + |
| 21 | +internal class AarDiffHtmlReport(private val aarDiff: AarDiff) : Report { |
| 22 | + override fun write(appendable: Appendable) { |
| 23 | + appendable.appendHTML().html { |
| 24 | + head { |
| 25 | + style(type = "text/css") { |
| 26 | + unsafe { |
| 27 | + raw( |
| 28 | + """ |
| 29 | + table{ |
| 30 | + border-collapse:collapse; |
| 31 | + border:1px solid #000; |
| 32 | + } |
| 33 | + |
| 34 | + table td{ |
| 35 | + border:1px solid #000; |
| 36 | + } |
| 37 | + """.trimIndent(), |
| 38 | + ) |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + body { |
| 44 | + h2 { +"Summary" } |
| 45 | + |
| 46 | + span { +"OLD: ${aarDiff.oldAar.filename}" } |
| 47 | + br() |
| 48 | + span { +"NEW: ${aarDiff.newAar.filename}" } |
| 49 | + br() |
| 50 | + br() |
| 51 | + |
| 52 | + toSummaryTable( |
| 53 | + "AAR", |
| 54 | + aarDiff.archive, |
| 55 | + Type.AAR_TYPES, |
| 56 | + skipIfEmptyTypes = setOf(Type.JarLibs, Type.ApiJar, Type.LintJar, Type.Native, Type.Res), |
| 57 | + ) |
| 58 | + |
| 59 | + br() |
| 60 | + |
| 61 | + toHtmlSummary("", aarDiff.jars) |
| 62 | + |
| 63 | + if (aarDiff.archive.changed) { |
| 64 | + br() |
| 65 | + details { |
| 66 | + summary { +"JAR" } |
| 67 | + toDetailReport(aarDiff.archive) |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + if (aarDiff.jars.changed) { |
| 72 | + br() |
| 73 | + details { |
| 74 | + summary { +"CLASSFILES" } |
| 75 | + toDetailReport(aarDiff.jars) |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +override fun toString() = buildString { write(this) } |
| 83 | +} |
0 commit comments