Skip to content

Commit

Permalink
feat(cli): interactive java support.
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Valdespino <[email protected]>
  • Loading branch information
darvld committed Nov 27, 2023
1 parent fc09961 commit a12dcb2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ dependencies {
}

runtimeIf(enableEspresso, projects.packages.graalvmJvm)
runtimeIf(enableEspresso, projects.packages.graalvmJava)
runtimeIf(enableEspresso, projects.packages.graalvmKt)
runtimeIf(enableLlvm, projects.packages.graalvmLlvm)
runtimeIf(enablePython, projects.packages.graalvmPy)
runtimeIf(enableRuby, projects.packages.graalvmRb)
runtimeIf(enableEspresso, projects.packages.graalvmKt)
runtimeIf(enableWasm, projects.packages.graalvmWasm)

api(libs.picocli)
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/src/main/kotlin/elide/tool/cli/GuestLanguage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ enum class GuestLanguage (
formalName = "JVM",
experimental = true,
unimplemented = true,
extensions = listOf("class"),
mimeTypes = emptyList(),
),

/** Interactive nested Java. */
JAVA (
id = "java",
formalName = "JVM",
experimental = true,
unimplemented = true,
extensions = listOf("java"),
mimeTypes = emptyList(),
),
Expand Down Expand Up @@ -139,6 +149,7 @@ enum class GuestLanguage (

// JVM extension guests
KOTLIN.id -> KOTLIN
JAVA.id -> JAVA
GROOVY.id -> GROOVY
else -> null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ import elide.runtime.plugins.env.EnvConfig.EnvVar
import elide.runtime.plugins.env.EnvConfig.EnvVariableSource.*
import elide.runtime.plugins.env.environment
import elide.runtime.plugins.js.JavaScript
import elide.runtime.plugins.jvm.Jvm
import elide.runtime.plugins.kotlin.Kotlin
import elide.runtime.plugins.vfs.vfs
import elide.tool.cli.*
import elide.tool.cli.GuestLanguage.*
Expand Down Expand Up @@ -1550,22 +1548,28 @@ import elide.tool.project.ProjectManager
logging.debug("Configuring Python VM")
installIntrinsics(intrinsics, GraalVMGuest.PYTHON, versionProp)
}
// install(elide.runtime.plugins.ruby.Ruby) {
// logging.debug("Configuring Ruby VM")
// installIntrinsics(intrinsics, GraalVMGuest.RUBY, versionProp)
// }
install(elide.runtime.plugins.ruby.Ruby) {
logging.debug("Configuring Ruby VM")
installIntrinsics(intrinsics, GraalVMGuest.RUBY, versionProp)
}

(language ?: LanguageSelector()).resolve().forEach { lang ->
when (lang) {
// Secondary Engines: JVM
JVM -> install(Jvm) {
logging.debug("Configuring JVM")
installIntrinsics(intrinsics, GraalVMGuest.JVM, versionProp)
JVM -> {
install(elide.runtime.plugins.jvm.Jvm) {
logging.debug("Configuring JVM")
multithreading = false
}

install(elide.runtime.plugins.java.Java) {
logging.debug("Configuring Java")
}
}

GROOVY -> logging.warn("Groovy runtime plugin is not yet implemented")

KOTLIN -> install(Kotlin) {
KOTLIN -> install(elide.runtime.plugins.kotlin.Kotlin) {
val classpathDir = workdir.cacheDirectory()
.resolve("elide-kotlin-runtime")
.absolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import elide.runtime.plugins.jvm.interop.guestClass
private val byteArray by context.guestClass("[B")

// cached guest exception classes
private val executionControlException by context.spiClass("ExecutionControlException")
private val executionControlException by context.executionControlClass("ExecutionControlException")
private val classInstallException by context.executionControlClass("ClassInstallException")
private val notImplementedException by context.executionControlClass("NotImplementedException")
private val engineTerminationException by context.executionControlClass("EngineTerminationException")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import elide.runtime.core.PolyglotContext
import elide.runtime.core.PolyglotContextBuilder
import elide.runtime.core.extensions.disableOptions
import elide.runtime.core.extensions.enableOptions
import elide.runtime.core.extensions.setOption
import elide.runtime.plugins.AbstractLanguagePlugin

/**
Expand All @@ -48,7 +49,6 @@ import elide.runtime.plugins.AbstractLanguagePlugin
"java.CHA",
"java.HotSwapAPI",
"java.InlineMethodHandle",
"java.MultiThreaded",
"java.Polyglot",
"java.SoftExit",
"java.SplitMethodHandles",
Expand All @@ -62,6 +62,9 @@ import elide.runtime.plugins.AbstractLanguagePlugin

// guest classpath
builder.option("java.Classpath", config.collectClasspath())

// threading
builder.setOption("java.MultiThreaded", config.multithreading)
}

public companion object Plugin : AbstractLanguagePlugin<JvmConfig, Jvm>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ import elide.runtime.plugins.AbstractLanguageConfig
/** Collection of classpath entries passed to Espresso. */
private val classpathEntries: MutableList<String> = mutableListOf()

/**
* Toggle support for multiple threads in the guest context.
*
* When using a context where [Jvm] is installed along other languages that don't support threading, this option
* should be disabled to avoid integration issues.
*/
public var multithreading: Boolean = true

/** Returns a string representation of the classpath to be used by the guest Espresso JVM. */
internal fun collectClasspath(): String {
return classpathEntries.joinToString(CLASSPATH_ENTRY_SEPARATOR)
Expand Down

0 comments on commit a12dcb2

Please sign in to comment.