Skip to content

Commit 4c62ea0

Browse files
committed
Make kapt work on JDK9+, add logging stream, make more stuff configurable
1 parent 89908ac commit 4c62ea0

File tree

7 files changed

+342
-127
lines changed

7 files changed

+342
-127
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ dependencies {
4545
testCompile group: 'junit', name: 'junit', version: '4.12'
4646

4747
testCompile "org.assertj:assertj-core:3.11.1"
48+
testImplementation "org.mockito:mockito-core:2.23.4"
49+
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0"
4850

4951
compile "me.eugeniomarletti.kotlin.metadata:kotlin-metadata:1.4.0"
5052

@@ -62,4 +64,5 @@ compileKotlin {
6264
}
6365
compileTestKotlin {
6466
kotlinOptions.jvmTarget = "1.8"
67+
kotlinOptions.freeCompilerArgs += ["-Xskip-runtime-version-check"]
6568
}

src/main/kotlin/StreamUtils.kt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.tschuchort.compiletest
2+
3+
import java.io.IOException
4+
import java.io.OutputStream
5+
6+
/** An output stream that does nothing, like /dev/null */
7+
internal object NullStream : OutputStream() {
8+
override fun write(b: Int) {
9+
//NoOp
10+
}
11+
12+
override fun close() {
13+
//NoOp
14+
}
15+
16+
override fun flush() {
17+
//NoOp
18+
}
19+
20+
override fun write(b: ByteArray, off: Int, len: Int) {
21+
//NoOp
22+
}
23+
24+
override fun write(b: ByteArray) {
25+
//NoOp
26+
}
27+
}
28+
29+
/** A combined stream that writes to all the output streams in [streams]. */
30+
@Suppress("MemberVisibilityCanBePrivate")
31+
internal class TeeOutputStream(val streams: Collection<OutputStream>) : OutputStream() {
32+
33+
constructor(vararg streams: OutputStream) : this(streams.toList())
34+
35+
@Synchronized
36+
@Throws(IOException::class)
37+
override fun write(b: Int) {
38+
for(stream in streams)
39+
stream.write(b)
40+
}
41+
42+
@Synchronized
43+
@Throws(IOException::class)
44+
override fun write(b: ByteArray) {
45+
for(stream in streams)
46+
stream.write(b)
47+
}
48+
49+
@Synchronized
50+
@Throws(IOException::class)
51+
override fun write(b: ByteArray, off: Int, len: Int) {
52+
for(stream in streams)
53+
stream.write(b, off, len)
54+
}
55+
56+
@Throws(IOException::class)
57+
override fun flush() {
58+
for(stream in streams)
59+
stream.flush()
60+
}
61+
62+
@Throws(IOException::class)
63+
override fun close() {
64+
closeImpl(streams)
65+
}
66+
67+
@Throws(IOException::class)
68+
private fun closeImpl(streamsToClose : Collection<OutputStream>) {
69+
try {
70+
streamsToClose.firstOrNull()?.close()
71+
}
72+
finally {
73+
if(streamsToClose.size > 1)
74+
closeImpl(streamsToClose.drop(1))
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)