/*
* 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.
val rootDisposable = Disposer.newDisposable()
- val compilerConfiguration = CompilerConfiguration().apply {
+ try {
- put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
- put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName)
- put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile)
- put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false)
+ val compilerConfiguration = CompilerConfiguration().apply {
- // Load Current Class loader to Compilation Class loader
- val currentClassLoader = classpathFromClasspathProperty()
- currentClassLoader?.forEach {
- add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it))
- }
+ put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
+ put(CommonConfigurationKeys.MODULE_NAME, blueprintSourceCode.moduleName)
+ put(JVMConfigurationKeys.OUTPUT_JAR, compiledJarFile)
+ put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, false)
- // Add all Kotlin Sources
- addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources)
+ // Load Current Class loader to Compilation Class loader
+ val currentClassLoader = classpathFromClasspathProperty()
+ currentClassLoader?.forEach {
+ add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(it))
+ }
- languageVersionSettings = LanguageVersionSettingsImpl(
- LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true)
- )
- }
+ // Add all Kotlin Sources
+ addKotlinSourceRoots(blueprintSourceCode.blueprintKotlinSources)
- //log.info("Executing with compiler configuration : $compilerConfiguration")
+ languageVersionSettings = LanguageVersionSettingsImpl(
+ LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlags.skipMetadataVersionCheck to true)
+ )
+ }
- environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration,
- EnvironmentConfigFiles.JVM_CONFIG_FILES)
+ //log.info("Executing with compiler configuration : $compilerConfiguration")
- // Compile Kotlin Sources
- val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
+ environment = KotlinCoreEnvironment.createForProduction(rootDisposable, compilerConfiguration,
+ EnvironmentConfigFiles.JVM_CONFIG_FILES)
- val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector,
- environment.configuration.languageVersionSettings)
+ // Compile Kotlin Sources
+ val compiled = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
- if (analyzerWithCompilerReport.hasErrors()) {
- return ResultWithDiagnostics.Failure(messageCollector.diagnostics)
+ val analyzerWithCompilerReport = AnalyzerWithCompilerReport(messageCollector,
+ environment.configuration.languageVersionSettings)
+
+ if (analyzerWithCompilerReport.hasErrors()) {
+ return ResultWithDiagnostics.Failure(messageCollector.diagnostics)
+ }
+ } finally {
+ rootDisposable.dispose()
}
}
/*
* 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.
import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
import org.springframework.stereotype.Service
import java.io.File
+import java.util.*
import kotlin.script.experimental.api.ResultValue
import kotlin.script.experimental.api.resultOrNull
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
return returnValue?.value!! as T
}
+ override fun <T> scriptInstance(scriptClassName: String): T {
+ val args = ArrayList<Any?>()
+ return Thread.currentThread().contextClassLoader.loadClass(scriptClassName).constructors
+ .single().newInstance(*args.toArray()) as T
+ }
}
fun getBluePrintScriptsJarName(blueprintContext: BluePrintContext): String {