Compare commits

...

1 Commits

Author SHA1 Message Date
Ilya Chernikov
07d1c2335c ~ deprecating script runtime 2021-07-06 18:05:08 +02:00
30 changed files with 79 additions and 44 deletions

View File

@@ -14,12 +14,13 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.dependencies
import java.io.File
@Deprecated("Use new scripting API")
interface KotlinScriptExternalDependencies : Comparable<KotlinScriptExternalDependencies> {
val javaHome: String? get() = null
val classpath: Iterable<File> get() = emptyList()

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.dependencies
@@ -22,8 +22,10 @@ import java.io.File
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
@Deprecated("Use new scripting API")
typealias Environment = Map<String, Any?>
@Deprecated("Use new scripting API")
interface ScriptDependenciesResolver {
enum class ReportSeverity { FATAL, ERROR, WARNING, INFO, DEBUG }
@@ -35,10 +37,13 @@ interface ScriptDependenciesResolver {
): Future<KotlinScriptExternalDependencies?> = PseudoFuture(null)
}
@Deprecated("Use new scripting API")
class BasicScriptDependenciesResolver : ScriptDependenciesResolver
@Deprecated("Use new scripting API")
fun KotlinScriptExternalDependencies?.asFuture(): PseudoFuture<KotlinScriptExternalDependencies?> = PseudoFuture(this)
@Deprecated("Use new scripting API")
class PseudoFuture<T>(private val value: T): Future<T> {
override fun get(): T = value
override fun get(p0: Long, p1: TimeUnit): T = value
@@ -47,6 +52,7 @@ class PseudoFuture<T>(private val value: T): Future<T> {
override fun isCancelled(): Boolean = false
}
@Deprecated("Use new scripting API")
interface ScriptContents {
val file: File?
val annotations: Iterable<Annotation>

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.experimental.dependencies
import kotlin.script.dependencies.Environment
import kotlin.script.dependencies.ScriptContents
@Deprecated("Use new scripting API")
interface AsyncDependenciesResolver : DependenciesResolver {
suspend fun resolveAsync(
scriptContents: ScriptContents, environment: Environment

View File

@@ -18,6 +18,7 @@ package kotlin.script.experimental.dependencies
import java.io.File
@Deprecated("Use new scripting API")
data class ScriptDependencies(
val javaHome: File? = null,
val classpath: List<File> = emptyList(),
@@ -26,6 +27,7 @@ data class ScriptDependencies(
val scripts: List<File> = emptyList()
) {
companion object {
@Suppress("DEPRECATION")
val Empty = ScriptDependencies()
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.experimental.dependencies
@@ -23,6 +23,7 @@ import kotlin.script.dependencies.ScriptContents
import kotlin.script.dependencies.ScriptDependenciesResolver
import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult
@Deprecated("Use new scripting API")
interface DependenciesResolver : ScriptDependenciesResolver {
fun resolve(scriptContents: ScriptContents, environment: Environment): ResolveResult
@@ -47,9 +48,11 @@ interface DependenciesResolver : ScriptDependenciesResolver {
}
}
@Deprecated("Use new scripting API")
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 { FATAL, ERROR, WARNING, INFO, DEBUG }
}
@Deprecated("Use new scripting API")
fun ScriptDependencies.asSuccess(): ResolveResult.Success = ResolveResult.Success(this)

View File

@@ -8,7 +8,7 @@ package kotlin.script.experimental.location
/**
* Describes where script files can be found
*/
@Deprecated("Experimental API")
@Deprecated("Use new scripting API")
enum class ScriptExpectedLocation {
SourcesOnly, // Under sources roots
TestsOnly, // Under test sources roots
@@ -17,7 +17,7 @@ enum class ScriptExpectedLocation {
Everywhere;
}
@Deprecated("Experimental API")
@Deprecated("Use new scripting API")
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class ScriptExpectedLocations(

View File

@@ -16,6 +16,7 @@
package kotlin.script.extensions
@Deprecated("Use new scripting API")
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class SamWithReceiverAnnotations(vararg val annotations: String)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.templates
@@ -22,13 +22,16 @@ import kotlin.reflect.KClass
import kotlin.script.dependencies.ScriptDependenciesResolver
import kotlin.script.experimental.dependencies.DependenciesResolver.NoDependencies
@Deprecated("Use new scripting API")
const val DEFAULT_SCRIPT_FILE_PATTERN = ".*\\.kts"
@Deprecated("Use new scripting API")
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class ScriptTemplateDefinition(val resolver: KClass<out ScriptDependenciesResolver> = NoDependencies::class,
val scriptFilePattern: String = DEFAULT_SCRIPT_FILE_PATTERN)
@Deprecated("Use new scripting API")
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class AcceptedAnnotations(vararg val supportedAnnotationClasses: KClass<out Annotation>)

View File

@@ -3,18 +3,20 @@
* 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("DEPRECATION")
package kotlin.script.templates
import kotlin.reflect.KClass
import kotlin.script.dependencies.Environment
@Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon")
@Deprecated("Use new scripting API")
// Note: all subclasses should provide the same constructor
open class ScriptTemplateAdditionalCompilerArgumentsProvider(val arguments: Iterable<String> = emptyList()) {
open fun getAdditionalCompilerArguments(@Suppress("UNUSED_PARAMETER") environment: Environment?): Iterable<String> = arguments
}
// Should be deprecated as well, but since we don't have replacement as of yet, leaving it as is
@Deprecated("Use new scripting API")
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class ScriptTemplateAdditionalCompilerArguments(

View File

@@ -19,15 +19,18 @@ package kotlin.script.templates.standard
/**
* Basic script definition template without parameters
*/
@Deprecated("Use new scripting API")
public abstract class SimpleScriptTemplate()
/**
* Script definition template with standard argv-like parameter; default for regular kotlin scripts
*/
@Deprecated("Use new scripting API")
public abstract class ScriptTemplateWithArgs(val args: Array<String>)
/**
* Script definition template with generic bindings parameter (String to Object)
*/
@Deprecated("Use new scripting API")
public abstract class ScriptTemplateWithBindings(val bindings: Map<String, Any?>)

View File

@@ -17,14 +17,13 @@ import kotlin.script.experimental.api.refineConfigurationBeforeEvaluate
import kotlin.script.experimental.jvmhost.jsr223.configureProvidedPropertiesFromJsr223Context
import kotlin.script.experimental.jvmhost.jsr223.importAllBindings
import kotlin.script.experimental.jvmhost.jsr223.jsr223
import kotlin.script.templates.standard.ScriptTemplateWithBindings
@Suppress("unused")
@KotlinScript(
compilationConfiguration = KotlinJsr223DefaultScriptCompilationConfiguration::class,
evaluationConfiguration = KotlinJsr223DefaultScriptEvaluationConfiguration::class
)
abstract class KotlinJsr223DefaultScript(val jsr223Bindings: Bindings) : ScriptTemplateWithBindings(jsr223Bindings) {
abstract class KotlinJsr223DefaultScript(val bindings: Bindings) {
private val myEngine: ScriptEngine? get() = bindings[KOTLIN_SCRIPT_ENGINE_BINDINGS_KEY]?.let { it as? ScriptEngine }
@@ -34,7 +33,7 @@ abstract class KotlinJsr223DefaultScript(val jsr223Bindings: Bindings) : ScriptT
fun eval(script: String, newBindings: Bindings): Any? =
withMyEngine {
val savedState =
newBindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY]?.takeIf { it === this.jsr223Bindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY] }
newBindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY]?.takeIf { it === this.bindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY] }
?.apply {
newBindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY] = null
}
@@ -47,10 +46,10 @@ abstract class KotlinJsr223DefaultScript(val jsr223Bindings: Bindings) : ScriptT
fun eval(script: String): Any? =
withMyEngine {
val savedState = jsr223Bindings.remove(KOTLIN_SCRIPT_STATE_BINDINGS_KEY)
val res = it.eval(script, jsr223Bindings)
val savedState = bindings.remove(KOTLIN_SCRIPT_STATE_BINDINGS_KEY)
val res = it.eval(script, bindings)
savedState?.apply {
jsr223Bindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY] = savedState
bindings[KOTLIN_SCRIPT_STATE_BINDINGS_KEY] = savedState
}
res
}

View File

@@ -10,6 +10,7 @@ import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.KJvmReplCompilerBase
import org.junit.Assert
import org.junit.Test
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.api.*
import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvm.BasicJvmReplEvaluator
@@ -17,7 +18,6 @@ import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.experimental.jvm.updateClasspath
import kotlin.script.experimental.jvm.util.classpathFromClass
import kotlin.script.experimental.jvmhost.createJvmScriptDefinitionFromTemplate
import kotlin.script.templates.standard.ScriptTemplateWithArgs
class ReplTest : TestCase() {

View File

@@ -21,6 +21,7 @@ import java.net.URLClassLoader
import java.nio.file.Files
import java.util.concurrent.TimeUnit
import java.util.jar.JarFile
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.api.*
import kotlin.script.experimental.host.BasicScriptingHost
import kotlin.script.experimental.host.FileBasedScriptSource
@@ -31,7 +32,9 @@ import kotlin.script.experimental.jvm.updateClasspath
import kotlin.script.experimental.jvm.util.KotlinJars
import kotlin.script.experimental.jvm.util.classpathFromClass
import kotlin.script.experimental.jvmhost.*
import kotlin.script.templates.standard.SimpleScriptTemplate
@KotlinScript
abstract class SimpleScriptTemplate()
class ScriptingHostTest : TestCase() {

View File

@@ -16,6 +16,9 @@ import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromT
@KotlinScript(fileExtension = "simplescript.kts")
abstract class SimpleScript
@KotlinScript
abstract class ScriptTemplateWithArgs(val args: Array<String>)
val simpleScriptCompilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
updateClasspath(classpathFromClass<SimpleScript>())
}

View File

@@ -2,7 +2,7 @@
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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")
@file:Suppress("unused", "DEPRECATION")
package kotlin.script.experimental.jvm.compat

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package kotlin.script.experimental.jvm.impl
import kotlinx.coroutines.runBlocking
@@ -20,6 +22,7 @@ import kotlin.script.experimental.jvm.JvmDependency
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportPosition
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportSeverity
@Deprecated("Use new scripting API")
class BridgeDependenciesResolver(
val scriptCompilationConfiguration: ScriptCompilationConfiguration,
val onConfigurationUpdated: (SourceCode, ScriptCompilationConfiguration) -> Unit = { _, _ -> },

View File

@@ -17,7 +17,6 @@ import kotlin.script.experimental.jvm.impl.toContainingJarOrNull
import kotlin.script.experimental.jvm.impl.toFileOrNull
import kotlin.script.experimental.jvm.impl.tryGetResourcePathForClass
import kotlin.script.experimental.jvm.impl.tryGetResourcePathForClassByName
import kotlin.script.templates.standard.ScriptTemplateWithArgs
// TODO: consider moving all these utilites to the build-common or some other shared compiler API module
@@ -442,11 +441,12 @@ object KotlinJars {
)
}
@Suppress("DEPRECATION")
val scriptRuntimeOrNull: File? by lazy {
getLib(
KOTLIN_SCRIPT_RUNTIME_JAR_PROPERTY,
KOTLIN_JAVA_SCRIPT_RUNTIME_JAR,
ScriptTemplateWithArgs::class
kotlin.script.templates.standard.ScriptTemplateWithArgs::class
)
}

View File

@@ -11,8 +11,6 @@ import org.jetbrains.kotlin.mainKts.impl.IvyResolver
import java.io.File
import java.nio.ByteBuffer
import java.security.MessageDigest
import kotlin.script.dependencies.ScriptContents
import kotlin.script.dependencies.ScriptDependenciesResolver
import kotlin.script.experimental.annotations.KotlinScript
import kotlin.script.experimental.api.*
import kotlin.script.experimental.dependencies.*
@@ -20,8 +18,6 @@ import kotlin.script.experimental.host.FileBasedScriptSource
import kotlin.script.experimental.host.FileScriptSource
import kotlin.script.experimental.host.ScriptingHostConfiguration
import kotlin.script.experimental.jvm.*
import kotlin.script.experimental.jvm.compat.mapLegacyDiagnosticSeverity
import kotlin.script.experimental.jvm.compat.mapLegacyScriptPosition
import kotlin.script.experimental.jvmhost.CompiledScriptJarsCache
import kotlin.script.experimental.jvmhost.jsr223.configureProvidedPropertiesFromJsr223Context
import kotlin.script.experimental.jvmhost.jsr223.importAllBindings
@@ -109,18 +105,6 @@ class MainKtsConfigurator : RefineScriptCompilationConfigurationHandler {
fun processAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
val diagnostics = arrayListOf<ScriptDiagnostic>()
fun report(severity: ScriptDependenciesResolver.ReportSeverity, message: String, position: ScriptContents.Position?) {
diagnostics.add(
ScriptDiagnostic(
ScriptDiagnostic.unspecifiedError,
message,
mapLegacyDiagnosticSeverity(severity),
context.script.locationId,
mapLegacyScriptPosition(position)
)
)
}
val annotations = context.collectedData?.get(ScriptCollectedData.collectedAnnotations)?.takeIf { it.isNotEmpty() }
?: return context.compilationConfiguration.asSuccess()

View File

@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")
package org.jetbrains.kotlin.script.jsr223
import org.jetbrains.kotlin.cli.common.repl.KOTLIN_SCRIPT_ENGINE_BINDINGS_KEY
@@ -9,9 +11,9 @@ import kotlin.script.templates.standard.ScriptTemplateWithBindings
@Suppress("unused")
@ScriptTemplateDefinition
abstract class KotlinStandardJsr223ScriptTemplate(val jsr223Bindings: Bindings) : ScriptTemplateWithBindings(jsr223Bindings) {
abstract class KotlinStandardJsr223ScriptTemplate(val jsr223Bindings: Bindings) {
private val myEngine: ScriptEngine? get() = bindings[KOTLIN_SCRIPT_ENGINE_BINDINGS_KEY]?.let { it as? ScriptEngine }
private val myEngine: ScriptEngine? get() = jsr223Bindings[KOTLIN_SCRIPT_ENGINE_BINDINGS_KEY]?.let { it as? ScriptEngine }
private inline fun<T> withMyEngine(body: (ScriptEngine) -> T): T =
myEngine?.let(body) ?: throw IllegalStateException("Script engine for `eval` call is not found")

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.definitions
import com.intellij.openapi.fileTypes.LanguageFileType

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.definitions
import com.intellij.openapi.fileTypes.LanguageFileType
@@ -21,7 +23,7 @@ import kotlin.script.experimental.jvm.compat.mapToLegacyExpectedLocations
import kotlin.script.experimental.jvm.impl.BridgeDependenciesResolver
import kotlin.script.experimental.util.getOrError
// temporary trick with passing Any as a template and overwriting it below, TODO: fix after introducing new script definitions hierarchy
@Deprecated("Use new scripting API")
abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinition(Any::class) {
abstract val scriptCompilationConfiguration: ScriptCompilationConfiguration

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.definitions
import java.io.File

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.definitions
import com.intellij.openapi.components.ServiceManager

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.definitions
import org.jetbrains.kotlin.scripting.resolve.KotlinScriptDefinitionFromAnnotatedTemplate

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.resolve
import kotlinx.coroutines.runBlocking
@@ -12,6 +14,7 @@ import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
import kotlin.script.experimental.dependencies.DependenciesResolver
// wraps AsyncDependenciesResolver to provide implementation for synchronous DependenciesResolver::resolve
@Deprecated("Use new scripting API")
class AsyncDependencyResolverWrapper(
override val delegate: AsyncDependenciesResolver
): AsyncDependenciesResolver, DependencyResolverWrapper<AsyncDependenciesResolver> {

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.resolve
import com.intellij.openapi.project.Project

View File

@@ -3,6 +3,8 @@
* 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("DEPRECATION")
package org.jetbrains.kotlin.scripting.resolve
import com.intellij.openapi.application.ApplicationManager

View File

@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.scripting.compiler.plugin.repl.messages.DiagnosticMessageHolder
import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write
import kotlin.script.experimental.dependencies.ScriptDependencies
class ReplCompilerStageHistory(private val state: GenericReplCompilerState) : BasicReplStageHistory<ScriptDescriptor>(state.lock) {
@@ -67,5 +66,6 @@ class GenericReplCompilerState(environment: KotlinCoreEnvironment, override val
val analyzerEngine = ReplCodeAnalyzerBase(environment)
var lastDependencies: ScriptDependencies? = null
@Suppress("DEPRECATION")
var lastDependencies: kotlin.script.experimental.dependencies.ScriptDependencies? = null
}

View File

@@ -17,7 +17,8 @@ import java.util.concurrent.atomic.AtomicInteger
import kotlin.script.experimental.api.SourceCode
import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.templates.standard.ScriptTemplateWithArgs
abstract class ScriptTemplateWithArgs(val args: Array<String>)
class ScriptProviderTest {

View File

@@ -2,7 +2,7 @@
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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")
@file:Suppress("unused", "DEPRECATION")
package org.jetbrains.kotlin.scripting.compiler.test
@@ -44,7 +44,6 @@ import kotlin.script.experimental.host.toScriptSource
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
import kotlin.script.templates.AcceptedAnnotations
import kotlin.script.templates.ScriptTemplateDefinition
import kotlin.script.templates.standard.ScriptTemplateWithArgs
// TODO: the contetnts of this file should go into ScriptTest.kt and replace appropriate xml-based functionality,
// as soon as the the latter is removed from the codebase
@@ -569,6 +568,8 @@ class ThrowingResolver : DependenciesResolver {
}
}
abstract class ScriptTemplateWithArgs(val args: Array<String>)
@ScriptTemplateDefinition(
scriptFilePattern = ".*\\.kts",
resolver = TestKotlinScriptDummyDependenciesResolver::class