Consolidate resolving in the new lib, deprecate it in script-util
also deprecate Import and CompileOptions annotations, because they do not seem generic enough. Create specific copie in the main-kts instead.
This commit is contained in:
@@ -29,7 +29,6 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":kotlin-scripting-jvm-host"))
|
||||
compileOnly(project(":kotlin-scripting-dependencies"))
|
||||
compileOnly(project(":kotlin-script-util"))
|
||||
runtime(project(":kotlin-compiler-embeddable"))
|
||||
runtime(project(":kotlin-scripting-compiler-embeddable"))
|
||||
runtime(project(":kotlin-scripting-jvm-host-embeddable"))
|
||||
@@ -38,7 +37,6 @@ dependencies {
|
||||
embedded(project(":kotlin-scripting-jvm")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-jvm-host")) { isTransitive = false }
|
||||
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
||||
embedded(project(":kotlin-script-util")) { isTransitive = false }
|
||||
embedded("org.apache.ivy:ivy:2.5.0")
|
||||
embedded(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
|
||||
embedded(commonDep("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm")) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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 org.jetbrains.kotlin.mainKts
|
||||
|
||||
/**
|
||||
* Import other script(s)
|
||||
*/
|
||||
@Target(AnnotationTarget.FILE)
|
||||
@Repeatable
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Import(vararg val paths: String)
|
||||
|
||||
/**
|
||||
* Compiler options that will be applied on script compilation
|
||||
*
|
||||
* @see [kotlin.script.experimental.api.compilerOptions]
|
||||
*/
|
||||
@Target(AnnotationTarget.FILE)
|
||||
@Repeatable
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class CompilerOptions(vararg val options: String)
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.mainKts.impl
|
||||
|
||||
import org.jetbrains.kotlin.script.util.DependsOn
|
||||
import org.jetbrains.kotlin.script.util.Repository
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
import kotlin.script.experimental.api.flatMapSuccess
|
||||
import kotlin.script.experimental.api.makeFailureResult
|
||||
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.tryAddRepository
|
||||
|
||||
suspend fun resolveFromAnnotations(resolver: ExternalDependenciesResolver, annotations: Iterable<Annotation>): ResultWithDiagnostics<List<File>> {
|
||||
annotations.forEach { annotation ->
|
||||
when (annotation) {
|
||||
is Repository -> {
|
||||
val repositoryCoordinates = with(annotation) { value.takeIf { it.isNotBlank() } ?: url }
|
||||
if (!resolver.tryAddRepository(repositoryCoordinates))
|
||||
return makeFailureResult("Unrecognized repository coordinates: $repositoryCoordinates")
|
||||
}
|
||||
is DependsOn -> {}
|
||||
else -> return makeFailureResult("Unknown annotation ${annotation.javaClass}")
|
||||
}
|
||||
}
|
||||
return annotations.filterIsInstance(DependsOn::class.java).flatMapSuccess { dep ->
|
||||
val artifactCoordinates =
|
||||
if (dep.value.isNotBlank()) dep.value
|
||||
else listOf(dep.groupId, dep.artifactId, dep.version).filter { it.isNotBlank() }.joinToString(":")
|
||||
resolver.resolve(artifactCoordinates)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,19 +7,13 @@ package org.jetbrains.kotlin.mainKts
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.kotlin.mainKts.impl.IvyResolver
|
||||
import org.jetbrains.kotlin.mainKts.impl.resolveFromAnnotations
|
||||
import org.jetbrains.kotlin.script.util.CompilerOptions
|
||||
import org.jetbrains.kotlin.script.util.DependsOn
|
||||
import org.jetbrains.kotlin.script.util.Import
|
||||
import org.jetbrains.kotlin.script.util.Repository
|
||||
import java.io.File
|
||||
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.CompoundDependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.*
|
||||
import kotlin.script.experimental.host.FileBasedScriptSource
|
||||
import kotlin.script.experimental.host.FileScriptSource
|
||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||
@@ -138,7 +132,7 @@ class MainKtsConfigurator : RefineScriptCompilationConfigurationHandler {
|
||||
|
||||
val resolveResult = try {
|
||||
runBlocking {
|
||||
resolveFromAnnotations(resolver, annotations.filter { it is DependsOn || it is Repository })
|
||||
resolver.resolveFromAnnotations( annotations.filter { it is DependsOn || it is Repository })
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
ResultWithDiagnostics.Failure(*diagnostics.toTypedArray(), e.asDiagnostics(path = context.script.locationId))
|
||||
|
||||
Reference in New Issue
Block a user