Add JSON module

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 08afa71d30
commit 5aa92fd600
  1. 2
      asm/build.gradle.kts
  2. 3
      asm/src/main/java/dev/openrs2/asm/AsmModule.kt
  3. 3
      conf/src/main/java/dev/openrs2/conf/ConfigProvider.kt
  4. 4
      deob-processor/src/main/java/dev/openrs2/deob/processor/NameMapProcessor.kt
  5. 1
      deob-util/build.gradle.kts
  6. 3
      deob-util/src/main/java/dev/openrs2/deob/util/map/NameMapProvider.kt
  7. 1
      deob/build.gradle.kts
  8. 3
      deob/src/main/java/dev/openrs2/deob/ProfileProvider.kt
  9. 27
      json/build.gradle.kts
  10. 8
      json/src/main/java/dev/openrs2/json/Json.kt
  11. 18
      json/src/main/java/dev/openrs2/json/JsonModule.kt
  12. 19
      json/src/main/java/dev/openrs2/json/ObjectMapperProvider.kt
  13. 1
      settings.gradle.kts
  14. 8
      yaml/src/main/java/dev/openrs2/yaml/Yaml.kt
  15. 1
      yaml/src/main/java/dev/openrs2/yaml/YamlModule.kt

@ -5,7 +5,7 @@ plugins {
dependencies {
api(project(":util"))
api(project(":yaml"))
api("com.fasterxml.jackson.core:jackson-databind:${Versions.jackson}")
api("com.google.inject:guice:${Versions.guice}")
api("org.ow2.asm:asm:${Versions.asm}")
api("org.ow2.asm:asm-commons:${Versions.asm}")

@ -3,12 +3,9 @@ package dev.openrs2.asm
import com.fasterxml.jackson.databind.Module
import com.google.inject.AbstractModule
import com.google.inject.multibindings.Multibinder
import dev.openrs2.yaml.YamlModule
public object AsmModule : AbstractModule() {
override fun configure() {
install(YamlModule)
Multibinder.newSetBinder(binder(), Module::class.java)
.addBinding().to(AsmJacksonModule::class.java)
}

@ -1,12 +1,13 @@
package dev.openrs2.conf
import com.fasterxml.jackson.databind.ObjectMapper
import dev.openrs2.yaml.Yaml
import java.nio.file.Files
import java.nio.file.Paths
import javax.inject.Inject
import javax.inject.Provider
public class ConfigProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<Config> {
public class ConfigProvider @Inject constructor(@Yaml private val mapper: ObjectMapper) : Provider<Config> {
override fun get(): Config {
if (Files.notExists(CONFIG_PATH)) {
Files.copy(EXAMPLE_CONFIG_PATH, CONFIG_PATH)

@ -2,6 +2,7 @@ package dev.openrs2.deob.processor
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.Guice
import com.google.inject.Key
import com.sun.source.util.Trees
import dev.openrs2.asm.MemberRef
import dev.openrs2.asm.toInternalClassName
@ -12,6 +13,7 @@ import dev.openrs2.deob.util.map.Field
import dev.openrs2.deob.util.map.Method
import dev.openrs2.deob.util.map.NameMap
import dev.openrs2.util.io.useAtomicBufferedWriter
import dev.openrs2.yaml.Yaml
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
@ -45,7 +47,7 @@ public class NameMapProcessor : AbstractProcessor() {
init {
val injector = Guice.createInjector(DeobfuscatorProcessorModule)
mapper = injector.getInstance(ObjectMapper::class.java)
mapper = injector.getInstance(Key.get(ObjectMapper::class.java, Yaml::class.java))
}
override fun init(env: ProcessingEnvironment) {

@ -5,6 +5,7 @@ plugins {
dependencies {
api(project(":asm"))
api(project(":yaml"))
}
publishing {

@ -1,13 +1,14 @@
package dev.openrs2.deob.util.map
import com.fasterxml.jackson.databind.ObjectMapper
import dev.openrs2.yaml.Yaml
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import javax.inject.Inject
import javax.inject.Provider
public class NameMapProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<NameMap> {
public class NameMapProvider @Inject constructor(@Yaml private val mapper: ObjectMapper) : Provider<NameMap> {
override fun get(): NameMap {
val combinedMap = NameMap()

@ -14,6 +14,7 @@ dependencies {
implementation(project(":bundler"))
implementation(project(":deob-annotations"))
implementation(project(":deob-util"))
implementation(project(":yaml"))
implementation("com.google.guava:guava:${Versions.guava}")
implementation("it.unimi.dsi:fastutil:${Versions.fastutil}")
implementation("org.jgrapht:jgrapht-core:${Versions.jgrapht}")

@ -1,12 +1,13 @@
package dev.openrs2.deob
import com.fasterxml.jackson.databind.ObjectMapper
import dev.openrs2.yaml.Yaml
import java.nio.file.Files
import java.nio.file.Paths
import javax.inject.Inject
import javax.inject.Provider
public class ProfileProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<Profile> {
public class ProfileProvider @Inject constructor(@Yaml private val mapper: ObjectMapper) : Provider<Profile> {
override fun get(): Profile {
return Files.newBufferedReader(PATH).use { reader ->
mapper.readValue(reader, Profile::class.java)

@ -0,0 +1,27 @@
plugins {
`maven-publish`
kotlin("jvm")
}
dependencies {
api("com.fasterxml.jackson.core:jackson-databind:${Versions.jackson}")
api("com.google.inject:guice:${Versions.guice}")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}")
}
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
pom {
packaging = "jar"
name.set("OpenRS2 JSON")
description.set(
"""
Guava module for creating a JSON ObjectMapper.
""".trimIndent()
)
}
}
}

@ -0,0 +1,8 @@
package dev.openrs2.json
import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
public annotation class Json

@ -0,0 +1,18 @@
package dev.openrs2.json
import com.fasterxml.jackson.databind.Module
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.inject.AbstractModule
import com.google.inject.Scopes
import com.google.inject.multibindings.Multibinder
public object JsonModule : AbstractModule() {
override fun configure() {
Multibinder.newSetBinder(binder(), Module::class.java)
bind(ObjectMapper::class.java)
.annotatedWith(Json::class.java)
.toProvider(ObjectMapperProvider::class.java)
.`in`(Scopes.SINGLETON)
}
}

@ -0,0 +1,19 @@
package dev.openrs2.json
import com.fasterxml.jackson.databind.Module
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.PropertyNamingStrategy
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import javax.inject.Inject
import javax.inject.Provider
public class ObjectMapperProvider @Inject constructor(
private val modules: Set<@JvmSuppressWildcards Module>
) : Provider<ObjectMapper> {
override fun get(): ObjectMapper {
return ObjectMapper()
.registerKotlinModule()
.registerModules(modules)
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
}
}

@ -19,6 +19,7 @@ include(
"deob-processor",
"deob-util",
"game",
"json",
"nonfree",
"nonfree:client",
"nonfree:gl",

@ -0,0 +1,8 @@
package dev.openrs2.yaml
import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION)
public annotation class Yaml

@ -11,6 +11,7 @@ public object YamlModule : AbstractModule() {
Multibinder.newSetBinder(binder(), Module::class.java)
bind(ObjectMapper::class.java)
.annotatedWith(Yaml::class.java)
.toProvider(ObjectMapperProvider::class.java)
.`in`(Scopes.SINGLETON)
}

Loading…
Cancel
Save