Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetuska committed Oct 23, 2021
1 parent 3d843d4 commit 86e348a
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 107 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.1.2
## Build Versions
* JVM: 11
* Gradle: 7.2
* Kotlin: 1.5.31
## Changes
* Typesafe versions of `KON` and `KObject` to improve extensibility and allow restricting value types.

# v1.1.1
## Changes
* New safe array setter `"key".to[1]` that works with single int arrays
Expand Down
57 changes: 25 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,31 @@ gradleEnterprise {
}

kotlin {
sourceSets {
commonMain {
dependencies {
api(project(":lib:kon-core"))
}
}
}
val serializationTargets = setOf(
linuxX64(),
linuxArm64(),
linuxArm32Hfp(),
iosArm32(),
iosArm64(),
iosX64(),
iosSimulatorArm64(),
watchosArm32(),
watchosArm64(),
watchosX86(),
watchosX64(),
watchosSimulatorArm64(),
tvosArm64(),
tvosX64(),
tvosSimulatorArm64(),
macosX64(),
macosArm64(),
mingwX86(),
mingwX64(),
)

sourceSets { commonMain { dependencies { api(project(":lib:kon-core")) } } }
val serializationTargets =
setOf(
linuxX64(),
linuxArm64(),
linuxArm32Hfp(),
iosArm32(),
iosArm64(),
iosX64(),
iosSimulatorArm64(),
watchosArm32(),
watchosArm64(),
watchosX86(),
watchosX64(),
watchosSimulatorArm64(),
tvosArm64(),
tvosX64(),
tvosSimulatorArm64(),
macosX64(),
macosArm64(),
mingwX86(),
mingwX64(),
)

serializationTargets.map {
it.compilations["main"].defaultSourceSet.dependencies {
api(project(":lib:kon-serialization"))
}
it.compilations["main"].defaultSourceSet.dependencies { api(project(":lib:kon-serialization")) }
}
}
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation("com.android.library:com.android.library.gradle.plugin:_")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:_")
implementation("org.jetbrains.kotlin:kotlin-serialization:_")
implementation("com.ncorti.ktfmt.gradle:plugin:_")
implementation("com.diffplug.spotless:spotless-plugin-gradle:_")
implementation("io.github.gradle-nexus:publish-plugin:_")
implementation("dev.petuska:klip-gradle-plugin:_")
implementation("com.github.jakemarsden:git-hooks-gradle-plugin:_")
Expand Down
13 changes: 6 additions & 7 deletions buildSrc/src/main/kotlin/plugin.common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinTest

plugins {
id("com.ncorti.ktfmt.gradle")
id("com.diffplug.spotless")
idea
}

Expand All @@ -18,15 +18,14 @@ idea {
}
}

