Skip to content

Commit

Permalink
Add TorConfig DSL (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Jan 2, 2024
1 parent 5bd3d88 commit d180058
Show file tree
Hide file tree
Showing 39 changed files with 4,757 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ apiValidation {
if (CHECK_PUBLICATION != null) {
ignoredProjects.add("check-publication")
} else {
nonPublicMarkers.add("io.matthewnelson.kmp.tor.common.annotation.InternalTorApi")
nonPublicMarkers.add("io.matthewnelson.kmp.tor.core.api.annotation.InternalKmpTorApi")
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gradle-kmp-configuration = "0.1.7"
gradle-kotlin = "1.9.21"
gradle-publish-maven = "0.25.3"

kmp-tor-core = "2.0.0-alpha02"
kmp-tor-core = "2.0.0-alpha03"
kmp-tor-resource = "408.10.0-SNAPSHOT"

kotlinx-coroutines = "1.7.3"
Expand Down
584 changes: 584 additions & 0 deletions library/runtime-api/api/runtime-api.api

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions library/runtime-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,19 @@ kmpConfiguration {
}
}
}

kotlin {
with(sourceSets) {
val jsMain = findByName("jsMain")
val jvmMain = findByName("jvmMain")

if (jsMain != null || jvmMain != null) {
val nonNativeMain = maybeCreate("nonNativeMain")
nonNativeMain.dependsOn(getByName("commonMain"))
jvmMain?.apply { dependsOn(nonNativeMain) }
jsMain?.apply { dependsOn(nonNativeMain) }
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2023 Matthew Nelson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
@file:Suppress("KotlinRedundantDiagnosticSuppress")

package io.matthewnelson.kmp.tor.runtime.api

/**
* Helper for non-Kotlin consumers instead of using
* `T.() -> Unit` which would force a return of `Unit`.
*
* e.g.
*
* // Java
* My.Builder(b -> {
* b.add(My.Factory.Companion, s -> {
* s.enable = true;
* });
* });
*
* // Kotlin
* My.Builder {
* add(My.Factory) {
* enable = true
* }
* }
*
* @see [ItBlock]
* @see [apply]
* */
public fun interface ThisBlock<in T: Any> {
public operator fun T.invoke()
}

/**
* Helper for non-Kotlin consumers instead of using
* `(T) -> Unit` which would force a return of `Unit`.
*
* e.g.
*
* // Java
* My.Builder(b -> {
* b.add(My.Factory.Companion, s -> {
* s.enable = true;
* });
* });
*
* // Kotlin
* My.Builder {
* it.add(My.Factory) { s ->
* s.enable = true
* }
* }
*
* @see [ThisBlock]
* @see [apply]
* */
public fun interface ItBlock<in T: Any> {
public operator fun invoke(it: T)
}

@Suppress("NOTHING_TO_INLINE")
public inline fun <T: Any> T.apply(block: ThisBlock<T>): T {
with(block) { invoke() }
return this
}

@Suppress("NOTHING_TO_INLINE")
public inline fun <T: Any> T.apply(block: ItBlock<T>): T {
block(this)
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.jvm.JvmName
import kotlin.jvm.JvmStatic

/**
* Holder for a port between 0 and 65535
* Holder for a port between 0 and 65535 (inclusive)
* */
public open class Port private constructor(
@JvmField
Expand All @@ -45,7 +45,7 @@ public open class Port private constructor(
}

/**
* Parses a String for a port between 0 and 65535.
* Parses a String for a port between 0 and 65535 (inclusive).
*
* String can be either a URL containing the port, or the
* port itself.
Expand All @@ -71,7 +71,7 @@ public open class Port private constructor(
}

/**
* Parses a String for a port between 0 and 65535.
* Parses a String for a port between 0 and 65535 (inclusive).
*
* String can be either a URL containing the port, or the
* port itself.
Expand All @@ -93,7 +93,7 @@ public open class Port private constructor(
}

/**
* A [Port] with a more constrained range of 1024 and 65535
* A [Port] with a more constrained range of 1024 and 65535 (inclusive)
* */
public class Proxy private constructor(value: Int): Port(value) {

Expand All @@ -111,7 +111,7 @@ public open class Port private constructor(
}

/**
* Parses a String for a port between 1024 and 65535.
* Parses a String for a port between 1024 and 65535 (inclusive).
*
* String can be either a URL containing the port, or the
* port itself.
Expand All @@ -135,7 +135,7 @@ public open class Port private constructor(
}

/**
* Parses a String for a port between 1024 and 65535.
* Parses a String for a port between 1024 and 65535 (inclusive).
*
* String can be either a URL containing the port, or the
* port itself.
Expand Down
Loading

0 comments on commit d180058

Please sign in to comment.