From d750b2ff22733f68607ae9b70e8083357c8dfe43 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 00:47:02 +0000 Subject: [PATCH 1/2] Update dependency io.github.usefulness.ktlint-gradle-plugin to v0.10.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f844fc95..ac4e71fa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ asm = "9.7" javaDiffUtils = "4.12" picnic = "0.7.0" kotlin = "2.0.20" -ktlint-gradle-plugin = "0.9.0" +ktlint-gradle-plugin = "0.10.0" r8 = "8.5.35" assertJ = "3.26.3" From af08c68401ffc57c25075269da2938f57d403b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Sat, 31 Aug 2024 08:07:20 +0200 Subject: [PATCH 2/2] Update klint --- build.gradle | 9 ++++++ .../kotlin/com/jakewharton/diffuse/diffuse.kt | 14 ++++----- .../kotlin/com/jakewharton/diffuse/members.kt | 8 ++--- .../diffuse/format/AndroidManifest.kt | 30 +++++++------------ .../jakewharton/diffuse/format/ApiMapping.kt | 10 +++---- .../diffuse/format/ArchiveFiles.kt | 14 ++++----- .../com/jakewharton/diffuse/format/Dex.kt | 3 +- .../com/jakewharton/diffuse/format/Jar.kt | 4 ++- .../diffuse/format/TypeDescriptor.kt | 4 +-- gradle/libs.versions.toml | 2 ++ .../kotlin/com/jakewharton/diffuse/io/Zip.kt | 3 +- .../com/jakewharton/diffuse/info/AabInfo.kt | 4 +-- .../com/jakewharton/diffuse/info/AarInfo.kt | 4 +-- .../com/jakewharton/diffuse/info/ApkInfo.kt | 4 +-- .../com/jakewharton/diffuse/info/DexInfo.kt | 4 +-- .../com/jakewharton/diffuse/info/JarInfo.kt | 4 +-- .../com/jakewharton/diffuse/report/strings.kt | 10 +++---- 17 files changed, 58 insertions(+), 73 deletions(-) diff --git a/build.gradle b/build.gradle index bb956d02..0feebe2b 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ plugins { subprojects { def javaTarget = JavaVersion.VERSION_11 + pluginManager.withPlugin(libs.plugins.kotlin.jvm.get().pluginId) { pluginManager.apply(libs.plugins.usefulness.ktlint.gradle.get().pluginId) @@ -24,6 +25,7 @@ subprojects { } } } + pluginManager.withPlugin("java") { tasks.withType(JavaCompile).configureEach { options.release.set(javaTarget.majorVersion.toInteger()) @@ -32,6 +34,13 @@ subprojects { from(rootProject.file("LICENSE")) } } + + pluginManager.withPlugin("io.github.usefulness.ktlint-gradle-plugin") { + ktlint { + ktlintVersion = libs.versions.ktlint.asProvider().get() + } + } + tasks.withType(Test).configureEach { useJUnitPlatform() } diff --git a/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt b/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt index 9c73cc2f..18122854 100644 --- a/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt +++ b/diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt @@ -171,14 +171,12 @@ private class DiffCommand( private val oldMapping by mappingFile("--old-mapping") private val newMapping by mappingFile("--new-mapping") - fun parse(old: Input, new: Input): BinaryDiff { - return when (type) { - BinaryType.Apk -> BinaryDiff.ofApk(old.toApk(), oldMapping, new.toApk(), newMapping) - BinaryType.Aab -> BinaryDiff.ofAab(old.toAab(), new.toAab()) - BinaryType.Aar -> BinaryDiff.ofAar(old.toAar(), oldMapping, new.toAar(), newMapping) - BinaryType.Jar -> BinaryDiff.ofJar(old.toJar(), oldMapping, new.toJar(), newMapping) - BinaryType.Dex -> BinaryDiff.ofDex(old.toDex(), oldMapping, new.toDex(), newMapping) - } + fun parse(old: Input, new: Input): BinaryDiff = when (type) { + BinaryType.Apk -> BinaryDiff.ofApk(old.toApk(), oldMapping, new.toApk(), newMapping) + BinaryType.Aab -> BinaryDiff.ofAab(old.toAab(), new.toAab()) + BinaryType.Aar -> BinaryDiff.ofAar(old.toAar(), oldMapping, new.toAar(), newMapping) + BinaryType.Jar -> BinaryDiff.ofJar(old.toJar(), oldMapping, new.toJar(), newMapping) + BinaryType.Dex -> BinaryDiff.ofDex(old.toDex(), oldMapping, new.toDex(), newMapping) } } diff --git a/diffuse/src/main/kotlin/com/jakewharton/diffuse/members.kt b/diffuse/src/main/kotlin/com/jakewharton/diffuse/members.kt index 7b65cde6..63e229c6 100644 --- a/diffuse/src/main/kotlin/com/jakewharton/diffuse/members.kt +++ b/diffuse/src/main/kotlin/com/jakewharton/diffuse/members.kt @@ -43,9 +43,7 @@ private fun Method.withoutSyntheticSuffix(): Method { private val lambdaClassSuffix = ".*?\\$\\\$Lambda\\$\\d+;".toRegex() -private fun TypeDescriptor.withoutSyntheticSuffix(): TypeDescriptor { - return when (value.matches(lambdaClassSuffix)) { - true -> TypeDescriptor(value.substringBeforeLast('$') + ";") - false -> this - } +private fun TypeDescriptor.withoutSyntheticSuffix(): TypeDescriptor = when (value.matches(lambdaClassSuffix)) { + true -> TypeDescriptor(value.substringBeforeLast('$') + ";") + false -> this } diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt index f73d708a..733f134e 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/AndroidManifest.kt @@ -45,9 +45,7 @@ class AndroidManifest private constructor( isNamespaceAware = true } - internal fun BinaryResourceFile.toManifest(arsc: Arsc? = null): AndroidManifest { - return toDocument(arsc).toManifest() - } + internal fun BinaryResourceFile.toManifest(arsc: Arsc? = null): AndroidManifest = toDocument(arsc).toManifest() @JvmStatic @JvmName("parse") @@ -57,11 +55,9 @@ class AndroidManifest private constructor( @JvmName("parse") fun Input.toManifest(): AndroidManifest = toUtf8().toManifest() - internal fun XmlNode.toManifest(): AndroidManifest { - return XmlProtoToXmlConverter.convert(XmlProtoNode(this)) - .apply { normalizeWhitespace() } - .toManifest() - } + internal fun XmlNode.toManifest(): AndroidManifest = XmlProtoToXmlConverter.convert(XmlProtoNode(this)) + .apply { normalizeWhitespace() } + .toManifest() private fun BinaryResourceFile.toDocument(arsc: Arsc?): Document { val rootChunk = requireNotNull(chunks.singleOrNull() as XmlChunk?) { @@ -134,11 +130,9 @@ class AndroidManifest private constructor( return document } - private fun String.toDocument(): Document { - return documentBuilderFactory.newDocumentBuilder() - .parse(InputSource(StringReader(this))) - .apply { normalizeWhitespace() } - } + private fun String.toDocument(): Document = documentBuilderFactory.newDocumentBuilder() + .parse(InputSource(StringReader(this))) + .apply { normalizeWhitespace() } private fun Document.normalizeWhitespace() { normalize() @@ -233,12 +227,10 @@ class AndroidManifest private constructor( override fun next() = item(index++) } - private fun Element.getAttributeOrNull(namespace: String?, name: String): String? { - return if (hasAttributeNS(namespace, name)) { - getAttributeNS(namespace, name) - } else { - null - } + private fun Element.getAttributeOrNull(namespace: String?, name: String): String? = if (hasAttributeNS(namespace, name)) { + getAttributeNS(namespace, name) + } else { + null } private const val ANDROID_NS = "http://schemas.android.com/apk/res/android" diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/ApiMapping.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/ApiMapping.kt index de775856..52972fd2 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/ApiMapping.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/ApiMapping.kt @@ -19,12 +19,10 @@ class ApiMapping private constructor(private val typeMappings: Map Type): ArchiveFiles { - return entries - .associate { - it.path to ArchiveFile(it.path, classifier(it.path), it.zipSize, it.uncompressedSize, it.isCompressed) - } - .plus("/" to ArchiveFile("/", Other, Size(22), Size.ZERO, false)) - .let(::ArchiveFiles) - } + fun Zip.toArchiveFiles(classifier: (String) -> Type): ArchiveFiles = entries + .associate { + it.path to ArchiveFile(it.path, classifier(it.path), it.zipSize, it.uncompressedSize, it.isCompressed) + } + .plus("/" to ArchiveFile("/", Other, Size(22), Size.ZERO, false)) + .let(::ArchiveFiles) } } diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Dex.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Dex.kt index 454a8ce8..a71e4e5d 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Dex.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Dex.kt @@ -13,7 +13,8 @@ class Dex private constructor( val classes: List, override val declaredMembers: List, override val referencedMembers: List, -) : BinaryFormat, CodeBinary { +) : BinaryFormat, + CodeBinary { override val members = declaredMembers + referencedMembers fun withMapping(mapping: ApiMapping): Dex { diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Jar.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Jar.kt index e4d0e932..bd34793d 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/Jar.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/Jar.kt @@ -11,7 +11,9 @@ class Jar private constructor( val classes: List, override val declaredMembers: List, override val referencedMembers: List, -) : BinaryFormat, CodeBinary { +) : BinaryFormat, + CodeBinary { + override val members = declaredMembers + referencedMembers companion object { diff --git a/formats/src/main/kotlin/com/jakewharton/diffuse/format/TypeDescriptor.kt b/formats/src/main/kotlin/com/jakewharton/diffuse/format/TypeDescriptor.kt index 0812faa6..6e31f8dd 100644 --- a/formats/src/main/kotlin/com/jakewharton/diffuse/format/TypeDescriptor.kt +++ b/formats/src/main/kotlin/com/jakewharton/diffuse/format/TypeDescriptor.kt @@ -2,9 +2,7 @@ package com.jakewharton.diffuse.format @JvmInline value class TypeDescriptor(val value: String) : Comparable { - override fun compareTo(other: TypeDescriptor): Int { - return sourceName.compareTo(other.sourceName) - } + override fun compareTo(other: TypeDescriptor): Int = sourceName.compareTo(other.sourceName) val sourceName get() = value.toHumanName() val simpleName get() = sourceName.substringAfterLast('.') diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ac4e71fa..62163709 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ kotlin = "2.0.20" ktlint-gradle-plugin = "0.10.0" r8 = "8.5.35" assertJ = "3.26.3" +ktlint = "1.3.1" [libraries] dalvikDx = { module = "com.jakewharton.android.repackaged:dalvik-dx", version.ref = "dalvikdx" } @@ -38,6 +39,7 @@ asm = { module = "org.ow2.asm:asm", version.ref = "asm" } diffUtils = { module = "io.github.java-diff-utils:java-diff-utils", version.ref = "javaDiffUtils" } picnic = { module = "com.jakewharton.picnic:picnic", version.ref = "picnic" } r8 = { module = "com.android.tools:r8", version.ref = "r8" } +ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint" } [plugins] usefulness-ktlint-gradle = { id = "io.github.usefulness.ktlint-gradle-plugin", version.ref = "ktlint-gradle-plugin" } diff --git a/io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt b/io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt index a53fa7aa..98df046e 100644 --- a/io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt +++ b/io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt @@ -111,7 +111,8 @@ internal fun Path.toZip(): Zip { internal class PathZip( fs: FileSystem, override val entries: List, -) : Zip, Closeable by fs { +) : Zip, + Closeable by fs { class Entry( private val root: Path, override val path: String, 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 c07e5a06..74dca0b3 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AabInfo.kt @@ -8,7 +8,5 @@ import com.jakewharton.diffuse.report.text.AabInfoTextReport class AabInfo( private val aab: Aab, ) : BinaryDiff { - override fun toTextReport(): Report { - return AabInfoTextReport(aab) - } + override fun toTextReport(): Report = 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 8d288bc8..ce2c4750 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/AarInfo.kt @@ -7,7 +7,5 @@ import com.jakewharton.diffuse.report.text.AarInfoTextReport class AarInfo( private val aar: Aar, ) : BinaryInfo { - override fun toTextReport(): Report { - return AarInfoTextReport(aar) - } + override fun toTextReport(): Report = 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 a7fa82d0..03eb053d 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/ApkInfo.kt @@ -7,7 +7,5 @@ import com.jakewharton.diffuse.report.text.ApkInfoTextReport class ApkInfo( private val apk: Apk, ) : BinaryInfo { - override fun toTextReport(): Report { - return ApkInfoTextReport(apk) - } + override fun toTextReport(): Report = 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 1a8c8aee..8ea2c83b 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/DexInfo.kt @@ -7,7 +7,5 @@ import com.jakewharton.diffuse.report.text.DexInfoTextReport class DexInfo( private val dex: Dex, ) : BinaryInfo { - override fun toTextReport(): Report { - return DexInfoTextReport(dex) - } + override fun toTextReport(): Report = 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 2b07bd53..c111b492 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/info/JarInfo.kt @@ -7,7 +7,5 @@ import com.jakewharton.diffuse.report.text.JarInfoTextReport class JarInfo( private val jar: Jar, ) : BinaryInfo { - override fun toTextReport(): Report { - return JarInfoTextReport(jar) - } + override fun toTextReport(): Report = JarInfoTextReport(jar) } diff --git a/reports/src/main/kotlin/com/jakewharton/diffuse/report/strings.kt b/reports/src/main/kotlin/com/jakewharton/diffuse/report/strings.kt index a7834bb8..d77f1e06 100644 --- a/reports/src/main/kotlin/com/jakewharton/diffuse/report/strings.kt +++ b/reports/src/main/kotlin/com/jakewharton/diffuse/report/strings.kt @@ -2,12 +2,10 @@ package com.jakewharton.diffuse.report import com.jakewharton.diffuse.io.Size -internal fun Int.toUnitString(unit: String, vararg specializations: Pair): String { - return buildString { - append(this@toUnitString) - append(' ') - append(specializations.toMap()[this@toUnitString] ?: unit) - } +internal fun Int.toUnitString(unit: String, vararg specializations: Pair): String = buildString { + append(this@toUnitString) + append(' ') + append(specializations.toMap()[this@toUnitString] ?: unit) } internal fun Int.toDiffString(zeroSign: Char? = null) = buildString {