diff --git a/CHANGELOG.md b/CHANGELOG.md index d5acd498..1bc1ed73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt b/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt index d5db4943..187d96a1 100644 --- a/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt +++ b/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt @@ -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) diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AabDiff.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AabDiff.kt index ba3e5350..fff9baa2 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AabDiff.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AabDiff.kt @@ -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) } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AarDiff.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AarDiff.kt index 7a82a6a5..d25cff22 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AarDiff.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/AarDiff.kt @@ -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) } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/ApkDiff.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/ApkDiff.kt index 6e8a5b09..4a4651a9 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/ApkDiff.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/ApkDiff.kt @@ -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) } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/DexDiff.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/DexDiff.kt index 7dd923d8..15bdd38b 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/DexDiff.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/DexDiff.kt @@ -32,7 +32,7 @@ internal class DexDiff(val oldDexes: List, val newDexes: List) : 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() = diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/JarDiff.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/JarDiff.kt index 580b4890..e2e3e2d2 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/diff/JarDiff.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/diff/JarDiff.kt @@ -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) } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt index e2781439..349d9f44 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt @@ -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) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt index 70311509..ab4dbc1d 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt @@ -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) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt index ed99c4b9..5e92d892 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt @@ -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) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt index fb9403e2..168d9adc 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt @@ -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) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt index 398bdaaa..6dfe33d4 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt @@ -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) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/Report.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/Report.kt index 835f2ff2..7dc25026 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/Report.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/Report.kt @@ -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") } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AabDiffTextReport.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AabDiffTextReport.kt index d54bfb75..e5bd4b27 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AabDiffTextReport.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AabDiffTextReport.kt @@ -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: ") @@ -48,6 +49,7 @@ internal class AabDiffTextReport(private val aabDiff: AabDiff) : Report { .toString() ) + if (summaryOnly) return@apply appendLine("==================") appendLine("==== base ====") appendLine("==================") diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AarDiffTextReport.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AarDiffTextReport.kt index ecaa8471..6fc27335 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AarDiffTextReport.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/AarDiffTextReport.kt @@ -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: ") @@ -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("=================") diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/ApkDiffTextReport.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/ApkDiffTextReport.kt index b8748ce9..8c55aa09 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/ApkDiffTextReport.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/ApkDiffTextReport.kt @@ -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: ") @@ -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("=================") diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/DexDiffTextReport.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/DexDiffTextReport.kt index d5575e3b..6189b815 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/DexDiffTextReport.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/DexDiffTextReport.kt @@ -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}" @@ -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()) } } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/JarDiffTextReport.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/JarDiffTextReport.kt index 66391f83..4ebe34f3 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/JarDiffTextReport.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/text/JarDiffTextReport.kt @@ -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: ") @@ -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("=================")