Skip to content

Commit

Permalink
Add optional userInput field
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsarkissian committed Apr 1, 2021
1 parent 492f081 commit 21f296d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class KotlinCompiler(

class Compiled(val files: Map<String, ByteArray> = emptyMap(), val mainClass: String? = null)

fun run(files: List<KtFile>, coreEnvironment: KotlinCoreEnvironment, args: String): ExecutionResult {
fun run(files: List<KtFile>, 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()
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/compiler/server/executor/JavaExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class JavaExecutor {
const val EXECUTION_TIMEOUT = 10000L
}

fun execute(args: List<String>): ProgramOutput {
fun execute(args: List<String>, userInput: String = ""): ProgramOutput {
return Runtime.getRuntime().exec(args.toTypedArray()).use {
outputStream.write(userInput.toByteArray())
outputStream.close()

val standardOut = InputStreamReader(this.inputStream).buffered()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/compiler/server/model/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectFile> = listOf(),
val confType: ProjectType = ProjectType.JAVA
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 21f296d

Please sign in to comment.