Skip to content

Commit

Permalink
Merge pull request JakeWharton#96 from usefulness/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Jun 26, 2022
2 parents dd31f8b + 1ea79d2 commit cb7cbc2
Show file tree
Hide file tree
Showing 38 changed files with 108 additions and 102 deletions.
5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true

[*.{kt,kts}]
ij_kotlin_imports_layout=*
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
disabled_rules=filename
18 changes: 9 additions & 9 deletions diffuse/src/main/kotlin/com/jakewharton/diffuse/diffuse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private fun ParameterHolder.binaryType(): FlagOption<BinaryType> {
"--apk" to BinaryType.Apk,
"--aar" to BinaryType.Aar,
"--aab" to BinaryType.Aab,
"--jar" to BinaryType.Jar
"--jar" to BinaryType.Jar,
)
.default(BinaryType.Apk)
}
Expand All @@ -83,7 +83,7 @@ private fun ParameterHolder.mappingFile(name: String): OptionWithValues<ApiMappi
return option(
name,
help = "Mapping file produced by R8 or ProGuard.",
metavar = "FILE"
metavar = "FILE",
)
.path(mustExist = true, canBeDir = false, mustBeReadable = true)
.convert { it.asInput().toApiMapping() }
Expand All @@ -92,20 +92,20 @@ private fun ParameterHolder.mappingFile(name: String): OptionWithValues<ApiMappi

