From: David ‘Bombe’ Roden Date: Sat, 2 Mar 2019 19:55:24 +0000 (+0100) Subject: ⬆️ Update Guice to 4.2.2 X-Git-Tag: v79^2~87 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=da8b893e6fc024b7d9f5ed1fc7632138dcd129e7;p=Sone.git ⬆️ Update Guice to 4.2.2 --- diff --git a/build.gradle b/build.gradle index 7e5604f..1cee731 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ dependencies { compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib' compile group: 'net.pterodactylus', name: 'utils', version: '0.12.4' - compile group: 'com.google.inject', name: 'guice', version: '3.0' + compile group: 'com.google.inject', name: 'guice', version: '4.2.2' compile group: 'com.google.guava', name: 'guava', version: '27.0.1-android' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.1' compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.9.1' diff --git a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt index a8da595..1253d0a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt @@ -6,6 +6,7 @@ import com.google.inject.Provides import freenet.client.HighLevelSimpleClient import freenet.node.Node import freenet.pluginmanager.PluginRespirator +import javax.inject.Provider import javax.inject.Singleton /** @@ -14,9 +15,9 @@ import javax.inject.Singleton class FreenetModule(private val pluginRespirator: PluginRespirator): Module { override fun configure(binder: Binder): Unit = binder.run { - bind(PluginRespirator::class.java).toProvider { pluginRespirator } - pluginRespirator.node!!.let { node -> bind(Node::class.java).toProvider { node } } - bind(HighLevelSimpleClient::class.java).toProvider { pluginRespirator.hlSimpleClient!! } + bind(PluginRespirator::class.java).toProvider(Provider { pluginRespirator }) + pluginRespirator.node!!.let { node -> bind(Node::class.java).toProvider(Provider { node }) } + bind(HighLevelSimpleClient::class.java).toProvider(Provider { pluginRespirator.hlSimpleClient!! }) } @Provides @Singleton diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt index f9119c3..360b0cd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt @@ -5,16 +5,16 @@ import com.google.inject.Module import javax.inject.Provider import kotlin.reflect.KClass -fun KClass.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider { instance } } +fun KClass.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider(Provider { instance }) } fun KClass.isProvidedBy(provider: com.google.inject.Provider) = Module { it.bind(this.java).toProvider(provider) } fun KClass.isProvidedBy(provider: KClass>) = Module { it.bind(this.java).toProvider(provider.java) } -inline fun KClass.isProvidedByMock() = Module { it.bind(this.java).toProvider { mock() } } +inline fun KClass.isProvidedByMock() = Module { it.bind(this.java).toProvider(Provider { mock() }) } inline fun Injector.getInstance() = getInstance(T::class.java)!! fun supply(javaClass: Class): Source = object : Source { override fun fromInstance(instance: T) = Module { it.bind(javaClass).toInstance(instance) } - override fun byInstance(instance: T) = Module { it.bind(javaClass).toProvider { instance } } + override fun byInstance(instance: T) = Module { it.bind(javaClass).toProvider(Provider { instance }) } override fun byProvider(provider: com.google.inject.Provider) = Module { it.bind(javaClass).toProvider(provider) } override fun byProvider(provider: Class>) = Module { it.bind(javaClass).toProvider(provider) } }