Source added
This commit is contained in:
parent
b2864b500e
commit
ba28ca859e
8352 changed files with 1487182 additions and 1 deletions
11
wire-handler/README.md
Normal file
11
wire-handler/README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Build
|
||||
|
||||
`./gradlew build`
|
||||
|
||||
# Move
|
||||
|
||||
`mv lib/build/libs/wire-handler-1.0.0.jar .`
|
||||
|
||||
# Update Signal project
|
||||
|
||||
If version or name changed, update `build.gradle` with new wire-handler jar path in `buildScript/dependencies`
|
||||
1
wire-handler/gradle
Symbolic link
1
wire-handler/gradle
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../gradle
|
||||
1
wire-handler/gradlew
vendored
Symbolic link
1
wire-handler/gradlew
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../gradlew
|
||||
1
wire-handler/gradlew.bat
vendored
Symbolic link
1
wire-handler/gradlew.bat
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../gradlew.bat
|
||||
17
wire-handler/lib/build.gradle.kts
Normal file
17
wire-handler/lib/build.gradle.kts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
|
||||
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.jvm") version "1.9.20"
|
||||
`java-library`
|
||||
}
|
||||
|
||||
version = "1.0.0"
|
||||
archivesName.set("wire-handler")
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.squareup.wire:wire-schema:4.4.3")
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.signal.wire
|
||||
|
||||
import com.squareup.wire.schema.SchemaHandler
|
||||
|
||||
class Factory : SchemaHandler.Factory {
|
||||
override fun create(): SchemaHandler {
|
||||
return Handler()
|
||||
}
|
||||
}
|
||||
54
wire-handler/lib/src/main/kotlin/org/signal/wire/Handler.kt
Normal file
54
wire-handler/lib/src/main/kotlin/org/signal/wire/Handler.kt
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package org.signal.wire
|
||||
|
||||
import com.squareup.wire.schema.*
|
||||
import okio.Path
|
||||
import okio.Path.Companion.toPath
|
||||
import java.lang.UnsupportedOperationException
|
||||
import java.nio.charset.Charset
|
||||
|
||||
/**
|
||||
* Iterate over all generated kotlin files and inline replace calls to countNonNull with calls to
|
||||
* a 'to be defined' where the proto is used implementation of 'countNonDefa' (short for countNonDefault).
|
||||
* This code runs as part of wire compilation via the gradle plugin system.
|
||||
*
|
||||
* To make the replacement easier, the new name is the same number of bytes as the old to allow using a
|
||||
* seeking read/write file descriptor to making the updates.
|
||||
*
|
||||
* The algorithm for searching/replacing is basic and could be optimized if necessary for faster build times.
|
||||
*/
|
||||
class Handler : SchemaHandler() {
|
||||
|
||||
companion object {
|
||||
private val CHECK_FUNCTION = "countNonNull".encodeToByteArray()
|
||||
private val REPLACEMENT = "countNonDefa".encodeToByteArray()
|
||||
}
|
||||
|
||||
override fun handle(schema: Schema, context: Context) {
|
||||
context.fileSystem
|
||||
.listRecursively(context.outDirectory)
|
||||
.filter { it.name.endsWith("kt") }
|
||||
.forEach { path: Path ->
|
||||
val readInput = ByteArray(CHECK_FUNCTION.size)
|
||||
context.fileSystem.openReadWrite(path, mustCreate = false, mustExist = true).use {
|
||||
var fileOffset = 0L
|
||||
|
||||
var read = it.read(fileOffset = fileOffset, array = readInput, arrayOffset = 0, byteCount = readInput.size)
|
||||
while (read >= 0) {
|
||||
if (readInput.contentEquals(CHECK_FUNCTION)) {
|
||||
it.write(fileOffset = fileOffset, array = REPLACEMENT, arrayOffset = 0, byteCount = REPLACEMENT.size)
|
||||
fileOffset += REPLACEMENT.size
|
||||
} else {
|
||||
fileOffset++
|
||||
}
|
||||
read = it.read(fileOffset = fileOffset, array = readInput, arrayOffset = 0, byteCount = readInput.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(extend: Extend, field: Field, context: Context): Path = throw UnsupportedOperationException()
|
||||
|
||||
override fun handle(service: Service, context: Context): List<Path> = throw UnsupportedOperationException()
|
||||
|
||||
override fun handle(type: Type, context: Context): Path = throw UnsupportedOperationException()
|
||||
}
|
||||
11
wire-handler/settings.gradle.kts
Normal file
11
wire-handler/settings.gradle.kts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/8.0.2/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = "wire-handler"
|
||||
include("lib")
|
||||
BIN
wire-handler/wire-handler-1.0.0.jar
Normal file
BIN
wire-handler/wire-handler-1.0.0.jar
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue