Sorting default jvm props and basic implementations
This commit is contained in:
@@ -22,6 +22,8 @@ class PropertiesBuilderDelegate<T: PropertiesBuilder>(val kclass: KClass<T>) {
|
||||
|
||||
inline fun <reified T : PropertiesBuilder> propertiesBuilder() = PropertiesBuilderDelegate(T::class)
|
||||
|
||||
fun buildScriptingProperties(body: ScriptingProperties.() -> Unit): ChainedPropertyBag =
|
||||
ScriptingProperties(body).build()
|
||||
|
||||
open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
|
||||
|
||||
@@ -31,12 +33,13 @@ open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
|
||||
|
||||
init {
|
||||
body()
|
||||
setup() // TODO: does it work?
|
||||
}
|
||||
|
||||
open fun setup() {}
|
||||
|
||||
internal fun makePropertyBag(): ChainedPropertyBag =
|
||||
ChainedPropertyBag.createOptimized(parentPropertiesBag ?: parentPropertiesBuilder?.makePropertyBag(), data)
|
||||
fun build(): ChainedPropertyBag =
|
||||
ChainedPropertyBag.createOptimized(parentPropertiesBag ?: parentPropertiesBuilder?.build(), data)
|
||||
|
||||
// --------------------------
|
||||
// DSL:
|
||||
@@ -75,6 +78,7 @@ open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
|
||||
// inclusion:
|
||||
|
||||
fun include(props: ScriptingProperties) {
|
||||
props.setup()
|
||||
data.putAll(props.data)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ open class ChainedPropertyBag internal constructor(private val parent: ChainedPr
|
||||
constructor(vararg pairs: Pair<TypedKey<*>, Any?>) : this(null, pairs.asIterable())
|
||||
|
||||
fun cloneWithNewParent(newParent: ChainedPropertyBag?): ChainedPropertyBag = when {
|
||||
this == newParent -> this
|
||||
newParent == null -> this
|
||||
parent == null -> createOptimized(newParent, data)
|
||||
else -> createOptimized(parent.cloneWithNewParent(newParent), data)
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.script.experimental.jvmhost
|
||||
|
||||
import kotlin.script.experimental.api.ScriptEvaluator
|
||||
import kotlin.script.experimental.host.BasicScriptingHost
|
||||
|
||||
open class BasicJvmScriptingHost(
|
||||
compiler: JvmScriptCompiler = JvmScriptCompiler(),
|
||||
evaluator: ScriptEvaluator = BasicJvmScriptEvaluator()
|
||||
) : BasicScriptingHost(compiler, evaluator)
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
package kotlin.script.experimental.jvmhost.impl
|
||||
@@ -41,12 +41,12 @@ import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
import kotlin.script.experimental.host.getMergedScriptText
|
||||
import kotlin.script.experimental.jvm.JvmDependency
|
||||
import kotlin.script.experimental.jvm.JvmScriptCompileConfigurationProperties
|
||||
import kotlin.script.experimental.jvm.JvmScriptEvaluationEnvironmentProperties
|
||||
import kotlin.script.experimental.jvm.KJVMCompilerProxy
|
||||
import kotlin.script.experimental.jvm.impl.BridgeDependenciesResolver
|
||||
import kotlin.script.experimental.jvmhost.JvmScriptEvaluationEnvironmentProperties
|
||||
import kotlin.script.experimental.jvmhost.KJvmCompilerProxy
|
||||
import kotlin.script.experimental.util.chainPropertyBags
|
||||
|
||||
class KJVMCompiledScript<out ScriptBase : Any>(
|
||||
class KJvmCompiledScript<out ScriptBase : Any>(
|
||||
override val configuration: ScriptCompileConfiguration,
|
||||
val generationState: GenerationState,
|
||||
val scriptClassFQName: String
|
||||
@@ -70,7 +70,7 @@ class KJVMCompiledScript<out ScriptBase : Any>(
|
||||
}
|
||||
}
|
||||
|
||||
class KJVMCompilerImpl(val hostEnvironment: ScriptingEnvironment) : KJVMCompilerProxy {
|
||||
class KJvmCompilerImpl(val hostEnvironment: ScriptingEnvironment) : KJvmCompilerProxy {
|
||||
|
||||
override fun compile(
|
||||
script: ScriptSource,
|
||||
@@ -192,7 +192,7 @@ class KJVMCompilerImpl(val hostEnvironment: ScriptingEnvironment) : KJVMCompiler
|
||||
org.jetbrains.kotlin.codegen.CompilationErrorHandler.THROW_EXCEPTION
|
||||
)
|
||||
|
||||
val res = KJVMCompiledScript<Any>(updatedScriptCompileConfiguration, generationState, scriptFileName.capitalize())
|
||||
val res = KJvmCompiledScript<Any>(updatedScriptCompileConfiguration, generationState, scriptFileName.capitalize())
|
||||
|
||||
return ResultWithDiagnostics.Success(res, messageCollector.diagnostics)
|
||||
} catch (ex: Throwable) {
|
||||
|
||||
+18
-15
@@ -1,18 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
package kotlin.script.experimental.jvmhost
|
||||
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.jvm.defaultJvmScriptingEnvironment
|
||||
import kotlin.script.experimental.jvmhost.impl.KJvmCompilerImpl
|
||||
import kotlin.script.experimental.util.chainPropertyBags
|
||||
|
||||
interface CompiledJvmScriptsCache {
|
||||
fun get(script: ScriptSource, configuration: ScriptCompileConfiguration): CompiledScript<*>?
|
||||
fun store(compiledScript: CompiledScript<*>, configuration: ScriptCompileConfiguration)
|
||||
|
||||
object NoCache : CompiledJvmScriptsCache {
|
||||
override fun get(script: ScriptSource, configuration: ScriptCompileConfiguration): CompiledScript<*>? = null
|
||||
override fun store(compiledScript: CompiledScript<*>, configuration: ScriptCompileConfiguration) {}
|
||||
}
|
||||
}
|
||||
|
||||
open class JvmScriptCompiler(
|
||||
val compilerProxy: KJVMCompilerProxy,
|
||||
val cache: CompiledJvmScriptsCache
|
||||
hostEnvironment: ScriptingEnvironment = defaultJvmScriptingEnvironment,
|
||||
val compilerProxy: KJvmCompilerProxy = KJvmCompilerImpl(hostEnvironment.cloneWithNewParent(defaultJvmScriptingEnvironment)),
|
||||
val cache: CompiledJvmScriptsCache = CompiledJvmScriptsCache.NoCache
|
||||
) : ScriptCompiler {
|
||||
|
||||
override suspend operator fun invoke(
|
||||
@@ -48,12 +61,7 @@ open class JvmScriptCompiler(
|
||||
}
|
||||
}
|
||||
|
||||
interface CompiledJvmScriptsCache {
|
||||
fun get(script: ScriptSource, configuration: ScriptCompileConfiguration): CompiledScript<*>?
|
||||
fun store(compiledScript: CompiledScript<*>, configuration: ScriptCompileConfiguration)
|
||||
}
|
||||
|
||||
interface KJVMCompilerProxy {
|
||||
interface KJvmCompilerProxy {
|
||||
fun compile(
|
||||
script: ScriptSource,
|
||||
scriptDefinition: ScriptDefinition,
|
||||
@@ -61,8 +69,3 @@ interface KJVMCompilerProxy {
|
||||
): ResultWithDiagnostics<CompiledScript<*>>
|
||||
}
|
||||
|
||||
class DummyCompiledJvmScriptCache : CompiledJvmScriptsCache {
|
||||
override fun get(script: ScriptSource, configuration: ScriptCompileConfiguration): CompiledScript<*>? = null
|
||||
override fun store(compiledScript: CompiledScript<*>, configuration: ScriptCompileConfiguration) {}
|
||||
}
|
||||
|
||||
+10
-3
@@ -1,13 +1,20 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.script.experimental.jvm.runners
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvmhost
|
||||
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.util.typedKey
|
||||
|
||||
open class BasicJvmScriptEvaluator() : ScriptEvaluator {
|
||||
object JvmScriptEvaluationEnvironmentProperties {
|
||||
val baseClassLoader by typedKey<ClassLoader?>(Thread.currentThread().contextClassLoader)
|
||||
}
|
||||
|
||||
open class BasicJvmScriptEvaluator : ScriptEvaluator {
|
||||
|
||||
override suspend operator fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
package kotlin.script.experimental.jvm.compat
|
||||
|
||||
import kotlin.script.dependencies.ScriptContents
|
||||
import kotlin.script.dependencies.ScriptDependenciesResolver
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -16,8 +16,8 @@ import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.JvmDependency
|
||||
import kotlin.script.experimental.jvm.mapToLegacyScriptReportPosition
|
||||
import kotlin.script.experimental.jvm.mapToLegacyScriptReportSeverity
|
||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportPosition
|
||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportSeverity
|
||||
|
||||
class BridgeDependenciesResolver(
|
||||
val scriptDefinition: ScriptDefinition,
|
||||
|
||||
@@ -6,10 +6,16 @@
|
||||
package kotlin.script.experimental.jvm
|
||||
|
||||
import org.jetbrains.kotlin.script.util.scriptCompilationClasspathFromContext
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.ScriptDefinitionProperties
|
||||
import kotlin.script.experimental.api.ScriptDependency
|
||||
import kotlin.script.experimental.api.ScriptingProperties
|
||||
import kotlin.script.experimental.api.addToListProperty
|
||||
|
||||
class JvmDependency(val classpath: List<File>) : ScriptDependency {
|
||||
constructor(vararg classpathEntries: File) : this(classpathEntries.asList())
|
||||
}
|
||||
|
||||
fun ScriptingProperties.jvmDependenciesFromCurrentContext(vararg libraries: String, wholeClasspath: Boolean = false) {
|
||||
jvmDependenciesFromClassloader(*libraries, wholeClasspath = wholeClasspath)
|
||||
}
|
||||
|
||||
+8
-10
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.PropertiesGroup
|
||||
import kotlin.script.experimental.api.ScriptingProperties
|
||||
import kotlin.script.experimental.util.typedKey
|
||||
|
||||
val jvmJavaHomeParams = with(JvmScriptCompileConfigurationProperties) {
|
||||
listOf(javaHomeDir to File(System.getProperty("java.home")))
|
||||
object JvmScriptCompileConfigurationProperties : PropertiesGroup {
|
||||
val javaHomeDir by typedKey<File>(File(System.getProperty("java.home")))
|
||||
}
|
||||
|
||||
object JvmJavaHomeScriptingProperties : ScriptingProperties(
|
||||
{
|
||||
JvmScriptCompileConfigurationProperties.javaHomeDir(File(System.getProperty("java.home")))
|
||||
})
|
||||
|
||||
val jvmJavaHomeScriptingProperties = JvmJavaHomeScriptingProperties
|
||||
|
||||
val ScriptingProperties.jvmCompileConfiguration get() = JvmScriptCompileConfigurationProperties
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.PropertiesGroup
|
||||
import kotlin.script.experimental.api.ScriptDependency
|
||||
import kotlin.script.experimental.api.ScriptingProperties
|
||||
import kotlin.script.experimental.util.typedKey
|
||||
|
||||
object JvmScriptCompileConfigurationProperties : PropertiesGroup {
|
||||
val javaHomeDir by typedKey<File>()
|
||||
}
|
||||
|
||||
val ScriptingProperties.jvmCompileConfiguration get() = JvmScriptCompileConfigurationProperties
|
||||
|
||||
class JvmDependency(val classpath: List<File>) : ScriptDependency {
|
||||
constructor(vararg classpathEntries: File) : this(classpathEntries.asList())
|
||||
}
|
||||
|
||||
@@ -9,6 +9,15 @@ import java.net.URLClassLoader
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.api.*
|
||||
|
||||
private object DefaultJvmScriptingEnvironmentPropertiesBuilder : ScriptingProperties() {
|
||||
init {
|
||||
ScriptingEnvironmentProperties.getScriptingClass(JvmGetScriptingClass())
|
||||
}
|
||||
}
|
||||
|
||||
val defaultJvmScriptingEnvironment = DefaultJvmScriptingEnvironmentPropertiesBuilder.build()
|
||||
|
||||
|
||||
class JvmGetScriptingClass : GetScriptingClass {
|
||||
|
||||
private var dependencies: List<ScriptDependency>? = null
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
|
||||
package kotlin.script.experimental.jvm
|
||||
|
||||
import kotlin.script.experimental.api.ScriptEvaluator
|
||||
import kotlin.script.experimental.host.BasicScriptingHost
|
||||
import kotlin.script.experimental.util.typedKey
|
||||
|
||||
open class JvmBasicScriptingHost(
|
||||
compiler: JvmScriptCompiler,
|
||||
evaluator: ScriptEvaluator
|
||||
) : BasicScriptingHost(compiler, evaluator)
|
||||
|
||||
object JvmScriptEvaluationEnvironmentProperties {
|
||||
val baseClassLoader by typedKey<ClassLoader?>()
|
||||
}
|
||||
Reference in New Issue
Block a user