From 7af2cf24d8788f2c1da09f925adb7521fa274267 Mon Sep 17 00:00:00 2001 From: jaysonminard Date: Wed, 16 Sep 2015 13:14:38 -0300 Subject: [PATCH] Kotlin M13 updates Release 0.5.0 --- CHANGELOG.md | 12 ++ README.md | 10 +- .../uy/klutter/aws/s3/AmazonS3Client_Ext.kt | 6 +- build.gradle | 3 + config-typesafe-jdk6/build.gradle | 3 + .../klutter/config/typesafe/InjektConfig.kt | 115 ++++++++++++++++++ .../config/typesafe/TestConfigLoading.kt | 8 +- .../config/typesafe/TestInjektConfig.kt | 77 ++++++++++++ config-typesafe-jdk7/build.gradle | 2 + .../typesafe/jdk7/TypesafeConfig_Jdk7_Ext.kt | 20 +-- config-typesafe-jdk8/build.gradle | 2 + .../kotlin/uy/klutter/core/jdk/Strings.kt | 4 +- .../kotlin/uy/klutter/core/uri/UriBuilder.kt | 2 +- .../kotlin/uy/klutter/core/uri/UrlEncoding.kt | 2 +- .../uy/klutter/core/uri/TestUriBuilder.kt | 3 +- .../kotlin/uy/klutter/elasticsearch/Client.kt | 8 +- .../uy/klutter/elasticsearch/Exceptions.kt | 2 - .../uy/klutter/elasticsearch/Indexing.kt | 1 - .../uy/klutter/elasticsearch/Kovenant.kt | 1 - gradle.properties | 16 ++- json-jackson-jdk6/build.gradle | 2 +- json-jackson-jdk8/build.gradle | 2 +- .../uy/klutter/graph/netflix/NetflixGraph.kt | 6 +- .../graph/netflix/internal/Building.kt | 2 +- .../klutter/graph/netflix/internal/Common.kt | 12 +- .../klutter/graph/netflix/TestNetflixGraph.kt | 7 +- .../klutter/vertx/KovenantVertxDispatcher.kt | 12 +- .../src/main/kotlin/uy/klutter/vertx/Vertx.kt | 8 +- .../main/kotlin/uy/klutter/vertx/VertxJson.kt | 16 +-- .../klutter/vertx/tests/TestVertxHelpers.kt | 26 ++++ 30 files changed, 316 insertions(+), 74 deletions(-) create mode 100644 config-typesafe-jdk6/src/main/kotlin/uy/klutter/config/typesafe/InjektConfig.kt create mode 100644 config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestInjektConfig.kt create mode 100644 vertx3-jdk8/src/test/kotlin/uy/klutter/vertx/tests/TestVertxHelpers.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index df83689..9e9799b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +========================================================= +2015-09-14 v0.5.0 release +========================================================= + +Kotlin M13 support, updated to Kovenant 2.5.0, Jackson 2.6.2, Injekt 1.5.0, ElasticSearch 1.7.2 + +========================================================= +2015-09-14 v0.4.0 release +========================================================= + +Added ElasticSearch helpers, integration with Kovenant promises in klutter/elasticsearch module, see module docs for more information + ========================================================= 2015-08-31 v0.3.0 release ========================================================= diff --git a/README.md b/README.md index 3f13c22..15f84cf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Kotlin M12](https://img.shields.io/badge/Kotlin-M12%20%40%200.12.1230-blue.svg)](http://kotlinlang.org) [![Maven Version](https://img.shields.io/maven-central/v/uy.klutter/klutter-all-jdk8.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22uy.klutter%22) [![CircleCI branch](https://img.shields.io/circleci/project/klutter/klutter/master.svg)](https://circleci.com/gh/klutter/klutter/tree/master) [![Issues](https://img.shields.io/github/issues/klutter/klutter.svg)](https://github.com/klutter/klutter/issues?q=is%3Aopen) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/klutter/klutter/blob/master/LICENSE) +[![Kotlin M13](https://img.shields.io/badge/Kotlin-M12%20%40%200.13.1513-blue.svg)](http://kotlinlang.org) [![Maven Version](https://img.shields.io/maven-central/v/uy.klutter/klutter-all-jdk8.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22uy.klutter%22) [![CircleCI branch](https://img.shields.io/circleci/project/klutter/klutter/master.svg)](https://circleci.com/gh/klutter/klutter/tree/master) [![Issues](https://img.shields.io/github/issues/klutter/klutter.svg)](https://github.com/klutter/klutter/issues?q=is%3Aopen) [![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/klutter/klutter/blob/master/LICENSE) # klutter Random small libraries, usually extensions making other libraries happier. @@ -10,8 +10,8 @@ rights for the code to be used in Klutter. Each module has its own set of dependencies. There is a main dependency which is always the most current JDK version of the module, and also a version suffixed by the JDK version for which it is compatible (that version or newer). -Include the dependency in your Gradle / Maven projects, ones that already have Kotlin configured for Kotlin M12 versions -`0.12.1218` or `0.12.1230` +Include the dependency in your Gradle / Maven projects, ones that already have Kotlin configured for Kotlin M13 versions +`0.13.1513` For example, for the whole package (one of `klutter-all` (lastest JDK), `klutter-all-jdk6`, `klutter-all-jdk7`, or `klutter-all-jdk8`) and using an open-ended dependency number while Klutter is in early active development: @@ -19,7 +19,7 @@ open-ended dependency number while Klutter is in early active development: **Gradle:** ``` -compile "uy.klutter:klutter-all:0.4.+" +compile "uy.klutter:klutter-all:0.5.+" ``` **Maven:** @@ -27,7 +27,7 @@ compile "uy.klutter:klutter-all:0.4.+" uy.klutter klutter-all - [0.4.0,0.5.0) + [0.5.0,0.6.0) ``` diff --git a/aws-s3-jdk6/src/main/kotlin/uy/klutter/aws/s3/AmazonS3Client_Ext.kt b/aws-s3-jdk6/src/main/kotlin/uy/klutter/aws/s3/AmazonS3Client_Ext.kt index 4765ca4..de44a9b 100644 --- a/aws-s3-jdk6/src/main/kotlin/uy/klutter/aws/s3/AmazonS3Client_Ext.kt +++ b/aws-s3-jdk6/src/main/kotlin/uy/klutter/aws/s3/AmazonS3Client_Ext.kt @@ -6,11 +6,11 @@ import com.amazonaws.services.s3.model.ObjectMetadata import org.apache.http.HttpStatus import uy.klutter.aws.defaultSafeCredentialsProviderChain -fun AmazonS3Client.exists(bucket: String, key: String): Boolean { +public fun AmazonS3Client.exists(bucket: String, key: String): Boolean { return ifExistsReturnMetadata(bucket, key) != null } -fun AmazonS3Client.ifExistsReturnMetadata(bucket: String, key: String): ObjectMetadata? { +public fun AmazonS3Client.ifExistsReturnMetadata(bucket: String, key: String): ObjectMetadata? { try { val metadata = getObjectMetadata(bucket, key) return metadata @@ -23,7 +23,7 @@ fun AmazonS3Client.ifExistsReturnMetadata(bucket: String, key: String): ObjectMe } -fun AmazonS3Client.ifExistsReturnUserMetadata(bucket: String, key: String): Map? { +public fun AmazonS3Client.ifExistsReturnUserMetadata(bucket: String, key: String): Map? { return ifExistsReturnMetadata(bucket, key)?.getUserMetadata() } diff --git a/build.gradle b/build.gradle index 60357fe..67cf56c 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,9 @@ subprojects { repositories { mavenCentral() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots' + } } dependencies { diff --git a/config-typesafe-jdk6/build.gradle b/config-typesafe-jdk6/build.gradle index 3cf34c8..43c5c09 100644 --- a/config-typesafe-jdk6/build.gradle +++ b/config-typesafe-jdk6/build.gradle @@ -1,3 +1,6 @@ dependencies { compile "com.typesafe:config:$version_typesafe_config" + compile "uy.kohesive.injekt:injekt-core:$version_kohesive_injekt" + + compile relativeProject(":klutter-json-jackson-jdk6") } \ No newline at end of file diff --git a/config-typesafe-jdk6/src/main/kotlin/uy/klutter/config/typesafe/InjektConfig.kt b/config-typesafe-jdk6/src/main/kotlin/uy/klutter/config/typesafe/InjektConfig.kt new file mode 100644 index 0000000..0fc0616 --- /dev/null +++ b/config-typesafe-jdk6/src/main/kotlin/uy/klutter/config/typesafe/InjektConfig.kt @@ -0,0 +1,115 @@ +package uy.klutter.config.typesafe + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.type.TypeFactory +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.typesafe.config.Config +import com.typesafe.config.ConfigRenderOptions +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.* +import kotlin.properties.Delegates + +/** + * A class that startups up an system using Injekt + TypesafeConfig, using the default global scope, and default object binder + */ +public abstract class KonfigAndInjektMain() : KonfigAndInjektScopedMain(Injekt) + +/** + * A startup module that registers and uses singletons/object factories from a specific scope, + * and an ObjectMapper to bind configuration properties into class instances. + */ +public abstract class KonfigAndInjektScopedMain(public val scope: InjektScope, public val mapper: ObjectMapper = jacksonObjectMapper()) : InjektModule, KonfigModule { + private val ADDON_ID = "Konfigure" + + protected var resolvedConfig: Config by Delegates.notNull() + + abstract fun configFactory(): Config + + private inner class ScopedKonfigRegistrar(val path: List, val scope: InjektScope) : KonfigRegistrar, InjektRegistrar by scope { + override fun importModule(atPath: String, module: KonfigModule) { + module.registerWith(ScopedKonfigRegistrar(path + atPath.split('.'), scope)) + } + + override fun bindClassAtConfigRoot(klass: TypeReference) { + val fullpath = path.filter { it.isNotBlank() }.map { it.removePrefix(".").removeSuffix(".") }.joinToString(".") + loadAndInject(resolvedConfig, fullpath, klass) + } + + override fun bindClassAtConfigPath(configPath: String, klass: TypeReference) { + val fullpath = (path + configPath.split('.')).filter { it.isNotBlank() }.map { it.removePrefix(".").removeSuffix(".") }.joinToString(".") + loadAndInject(resolvedConfig, fullpath, klass) + } + + @Suppress("UNCHECKED_CAST") + fun loadAndInject(config: Config, fullPath: String, klass: TypeReference) { + val configAtPath = config.getConfig(fullPath) + val asJson = configAtPath.root().render(ConfigRenderOptions.concise().setJson(true)) + val instance: T = mapper.readValue(asJson, TypeFactory.defaultInstance().constructType(klass.type))!! + scope.registrar.addSingleton(klass, instance) + } + } + + init { + resolvedConfig = configFactory() + val registrar = ScopedKonfigRegistrar(emptyList(), scope) + registrar.registerConfigurables() + scope.registrar.registerInjectables() + } +} + +public interface KonfigRegistrar : InjektRegistrar { + /** + * import a module loading it and any submodules immediately + */ + fun importModule(atPath: String, module: KonfigModule) + + /** + * bind a class bindings its values from a configuration path immediately + */ + final inline fun bindClassAtConfigPath(configPath: String) { + bindClassAtConfigPath(configPath, fullType()) + } + + /** + * bind a class bindings its values from a configuration path immediately + */ + fun bindClassAtConfigPath(configPath: String, klass: TypeReference) + + /** + * bind a class bindings its values from a configuration path immediately + */ + final inline fun bindClassAtConfigPath(configPath: String, klass: Class) { + bindClassAtConfigPath(configPath, fullType()) + } + + /** + * bind a class bindings its values from the root of the current configuration path immediately + */ + final inline fun bindClassAtConfigRoot() { + bindClassAtConfigRoot(fullType()) + } + + /** + * bind a class bindings its values from the root of the current configuration path immediately + */ + fun bindClassAtConfigRoot(klass: TypeReference) + + /** + * bind a class bindings its values from the root of the current configuration path immediately + */ + final inline fun bindClassAtConfigRoot(klass: Class) { + bindClassAtConfigRoot(fullType()) + } +} + +/** + * A package of configuration bound items that can be included into a scope of someone else + */ +public interface KonfigModule { + final internal fun registerWith(intoModule: KonfigRegistrar) { + intoModule.registerConfigurables() + } + + fun KonfigRegistrar.registerConfigurables() +} + diff --git a/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestConfigLoading.kt b/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestConfigLoading.kt index e72a99e..683e385 100644 --- a/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestConfigLoading.kt +++ b/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestConfigLoading.kt @@ -1,21 +1,21 @@ -package uy.klutter.config.typesafe +package uy.klutter.config.typesafe.tests import com.typesafe.config.ConfigFactory import org.junit.AfterClass import org.junit.Before import org.junit.BeforeClass import org.junit.Test -import kotlin.platform.platformStatic +import uy.klutter.config.typesafe.* import kotlin.test.assertEquals public class TestConfigLoading { companion object { - @BeforeClass @platformStatic public fun setupSystemProps() { + @BeforeClass @JvmStatic public fun setupSystemProps() { System.setProperty("systemKey", "value System") System.setProperty("base.value4", "four-sys") } - @AfterClass @platformStatic public fun removeSystemProps() { + @AfterClass @JvmStatic public fun removeSystemProps() { System.clearProperty("base.value4") System.clearProperty("systemKey") ConfigFactory.invalidateCaches() diff --git a/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestInjektConfig.kt b/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestInjektConfig.kt new file mode 100644 index 0000000..babaf4e --- /dev/null +++ b/config-typesafe-jdk6/src/test/kotlin/uy/klutter/config/typesafe/TestInjektConfig.kt @@ -0,0 +1,77 @@ +package uy.klutter.config.typesafe.tests + +import com.typesafe.config.Config +import org.junit.Test +import uy.klutter.config.typesafe.* +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.InjektModule +import uy.kohesive.injekt.api.InjektRegistrar +import kotlin.test.assertEquals + +class TestTypesafeConfigInjection { + companion object : KonfigAndInjektMain() { + override fun configFactory(): Config { + return loadConfig(MapAsConfig(kotlin.mapOf( + "http" to kotlin.mapOf("httpPort" to 8080, "workerThreads" to 16), + "data" to kotlin.mapOf("bucket" to "com.test.bucket", "region" to "us-east"), + "other" to kotlin.mapOf("name" to "frisbee")))) + } + + override fun KonfigRegistrar.registerConfigurables() { + bindClassAtConfigPath("http") + bindClassAtConfigPath("data") + importModule("other", OtherModule) + } + + override fun InjektRegistrar.registerInjectables() { + addFactory { ConfiguredThing() } + importModule(OtherModule) + } + + } + + @Test public fun testConfigSingletonsExist() { + val matchHttp = HttpConfig(8080,16) + val matchData = DataConfig("com.test.bucket", "us-east") + + assertEquals(matchHttp, Injekt.get()) + assertEquals(matchData, Injekt.get()) + } + + @Test public fun testFactoryUsingConfigWorks() { + val matchHttp = HttpConfig(8080,16) + val matchData = DataConfig("com.test.bucket", "us-east") + + val thing = Injekt.get() + assertEquals(matchHttp, thing.httpCfg) + assertEquals(matchData, thing.dataCfg) + } + + @Test public fun testWithModules() { + val thing = Injekt.get() + assertEquals("frisbee", thing.cfg.name) + } + + + data class HttpConfig(val httpPort: Int, val workerThreads: Int) + data class DataConfig(val bucket: String, val region: String) + data class ConfiguredThing(val httpCfg: HttpConfig = Injekt.get(), val dataCfg: DataConfig = Injekt.get()) +} + + +data class OtherConfig(val name: String) +data class OtherThingWantingConfig(val cfg: OtherConfig = Injekt.get()) + +public object OtherModule : KonfigModule, InjektModule { + override fun KonfigRegistrar.registerConfigurables() { + bindClassAtConfigRoot() + } + + override fun InjektRegistrar.registerInjectables() { + addFactory { OtherThingWantingConfig() } + } +} + + + + diff --git a/config-typesafe-jdk7/build.gradle b/config-typesafe-jdk7/build.gradle index 1d054ba..edfbde7 100644 --- a/config-typesafe-jdk7/build.gradle +++ b/config-typesafe-jdk7/build.gradle @@ -1,4 +1,6 @@ dependencies { compile relativeProject(":klutter-config-typesafe-jdk6") compile "com.typesafe:config:$version_typesafe_config" + + compile relativeProject(":klutter-json-jackson-jdk6") } \ No newline at end of file diff --git a/config-typesafe-jdk7/src/main/kotlin/uy/klutter/config/typesafe/jdk7/TypesafeConfig_Jdk7_Ext.kt b/config-typesafe-jdk7/src/main/kotlin/uy/klutter/config/typesafe/jdk7/TypesafeConfig_Jdk7_Ext.kt index 3a66c12..ac931b1 100644 --- a/config-typesafe-jdk7/src/main/kotlin/uy/klutter/config/typesafe/jdk7/TypesafeConfig_Jdk7_Ext.kt +++ b/config-typesafe-jdk7/src/main/kotlin/uy/klutter/config/typesafe/jdk7/TypesafeConfig_Jdk7_Ext.kt @@ -4,16 +4,16 @@ import uy.klutter.config.typesafe.ConfiguredValue import java.nio.file.Path import java.nio.file.Paths -fun ConfiguredValue.asPath(): Path = Paths.get(cfg.getString(key).trim()).toAbsolutePath() -fun ConfiguredValue.asPathOrNull(): Path? = if (exists()) asPath() else null +public fun ConfiguredValue.asPath(): Path = Paths.get(cfg.getString(key).trim()).toAbsolutePath() +public fun ConfiguredValue.asPathOrNull(): Path? = if (exists()) asPath() else null -fun ConfiguredValue.asPathRelative(relativeTo: Path): Path = relativeTo.resolve(cfg.getString(key).trim()).toAbsolutePath() -fun ConfiguredValue.asPathRelativeOrNull(relativeTo: Path): Path? = if (exists()) asPathRelative(relativeTo) else null +public fun ConfiguredValue.asPathRelative(relativeTo: Path): Path = relativeTo.resolve(cfg.getString(key).trim()).toAbsolutePath() +public fun ConfiguredValue.asPathRelativeOrNull(relativeTo: Path): Path? = if (exists()) asPathRelative(relativeTo) else null -fun ConfiguredValue.asPathSibling(relativeTo: Path): Path = relativeTo.resolveSibling(cfg.getString(key).trim()).toAbsolutePath() -fun ConfiguredValue.asPathSiblingOrNull(relativeTo: Path): Path? = if (exists()) asPathSibling(relativeTo) else null +public fun ConfiguredValue.asPathSibling(relativeTo: Path): Path = relativeTo.resolveSibling(cfg.getString(key).trim()).toAbsolutePath() +public fun ConfiguredValue.asPathSiblingOrNull(relativeTo: Path): Path? = if (exists()) asPathSibling(relativeTo) else null -fun ConfiguredValue.asPathList(): List = cfg.getStringList(key).map { Paths.get(it).toAbsolutePath() } -fun ConfiguredValue.asPathList(defaultValue: List): List = if (exists()) asPathList() else defaultValue -fun ConfiguredValue.asPathListOrNull(): List? = if (exists()) asPathList() else null -fun ConfiguredValue.asPathListOrEmpty(): List = asPathList(emptyList()) \ No newline at end of file +public fun ConfiguredValue.asPathList(): List = cfg.getStringList(key).map { Paths.get(it).toAbsolutePath() } +public fun ConfiguredValue.asPathList(defaultValue: List): List = if (exists()) asPathList() else defaultValue +public fun ConfiguredValue.asPathListOrNull(): List? = if (exists()) asPathList() else null +public fun ConfiguredValue.asPathListOrEmpty(): List = asPathList(emptyList()) \ No newline at end of file diff --git a/config-typesafe-jdk8/build.gradle b/config-typesafe-jdk8/build.gradle index 8150d27..adb78ef 100644 --- a/config-typesafe-jdk8/build.gradle +++ b/config-typesafe-jdk8/build.gradle @@ -1,5 +1,7 @@ dependencies { compile relativeProject(':klutter-config-typesafe-jdk6') compile relativeProject(':klutter-config-typesafe-jdk7') + compile relativeProject(":klutter-json-jackson-jdk8") + compile "com.typesafe:config:$version_typesafe_config_jdk8" } \ No newline at end of file diff --git a/core-jdk6/src/main/kotlin/uy/klutter/core/jdk/Strings.kt b/core-jdk6/src/main/kotlin/uy/klutter/core/jdk/Strings.kt index e599ebf..1d6e994 100644 --- a/core-jdk6/src/main/kotlin/uy/klutter/core/jdk/Strings.kt +++ b/core-jdk6/src/main/kotlin/uy/klutter/core/jdk/Strings.kt @@ -77,7 +77,7 @@ public fun String.mustEndWith(postfix: Char): String { } } -inline public fun String.whenStartsWith(prefix: String, thenWithRest: (String)->Unit): Boolean { +public inline fun String.whenStartsWith(prefix: String, thenWithRest: (String)->Unit): Boolean { if (this.startsWith(prefix)) { thenWithRest(this.exceptStarting(prefix.length())) return true @@ -86,7 +86,7 @@ inline public fun String.whenStartsWith(prefix: String, thenWithRest: (String)-> } -inline public fun String.whenStartsWith(prefixes: List, thenWithRest: (String)->Unit): Boolean { +public inline fun String.whenStartsWith(prefixes: List, thenWithRest: (String)->Unit): Boolean { prefixes.forEach { prefix -> if (this.startsWith(prefix)) { thenWithRest(this.exceptStarting(prefix.length())) diff --git a/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UriBuilder.kt b/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UriBuilder.kt index 9563982..815bc31 100644 --- a/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UriBuilder.kt +++ b/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UriBuilder.kt @@ -59,7 +59,7 @@ public interface ImmutableUri { fun fragmentAsDecodedQueryDeduped(): Map? = if (encodedFragment == null) null else UrlEncoding.decodeQueryToMap(encodedFragment!!) } -class UriBuilder(scheme: String? = null, encodedUserInfo: String? = null, host: String? = null, port: Int? = null, encodedPath: String? = null, encodedQuery: String? = null, encodedFragment: String? = null): ImmutableUri { +public class UriBuilder(scheme: String? = null, encodedUserInfo: String? = null, host: String? = null, port: Int? = null, encodedPath: String? = null, encodedQuery: String? = null, encodedFragment: String? = null): ImmutableUri { override var scheme: String? = scheme override var host: String? = host override var port: Int? = port diff --git a/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UrlEncoding.kt b/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UrlEncoding.kt index 2c057f2..4be8049 100644 --- a/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UrlEncoding.kt +++ b/core-jdk6/src/main/kotlin/uy/klutter/core/uri/UrlEncoding.kt @@ -309,7 +309,7 @@ public object UrlEncoding { var state: ParseState = ParseState.sText var i = 0 var code = 0 - val c: Char + var c: Char var pos = 0 var ofs = 0 var buf: ByteArray? = null diff --git a/core-jdk6/src/test/kotlin/uy/klutter/core/uri/TestUriBuilder.kt b/core-jdk6/src/test/kotlin/uy/klutter/core/uri/TestUriBuilder.kt index 8c821ba..7da8fef 100644 --- a/core-jdk6/src/test/kotlin/uy/klutter/core/uri/TestUriBuilder.kt +++ b/core-jdk6/src/test/kotlin/uy/klutter/core/uri/TestUriBuilder.kt @@ -1,6 +1,7 @@ -package uy.klutter.core.uri +package uy.klutter.core.uri.tests import org.junit.Test +import uy.klutter.core.uri.buildUri import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNull diff --git a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Client.kt b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Client.kt index d7a399a..35fba04 100644 --- a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Client.kt +++ b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Client.kt @@ -25,11 +25,11 @@ import uy.klutter.core.common.with import java.nio.file.Path public object EsConfig { - public volatile var adminActionTimeoutInSeconds: Long = 30 - public volatile var indexReplicaCount: Int = 1 - public volatile var indexShardCount: Int = 4 + public @Volatile var adminActionTimeoutInSeconds: Long = 30 + public @Volatile var indexReplicaCount: Int = 1 + public @Volatile var indexShardCount: Int = 4 - public volatile var objectMapper: ObjectMapper = jacksonObjectMapper() + public @Volatile var objectMapper: ObjectMapper = jacksonObjectMapper() } diff --git a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Exceptions.kt b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Exceptions.kt index a411633..ae5adf4 100644 --- a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Exceptions.kt +++ b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Exceptions.kt @@ -1,7 +1,5 @@ package uy.klutter.elasticsearch -import nl.komponents.kovenant.Deferred - public class WrappedThrowableException(cause: Throwable): Exception(cause.getMessage(), cause) public fun wrapThrowable(rawEx: Throwable): Exception = if (rawEx is Exception) rawEx else WrappedThrowableException(rawEx) diff --git a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Indexing.kt b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Indexing.kt index 6c7b05b..1dc106e 100644 --- a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Indexing.kt +++ b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Indexing.kt @@ -2,7 +2,6 @@ package uy.klutter.elasticsearch import org.elasticsearch.action.index.IndexRequestBuilder - public fun IndexRequestBuilder.setSourceFromObject(pojo: Any) { setSource(EsConfig.objectMapper.writeValueAsString(pojo)) } diff --git a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Kovenant.kt b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Kovenant.kt index fce7600..7cbc337 100644 --- a/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Kovenant.kt +++ b/elasticsearch-jdk7/src/main/kotlin/uy/klutter/elasticsearch/Kovenant.kt @@ -7,7 +7,6 @@ import org.elasticsearch.action.ActionListener import org.elasticsearch.action.ActionRequest import org.elasticsearch.action.ActionRequestBuilder import org.elasticsearch.action.ActionResponse -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse import org.elasticsearch.client.ElasticsearchClient public fun promiseResult(deferred: Deferred): ActionListener { diff --git a/gradle.properties b/gradle.properties index 5af6e87..74c4451 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,11 @@ -version=0.4.0 +version=0.5.0 group=uy.klutter version_gradle=2.5 -version_kotlin=0.12.1230 +version_kotlin=0.13.1513 +version_dokka=0.1-SNAPSHOT -version_kohesive_injekt=1.4.1 +version_kohesive_injekt=1.5.0 version_junit=4.12 version_slf4j=1.7.12 @@ -12,7 +13,9 @@ version_logback=1.1.3 version_aws_sdk=1.10.11 -version_jackson=2.6.1 + +version_jackson_kotlin=2.6.2 +version_jackson=2.6.2 version_jodatime=2.8.2 @@ -21,8 +24,9 @@ version_typesafe_config=1.2.1 version_typesafe_config_jdk8=1.3.0 version_vertx=3.0.0 -version_kovenant=2.3.3 + +version_kovenant=2.5.0 version_netflix_graph=1.5.2 -version_elasticsearch=1.6.0 \ No newline at end of file +version_elasticsearch=1.7.2 \ No newline at end of file diff --git a/json-jackson-jdk6/build.gradle b/json-jackson-jdk6/build.gradle index 0eb3639..5c034e3 100644 --- a/json-jackson-jdk6/build.gradle +++ b/json-jackson-jdk6/build.gradle @@ -1,4 +1,4 @@ dependencies { compile "uy.kohesive.injekt:injekt-core:${version_kohesive_injekt}" - compile "com.fasterxml.jackson.module:jackson-module-kotlin:$version_jackson" + compile "com.fasterxml.jackson.module:jackson-module-kotlin:$version_jackson_kotlin" } diff --git a/json-jackson-jdk8/build.gradle b/json-jackson-jdk8/build.gradle index 61e92d4..6204221 100644 --- a/json-jackson-jdk8/build.gradle +++ b/json-jackson-jdk8/build.gradle @@ -1,7 +1,7 @@ dependencies { compile "uy.kohesive.injekt:injekt-core:${version_kohesive_injekt}" - compile "com.fasterxml.jackson.module:jackson-module-kotlin:$version_jackson" + compile "com.fasterxml.jackson.module:jackson-module-kotlin:$version_jackson_kotlin" compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$version_jackson" compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$version_jackson" compile "com.fasterxml.jackson.module:jackson-module-parameter-names:$version_jackson" diff --git a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/NetflixGraph.kt b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/NetflixGraph.kt index bf3cf7e..60df290 100644 --- a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/NetflixGraph.kt +++ b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/NetflixGraph.kt @@ -5,7 +5,7 @@ import java.io.InputStream public inline fun , reified R : Enum> defineGraphSchema(defaultStructure: RelationStructure, init: GraphSchemaBuilder.() -> Unit): CompiledGraphSchema { - val schema = GraphSchemaBuilder(javaClass(), javaClass(), defaultStructure) + val schema = GraphSchemaBuilder(N::class.java, R::class.java, defaultStructure) schema.init() return CompiledGraphSchema(schema) } @@ -17,7 +17,7 @@ public fun , R : Enum> constructGraph(schema: CompiledGraphSchema } public inline fun , reified R : Enum> useGraph(inputStream: InputStream, run: ReadOnlyGraph.() -> Unit): ReadOnlyGraph { - val graph = ReadOnlyGraph(javaClass(), javaClass(), inputStream) + val graph = ReadOnlyGraph(N::class.java, R::class.java, inputStream) graph.run() return graph } @@ -40,7 +40,7 @@ public enum class RelationStructure(override val flags: Int) : GraphRelationOpti HASH(com.netflix.nfgraph.spec.NFPropertySpec.HASH) } -private interface GraphRelationOptions { +internal interface GraphRelationOptions { val flags: Int } diff --git a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Building.kt b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Building.kt index e40b381..1d15758 100644 --- a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Building.kt +++ b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Building.kt @@ -74,7 +74,7 @@ public class CompiledGraphSchema, R : Enum>(val schema: GraphSche val fullyQualify = groupMembers.size() > 1 groupMembers.forEach { trippleKey -> val relateName = if (fullyQualify) "${trippleKey.relationship.name()}.${trippleKey.toNode.name()}" else trippleKey.relationship.name() - propSpecs.add(NFPropertySpec(relateName, trippleKey.toNode.name(), relationshipFlags.get(trippleKey))) + propSpecs.add(NFPropertySpec(relateName, trippleKey.toNode.name(), relationshipFlags.get(trippleKey) ?: 0)) } } } diff --git a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Common.kt b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Common.kt index 1e09eda..56eab7b 100644 --- a/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Common.kt +++ b/netflix-graph-jdk6/src/main/kotlin/uy/klutter/graph/netflix/internal/Common.kt @@ -1,12 +1,12 @@ package uy.klutter.graph.netflix.internal -private data class RelationshipPairKey, R : Enum>(val fromNode: N, val relationship: R) -private data class RelationshipTrippleKey, R : Enum>(val fromNode: N, val relationship: R, val toNode: N) +internal data class RelationshipPairKey, R : Enum>(val fromNode: N, val relationship: R) +internal data class RelationshipTrippleKey, R : Enum>(val fromNode: N, val relationship: R, val toNode: N) -private val GRAPH_MARKERS_HEADER = "**KOTLIN-NFGRAPH**" -private val GRAPH_MARKERS_SCHEMA_HEADER = "**SCHEMA**" -private val GRAPH_MARKERS_ORDINAL_HEADER = "**ORDINALS**" -private val GRAPH_MARKERS_GRAPH_HEADER = "**GRAPH**" +internal val GRAPH_MARKERS_HEADER = "**KOTLIN-NFGRAPH**" +internal val GRAPH_MARKERS_SCHEMA_HEADER = "**SCHEMA**" +internal val GRAPH_MARKERS_ORDINAL_HEADER = "**ORDINALS**" +internal val GRAPH_MARKERS_GRAPH_HEADER = "**GRAPH**" diff --git a/netflix-graph-jdk6/src/test/kotlin/uy/klutter/graph/netflix/TestNetflixGraph.kt b/netflix-graph-jdk6/src/test/kotlin/uy/klutter/graph/netflix/TestNetflixGraph.kt index 26a8e54..9443281 100644 --- a/netflix-graph-jdk6/src/test/kotlin/uy/klutter/graph/netflix/TestNetflixGraph.kt +++ b/netflix-graph-jdk6/src/test/kotlin/uy/klutter/graph/netflix/TestNetflixGraph.kt @@ -1,12 +1,13 @@ -package uy.klutter.graph.netflix +package uy.klutter.graph.netflix.tests import org.junit.Test +import uy.klutter.graph.netflix.* import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import kotlin.test import kotlin.test.assertEquals -import uy.klutter.graph.netflix.MyNodes.* -import uy.klutter.graph.netflix.MyRelations.* +import uy.klutter.graph.netflix.tests.MyNodes.* +import uy.klutter.graph.netflix.tests.MyRelations.* enum class MyNodes { Movie, diff --git a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/KovenantVertxDispatcher.kt b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/KovenantVertxDispatcher.kt index 74832b5..2b89257 100644 --- a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/KovenantVertxDispatcher.kt +++ b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/KovenantVertxDispatcher.kt @@ -7,7 +7,7 @@ import nl.komponents.kovenant.DispatcherContext // -- connects the context of Kovenant promises to dispatch into Vert.x thread and context management. -class VertxKovenantContext(val originalContext: nl.komponents.kovenant.Context) : nl.komponents.kovenant.Context { +internal class VertxKovenantContext(val originalContext: nl.komponents.kovenant.Context) : nl.komponents.kovenant.Context { override val callbackContext: DispatcherContext get() { val currentVertxContext = vertxContext() @@ -31,7 +31,7 @@ class VertxKovenantContext(val originalContext: nl.komponents.kovenant.Context) get() = { curVal: Any, newVal: Any -> throw IllegalStateException("Value[$curVal] is set, can't override with new value[$newVal]") } } -class VertxCallbackDispatcherContext(private val ctx: Context) : DispatcherContext { +internal class VertxCallbackDispatcherContext(private val ctx: Context) : DispatcherContext { override val dispatcher: Dispatcher get() = VertxCallbackDispatcher(ctx) override val errorHandler: (Exception) -> Unit @@ -39,7 +39,7 @@ class VertxCallbackDispatcherContext(private val ctx: Context) : DispatcherConte } -class VertxCallbackDispatcher(private val ctx: Context) : BasicDispatcher() { +internal class VertxCallbackDispatcher(private val ctx: Context) : BasicDispatcher() { override fun offer(task: () -> Unit): Boolean { ctx.runOnContext { task() @@ -49,7 +49,7 @@ class VertxCallbackDispatcher(private val ctx: Context) : BasicDispatcher() { } -class VertxWorkerDispatcherContext(private val ctx: Context) : DispatcherContext { +internal class VertxWorkerDispatcherContext(private val ctx: Context) : DispatcherContext { override val dispatcher: Dispatcher get() = VertxWorkerDispatcher(ctx) override val errorHandler: (Exception) -> Unit @@ -57,7 +57,7 @@ class VertxWorkerDispatcherContext(private val ctx: Context) : DispatcherContext } -class VertxWorkerDispatcher(private val ctx: Context) : BasicDispatcher() { +internal class VertxWorkerDispatcher(private val ctx: Context) : BasicDispatcher() { override fun offer(task: () -> Unit): Boolean { ctx.owner().executeBlocking({ task() @@ -66,7 +66,7 @@ class VertxWorkerDispatcher(private val ctx: Context) : BasicDispatcher() { } } -abstract class BasicDispatcher : Dispatcher { +internal abstract class BasicDispatcher : Dispatcher { override fun stop(force: Boolean, timeOutMs: Long, block: Boolean): List<() -> Unit> = throw UnsupportedOperationException() override fun tryCancel(task: () -> Unit): Boolean = false override val terminated: Boolean diff --git a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/Vertx.kt b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/Vertx.kt index ec59a3f..5b1cc13 100644 --- a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/Vertx.kt +++ b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/Vertx.kt @@ -222,7 +222,7 @@ public fun Vertx.promiseClose(): Promise { * vertx dispatching are united, this is the same as doing async { ... } in Kovenant, no need to call on a * vertx instance. */ -public fun Vertx.promiseExecuteBlocking(blockingCode: () -> T): Promise { +public fun Vertx.promiseExecuteBlocking(blockingCode: () -> T): Promise { VertxInit.ensure() val deferred = deferred() @@ -241,7 +241,7 @@ public fun Vertx.promiseExecuteBlocking(blockingCode: () -> T): Promise Vertx.executeBlocking(blockingCode: () -> T): Promise { +public fun Vertx.executeBlocking(blockingCode: () -> T): Promise { VertxInit.ensure() val deferred = deferred() @@ -291,7 +291,7 @@ public object VertxInit { } - @suppress("NOTHING_TO_INLINE") + @Suppress("NOTHING_TO_INLINE") public inline fun ensure() { // TODO: here to be sure we have intiailized anything related before using, // although this function may remain empty it causes initializers on the @@ -309,7 +309,7 @@ public object VertxInit { * return deferred.promise * } */ -public fun promiseResult(deferred: Deferred): (AsyncResult) -> Unit { +public fun promiseResult(deferred: Deferred): (AsyncResult) -> Unit { return { completion -> if (completion.succeeded()) { deferred.resolve(completion.result()) diff --git a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/VertxJson.kt b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/VertxJson.kt index 8b89d9e..e4c7a95 100644 --- a/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/VertxJson.kt +++ b/vertx3-jdk8/src/main/kotlin/uy/klutter/vertx/VertxJson.kt @@ -7,29 +7,29 @@ import uy.klutter.core.jdk8.toIsoString import java.time.temporal.Temporal -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun jsonObjectFromString(json: String): JsonObject { return JsonObject(json) } -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun jsonArrayFromString(json: String): JsonArray { return JsonArray(json) } -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun jsonObjectFromMap(map: Map): JsonObject { return JsonObject(map) } -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun jsonArrayFromList(list: List): JsonArray { return JsonArray(list) } -@suppress("NOTHING_TO_INLINE", "UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN") +@Suppress("NOTHING_TO_INLINE", "UNCHECKED_CAST", "PLATFORM_CLASS_MAPPED_TO_KOTLIN") public inline fun jsonObjectFromPojo(something: Any): JsonObject { - return jsonObjectFromMap(Json.mapper.convertValue(something, javaClass>()) as Map) + return jsonObjectFromMap(Json.mapper.convertValue(something, java.util.Map::class.java) as Map) } public inline fun jsonObject(init: JsonObject.() -> Unit): JsonObject { @@ -64,10 +64,10 @@ public inline fun JsonArray.addArray(init: JsonArray.() -> Unit): JsonArray { return this } -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun JsonObject.putDateIsoString(name: String, value: Temporal): JsonObject = put(name, value.toIsoString()) -@suppress("NOTHING_TO_INLINE") +@Suppress("NOTHING_TO_INLINE") public inline fun JsonArray.addDateIsoString(value: Temporal): JsonArray = add(value.toIsoString()) diff --git a/vertx3-jdk8/src/test/kotlin/uy/klutter/vertx/tests/TestVertxHelpers.kt b/vertx3-jdk8/src/test/kotlin/uy/klutter/vertx/tests/TestVertxHelpers.kt new file mode 100644 index 0000000..289f0b5 --- /dev/null +++ b/vertx3-jdk8/src/test/kotlin/uy/klutter/vertx/tests/TestVertxHelpers.kt @@ -0,0 +1,26 @@ +package uy.klutter.vertx.tests + +import io.vertx.core.AbstractVerticle +import org.junit.Test +import uy.klutter.vertx.promiseClose +import uy.klutter.vertx.promiseDeployVerticle +import uy.klutter.vertx.promiseUndeploy +import uy.klutter.vertx.vertx + + +public class TestVertxHelpers { + @Test public fun testStartupAndDeployPromises() { + val _vertx = vertx().get() + val _deployment = _vertx.promiseDeployVerticle(TestVertxVerticle::class.java).get() + _vertx.promiseUndeploy(_deployment).get() + _vertx.promiseClose().get() + + } +} + +public class TestVertxVerticle : AbstractVerticle() { + override fun start() { + println("Started") + } + +} \ No newline at end of file