@@ -43,12 +43,13 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
43
43
import org.jetbrains.kotlin.resolve.BindingContext
44
44
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
45
45
import java.io.File
46
+ import java.net.URLClassLoader
46
47
47
48
class Environment (
48
49
val classpath : List <String >,
49
50
kotlinLanguageVersion : LanguageVersion ,
50
51
javaLanguageVersion : JvmTarget = JvmTarget .JVM_1_8 ,
51
- numberOfThreads : Int? = null
52
+ numberOfThreads : Int? = null ,
52
53
) {
53
54
val disposable = Disposer .newDisposable()
54
55
val configuration = compilerConfiguration(classpath, kotlinLanguageVersion, javaLanguageVersion, numberOfThreads)
@@ -114,6 +115,9 @@ fun compilerConfiguration(
114
115
numberOfThreads : Int? ,
115
116
): CompilerConfiguration {
116
117
val classpathFiles = classpath.map(::File )
118
+
119
+ println (version(classpathFiles))
120
+
117
121
val versionSettings = LanguageVersionSettingsImpl (
118
122
languageVersion,
119
123
ApiVersion .createByLanguageVersion(languageVersion),
@@ -128,3 +132,22 @@ fun compilerConfiguration(
128
132
}
129
133
}
130
134
135
+ fun version (classpathFiles : List <File >): String {
136
+ class Loader (classpath : List <File >) : URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), null ) {
137
+ override fun loadClass (name : String ): Class <* > {
138
+ if (name.startsWith(" java.lang." )) {
139
+ return super .loadClass(name)
140
+ }
141
+ val loadedClass = findLoadedClass(name)
142
+ if (loadedClass != null ) {
143
+ return loadedClass
144
+ }
145
+ return findClass(name);
146
+ }
147
+ }
148
+ Loader (classpathFiles).use {
149
+ // FIXME ClassNotFoundException, NoSuchFieldException
150
+ val kotlinVersion = it.loadClass(" kotlin.KotlinVersion" ).getField(" CURRENT" ).get(null )
151
+ return kotlinVersion.javaClass.getMethod(" toString" ).invoke(kotlinVersion).toString()
152
+ }
153
+ }
0 commit comments