From 876c111bcc4f21f707cd9763c2cea5daa72b849b Mon Sep 17 00:00:00 2001 From: Aristos Pasalides Date: Wed, 15 Dec 2021 23:12:36 +0200 Subject: [PATCH] Implemented No-Op artifact. --- build.gradle | 38 +++++++++++++++++++++++++++++++++--- src/main/kotlin/ktee/KTee.kt | 35 ++++++++------------------------- src/noop/kotlin/ktee/KTee.kt | 16 +++++++++++++++ 3 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 src/noop/kotlin/ktee/KTee.kt diff --git a/build.gradle b/build.gradle index 7cf43d5..5d2b11c 100644 --- a/build.gradle +++ b/build.gradle @@ -17,15 +17,25 @@ tasks { } } +sourceSets { + noop { + java.srcDir 'src/noop/kotlin' + } +} + dependencies { implementation platform('org.jetbrains.kotlin:kotlin-bom') implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' - implementation 'org.slf4j:slf4j-api:1.7.28' - testImplementation 'org.slf4j:slf4j-simple:1.7.28' + implementation 'org.slf4j:slf4j-api:1.7.32' + testImplementation 'org.slf4j:slf4j-simple:1.7.32' + testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5' + + noopImplementation 'org.slf4j:slf4j-nop:1.7.32' + noopImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' } task dokkaJar(type: Jar) { @@ -41,8 +51,28 @@ task sourcesJar(type: Jar) { from(sourceSets.getByName("main").allSource) } +task noopSources(type: Jar) { + archiveClassifier.set("sources") + from(sourceSets.noop.allSource) +} + +task noopBinary(type: Jar) { + archiveClassifier.set("") + from(sourceSets.noop.output) +} + publishing { publications { + noop(MavenPublication) { + artifact noopSources + artifact noopBinary + + pom { + name = "ktee-noop" + artifactId = "ktee-noop" + } + } + mavenJava(MavenPublication) { from components.java artifact sourcesJar @@ -50,7 +80,8 @@ publishing { pom { name = "ktee" - description = "KTee is Tee for Kotlin code pipelines. If you love the unix command line tee, you know what we mean." + description = "KTee is Tee for Kotlin code pipelines. " + + "If you love the unix command line tee, you know what we mean." url.set("https://github.com/medly/ktee") licenses { license { @@ -103,4 +134,5 @@ signing { def signingPassword = System.getenv("OSSRH_SIGNING_PASSPHRASE") useInMemoryPgpKeys(signingKey, signingPassword) sign publishing.publications.mavenJava + sign publishing.publications.noop } diff --git a/src/main/kotlin/ktee/KTee.kt b/src/main/kotlin/ktee/KTee.kt index 43a802a..533a311 100644 --- a/src/main/kotlin/ktee/KTee.kt +++ b/src/main/kotlin/ktee/KTee.kt @@ -1,26 +1,7 @@ package ktee -import ktee.KTee.Companion.debug import org.slf4j.Logger -class KTee { - companion object { - var debugChanged = false - private set - - /** - * If debug is set to false, all tee - * functions won't output anything. - * - * Variable can be set only once! - */ - var debug = true - @Synchronized set(value) { - if(!debugChanged) { debugChanged = true; field = value } - else throw IllegalStateException("Variable debug has already been set once.") - } - } } - /** * Prints the value to the stdout and returns the same value. Useful when chaining * methods. For example: @@ -30,53 +11,53 @@ class KTee { * myList.map(fn).tee(">>> ").reduce(fn) * */ -fun T.tee(marker: String = "") = apply { if (debug) println(marker + this) } +fun T.tee(marker: String = "") = apply { println(marker + this) } /** * * executes the lambda with the value of the chain and writes the * */ -inline fun T.tee(fn: (T) -> String) = apply { if (debug) println(fn(this)) } +inline fun T.tee(fn: (T) -> String) = apply { println(fn(this)) } /** * logs the value to the given logger at info level. Message can be customized using message parameter */ fun T.teeToInfo(logger: Logger, message: String = "{}") - = apply { if (debug) logger.info(message, this) } + = apply { logger.info(message, this) } /** * Evaluates the lambda and logs the result (of evaluation) to the given logger at info level * */ inline fun T.teeToInfo(logger: Logger, fn: (T) -> String) - = apply { if (debug) logger.info(fn(this), this) } + = apply { logger.info(fn(this), this) } /** * logs the value to the given logger at info level. Message can be customized using message parameter */ fun T.teeToDebug(logger: Logger, message: String = "{}") - = apply { if (debug) logger.debug(message, this) } + = apply { logger.debug(message, this) } /** * Evaluates the lambda and logs the result (of evaluation) to the given logger at debug level * */ inline fun T.teeToDebug(logger: Logger, fn: (T) -> String) - = apply { if (debug) logger.debug(fn(this), this) } + = apply { logger.debug(fn(this), this) } /** * logs the value to the given logger at trace level. Message can be customized using message parameter */ fun T.teeToTrace(logger: Logger, message: String = "{}") - = apply { if (debug) logger.trace(message, this) } + = apply { logger.trace(message, this) } /** * Evaluates the lambda and logs the result (of evaluation) to the given logger at trace level * */ inline fun T.teeToTrace(logger: Logger, fn: (T) -> String) - = apply { if (debug) logger.trace(fn(this), this) } + = apply { logger.trace(fn(this), this) } diff --git a/src/noop/kotlin/ktee/KTee.kt b/src/noop/kotlin/ktee/KTee.kt new file mode 100644 index 0000000..6aa9d28 --- /dev/null +++ b/src/noop/kotlin/ktee/KTee.kt @@ -0,0 +1,16 @@ +package ktee + +import org.slf4j.Logger + +inline fun T.tee(fn: (T) -> String) = this +inline fun T.tee(marker: String = "") = this +inline fun T.teeToInfo(logger: Logger, fn: (T) -> String) = this +inline fun T.teeToDebug(logger: Logger, fn: (T) -> String) = this +inline fun T.teeToTrace(logger: Logger, fn: (T) -> String) = this +inline fun T.teeToInfo(logger: Logger, message: String = "{}") = this +inline fun T.teeToDebug(logger: Logger, message: String = "{}") = this +inline fun T.teeToTrace(logger: Logger, message: String = "{}") = this + + + +