From 21f296dc02b2ce04c8585c5e6c729f141e864949 Mon Sep 17 00:00:00 2001 From: Aaron Sarkissian Date: Thu, 1 Apr 2021 19:06:48 +0400 Subject: [PATCH] Add optional userInput field --- .../com/compiler/server/compiler/components/KotlinCompiler.kt | 4 ++-- src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt | 3 ++- src/main/kotlin/com/compiler/server/model/Project.kt | 1 + .../com/compiler/server/service/KotlinProjectExecutor.kt | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/compiler/server/compiler/components/KotlinCompiler.kt b/src/main/kotlin/com/compiler/server/compiler/components/KotlinCompiler.kt index b1b9786ba..edb5102e2 100644 --- a/src/main/kotlin/com/compiler/server/compiler/components/KotlinCompiler.kt +++ b/src/main/kotlin/com/compiler/server/compiler/components/KotlinCompiler.kt @@ -40,11 +40,11 @@ class KotlinCompiler( class Compiled(val files: Map = emptyMap(), val mainClass: String? = null) - fun run(files: List, coreEnvironment: KotlinCoreEnvironment, args: String): ExecutionResult { + fun run(files: List, coreEnvironment: KotlinCoreEnvironment, args: String, userInput: String): ExecutionResult { return execute(files, coreEnvironment) { output, compiled -> val mainClass = JavaRunnerExecutor::class.java.name val arguments = listOfNotNull(compiled.mainClass) + args.split(" ") - javaExecutor.execute(argsFrom(mainClass, output, arguments)) + javaExecutor.execute(argsFrom(mainClass, output, arguments), userInput) .asExecutionResult() } } diff --git a/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt b/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt index 4dabafbf8..1335ae00f 100644 --- a/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt +++ b/src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt @@ -20,8 +20,9 @@ class JavaExecutor { const val EXECUTION_TIMEOUT = 10000L } - fun execute(args: List): ProgramOutput { + fun execute(args: List, userInput: String = ""): ProgramOutput { return Runtime.getRuntime().exec(args.toTypedArray()).use { + outputStream.write(userInput.toByteArray()) outputStream.close() val standardOut = InputStreamReader(this.inputStream).buffered() diff --git a/src/main/kotlin/com/compiler/server/model/Project.kt b/src/main/kotlin/com/compiler/server/model/Project.kt index 07b5a24d4..e40d47c47 100644 --- a/src/main/kotlin/com/compiler/server/model/Project.kt +++ b/src/main/kotlin/com/compiler/server/model/Project.kt @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonValue @JsonIgnoreProperties(ignoreUnknown = true) data class Project( val args: String = "", + val userInput: String = "", val files: List = listOf(), val confType: ProjectType = ProjectType.JAVA ) diff --git a/src/main/kotlin/com/compiler/server/service/KotlinProjectExecutor.kt b/src/main/kotlin/com/compiler/server/service/KotlinProjectExecutor.kt index 9a0f0627c..efe43867a 100644 --- a/src/main/kotlin/com/compiler/server/service/KotlinProjectExecutor.kt +++ b/src/main/kotlin/com/compiler/server/service/KotlinProjectExecutor.kt @@ -25,7 +25,7 @@ class KotlinProjectExecutor( fun run(project: Project): ExecutionResult { return kotlinEnvironment.environment { environment -> val files = getFilesFrom(project, environment).map { it.kotlinFile } - kotlinCompiler.run(files, environment, project.args) + kotlinCompiler.run(files, environment, project.args, project.userInput) } }