Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## [Unreleased]
[Unreleased]: https://github.com/JakeWharton/diffuse/compare/0.3.0...HEAD

**Added**
- Add `--summary-only` flag.

## [0.3.0] - 2024-02-20
[0.3.0]: https://github.com/JakeWharton/diffuse/releases/tag/0.3.0
Expand Down
11 changes: 9 additions & 2 deletions diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,16 @@ private class OutputOptions(outputFs: FileSystem, private val output: PrintStrea
}
}

private val summaryOnly by
option(
"--summary-only",
help = "Skip generating detailed reports, outputting only the summary.",
)
.flag()

fun write(reportFactory: Report.Factory) {
val textReport by lazy(NONE) { reportFactory.toTextReport().toString() }
val htmlReport by lazy(NONE) { reportFactory.toHtmlReport().toString() }
val textReport by lazy(NONE) { reportFactory.toTextReport(summaryOnly).toString() }
val htmlReport by lazy(NONE) { reportFactory.toHtmlReport(summaryOnly).toString() }

text?.writeText(textReport)
html?.writeText(htmlReport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ internal class AabDiff(val oldAab: Aab, val newAab: Aab) : BinaryDiff {
ModuleDiff(oldModule, newAab.featureModules.getValue(name))
}

override fun toTextReport(): Report = AabDiffTextReport(this)
override fun toTextReport(summaryOnly: Boolean): Report = AabDiffTextReport(this, summaryOnly)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ internal class AarDiff(
val jars = JarsDiff(oldAar.jars, oldMapping, newAar.jars, newMapping)
val manifest = ManifestDiff(oldAar.manifest, newAar.manifest)

override fun toTextReport(): Report = AarDiffTextReport(this)
override fun toTextReport(summaryOnly: Boolean): Report = AarDiffTextReport(this, summaryOnly)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ internal class ApkDiff(

val lintMessages = listOfNotNull(archive.resourcesArscCompression())

override fun toTextReport(): Report = ApkDiffTextReport(this)
override fun toTextReport(summaryOnly: Boolean): Report = ApkDiffTextReport(this, summaryOnly)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class DexDiff(val oldDexes: List<Dex>, val newDexes: List<Dex>) : Binar

val changed = strings.changed || types.changed || methods.changed || fields.changed

override fun toTextReport(): Report = DexDiffTextReport(this)
override fun toTextReport(summaryOnly: Boolean): Report = DexDiffTextReport(this, summaryOnly)
}

internal fun DexDiff.toSummaryTable() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ internal class JarDiff(

val changed = jars.changed || archive.changed

override fun toTextReport(): Report = JarDiffTextReport(this)
override fun toTextReport(summaryOnly: Boolean): Report = JarDiffTextReport(this, summaryOnly)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.text.AabInfoTextReport

class AabInfo(private val aab: Aab) : BinaryDiff {
override fun toTextReport(): Report {
override fun toTextReport(summaryOnly: Boolean): Report {
return AabInfoTextReport(aab)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.text.AarInfoTextReport

class AarInfo(private val aar: Aar) : BinaryInfo {
override fun toTextReport(): Report {
override fun toTextReport(summaryOnly: Boolean): Report {
return AarInfoTextReport(aar)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.text.ApkInfoTextReport

class ApkInfo(private val apk: Apk) : BinaryInfo {
override fun toTextReport(): Report {
override fun toTextReport(summaryOnly: Boolean): Report {
return ApkInfoTextReport(apk)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.text.DexInfoTextReport

class DexInfo(private val dex: Dex) : BinaryInfo {
override fun toTextReport(): Report {
override fun toTextReport(summaryOnly: Boolean): Report {
return DexInfoTextReport(dex)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.text.JarInfoTextReport

class JarInfo(private val jar: Jar) : BinaryInfo {
override fun toTextReport(): Report {
override fun toTextReport(summaryOnly: Boolean): Report {
return JarInfoTextReport(jar)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ interface Report {
fun write(appendable: Appendable)

interface Factory {
fun toTextReport(): Report
fun toTextReport(summaryOnly: Boolean): Report

fun toHtmlReport(): Report {
fun toHtmlReport(summaryOnly: Boolean): Report {
TODO("Implement HTML reporting")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import com.jakewharton.picnic.TextAlignment.BottomLeft
import com.jakewharton.picnic.TextAlignment.MiddleCenter
import com.jakewharton.picnic.TextAlignment.MiddleRight

internal class AabDiffTextReport(private val aabDiff: AabDiff) : Report {
internal class AabDiffTextReport(private val aabDiff: AabDiff, private val summaryOnly: Boolean) :
Report {
override fun write(appendable: Appendable) {
appendable.apply {
append("OLD: ")
Expand Down Expand Up @@ -48,6 +49,7 @@ internal class AabDiffTextReport(private val aabDiff: AabDiff) : Report {
.toString()
)

if (summaryOnly) return@apply
appendLine("==================")
appendLine("==== base ====")
appendLine("==================")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.jakewharton.diffuse.diff.toSummaryTable
import com.jakewharton.diffuse.format.ArchiveFile.Type
import com.jakewharton.diffuse.report.Report

internal class AarDiffTextReport(private val aarDiff: AarDiff) : Report {
internal class AarDiffTextReport(private val aarDiff: AarDiff, private val summaryOnly: Boolean) :
Report {
override fun write(appendable: Appendable) {
appendable.apply {
append("OLD: ")
Expand All @@ -25,6 +26,8 @@ internal class AarDiffTextReport(private val aarDiff: AarDiff) : Report {
)
appendLine()
appendLine(aarDiff.jars.toSummaryTable("JAR"))

if (summaryOnly) return@apply
if (aarDiff.archive.changed) {
appendLine()
appendLine("=================")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import com.jakewharton.diffuse.format.ArchiveFile.Type
import com.jakewharton.diffuse.report.Report
import com.jakewharton.diffuse.report.toSummaryString

internal class ApkDiffTextReport(private val apkDiff: ApkDiff) : Report {
internal class ApkDiffTextReport(private val apkDiff: ApkDiff, private val summaryOnly: Boolean) :
Report {
override fun write(appendable: Appendable) {
appendable.apply {
append("OLD: ")
Expand Down Expand Up @@ -58,6 +59,8 @@ internal class ApkDiffTextReport(private val apkDiff: ApkDiff) : Report {
appendLine(apkDiff.dex.toSummaryTable())
appendLine()
appendLine(apkDiff.arsc.toSummaryTable())

if (summaryOnly) return@apply
if (apkDiff.archive.changed || apkDiff.signatures.changed) {
appendLine()
appendLine("=================")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.jakewharton.diffuse.diff.DexDiff
import com.jakewharton.diffuse.diff.toDetailReport
import com.jakewharton.diffuse.report.Report

internal class DexDiffTextReport(private val dexDiff: DexDiff) : Report {
internal class DexDiffTextReport(private val dexDiff: DexDiff, private val summaryOnly: Boolean) :
Report {
private val oldDex =
requireNotNull(dexDiff.oldDexes.singleOrNull()) {
"Dex diff report only supports a single old dex. Found: ${dexDiff.oldDexes}"
Expand All @@ -21,6 +22,8 @@ internal class DexDiffTextReport(private val dexDiff: DexDiff) : Report {
append("NEW: ")
appendLine(newDex.filename)
appendLine()

if (summaryOnly) return@apply
appendLine(dexDiff.toDetailReport())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import com.jakewharton.diffuse.diff.toSummaryTable
import com.jakewharton.diffuse.format.ArchiveFile.Type
import com.jakewharton.diffuse.report.Report

internal class JarDiffTextReport(private val jarDiff: JarDiff) : Report {
internal class JarDiffTextReport(private val jarDiff: JarDiff, private val summaryOnly: Boolean) :
Report {
override fun write(appendable: Appendable) {
appendable.apply {
append("OLD: ")
Expand All @@ -19,6 +20,8 @@ internal class JarDiffTextReport(private val jarDiff: JarDiff) : Report {
appendLine(jarDiff.archive.toSummaryTable("JAR", Type.JAR_TYPES))
appendLine()
appendLine(jarDiff.jars.toSummaryTable("CLASSES"))

if (summaryOnly) return@apply
if (jarDiff.archive.changed) {
appendLine()
appendLine("=================")
Expand Down