Kapt3: Serialize annotation processor options to base64 to support spaces in option values
This commit is contained in:
+2
-1
@@ -108,7 +108,8 @@ class Kapt3IT : BaseGradleIT() {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
assertContains("Options: {suffix=Customized, justColon=:, justEquals==, containsColon=a:b, " +
|
||||
"containsEquals=a=b, startsWithColon=:a, startsWithEquals==a, endsWithColon=a:, endsWithEquals=a:}")
|
||||
"containsEquals=a=b, startsWithColon=:a, startsWithEquals==a, endsWithColon=a:, " +
|
||||
"endsWithEquals=a:, withSpace=a b c}")
|
||||
assertFileExists("build/generated/source/kapt/main/example/TestClassCustomized.java")
|
||||
assertFileExists("build/classes/main/example/TestClass.class")
|
||||
assertFileExists("build/classes/main/example/TestClassCustomized.class")
|
||||
|
||||
+1
@@ -31,5 +31,6 @@ kapt {
|
||||
arg("startsWithEquals", "=a")
|
||||
arg("endsWithColon", "a:")
|
||||
arg("endsWithEquals", "a:")
|
||||
arg("withSpace", "a b c") // key doesn't support spaces
|
||||
}
|
||||
}
|
||||
+19
-4
@@ -29,8 +29,11 @@ import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.android.AndroidGradleWrapper
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.SyncOutputTask
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.ObjectOutputStream
|
||||
import javax.xml.bind.DatatypeConverter
|
||||
import javax.xml.bind.DatatypeConverter.printBase64Binary
|
||||
|
||||
// apply plugin: 'kotlin-kapt'
|
||||
class Kapt3GradleSubplugin : Plugin<Project> {
|
||||
@@ -171,15 +174,27 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
|
||||
val apOptions = kaptExtension.getAdditionalArguments(project, variantData, androidPlugin) + androidOptions
|
||||
|
||||
for ((key, value) in apOptions) {
|
||||
pluginOptions += SubpluginOption("apoption", "$key:$value")
|
||||
}
|
||||
SubpluginOption("apoptions", encodeAnnotationProcessingOptions(apOptions))
|
||||
|
||||
addMiscOptions(pluginOptions)
|
||||
|
||||
return pluginOptions
|
||||
}
|
||||
|
||||
fun encodeAnnotationProcessingOptions(options: Map<String, String>): String {
|
||||
val os = ByteArrayOutputStream()
|
||||
val oos = ObjectOutputStream(os)
|
||||
|
||||
oos.writeInt(options.size)
|
||||
for ((k, v) in options.entries) {
|
||||
oos.writeUTF(k)
|
||||
oos.writeUTF(v)
|
||||
}
|
||||
|
||||
oos.flush()
|
||||
return printBase64Binary(os.toByteArray())
|
||||
}
|
||||
|
||||
private fun Kapt3SubpluginContext.addMiscOptions(pluginOptions: MutableList<SubpluginOption>) {
|
||||
if (kaptExtension.generateStubs) {
|
||||
project.logger.warn("'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin")
|
||||
|
||||
Reference in New Issue
Block a user