private class OutputOptions(
outputFs: FileSystem,
private val output: PrintStream
private val output: PrintStream,
) : OptionGroup(name = "Output options") {
private val text by option(
help = "File to write text report. Note: Specifying this option will disable printing the text report to standard out by default. Specify '--stdout text' to restore that behavior.",
metavar = "FILE"
metavar = "FILE",
)
.path(fileSystem = outputFs)
private val html by option(
help = "File to write HTML report. Note: Specifying this option will disable printing the text report to standard out by default. Specify '--stdout text' to restore that behavior.",
metavar = "FILE"
metavar = "FILE",
)
.path(fileSystem = outputFs)
private val stdout by option(
help = "Report to print to standard out. By default, The text report will be printed to standard out ONLY when neither --text nor --html are specified."
help = "Report to print to standard out. By default, The text report will be printed to standard out ONLY when neither --text nor --html are specified.",
)
.choice("text" to ReportType.Text, "html" to ReportType.Html)
.defaultLazy {
Expand Down Expand Up @@ -157,7 +157,7 @@ private class InfoCommand(
private class DiffCommand(
inputFs: FileSystem,
outputFs: FileSystem,
output: PrintStream
output: PrintStream,
) : CliktCommand(name = "diff", help = "Display changes between two binaries.") {
private val inputOptions by object : OptionGroup("Input options") {
private val type by binaryType()
Expand Down Expand Up @@ -192,14 +192,14 @@ private class DiffCommand(

private class MembersCommand(
inputFs: FileSystem,
private val stdout: PrintStream
private val stdout: PrintStream,
) : CliktCommand(name = "members", help = "List methods or fields of a binary.") {
private val binary by argument("FILE", help = "Input file.")
.path(mustExist = true, canBeDir = false, mustBeReadable = true, fileSystem = inputFs)

private val hideSyntheticNumbers by option(
"--hide-synthetic-numbers",
help = "Remove synthetic numbers from type and method names. This is useful to prevent noise when diffing output."
help = "Remove synthetic numbers from type and method names. This is useful to prevent noise when diffing output.",
)
.flag()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ abstract class BaseFunctionalTest {
if (mappingAResource == null || mappingBResource == null) {
main(
"diff",
"--$mode", artifactAResource, artifactBResource,
"--text", diffOutput.path,
"--$mode",
artifactAResource,
artifactBResource,
"--text",
diffOutput.path,
)
} else {
main(
Expand All @@ -43,8 +46,10 @@ abstract class BaseFunctionalTest {
}
main(
"info",
"--$mode", artifactBResource,
"--text", infoOutput.path,
"--$mode",
artifactBResource,
"--text",
infoOutput.path,
)

assertThat(diffOutput).hasSameTextualContentAs(expectedDiff)
Expand Down
4 changes: 2 additions & 2 deletions formats/src/main/kotlin/com/jakewharton/diffuse/format/Aab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class Aab private constructor(
override val filename: String?,
val apiMapping: ApiMapping,
val baseModule: Module,
val featureModules: Map<String, Module>
val featureModules: Map<String, Module>,
) : BinaryFormat {
// TODO remove toTypedArray call https://youtrack.jetbrains.com/issue/KT-12663
val modules get() = listOf(baseModule, *featureModules.values.toTypedArray())

class Module private constructor(
val files: ArchiveFiles,
val manifest: AndroidManifest,
val dexes: List<Dex>
val dexes: List<Dex>,
) {
companion object {
internal const val manifestFilePath = "manifest/${AndroidManifest.NAME}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Aar private constructor(
val files: ArchiveFiles,
val manifest: AndroidManifest,
val classes: Jar,
val libs: List<Jar>
val libs: List<Jar>,
) : BinaryFormat {
/** The `classes.jar` and any additional jars from `libs/`. */
// TODO remove toTypedArray call https://youtrack.jetbrains.com/issue/KT-12663
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AndroidManifest private constructor(
val xml: String,
val packageName: String,
val versionName: String?,
val versionCode: Long?
val versionCode: Long?,
) {
companion object {
const val NAME = "AndroidManifest.xml"
Expand Down Expand Up @@ -142,7 +142,7 @@ class AndroidManifest private constructor(
val emptyNodes = XPathFactory.newInstance().newXPath().evaluate(
"//text()[normalize-space()='']",
this,
XPathConstants.NODESET
XPathConstants.NODESET,
) as NodeList
for (emptyNode in emptyNodes) {
emptyNode.parentNode.removeChild(emptyNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ApiMapping private constructor(private val typeMappings: Map<TypeDescripto
if (line.startsWith(' ')) {
val result = memberLine.matchEntire(line)
?: throw IllegalArgumentException(
"Unable to parse line ${index + 1} as member mapping: $line"
"Unable to parse line ${index + 1} as member mapping: $line",
)
val (_, returnType, fromName, parameters, toName) = result.groupValues

Expand All @@ -113,7 +113,7 @@ class ApiMapping private constructor(private val typeMappings: Map<TypeDescripto

val result = typeLine.matchEntire(line)
?: throw IllegalArgumentException(
"Unable to parse line ${index + 1} as type mapping: $line"
"Unable to parse line ${index + 1} as type mapping: $line",
)
val (_, fromType, toType) = result.groupValues

Expand Down Expand Up @@ -155,13 +155,13 @@ class ApiMapping private constructor(private val typeMappings: Map<TypeDescripto
private data class MethodSignature(
val returnType: TypeDescriptor,
val name: String,
val parameterTypes: List<TypeDescriptor>
val parameterTypes: List<TypeDescriptor>,
)

private data class TypeMapping(
val typeDescriptor: TypeDescriptor,
val fields: Map<String, String>,
val methods: Map<MethodSignature, String>
val methods: Map<MethodSignature, String>,
) {
operator fun get(field: String) = fields[field]
operator fun get(method: MethodSignature) = methods[method]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Apk private constructor(
val dexes: List<Dex>,
val arsc: Arsc,
val manifest: AndroidManifest,
val signatures: Signatures
val signatures: Signatures,
) : BinaryFormat {
companion object {
internal val classesDexRegex = Regex("classes\\d*\\.dex")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class ArchiveFile(
val type: Type,
val size: Size,
val uncompressedSize: Size,
val isCompressed: Boolean
val isCompressed: Boolean,
) {
enum class Type {
Dex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.jakewharton.diffuse.io.Size
import com.jakewharton.diffuse.io.Zip

class ArchiveFiles internal constructor(
private val files: Map<String, ArchiveFile>
private val files: Map<String, ArchiveFile>,
) : Map<String, ArchiveFile> by files {
override fun hashCode() = files.hashCode()
override fun equals(other: Any?) = other is ArchiveFiles && files == other.files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.jakewharton.diffuse.io.Input

class Arsc private constructor(
val configs: List<String>,
val entries: Map<Int, Entry>
val entries: Map<Int, Entry>,
) {
data class Entry(
val type: String,
val name: String
val name: String,
) : Comparable<Entry> {
override fun compareTo(other: Entry) = comparator.compare(this, other)
override fun toString() = "$type/$name"
Expand Down
18 changes: 9 additions & 9 deletions formats/src/main/kotlin/com/jakewharton/diffuse/format/Class.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.objectweb.asm.Opcodes
class Class private constructor(
val descriptor: TypeDescriptor,
val declaredMembers: List<Member>,
val referencedMembers: List<Member>
val referencedMembers: List<Member>,
) {
override fun toString() = descriptor.toString()
override fun hashCode() = Objects.hash(descriptor, declaredMembers, referencedMembers)
Expand All @@ -39,7 +39,7 @@ class Class private constructor(

private class DeclaredMembersVisitor(
val type: TypeDescriptor,
val methodVisitor: MethodVisitor
val methodVisitor: MethodVisitor,
) : ClassVisitor(Opcodes.ASM7) {
val members = mutableListOf<Member>()

Expand All @@ -48,7 +48,7 @@ private class DeclaredMembersVisitor(
name: String,
descriptor: String,
signature: String?,
exceptions: Array<out String>?
exceptions: Array<out String>?,
): MethodVisitor? {
members += parseMethod(type, name, descriptor)
return methodVisitor
Expand All @@ -59,7 +59,7 @@ private class DeclaredMembersVisitor(
name: String,
descriptor: String,
signature: String?,
value: Any?
value: Any?,
): FieldVisitor? {
members += Field(type, name, TypeDescriptor(descriptor))
return null
Expand All @@ -74,7 +74,7 @@ private class ReferencedMembersVisitor : MethodVisitor(Opcodes.ASM7) {
owner: String,
name: String,
descriptor: String,
isInterface: Boolean
isInterface: Boolean,
) {
val ownerType = parseOwner(owner)
val referencedMethod = parseMethod(ownerType, name, descriptor)
Expand All @@ -85,7 +85,7 @@ private class ReferencedMembersVisitor : MethodVisitor(Opcodes.ASM7) {
name: String?,
descriptor: String?,
bootstrapMethodHandle: Handle,
vararg bootstrapMethodArguments: Any?
vararg bootstrapMethodArguments: Any?,
) {
members += parseHandle(bootstrapMethodHandle)

Expand Down Expand Up @@ -114,7 +114,7 @@ private class ReferencedMembersVisitor : MethodVisitor(Opcodes.ASM7) {
opcode: Int,
owner: String,
name: String,
descriptor: String
descriptor: String,
) {
val ownerType = parseOwner(owner)
val referencedField = Field(ownerType, name, TypeDescriptor(descriptor))
Expand All @@ -134,7 +134,7 @@ private class ReferencedMembersVisitor : MethodVisitor(Opcodes.ASM7) {
private fun parseMethod(
owner: TypeDescriptor,
name: String,
descriptor: String
descriptor: String,
): Method {
val parameterTypes = mutableListOf<TypeDescriptor>()
var i = 1
Expand Down Expand Up @@ -164,5 +164,5 @@ private val lambdaMetaFactory = Handle(
"java/lang/invoke/LambdaMetafactory",
"metafactory",
"(Ljava/lang/invoke/MethodHandles\$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;",
false
false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Dex private constructor(
val types: List<String>,
val classes: List<TypeDescriptor>,
override val declaredMembers: List<Member>,
override val referencedMembers: List<Member>
override val referencedMembers: List<Member>,
) : CodeBinary {
override val members = declaredMembers + referencedMembers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Jar private constructor(
val files: ArchiveFiles,
val classes: List<Class>,
override val declaredMembers: List<Member>,
override val referencedMembers: List<Member>
override val referencedMembers: List<Member>,
) : BinaryFormat, CodeBinary {
override val members = declaredMembers + referencedMembers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sealed class Member : Comparable<Member> {
data class Field(
override val declaringType: TypeDescriptor,
override val name: String,
val type: TypeDescriptor
val type: TypeDescriptor,
) : Member() {
override fun toString() = "${declaringType.sourceName} $name: ${type.simpleName}"

Expand All @@ -40,7 +40,7 @@ data class Method(
override val declaringType: TypeDescriptor,
override val name: String,
val parameterTypes: List<TypeDescriptor>,
val returnType: TypeDescriptor
val returnType: TypeDescriptor,
) : Member() {
override fun toString() = buildString {
append(declaringType.sourceName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import okio.ByteString.Companion.toByteString
data class Signatures(
val v1: List<ByteString>,
val v2: List<ByteString>,
val v3: List<ByteString>
val v3: List<ByteString>,
) {
companion object {
@JvmStatic
Expand All @@ -26,7 +26,7 @@ data class Signatures(
return Signatures(
result.v1SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
result.v2SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
result.v3SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted()
result.v3SchemeSigners.map { it.certificate.encoded.toByteString().sha1() }.sorted(),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ asm = "9.3"
javaDiffUtils = "4.11"
picnic = "0.6.0"
kotlin = "1.7.0"
kotlinter = "3.10.0"
kotlinter = "3.11.1"
r8 = "3.3.28"
assertJ = "3.23.1"

Expand Down
6 changes: 3 additions & 3 deletions io/src/main/kotlin/com/jakewharton/diffuse/io/Input.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface Input {
}

class PathInput internal constructor(
val path: Path
val path: Path,
) : Input {
override val name get() = path.fileName.toString()
override fun source() = path.source().buffer()
Expand All @@ -45,7 +45,7 @@ class PathInput internal constructor(

class BytesInput internal constructor(
override val name: String,
val bytes: ByteString
val bytes: ByteString,
) : Input {
override fun source(): BufferedSource = Buffer().write(bytes)
override fun toByteArray() = bytes.toByteArray()
Expand All @@ -55,7 +55,7 @@ class BytesInput internal constructor(

class StringInput internal constructor(
override val name: String,
private val string: String
private val string: String,
) : Input {
private val bytes = string.encodeUtf8()

Expand Down
Loading

0 comments on commit cb7cbc2

Please sign in to comment.