From ca06d38c5bd81f59101b1b92b170cbdc85392f43 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Fri, 28 Jul 2017 20:05:32 +0300 Subject: [PATCH] script.runtime 1.1.4: Copy new API to kotlin.script.experimental package Minor: Move Environment type alias to resolvers_deprecated.kt file --- .../kotlin/script/dependencies/resolvers.kt | 4 +- .../dependencies/resolvers_deprecated.kt | 2 + .../dependencies/AsyncDependenciesResolver.kt | 34 ++++++++++ .../experimental/dependencies/dependencies.kt | 31 +++++++++ .../experimental/dependencies/resolvers.kt | 63 +++++++++++++++++++ 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 core/script.runtime/src/kotlin/script/experimental/dependencies/AsyncDependenciesResolver.kt create mode 100644 core/script.runtime/src/kotlin/script/experimental/dependencies/dependencies.kt create mode 100644 core/script.runtime/src/kotlin/script/experimental/dependencies/resolvers.kt diff --git a/core/script.runtime/src/kotlin/script/dependencies/resolvers.kt b/core/script.runtime/src/kotlin/script/dependencies/resolvers.kt index 0187f06df27..95c1366d2b8 100644 --- a/core/script.runtime/src/kotlin/script/dependencies/resolvers.kt +++ b/core/script.runtime/src/kotlin/script/dependencies/resolvers.kt @@ -21,8 +21,6 @@ package kotlin.script.dependencies import java.io.File import kotlin.script.dependencies.DependenciesResolver.ResolveResult -typealias Environment = Map - interface DependenciesResolver : ScriptDependenciesResolver { fun resolve(scriptContents: ScriptContents, environment: Environment): ResolveResult @@ -55,7 +53,7 @@ interface ScriptContents { data class Position(val line: Int, val col: Int) } -data class ScriptReport(val message: String, val severity: Severity = ScriptReport.Severity.ERROR, val position: Position? = null) { +data class ScriptReport(val message: String, val severity: Severity = Severity.ERROR, val position: Position? = null) { data class Position(val startLine: Int, val startColumn: Int, val endLine: Int? = null, val endColumn: Int? = null) enum class Severity { ERROR, WARNING, INFO, DEBUG } } diff --git a/core/script.runtime/src/kotlin/script/dependencies/resolvers_deprecated.kt b/core/script.runtime/src/kotlin/script/dependencies/resolvers_deprecated.kt index 27f5bf92ecd..48de540c9ea 100644 --- a/core/script.runtime/src/kotlin/script/dependencies/resolvers_deprecated.kt +++ b/core/script.runtime/src/kotlin/script/dependencies/resolvers_deprecated.kt @@ -21,6 +21,8 @@ package kotlin.script.dependencies import java.util.concurrent.Future import java.util.concurrent.TimeUnit +typealias Environment = Map + interface ScriptDependenciesResolver { enum class ReportSeverity { ERROR, WARNING, INFO, DEBUG } diff --git a/core/script.runtime/src/kotlin/script/experimental/dependencies/AsyncDependenciesResolver.kt b/core/script.runtime/src/kotlin/script/experimental/dependencies/AsyncDependenciesResolver.kt new file mode 100644 index 00000000000..65cd203508f --- /dev/null +++ b/core/script.runtime/src/kotlin/script/experimental/dependencies/AsyncDependenciesResolver.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress("unused") + +package kotlin.script.experimental.dependencies + +import kotlin.script.dependencies.Environment + +interface AsyncDependenciesResolver : DependenciesResolver { + suspend fun resolveAsync( + scriptContents: ScriptContents, environment: Environment + ): DependenciesResolver.ResolveResult + + /* 'resolve' implementation is supposed to invoke resolveAsync in a blocking manner + * To avoid dependency on kotlinx-coroutines-core we leave this method unimplemented + * and provide 'resolve' implementation when loading resolver. + */ + override fun resolve(scriptContents: ScriptContents, environment: Environment): DependenciesResolver.ResolveResult + = /*runBlocking { resolveAsync(scriptContents, environment) } */ throw NotImplementedError() +} \ No newline at end of file diff --git a/core/script.runtime/src/kotlin/script/experimental/dependencies/dependencies.kt b/core/script.runtime/src/kotlin/script/experimental/dependencies/dependencies.kt new file mode 100644 index 00000000000..b3f709c58dd --- /dev/null +++ b/core/script.runtime/src/kotlin/script/experimental/dependencies/dependencies.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.script.experimental.dependencies + +import java.io.File + +data class ScriptDependencies( + val javaHome: File? = null, + val classpath: List = emptyList(), + val imports: List = emptyList(), + val sources: List = emptyList(), + val scripts: List = emptyList() +) { + companion object { + val Empty = ScriptDependencies() + } +} \ No newline at end of file diff --git a/core/script.runtime/src/kotlin/script/experimental/dependencies/resolvers.kt b/core/script.runtime/src/kotlin/script/experimental/dependencies/resolvers.kt new file mode 100644 index 00000000000..120e10676c3 --- /dev/null +++ b/core/script.runtime/src/kotlin/script/experimental/dependencies/resolvers.kt @@ -0,0 +1,63 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress("unused") + +package kotlin.script.experimental.dependencies + +import java.io.File +import kotlin.script.dependencies.Environment +import kotlin.script.dependencies.ScriptDependenciesResolver +import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult + +interface DependenciesResolver : ScriptDependenciesResolver { + fun resolve(scriptContents: ScriptContents, environment: Environment): ResolveResult + + object NoDependencies : DependenciesResolver { + override fun resolve(scriptContents: ScriptContents, environment: Environment) = ScriptDependencies.Empty.asSuccess() + } + + sealed class ResolveResult { + abstract val dependencies: ScriptDependencies? + abstract val reports: List + + data class Success( + override val dependencies: ScriptDependencies, + override val reports: List = listOf() + ) : ResolveResult() + + data class Failure(override val reports: List) : ResolveResult() { + constructor(vararg reports: ScriptReport) : this(reports.asList()) + + override val dependencies: ScriptDependencies? get() = null + } + } +} + +interface ScriptContents { + val file: File? + val annotations: Iterable + val text: CharSequence? + + data class Position(val line: Int, val col: Int) +} + +data class ScriptReport(val message: String, val severity: Severity = Severity.ERROR, val position: Position? = null) { + data class Position(val startLine: Int, val startColumn: Int, val endLine: Int? = null, val endColumn: Int? = null) + enum class Severity { ERROR, WARNING, INFO, DEBUG } +} + +fun ScriptDependencies.asSuccess(): ResolveResult.Success = ResolveResult.Success(this) \ No newline at end of file