Skip to content

Commit

Permalink
Change redirection call signature to enable Java interop.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jun 10, 2020
1 parent f49a421 commit cf98273
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.io.StringWriter
import java.util.Properties

group = "com.github.cs125-illinois"
version = "2020.6.0"
version = "2020.6.1"

plugins {
kotlin("jvm")
Expand Down
19 changes: 12 additions & 7 deletions core/src/main/kotlin/Sandbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type

private typealias SandboxCallableArguments<T> = (Pair<ClassLoader, (() -> Unit) -> Pair<String, String>>) -> T
private typealias SandboxCallableArguments<T> = (Pair<ClassLoader, (() -> Any?) -> Sandbox.RedirectedOutput>) -> T

object Sandbox {
@JsonClass(generateAdapter = true)
class ClassLoaderConfiguration(
val whitelistedClasses: Set<String> = DEFAULT_WHITELISTED_CLASSES,
blacklistedClasses: Set<String> = DEFAULT_BLACKLISTED_CLASSES,
unsafeExceptions: Set<String> = DEFAULT_UNSAFE_EXCEPTIONS,
isolatedClasses: Set<String> = DEFAULT_ISOLATED_CLASSES
isolatedClasses: Set<String> = DEFAULT_ISOLATED_CLASSES,
val isWhiteList: Boolean? = null
) {
val blacklistedClasses = blacklistedClasses.union(PERMANENTLY_BLACKLISTED_CLASSES)
val unsafeExceptions = unsafeExceptions.union(ALWAYS_UNSAFE_EXCEPTIONS)
Expand Down Expand Up @@ -619,7 +620,8 @@ object Sandbox {
}
}

private val isWhiteList = whitelistedClasses.isNotEmpty()
private val isWhiteList = classLoaderConfiguration.isWhiteList ?: whitelistedClasses.isNotEmpty()

private fun delegateClass(name: String): Class<*> {
val klass = super.loadClass(name)
loadedClasses.add(name)
Expand Down Expand Up @@ -1223,18 +1225,21 @@ object Sandbox {
}
}

data class RedirectedOutput(val stdout: String, val stderr: String, val returned: Any?)

@JvmStatic
fun redirectOutput(block: () -> Unit): Pair<String, String> {
fun redirectOutput(block: () -> Any?): RedirectedOutput {
val confinedTask = confinedTaskByThreadGroup() ?: check { "should only be used from a confined task" }
check(!confinedTask.redirectingOutput) { "can't nest calls to redirectOutput" }

confinedTask.redirectingOutput = true
block()
val returned = block()
confinedTask.redirectingOutput = false

val toReturn = Pair(
val toReturn = RedirectedOutput(
confinedTask.redirectedOutputLines[TaskResults.OutputLine.Console.STDOUT].toString(),
confinedTask.redirectedOutputLines[TaskResults.OutputLine.Console.STDERR].toString()
confinedTask.redirectedOutputLines[TaskResults.OutputLine.Console.STDERR].toString(),
returned
)
confinedTask.redirectedOutputLines[TaskResults.OutputLine.Console.STDOUT] = StringBuilder()
confinedTask.redirectedOutputLines[TaskResults.OutputLine.Console.STDERR] = StringBuilder()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/server/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import edu.illinois.cs.cs125.jeed.core.moshi.TemplatedSourceResult

@JsonClass(generateAdapter = true)
class CompletedTasks(
var snippet: Snippet? = null,
var template: TemplatedSourceResult? = null,
var snippet: Snippet? = null,
var compilation: CompiledSourceResult? = null,
var kompilation: CompiledSourceResult? = null,
var checkstyle: CheckstyleResults? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2020.5.6
version=2020.6.0

0 comments on commit cf98273

Please sign in to comment.