diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-17 19:33:45 -0400 |
---|---|---|
committer | Brinda Santh <brindasanth@in.ibm.com> | 2019-09-18 14:51:24 -0400 |
commit | 996d0b3caf7bf767747b8c369d2ccc579711d092 (patch) | |
tree | 71e2f62ef4cd07badc7a308680d3bae61577963c /ms/controllerblueprints/modules/blueprint-core | |
parent | b5abd9e25ce4847d163fc01c560dd9eaad11e79a (diff) |
Simplify script compilation implementation.
Change-Id: Ib0ce35fe843aef73d7ffc3d980e9244941f48914
Issue-ID: CCSDK-1469
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/blueprint-core')
6 files changed, 176 insertions, 385 deletions
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt new file mode 100644 index 000000000..baae3372d --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompileService.kt @@ -0,0 +1,174 @@ +/* + * Copyright © 2019 IBM. + * + * 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.onap.ccsdk.cds.controllerblueprints.core.scripts + +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope +import org.jetbrains.kotlin.cli.common.ExitCode +import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler +import org.jetbrains.kotlin.config.Services +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists +import org.onap.ccsdk.cds.controllerblueprints.core.logger +import java.io.File +import java.net.URLClassLoader +import java.util.* +import kotlin.script.experimental.api.SourceCode +import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty +import kotlin.system.measureTimeMillis + + +open class BluePrintCompileService { + val log = logger(BluePrintCompileService::class) + + companion object { + val classPaths = classpathFromClasspathProperty()?.joinToString(File.pathSeparator) { + it.absolutePath + } + } + + /** Compile the [bluePrintSourceCode] and get the [kClassName] instance for the constructor [args] */ + suspend fun <T> eval(bluePrintSourceCode: BluePrintSourceCode, kClassName: String, + args: ArrayList<Any?>?): T { + /** Compile the source code */ + compile(bluePrintSourceCode) + /** Get the class loader with compiled jar */ + val classLoaderWithDependencies = BluePrintCompileCache.classLoader(bluePrintSourceCode.cacheKey) + /* Create the instance from the class loader */ + return instance(classLoaderWithDependencies, kClassName, args) + } + + /** Compile [bluePrintSourceCode] and put into cache */ + suspend fun compile(bluePrintSourceCode: BluePrintSourceCode) { + //TODO("Include Multiple folders") + val sourcePath = bluePrintSourceCode.blueprintKotlinSources.first() + val compiledJarFile = bluePrintSourceCode.targetJarFile + + /** Check cache is present for the blueprint scripts */ + val hasCompiledCache = BluePrintCompileCache.hasClassLoader(bluePrintSourceCode.cacheKey) + + log.debug("Jar Exists : ${compiledJarFile.exists()}, Regenerate : ${bluePrintSourceCode.regenerate}," + + " Compiled hash(${bluePrintSourceCode.cacheKey}) : $hasCompiledCache") + + if (!compiledJarFile.exists() || bluePrintSourceCode.regenerate || !hasCompiledCache) { + log.info("compiling for cache key(${bluePrintSourceCode.cacheKey})") + coroutineScope { + val timeTaken = measureTimeMillis { + /** Create compile arguments */ + val args = mutableListOf<String>().apply { + add("-no-stdlib") + add("-no-reflect") + add("-module-name") + add(bluePrintSourceCode.moduleName) + add("-cp") + add(classPaths!!) + add(sourcePath) + add("-d") + add(compiledJarFile.absolutePath) + } + val deferredCompile = async { + val k2jvmCompiler = K2JVMCompiler() + /** Construct Arguments */ + val arguments = k2jvmCompiler.createArguments() + parseCommandLineArguments(args, arguments) + val messageCollector = CompilationMessageCollector() + /** Compile with arguments */ + val exitCode: ExitCode = k2jvmCompiler.exec(messageCollector, Services.EMPTY, arguments) + when (exitCode) { + ExitCode.OK -> { + checkFileExists(compiledJarFile) + { "couldn't generate compiled jar(${compiledJarFile.absolutePath})" } + } + else -> { + throw BluePrintException("$exitCode :${messageCollector.errors().joinToString("\n")}") + } + } + } + deferredCompile.await() + } + log.info("compiled in ($timeTaken)mSec for cache key(${bluePrintSourceCode.cacheKey})") + } + } + } + + /** create class [kClassName] instance from [classLoader] */ + fun <T> instance(classLoader: URLClassLoader, kClassName: String, args: ArrayList<Any?>? = arrayListOf()): T { + val kClazz = classLoader.loadClass(kClassName) + ?: throw BluePrintException("failed to load class($kClassName) from current class loader.") + + val instance = if (args.isNullOrEmpty()) { + kClazz.newInstance() + } else { + kClazz.constructors + .single().newInstance(*args.toArray()) + } ?: throw BluePrintException("failed to create class($kClassName) instance for constructor argument($args).") + return instance as T + } +} + +/** Compile source code information */ +open class BluePrintSourceCode : SourceCode { + lateinit var blueprintKotlinSources: MutableList<String> + lateinit var moduleName: String + lateinit var targetJarFile: File + lateinit var cacheKey: String + var regenerate: Boolean = false + + override val text: String + get() = "" + + override val locationId: String? = null + + override val name: String? + get() = moduleName +} + +/** Class to collect compilation Data */ +data class CompiledMessageData( + val severity: CompilerMessageSeverity, + val message: String, + val location: CompilerMessageLocation? +) + +/** Class to collect compilation results */ +class CompilationMessageCollector : MessageCollector { + + private val compiledMessages: MutableList<CompiledMessageData> = arrayListOf() + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { + synchronized(compiledMessages) { + compiledMessages.add(CompiledMessageData(severity, message, location)) + } + } + + override fun hasErrors() = + synchronized(compiledMessages) { + compiledMessages.any { it.severity.isError } + } + + override fun clear() { + synchronized(compiledMessages) { + compiledMessages.clear() + } + } + + fun errors(): List<CompiledMessageData> = compiledMessages.filter { it.severity == CompilerMessageSeverity.ERROR } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt deleted file mode 100644 index 2f131f6f6..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompiledScript.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.onap.ccsdk.cds.controllerblueprints.core.scripts - -import java.io.Serializable -import kotlin.reflect.KClass -import kotlin.script.experimental.api.* - -open class BluePrintCompiledScript<out BCS : String>( - val cacheKey: String, - val scriptCompilationConfiguration: ScriptCompilationConfiguration) : - CompiledScript<BCS>, Serializable { - - lateinit var scriptClassFQName: String - - override val compilationConfiguration: ScriptCompilationConfiguration - get() = scriptCompilationConfiguration - - override suspend fun getClass(scriptEvaluationConfiguration: ScriptEvaluationConfiguration?) - : ResultWithDiagnostics<KClass<*>> = try { - - /** Get the class loader from the cache */ - val classLoaderWithDependencies = BluePrintCompileCache.classLoader(cacheKey) - - val clazz = classLoaderWithDependencies.loadClass(scriptClassFQName).kotlin - clazz.asSuccess() - } catch (e: Throwable) { - ResultWithDiagnostics.Failure( - ScriptDiagnostic( - "Unable to instantiate class $scriptClassFQName", - exception = e - ) - ) - } - -} - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt deleted file mode 100644 index 546631240..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintCompilerProxy.kt +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.onap.ccsdk.cds.controllerblueprints.core.scripts - -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys -import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoots -import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback -import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity -import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler -import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot -import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer -import org.jetbrains.kotlin.config.* -import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists -import org.slf4j.LoggerFactory -import kotlin.script.experimental.api.* -import kotlin.script.experimental.host.ScriptingHostConfiguration -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty -import kotlin.script.experimental.jvmhost.KJvmCompilerProxy - -open class BluePrintsCompilerProxy(private val hostConfiguration: ScriptingHostConfiguration) : KJvmCompilerProxy { - - private val log = LoggerFactory.getLogger(BluePrintsCompilerProxy::class.java)!! - - override fun compile(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration) - : ResultWithDiagnostics<CompiledScript<*>> { - - val messageCollector = ScriptDiagnosticsMessageCollector() - - fun failure(vararg diagnostics: ScriptDiagnostic): ResultWithDiagnostics.Failure = - ResultWithDiagnostics.Failure(*messageCollector.diagnostics.toTypedArray(), *diagnostics) - - // Compile the Code - try { - - log.trace("Scripting Host Configuration : $hostConfiguration") - - setIdeaIoUseFallback() - - val blueprintSourceCode = script as BluePrintSourceCode - - val compiledJarFile = blueprintSourceCode.targetJarFile - - /** Check cache is present for the blueprint scripts */ - val hasCompiledCache = BluePrintCompileCache.hasClassLoader(blueprintSourceCode.cacheKey) - - log.debug("Jar Exists : ${compiledJarFile.exists()}, Regenerate : ${blueprintSourceCode.regenerate}," + - " Compiled hash(${blueprintSourceCode.cacheKey}) : $hasCompiledCache") - - if (!compiledJarFile.exists() || blueprintSourceCode.regenerate || !hasCompiledCache) { - log.info("compiling for cache key(${blueprintSourceCode.cacheKey})") - - var environment: KotlinCoreEnvironment? = null - - val rootDisposable = Disposer.newDisposable() - - try { - - // Clean the cache, if present - if (hasCompiledCache) { - BluePrintCompileCache.cleanClassLoader(blueprintSourceCode.cacheKey) - } - - val compilerConfiguration = CompilerConfiguration().apply { - - put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) - put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName) - put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile) - put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false) - - // Load Current Class loader to Compilation Class loader - val currentClassLoader = classpathFromClasspathProperty() - currentClassLoader?.forEach { - add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it)) - } - - // Add all Kotlin Sources - addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources) - // for Kotlin 1.3.30 greater - //add(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS, ScriptingCompilerConfigurationComponentRegistrar()) - - languageVersionSettings = LanguageVersionSettingsImpl( - LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true) - ) - } - - //log.info("Executing with compiler configuration : $compilerConfiguration") - - environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration, - EnvironmentConfigFiles.JVM_CONFIG_FILES) - - // Compile Kotlin Sources - val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment) - - val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector, - environment.configuration.languageVersionSettings) - - if (analyzerWithCompilerReport.hasErrors()) { - return ResultWithDiagnostics.Failure(messageCollector.diagnostics) - } - } finally { - rootDisposable.dispose() - } - } - - checkFileExists(compiledJarFile) { "couldn't generate compiled jar(${compiledJarFile.absolutePath})" } - - val compiledScript = BluePrintCompiledScript<String>(blueprintSourceCode.cacheKey, scriptCompilationConfiguration) - - return compiledScript.asSuccess() - - } catch (ex: Throwable) { - return failure(ex.asDiagnostics()) - } - } -} - -class ScriptDiagnosticsMessageCollector : MessageCollector { - - private val _diagnostics = arrayListOf<ScriptDiagnostic>() - - val diagnostics: List<ScriptDiagnostic> get() = _diagnostics - - override fun clear() { - _diagnostics.clear() - } - - override fun hasErrors(): Boolean = - _diagnostics.any { it.severity == ScriptDiagnostic.Severity.ERROR } - - - override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation?) { - val mappedSeverity = when (severity) { - CompilerMessageSeverity.EXCEPTION, - CompilerMessageSeverity.ERROR -> ScriptDiagnostic.Severity.ERROR - CompilerMessageSeverity.STRONG_WARNING, - CompilerMessageSeverity.WARNING -> ScriptDiagnostic.Severity.WARNING - CompilerMessageSeverity.INFO -> ScriptDiagnostic.Severity.INFO - CompilerMessageSeverity.LOGGING -> ScriptDiagnostic.Severity.DEBUG - else -> null - } - if (mappedSeverity != null) { - val mappedLocation = location?.let { - if (it.line < 0 && it.column < 0) null // special location created by CompilerMessageLocation.create - else SourceCode.Location(SourceCode.Position(it.line, it.column)) - } - _diagnostics.add(ScriptDiagnostic(message, mappedSeverity, location?.path, mappedLocation)) - } - } -} - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt deleted file mode 100644 index d35f2b49b..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptingHost.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.onap.ccsdk.cds.controllerblueprints.core.scripts - -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.slf4j.LoggerFactory -import java.util.* -import kotlin.reflect.full.createInstance -import kotlin.script.experimental.api.* -import kotlin.script.experimental.host.BasicScriptingHost -import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration -import kotlin.script.experimental.jvmhost.JvmScriptCompiler -import kotlin.script.experimental.jvmhost.impl.withDefaults - -val blueprintScriptCompiler = JvmScriptCompiler(defaultJvmScriptingHostConfiguration, - BluePrintsCompilerProxy(defaultJvmScriptingHostConfiguration.withDefaults())) - -open class BlueprintScriptingHost(evaluator: ScriptEvaluator) : BasicScriptingHost(blueprintScriptCompiler, evaluator) { - - override fun eval(script: SourceCode, compilationConfiguration: ScriptCompilationConfiguration, - evaluationConfiguration: ScriptEvaluationConfiguration?): ResultWithDiagnostics<EvaluationResult> = - - runInCoroutineContext { - blueprintScriptCompiler(script, compilationConfiguration) - .onSuccess { compiledScript -> - evaluator(compiledScript, evaluationConfiguration ?: ScriptEvaluationConfiguration.Default) - }.onFailure { failedResult -> - val messages = failedResult.reports.joinToString("\n") - throw BluePrintProcessorException(messages) - } - } -} - -open class BluePrintScriptEvaluator(private val scriptClassName: String) : ScriptEvaluator { - - private val log = LoggerFactory.getLogger(BluePrintScriptEvaluator::class.java)!! - - override suspend operator fun invoke(compiledScript: CompiledScript<*>, - scriptEvaluationConfiguration: ScriptEvaluationConfiguration - ): ResultWithDiagnostics<EvaluationResult> = - try { - log.debug("Getting script class name($scriptClassName) from the compiled sources ") - - val bluePrintCompiledScript = compiledScript as BluePrintCompiledScript - bluePrintCompiledScript.scriptClassFQName = scriptClassName - - when (val classResult = compiledScript.getClass(scriptEvaluationConfiguration)) { - is ResultWithDiagnostics.Failure -> classResult - is ResultWithDiagnostics.Success -> { - - val scriptClass = classResult.value - val args = ArrayList<Any?>() - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.providedProperties)?.forEach { - args.add(it.value) - } - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.implicitReceivers)?.let { - args.addAll(it) - } - scriptEvaluationConfiguration.get(ScriptEvaluationConfiguration.constructorArgs)?.let { - args.addAll(it) - } - - val instance = if (args.isNotEmpty()) { - scriptClass.java.constructors.single().newInstance(*args.toArray()) - ?: throw BluePrintProcessorException("failed to create instance from the script") - } else { - scriptClass.createInstance() - } - - log.debug("Created script instance of type ${instance.javaClass}") - - ResultWithDiagnostics.Success(EvaluationResult(ResultValue.Value(scriptClass.qualifiedName!!, - instance, "", instance), - scriptEvaluationConfiguration)) - } - } - } catch (e: Throwable) { - ResultWithDiagnostics.Failure(e.asDiagnostics("Error evaluating script")) - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt deleted file mode 100644 index e01923723..000000000 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsConfiguration.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.onap.ccsdk.cds.controllerblueprints.core.scripts - -import java.io.File -import kotlin.script.experimental.annotations.KotlinScript -import kotlin.script.experimental.api.* -import kotlin.script.experimental.jvm.jvm -import kotlin.script.experimental.jvm.util.classpathFromClasspathProperty - -@KotlinScript( - fileExtension = "cba.kts", - compilationConfiguration = BluePrintScripCompilationConfiguration::class, - displayName = "Controller Blueprint Archive Kotlin Scripts" -) -abstract class BluePrintKotlinScript - -object BluePrintScripCompilationConfiguration : ScriptCompilationConfiguration( - { - jvm { - //classpathFromClassloader(BluePrintScripCompilationConfiguration::class.java.classLoader) - classpathFromClasspathProperty() - } - ide { - acceptedLocations(ScriptAcceptedLocation.Everywhere) - } - - } -) - -open class BluePrintSourceCode : SourceCode { - lateinit var blueprintKotlinSources: MutableList<String> - lateinit var moduleName: String - lateinit var targetJarFile: File - lateinit var cacheKey: String - var regenerate: Boolean = false - - override val text: String - get() = "" - - override val locationId: String? = null - - override val name: String? - get() = moduleName -} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt index 360035327..c067bf3d9 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/scripts/BluePrintScriptsServiceImpl.kt @@ -24,9 +24,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import java.util.* -import kotlin.script.experimental.api.ResultValue -import kotlin.script.experimental.api.resultOrNull -import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate open class BluePrintScriptsServiceImpl : BluePrintScriptsService { @@ -34,14 +31,8 @@ open class BluePrintScriptsServiceImpl : BluePrintScriptsService { val log = logger(BluePrintScriptsServiceImpl::class) override suspend fun <T> scriptInstance(bluePrintSourceCode: BluePrintSourceCode, scriptClassName: String): T { - val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<BluePrintKotlinScript>() - val scriptEvaluator = BluePrintScriptEvaluator(scriptClassName) - - val compiledResponse = BlueprintScriptingHost(scriptEvaluator) - .eval(bluePrintSourceCode, compilationConfiguration, null) - - val returnValue = compiledResponse.resultOrNull()?.returnValue as? ResultValue.Value - return returnValue?.value!! as T + val bluePrintCompileService = BluePrintCompileService() + return bluePrintCompileService.eval(bluePrintSourceCode, scriptClassName, null) } override suspend fun <T> scriptInstance(blueprintBasePath: String, artifactName: String, artifactVersion: String, |