Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency io.github.usefulness.ktlint-gradle-plugin to v0.10.0 #357

Merged
merged 2 commits into from
Aug 31, 2024
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
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -24,6 +25,7 @@ subprojects {
}
}
}

pluginManager.withPlugin("java") {
tasks.withType(JavaCompile).configureEach {
options.release.set(javaTarget.majorVersion.toInteger())
Expand All @@ -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()
}
Expand Down
14 changes: 6 additions & 8 deletions diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 3 additions & 5 deletions diffuse/src/main/kotlin/com/jakewharton/diffuse/members.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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?) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ class ApiMapping private constructor(private val typeMappings: Map<TypeDescripto
* Given a [TypeDescriptor] which is typically obfuscated, return a new [TypeDescriptor] for the
* original name or return [type] if not included in the mapping.
*/
operator fun get(type: TypeDescriptor): TypeDescriptor {
return typeMappings[type.componentDescriptor]
?.typeDescriptor
?.asArray(type.arrayArity)
?: type
}
operator fun get(type: TypeDescriptor): TypeDescriptor = typeMappings[type.componentDescriptor]
?.typeDescriptor
?.asArray(type.arrayArity)
?: type

/**
* Given a [Member] which is typically obfuscated, return a new [Member] with the types and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ class ArchiveFiles internal constructor(
companion object {
@JvmStatic
@JvmName("parse")
fun Zip.toArchiveFiles(classifier: (String) -> 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Dex private constructor(
val classes: List<TypeDescriptor>,
override val declaredMembers: List<Member>,
override val referencedMembers: List<Member>,
) : BinaryFormat, CodeBinary {
) : BinaryFormat,
CodeBinary {
override val members = declaredMembers + referencedMembers

fun withMapping(mapping: ApiMapping): Dex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Jar private constructor(
val classes: List<Class>,
override val declaredMembers: List<Member>,
override val referencedMembers: List<Member>,
) : BinaryFormat, CodeBinary {
) : BinaryFormat,
CodeBinary {

override val members = declaredMembers + referencedMembers

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.jakewharton.diffuse.format

@JvmInline
value class TypeDescriptor(val value: String) : Comparable<TypeDescriptor> {
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('.')
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ 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"
ktlint = "1.3.1"

[libraries]
dalvikDx = { module = "com.jakewharton.android.repackaged:dalvik-dx", version.ref = "dalvikdx" }
Expand All @@ -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" }
Expand Down
3 changes: 2 additions & 1 deletion io/src/main/kotlin/com/jakewharton/diffuse/io/Zip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ internal fun Path.toZip(): Zip {
internal class PathZip(
fs: FileSystem,
override val entries: List<Zip.Entry>,
) : Zip, Closeable by fs {
) : Zip,
Closeable by fs {
class Entry(
private val root: Path,
override val path: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package com.jakewharton.diffuse.report

import com.jakewharton.diffuse.io.Size

internal fun Int.toUnitString(unit: String, vararg specializations: Pair<Int, String>): String {
return buildString {
append(this@toUnitString)
append(' ')
append(specializations.toMap()[this@toUnitString] ?: unit)
}
internal fun Int.toUnitString(unit: String, vararg specializations: Pair<Int, String>): String = buildString {
append(this@toUnitString)
append(' ')
append(specializations.toMap()[this@toUnitString] ?: unit)
}

internal fun Int.toDiffString(zeroSign: Char? = null) = buildString {
Expand Down