Escape arguments when Gradle plugin launches out of process compilation

#KT-39755 Fixed
This commit is contained in:
Andrey Uskov
2020-06-26 19:34:57 +03:00
parent 90dae320c3
commit f4e9acb233
10 changed files with 97 additions and 2 deletions
@@ -100,6 +100,18 @@ class KotlinGradleIT : BaseGradleIT() {
}
}
@Test
fun testKotlinCompileInFolderWithSpaces() {
val project = Project(projectName = "Project Path With Spaces")
project.build("build") {
assertSuccessful()
assertReportExists()
assertTasksExecuted(":compileKotlin", ":compileTestKotlin")
assertNotContains("Forcing System.gc")
}
}
@Test
fun testLogLevelForceGC() {
val debugProject = Project("simpleProject", minLogLevel = LogLevel.LIFECYCLE)
@@ -0,0 +1,26 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:12.0'
testCompile 'org.testng:testng:6.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
test {
useTestNG()
}
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -Dkotlin.compiler.execution.strategy="out-of-process"
@@ -0,0 +1,3 @@
package demo
open class Greeter(val greeting: String)
@@ -0,0 +1,18 @@
package demo
import com.google.common.base.Joiner
import java.util.ArrayList
class KotlinGreetingJoiner(val greeter: Greeter) {
val names = ArrayList<String?>()
fun addName(name: String?): Unit {
names.add(name)
}
fun getJoinedGreeting(): String? {
val joiner = Joiner.on(" and ").skipNulls();
return "${greeter.greeting} ${joiner.join(names)}"
}
}
@@ -0,0 +1,10 @@
package demo
import org.testng.Assert.assertEquals
class TestGreeter {
fun test() {
val greeter = Greeter("Hi!")
assertEquals("Hi!", greeter.greeting)
}
}
@@ -0,0 +1,17 @@
package demo
import org.testng.Assert.assertEquals
import org.testng.annotations.Test as test
class TestKotlinGreetingJoiner() {
@test
fun test() {
val example : KotlinGreetingJoiner = KotlinGreetingJoiner(Greeter("Hi"))
example.addName("Harry")
example.addName("Ron")
example.addName("Hermione")
assertEquals(example.getJoinedGreeting(), "Hi Harry and Ron and Hermione")
}
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.compilerRunner
import groovy.json.StringEscapeUtils
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
@@ -124,9 +125,10 @@ internal fun runToolInSeparateProcess(
}
private fun writeArgumentsToFile(directory: File, argsArray: Array<String>): File {
val compilerOptions = File.createTempFile(LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "_", ".compiler.options", directory)
val compilerOptions =
File.createTempFile(LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "_", ".compiler.options", directory)
compilerOptions.deleteOnExit()
compilerOptions.writeText(argsArray.joinToString(" "))
compilerOptions.writeText(argsArray.joinToString(" ") { "\"${StringEscapeUtils.escapeJava(it)}\"" })
return compilerOptions
}