ktfmt {
// googleStyle()
spotless {
kotlin { ktfmt() }
kotlinGradle { ktfmt() }
}

tasks {
withType<Test> {
useJUnitPlatform()
}

withType<Test> { useJUnitPlatform() }

afterEvaluate {
if (tasks.findByName("compile") == null) {
register("compile") {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/plugin.git-hooks.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
gitHooks {
setHooks(
mapOf(
"pre-commit" to "ktfmtFormat",
"pre-push" to "ktfmtCheck"
"pre-commit" to "spotlessApply",
"pre-push" to "spotlessCheck"
)
)
}
14 changes: 2 additions & 12 deletions lib/kon-core/src/commonMain/kotlin/KObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@ package dev.petuska.kon
import dev.petuska.kon.util.toJson

/** A [MutableMap] to represent a JSON object. */
public typealias KON = MutableMap<String, Any?>
public typealias KON = TypedKON<Any?>

/** A wrapper around [MutableMap] to represent a JSON object */
public interface KObject : KON {
/**
* Adds a field
* @receiver field name
* @param value field value
*/
@KONSetterDsl
public infix fun String.to(value: Any?) {
this@KObject[this] = value
}

public interface KObject : TypedKObject<Any?>, KON {
/**
* Adds an object field
* @receiver field name
Expand Down
33 changes: 33 additions & 0 deletions lib/kon-core/src/commonMain/kotlin/TypedKObject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dev.petuska.kon

import dev.petuska.kon.util.toJson

/** A [MutableMap] to represent a JSON object. */
public typealias TypedKON<V> = MutableMap<String, V>

/** A wrapper around [MutableMap] to represent a JSON object */
public interface TypedKObject<V> : TypedKON<V> {
/**
* Adds a field
* @receiver field name
* @param value field value
*/
@KONSetterDsl
public infix fun String.to(value: V) {
this@TypedKObject[this] = value
}
}

/**
* Builds an object. Overrides [Any::toString] to return JSON object notation.
* @param obj object builder
*/
@KONBuilderDsl
public inline fun <V> kobj(
base: TypedKON<V> = mutableMapOf(),
obj: TypedKObject<V>.() -> Unit = {}
): TypedKObject<V> =
object : TypedKObject<V>, TypedKON<V> by base {
override fun toString(): String = toJson()
}
.apply(obj)
4 changes: 2 additions & 2 deletions lib/kon-core/src/commonMain/kotlin/annotations.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.petuska.kon

/** Marks DSLs with side effects that build and sets entities */
@DslMarker @Retention(AnnotationRetention.SOURCE) public annotation class KONSetterDsl
@DslMarker @Retention(AnnotationRetention.SOURCE) internal annotation class KONSetterDsl

/** Marks DSLs with no side effects that build entities */
@DslMarker @Retention(AnnotationRetention.SOURCE) public annotation class KONBuilderDsl
@DslMarker @Retention(AnnotationRetention.SOURCE) internal annotation class KONBuilderDsl
10 changes: 1 addition & 9 deletions lib/kon-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@ plugins {

description = "KON interop with kotlinx-serialization"

kotlin {
sourceSets {
commonMain {
dependencies {
api(project(":lib:kon-core"))
}
}
}
}
kotlin { sourceSets { commonMain { dependencies { api(project(":lib:kon-core")) } } } }
1 change: 0 additions & 1 deletion sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
repositories {
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
}

description = "Local consumer sandbox"
Expand Down
10 changes: 5 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

rootProject.name = "kon"

include(":test")

include(
":lib:kon-core",
":lib:kon-serialization",
":lib:kon-core",
":lib:kon-serialization",
)

refreshVersions {
extraArtifactVersionKeyRules(rootDir.resolve("versions.rules"))
}
refreshVersions { extraArtifactVersionKeyRules(rootDir.resolve("versions.rules")) }
34 changes: 11 additions & 23 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
plugins {
id("plugin.library-mpp")
}
plugins { id("plugin.library-mpp") }

description = "Local test utilities"

Expand All @@ -14,28 +12,18 @@ kotlin {
api("dev.petuska:klip:_")
}
}
named("jvmMain") {
dependencies {
api(kotlin("test-junit5"))
}
}
named("jsMain") {
dependencies {
api(kotlin("test-js"))
}
}
named("jvmMain") { dependencies { api(kotlin("test-junit5")) } }
named("jsMain") { dependencies { api(kotlin("test-js")) } }
}

val targetsWithCoroutines = util.KotlinTargetDetails.values()
.filter(util.KotlinTargetDetails::hasCoroutines)
.map(util.KotlinTargetDetails::presetName)
val targetsWithCoroutines =
util.KotlinTargetDetails.values()
.filter(util.KotlinTargetDetails::hasCoroutines)
.map(util.KotlinTargetDetails::presetName)

targets.filter { it.preset?.name in targetsWithCoroutines }
.forEach {
it.compilations["main"].defaultSourceSet {
dependencies {
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:_")
}
}
targets.filter { it.preset?.name in targetsWithCoroutines }.forEach {
it.compilations["main"].defaultSourceSet {
dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core:_") }
}
}
}
15 changes: 2 additions & 13 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
####
#### suppress inspection "SpellCheckingInspection" for whole file
#### suppress inspection "UnusedProperty" for whole file

#======================================= Plugins ========================================
plugin.android=7.0.3

plugin.com.github.jakemarsden.git-hooks=0.0.2

version.com.diffplug.spotless..spotless-plugin-gradle=5.17.0
version.com.github.jakemarsden..git-hooks-gradle-plugin=0.0.2

version.com.ncorti.ktfmt.gradle..plugin=0.7.0

version.io.github.gradle-nexus..publish-plugin=1.1.0

version.org.jetbrains.dokka..dokka-gradle-plugin=1.5.31

#====================================== Libraries =======================================
version.klip=0.2.2

version.klip=0.2.2
version.kotlinx.serialization=1.3.0

version.kotlin=1.5.31

version.kotlinx.coroutines=1.5.2

0 comments on commit 86e348a

Please sign in to comment.