Encode all compiler plugin arguments for Android Extensions in kapt
Commas in option values breaks the option parsing in daemon (KT-20235).
This commit is contained in:
+2
-2
@@ -128,7 +128,7 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
addVariant(sourceSet)
|
||||
}
|
||||
|
||||
return pluginOptions
|
||||
return wrapPluginOptions(pluginOptions, "configuration")
|
||||
}
|
||||
|
||||
private fun getLayoutDirectories(resDirectories: Collection<File>): List<File> {
|
||||
@@ -198,7 +198,7 @@ class AndroidSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
addSourceSetAsVariant(variantName)
|
||||
}
|
||||
|
||||
return pluginOptions
|
||||
return wrapPluginOptions(pluginOptions, "configuration")
|
||||
}
|
||||
|
||||
// Android25ProjectHandler.KaptVariant actually contains BaseVariant, not BaseVariantData
|
||||
|
||||
+9
-9
@@ -30,12 +30,12 @@ import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.ObjectOutputStream
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedSourcesDir
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedClassesDir
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.getKaptGeneratedKotlinSourcesDir
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.util.*
|
||||
|
||||
// apply plugin: 'kotlin-kapt'
|
||||
@@ -234,9 +234,9 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
androidPlugin
|
||||
) + androidOptions + mapOf("kapt.kotlin.generated" to kotlinSourcesOutputDir.absolutePath)
|
||||
|
||||
pluginOptions += SubpluginOption("apoptions", encodeOptions(apOptions))
|
||||
pluginOptions += SubpluginOption("apoptions", encodeList(apOptions))
|
||||
|
||||
pluginOptions += SubpluginOption("javacArguments", encodeOptions(kaptExtension.getJavacOptions()))
|
||||
pluginOptions += SubpluginOption("javacArguments", encodeList(kaptExtension.getJavacOptions()))
|
||||
|
||||
addMiscOptions(pluginOptions)
|
||||
|
||||
@@ -245,19 +245,19 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
|
||||
private fun Kapt3SubpluginContext.buildAndAddOptionsTo(container: CompilerPluginOptions, aptMode: String) {
|
||||
val compilerPluginId = getCompilerPluginId()
|
||||
for (option in buildOptions(aptMode)) {
|
||||
for (option in wrapPluginOptions(buildOptions(aptMode), "configuration")) {
|
||||
container.addPluginArgument(compilerPluginId, option.key, option.value)
|
||||
}
|
||||
}
|
||||
|
||||
fun encodeOptions(options: Map<String, String>): String {
|
||||
private fun encodeList(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)
|
||||
for ((key, value) in options.entries) {
|
||||
oos.writeUTF(key)
|
||||
oos.writeUTF(value)
|
||||
}
|
||||
|
||||
oos.flush()
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ObjectOutputStream
|
||||
import java.util.*
|
||||
|
||||
fun encodePluginOptions(options: Map<String, List<String>>): String {
|
||||
val os = ByteArrayOutputStream()
|
||||
val oos = ObjectOutputStream(os)
|
||||
|
||||
oos.writeInt(options.size)
|
||||
for ((key, values) in options.entries) {
|
||||
oos.writeUTF(key)
|
||||
|
||||
oos.writeInt(values.size)
|
||||
for (value in values) {
|
||||
oos.writeUTF(value)
|
||||
}
|
||||
}
|
||||
|
||||
oos.flush()
|
||||
return Base64.getEncoder().encodeToString(os.toByteArray())
|
||||
}
|
||||
|
||||
fun wrapPluginOptions(options: List<SubpluginOption>, newOptionName: String): List<SubpluginOption> {
|
||||
val groupedOptions = options.groupBy { it.key }.mapValues { opt -> opt.value.map { it.value } }
|
||||
val encodedOptions = encodePluginOptions(groupedOptions)
|
||||
val singleOption = SubpluginOption(newOptionName, encodedOptions)
|
||||
return listOf(singleOption)
|
||||
}
|
||||
Reference in New Issue
Block a user