Skip to content

Commit 33ae57c

Browse files
committed
Prepare for MMP
1 parent 650c077 commit 33ae57c

28 files changed

+560
-465
lines changed

build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ tasks.test {
2626
repositories {
2727
jcenter()
2828
mavenCentral()
29+
mavenLocal()
2930
maven { url "https://maven.fabricmc.net" }
3031
maven { url "https://jitpack.io" }
3132
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
3233
maven { url "https://dl.bintray.com/kotlin/kotlin-dev/" }
3334
}
3435

3536
dependencies {
36-
compile("com.google.guava:guava:28.0-jre")
37-
compile("com.github.Chocohead:Tiny-Mappings-Parser:d96d4070293d9e7054693c21552eb1eb2b149679")
38-
compile("org.apache.commons:commons-lang3:3.9")
37+
compile("me.shedaniel:tiny-parser:1.0.0")
38+
// compile("com.github.Chocohead:Tiny-Mappings-Parser:d96d4070293d9e7054693c21552eb1eb2b149679")
3939
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0")
4040
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
4141
compile("org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC")
4242
compile("org.jetbrains.kotlin:kotlin-reflect:1.4.0")
43-
compile("io.fastjson:boon:0.34")
4443
compile("ch.qos.logback:logback-classic:1.2.3")
4544
compile("org.dom4j:dom4j:2.1.3")
4645
compile("net.fabricmc:stitch:0.5.1+build.77") {
@@ -49,6 +48,9 @@ dependencies {
4948

5049
testCompile("org.junit.jupiter:junit-jupiter:5.6.2")
5150
testCompile("org.jetbrains.kotlin:kotlin-test-junit5:1.4.0")
51+
52+
compile("com.soywiz.korlibs.korio:korio:$korlibs_version")
53+
compile("com.squareup.okio:okio-multiplatform:$okio_version")
5254
}
5355

5456
compileKotlin {

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
okio_version=2.9.0
2+
korlibs_version=2.0.0-rc2

gradle/wrapper/gradle-wrapper.jar

508 Bytes
Binary file not shown.
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Fri Jun 19 23:47:25 HKT 2020
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
31
distributionBase=GRADLE_USER_HOME
42
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
64
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85+
8586
# Determine the Java command to use to start the JVM.
8687
if [ -n "$JAVA_HOME" ] ; then
8788
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
129130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
132134
JAVACMD=`cygpath --unix "$JAVACMD"`
133135

134136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

+7-18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
3235
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
3336
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
3437

@@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
3740

3841
set JAVA_EXE=java.exe
3942
%JAVA_EXE% -version >NUL 2>&1
40-
if "%ERRORLEVEL%" == "0" goto init
43+
if "%ERRORLEVEL%" == "0" goto execute
4144

4245
echo.
4346
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -51,7 +54,7 @@ goto fail
5154
set JAVA_HOME=%JAVA_HOME:"=%
5255
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5356

54-
if exist "%JAVA_EXE%" goto init
57+
if exist "%JAVA_EXE%" goto execute
5558

5659
echo.
5760
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -61,28 +64,14 @@ echo location of your Java installation.
6164

6265
goto fail
6366

64-
:init
65-
@rem Get command-line arguments, handling Windows variants
66-
67-
if not "%OS%" == "Windows_NT" goto win9xME_args
68-
69-
:win9xME_args
70-
@rem Slurp the command line arguments.
71-
set CMD_LINE_ARGS=
72-
set _SKIP=2
73-
74-
:win9xME_args_slurp
75-
if "x%~1" == "x" goto execute
76-
77-
set CMD_LINE_ARGS=%*
78-
7967
:execute
8068
@rem Setup the command line
8169

8270
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
8371

72+
8473
@rem Execute Gradle
85-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
8675

8776
:end
8877
@rem End local scope for the variables with windows NT shell
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package me.shedaniel.linkie
22

3-
import java.io.File
4-
import java.time.Duration
3+
import com.soywiz.klock.TimeSpan
4+
import com.soywiz.klock.milliseconds
5+
import com.soywiz.korio.file.VfsFile
6+
import com.soywiz.korio.file.std.localCurrentDirVfs
7+
import me.shedaniel.linkie.utils.div
58

6-
data class LinkieConfig(
7-
val cacheDirectory: File,
9+
data class LinkieConfig constructor(
10+
val cacheDirectory: VfsFile,
811
val maximumLoadedVersions: Int,
912
val namespaces: Iterable<Namespace>,
10-
val reloadCycleDuration: Duration,
13+
val reloadCycleDuration: TimeSpan,
1114
) {
1215
companion object {
1316
@JvmStatic
1417
val DEFAULT = LinkieConfig(
15-
cacheDirectory = File(System.getProperty("user.dir"), ".linkie-cache"),
18+
cacheDirectory = (localCurrentDirVfs / ".linkie-cache").jail(),
1619
maximumLoadedVersions = 2,
1720
namespaces = listOf(),
18-
reloadCycleDuration = Duration.ofMillis(1800000)
21+
reloadCycleDuration = 1800000.milliseconds
1922
)
2023
}
2124
}

src/main/kotlin/me/shedaniel/linkie/MappingBuffers.kt

+42-64
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package me.shedaniel.linkie
22

3-
import org.boon.primitive.ByteBuf
4-
import org.boon.primitive.InputByteArray
5-
import java.io.ByteArrayInputStream
6-
import java.io.ByteArrayOutputStream
7-
import java.util.zip.GZIPInputStream
8-
import java.util.zip.GZIPOutputStream
3+
import okio.Buffer
4+
import okio.BufferedSink
5+
import okio.BufferedSource
6+
import kotlin.properties.Delegates
97

108
fun ByteBuffer.writeMappingsContainer(mappingsContainer: MappingsContainer) {
119
writeNotNullString(mappingsContainer.version)
@@ -155,73 +153,53 @@ fun ByteBuffer.readMagic(original: String): String? {
155153
}
156154
}
157155

158-
fun inputBuffer(capacity: Int = 2048): ByteBuffer = ByteBuffer(input = ByteBuf.create(capacity))
159-
fun outputBuffer(byteArray: ByteArray): ByteBuffer = ByteBuffer(output = InputByteArray(byteArray))
160-
fun outputCompressedBuffer(byteArray: ByteArray): ByteBuffer = outputBuffer(GZIPInputStream(ByteArrayInputStream(byteArray)).use { it.readBytes() })
156+
fun inputBuffer(): ByteBuffer = ByteBuffer(Buffer() as BufferedSink)
157+
fun outputBuffer(byteArray: ByteArray): ByteBuffer = ByteBuffer(Buffer() as BufferedSource).apply { writeByteArray(byteArray) }
158+
@JvmName("outputBuffer_")
159+
fun ByteArray.outputBuffer(): ByteBuffer = outputBuffer(this)
161160

162161
@OptIn(ExperimentalUnsignedTypes::class)
163162
@Suppress("unused")
164-
class ByteBuffer(private val input: ByteBuf? = null, private val output: InputByteArray? = null) {
165-
fun writeByte(byte: Byte) {
166-
input!!.add(byte)
167-
}
168-
169-
fun writeByteArray(array: ByteArray) {
170-
input!!.add(array)
171-
}
172-
173-
fun writeBoolean(boolean: Boolean) {
174-
input!!.writeBoolean(boolean)
175-
}
176-
177-
fun writeShort(short: Short) {
178-
input!!.add(short)
179-
}
180-
181-
fun writeUnsignedShort(short: UShort) {
182-
input!!.add(short.toShort())
183-
}
184-
185-
fun writeInt(int: Int) {
186-
input!!.add(int)
187-
}
188-
189-
fun writeLong(long: Long) {
190-
input!!.add(long)
191-
}
163+
class ByteBuffer {
164+
var source by Delegates.notNull<BufferedSource>()
165+
var sink by Delegates.notNull<BufferedSink>()
192166

193-
fun writeFloat(float: Float) {
194-
input!!.add(float)
167+
constructor(source: BufferedSource) {
168+
this.source = source
195169
}
196170

197-
fun writeDouble(double: Double) {
198-
input!!.add(double)
171+
constructor(sink: BufferedSink) {
172+
this.sink = sink
199173
}
200174

201-
fun writeChar(char: Char) {
202-
input!!.add(char)
203-
}
175+
fun writeByte(byte: Byte) = sink.writeByte(byte.toInt())
176+
fun writeByteArray(array: ByteArray) = sink.write(array)
177+
fun writeBoolean(boolean: Boolean) = sink.writeByte(if (boolean) 1 else 0)
178+
fun writeShort(short: Short) = sink.writeShort(short.toInt())
179+
fun writeUnsignedShort(short: UShort) = writeShort(short.toShort())
180+
fun writeInt(int: Int) = sink.writeInt(int)
181+
fun writeLong(long: Long) = sink.writeLong(long)
182+
fun writeFloat(float: Float) = writeInt(float.toBits())
183+
fun writeDouble(double: Double) = writeLong(double.toBits())
184+
fun writeChar(char: Char) = writeByte(char.toByte())
204185

205186
inline fun <T> writeCollection(collection: Collection<T>, crossinline writer: ByteBuffer.(T) -> Unit) {
206187
writeInt(collection.size)
207188
collection.forEach { writer(this, it) }
208189
}
209190

210-
fun toByteArray(): ByteArray = input!!.toBytes()
211-
fun toCompressedByteArray(): ByteArray = ByteArrayOutputStream().also { outputStream ->
212-
GZIPOutputStream(outputStream).use { it.write(toByteArray()) }
213-
}.toByteArray()
214-
215-
fun readByte(): Byte = output!!.readByte()
216-
fun readByteArray(length: Int): ByteArray = output!!.readBytes(length)
217-
fun readBoolean(): Boolean = output!!.readBoolean()
218-
fun readShort(): Short = output!!.readShort()
219-
fun readUnsignedShort(): UShort = output!!.readShort().toUShort()
220-
fun readInt(): Int = output!!.readInt()
221-
fun readLong(): Long = output!!.readLong()
222-
fun readFloat(): Float = output!!.readFloat()
223-
fun readDouble(): Double = output!!.readDouble()
224-
fun readChar(): Char = output!!.readChar()
191+
fun toByteArray(): ByteArray = source.readByteArray()
192+
193+
fun readByte(): Byte = source.readByte()
194+
fun readByteArray(length: Int): ByteArray = source.readByteArray(length.toLong())
195+
fun readBoolean(): Boolean = source.readByte().toInt() == 1
196+
fun readShort(): Short = source.readShort()
197+
fun readUnsignedShort(): UShort = source.readShort().toUShort()
198+
fun readInt(): Int = source.readInt()
199+
fun readLong(): Long = source.readLong()
200+
fun readFloat(): Float = Float.fromBits(source.readInt())
201+
fun readDouble(): Double = Double.fromBits(source.readLong())
202+
fun readChar(): Char = source.readByte().toChar()
225203

226204
inline fun <T> readCollection(crossinline reader: ByteBuffer.() -> T): List<T> {
227205
val size = readInt()
@@ -242,14 +220,14 @@ class ByteBuffer(private val input: ByteBuf? = null, private val output: InputBy
242220

243221
fun writeNotNullString(string: String) {
244222
writeUnsignedShort((string.length + 1).toUShort())
245-
writeByteArray(string.toByteArray())
223+
sink.writeUtf8(string)
246224
}
247225

248226
fun readStringOrNull(): String? {
249-
val length = readUnsignedShort().toInt()
250-
if (length == 0) return null
251-
return readByteArray(length - 1).toString(Charsets.UTF_8)
227+
val length = readUnsignedShort().toLong()
228+
if (length == 0L) return null
229+
return source.readUtf8(length - 1)
252230
}
253231

254232
fun readNotNullString(): String = readStringOrNull()!!
255-
}
233+
}

src/main/kotlin/me/shedaniel/linkie/Mappings.kt

+15-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package me.shedaniel.linkie
22

33
import kotlinx.serialization.Serializable
44
import me.shedaniel.linkie.MappingsContainer.MappingSource
5-
import me.shedaniel.linkie.utils.*
5+
import me.shedaniel.linkie.utils.info
6+
import me.shedaniel.linkie.utils.mapIntermediaryDescToNamed
7+
import me.shedaniel.linkie.utils.remapDescriptor
8+
import me.shedaniel.linkie.utils.singleSequenceOf
69

710
interface MappingsMetadata {
811
val version: String
@@ -26,8 +29,8 @@ data class MappingsContainer(
2629
override var mappingSource: MappingSource? = null,
2730
override var namespace: String = "",
2831
) : MappingsMetadata, me.shedaniel.linkie.namespaces.MappingsContainerBuilder {
29-
override fun build(version: String): MappingsContainer = this
30-
32+
override suspend fun build(version: String): MappingsContainer = this
33+
3134
fun toSimpleMappingsMetadata(): MappingsMetadata = SimpleMappingsMetadata(
3235
version = version,
3336
name = name,
@@ -126,22 +129,24 @@ fun Class.getFieldByObfName(obf: String): Field? {
126129
return null
127130
}
128131

129-
inline fun buildMappings(
132+
suspend inline fun buildMappings(
130133
version: String,
131134
name: String,
132135
fillFieldDesc: Boolean = true,
133136
fillMethodDesc: Boolean = true,
134137
expendIntermediaryToMapped: Boolean = false,
135-
crossinline builder: MappingsContainerBuilder.() -> Unit,
138+
crossinline builder: suspend MappingsBuilder.() -> Unit,
136139
): MappingsContainer =
137-
MappingsContainerBuilder(
140+
MappingsBuilder(
138141
fillFieldDesc,
139142
fillMethodDesc,
140143
expendIntermediaryToMapped,
141144
container = MappingsContainer(version, name = name)
142-
).also(builder).build()
145+
).also {
146+
builder(it)
147+
}.build()
143148

144-
class MappingsContainerBuilder(
149+
class MappingsBuilder(
145150
val fillFieldDesc: Boolean,
146151
val fillMethodDesc: Boolean,
147152
val expendIntermediaryToMapped: Boolean,
@@ -174,7 +179,7 @@ class MappingsContainerBuilder(
174179
container.mappingSource = mappingSource
175180
}
176181

177-
fun edit(operator: MappingsContainer.() -> Unit) {
182+
suspend fun edit(operator: suspend MappingsContainer.() -> Unit) {
178183
operator(container)
179184
}
180185

@@ -465,4 +470,4 @@ data class Obf(
465470

466471
fun isMerged(): Boolean = merged != null
467472
fun isEmpty(): Boolean = client == null && server == null && merged == null
468-
}
473+
}

0 commit comments

Comments
 (0)