Skip to content

Commit 4102306

Browse files
committed
Support aar diff html reports
1 parent 0c4e892 commit 4102306

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

reports/src/main/kotlin/com/jakewharton/diffuse/diff/AarDiff.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.jakewharton.diffuse.diff
33
import com.jakewharton.diffuse.format.Aar
44
import com.jakewharton.diffuse.format.ApiMapping
55
import com.jakewharton.diffuse.report.Report
6+
import com.jakewharton.diffuse.report.html.AarDiffHtmlReport
67
import com.jakewharton.diffuse.report.text.AarDiffTextReport
78

89
internal class AarDiff(
@@ -16,4 +17,5 @@ internal class AarDiff(
1617
val manifest = ManifestDiff(oldAar.manifest, newAar.manifest)
1718

1819
override fun toTextReport(): Report = AarDiffTextReport(this)
20+
override fun toHtmlReport(): Report = AarDiffHtmlReport(this)
1921
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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

Comments
 (0)