Skip to content

Commit 876c111

Browse files
author
Aristos Pasalides
committed
Implemented No-Op artifact.
1 parent 091249c commit 876c111

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

build.gradle

+35-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,25 @@ tasks {
1717
}
1818
}
1919

20+
sourceSets {
21+
noop {
22+
java.srcDir 'src/noop/kotlin'
23+
}
24+
}
25+
2026
dependencies {
2127
implementation platform('org.jetbrains.kotlin:kotlin-bom')
2228
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
2329

24-
implementation 'org.slf4j:slf4j-api:1.7.28'
25-
testImplementation 'org.slf4j:slf4j-simple:1.7.28'
30+
implementation 'org.slf4j:slf4j-api:1.7.32'
31+
testImplementation 'org.slf4j:slf4j-simple:1.7.32'
32+
2633

2734
testImplementation 'org.jetbrains.kotlin:kotlin-test'
2835
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
36+
37+
noopImplementation 'org.slf4j:slf4j-nop:1.7.32'
38+
noopImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
2939
}
3040

3141
task dokkaJar(type: Jar) {
@@ -41,16 +51,37 @@ task sourcesJar(type: Jar) {
4151
from(sourceSets.getByName("main").allSource)
4252
}
4353

54+
task noopSources(type: Jar) {
55+
archiveClassifier.set("sources")
56+
from(sourceSets.noop.allSource)
57+
}
58+
59+
task noopBinary(type: Jar) {
60+
archiveClassifier.set("")
61+
from(sourceSets.noop.output)
62+
}
63+
4464
publishing {
4565
publications {
66+
noop(MavenPublication) {
67+
artifact noopSources
68+
artifact noopBinary
69+
70+
pom {
71+
name = "ktee-noop"
72+
artifactId = "ktee-noop"
73+
}
74+
}
75+
4676
mavenJava(MavenPublication) {
4777
from components.java
4878
artifact sourcesJar
4979
artifact dokkaJar
5080

5181
pom {
5282
name = "ktee"
53-
description = "KTee is Tee for Kotlin code pipelines. If you love the unix command line tee, you know what we mean."
83+
description = "KTee is Tee for Kotlin code pipelines. " +
84+
"If you love the unix command line tee, you know what we mean."
5485
url.set("https://github.com/medly/ktee")
5586
licenses {
5687
license {
@@ -103,4 +134,5 @@ signing {
103134
def signingPassword = System.getenv("OSSRH_SIGNING_PASSPHRASE")
104135
useInMemoryPgpKeys(signingKey, signingPassword)
105136
sign publishing.publications.mavenJava
137+
sign publishing.publications.noop
106138
}

src/main/kotlin/ktee/KTee.kt

+8-27
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
package ktee
22

3-
import ktee.KTee.Companion.debug
43
import org.slf4j.Logger
54

6-
class KTee {
7-
companion object {
8-
var debugChanged = false
9-
private set
10-
11-
/**
12-
* If debug is set to false, all tee
13-
* functions won't output anything.
14-
*
15-
* Variable can be set only once!
16-
*/
17-
var debug = true
18-
@Synchronized set(value) {
19-
if(!debugChanged) { debugChanged = true; field = value }
20-
else throw IllegalStateException("Variable debug has already been set once.")
21-
}
22-
} }
23-
245
/**
256
* Prints the value to the stdout and returns the same value. Useful when chaining
267
* methods. For example:
@@ -30,53 +11,53 @@ class KTee {
3011
* myList.map(fn).tee(">>> ").reduce(fn)
3112
*
3213
*/
33-
fun <T> T.tee(marker: String = "") = apply { if (debug) println(marker + this) }
14+
fun <T> T.tee(marker: String = "") = apply { println(marker + this) }
3415

3516
/**
3617
*
3718
* executes the lambda with the value of the chain and writes the
3819
*
3920
*/
40-
inline fun <T> T.tee(fn: (T) -> String) = apply { if (debug) println(fn(this)) }
21+
inline fun <T> T.tee(fn: (T) -> String) = apply { println(fn(this)) }
4122

4223
/**
4324
* logs the value to the given logger at info level. Message can be customized using message parameter
4425
*/
4526
fun <T> T.teeToInfo(logger: Logger, message: String = "{}")
46-
= apply { if (debug) logger.info(message, this) }
27+
= apply { logger.info(message, this) }
4728

4829
/**
4930
* Evaluates the lambda and logs the result (of evaluation) to the given logger at info level
5031
*
5132
*/
5233
inline fun <T> T.teeToInfo(logger: Logger, fn: (T) -> String)
53-
= apply { if (debug) logger.info(fn(this), this) }
34+
= apply { logger.info(fn(this), this) }
5435

5536
/**
5637
* logs the value to the given logger at info level. Message can be customized using message parameter
5738
*/
5839
fun <T> T.teeToDebug(logger: Logger, message: String = "{}")
59-
= apply { if (debug) logger.debug(message, this) }
40+
= apply { logger.debug(message, this) }
6041

6142
/**
6243
* Evaluates the lambda and logs the result (of evaluation) to the given logger at debug level
6344
*
6445
*/
6546
inline fun <T> T.teeToDebug(logger: Logger, fn: (T) -> String)
66-
= apply { if (debug) logger.debug(fn(this), this) }
47+
= apply { logger.debug(fn(this), this) }
6748

6849
/**
6950
* logs the value to the given logger at trace level. Message can be customized using message parameter
7051
*/
7152
fun <T> T.teeToTrace(logger: Logger, message: String = "{}")
72-
= apply { if (debug) logger.trace(message, this) }
53+
= apply { logger.trace(message, this) }
7354

7455
/**
7556
* Evaluates the lambda and logs the result (of evaluation) to the given logger at trace level
7657
*
7758
*/
7859
inline fun <T> T.teeToTrace(logger: Logger, fn: (T) -> String)
79-
= apply { if (debug) logger.trace(fn(this), this) }
60+
= apply { logger.trace(fn(this), this) }
8061

8162

8263

src/noop/kotlin/ktee/KTee.kt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ktee
2+
3+
import org.slf4j.Logger
4+
5+
inline fun <T> T.tee(fn: (T) -> String) = this
6+
inline fun <T> T.tee(marker: String = "") = this
7+
inline fun <T> T.teeToInfo(logger: Logger, fn: (T) -> String) = this
8+
inline fun <T> T.teeToDebug(logger: Logger, fn: (T) -> String) = this
9+
inline fun <T> T.teeToTrace(logger: Logger, fn: (T) -> String) = this
10+
inline fun <T> T.teeToInfo(logger: Logger, message: String = "{}") = this
11+
inline fun <T> T.teeToDebug(logger: Logger, message: String = "{}") = this
12+
inline fun <T> T.teeToTrace(logger: Logger, message: String = "{}") = this
13+
14+
15+
16+

0 commit comments

Comments
 (0)