diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index b5b99788a..7f7d14b2f 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -1690,9 +1690,9 @@
-
-
-
+
+
+
@@ -1700,9 +1700,9 @@
-
-
-
+
+
+
diff --git a/settings.gradle.kts b/settings.gradle.kts
index c9ddae1cc..2d7280246 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -30,7 +30,7 @@ dependencyResolutionManagement {
val kotlinVersion: String by extra
val analyzerCommonsVersionStr = "2.12.0.2964"
- val sonarPluginApi = "10.3.0.1951"
+ val sonarPluginApi = "10.11.0.2468"
val slf4jApi = "1.7.30"
create("libs") {
diff --git a/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/KotlinCoreEnvironmentTools.kt b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/KotlinCoreEnvironmentTools.kt
index ce4f7e59e..3927880a6 100644
--- a/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/KotlinCoreEnvironmentTools.kt
+++ b/sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/frontend/KotlinCoreEnvironmentTools.kt
@@ -43,12 +43,13 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
import java.io.File
+import java.net.URLClassLoader
class Environment(
val classpath: List,
kotlinLanguageVersion: LanguageVersion,
javaLanguageVersion: JvmTarget = JvmTarget.JVM_1_8,
- numberOfThreads: Int? = null
+ numberOfThreads: Int? = null,
) {
val disposable = Disposer.newDisposable()
val configuration = compilerConfiguration(classpath, kotlinLanguageVersion, javaLanguageVersion, numberOfThreads)
@@ -114,6 +115,9 @@ fun compilerConfiguration(
numberOfThreads: Int?,
): CompilerConfiguration {
val classpathFiles = classpath.map(::File)
+
+ println(version(classpathFiles))
+
val versionSettings = LanguageVersionSettingsImpl(
languageVersion,
ApiVersion.createByLanguageVersion(languageVersion),
@@ -128,3 +132,22 @@ fun compilerConfiguration(
}
}
+fun version(classpathFiles: List): String {
+ class Loader(classpath: List) : URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), null) {
+ override fun loadClass(name: String): Class<*> {
+ if (name.startsWith("java.lang.")) {
+ return super.loadClass(name)
+ }
+ val loadedClass = findLoadedClass(name)
+ if (loadedClass != null) {
+ return loadedClass
+ }
+ return findClass(name);
+ }
+ }
+ Loader(classpathFiles).use {
+ // FIXME ClassNotFoundException, NoSuchFieldException
+ val kotlinVersion = it.loadClass("kotlin.KotlinVersion").getField("CURRENT").get(null)
+ return kotlinVersion.javaClass.getMethod("toString").invoke(kotlinVersion).toString()
+ }
+}
diff --git a/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/KotlinSensor.kt b/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/KotlinSensor.kt
index f8740ac2e..87c9b01ee 100644
--- a/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/KotlinSensor.kt
+++ b/sonar-kotlin-plugin/src/main/java/org/sonarsource/kotlin/plugin/KotlinSensor.kt
@@ -31,6 +31,7 @@ import org.sonar.api.issue.NoSonarFilter
import org.sonar.api.measures.FileLinesContextFactory
import org.sonarsource.analyzer.commons.ProgressReport
import org.sonarsource.kotlin.api.checks.hasCacheEnabled
+import org.sonarsource.kotlin.api.common.KOTLIN_LANGUAGE_VERSION
import org.sonarsource.kotlin.api.common.KotlinLanguage
import org.sonarsource.kotlin.api.common.measureDuration
import org.sonarsource.kotlin.api.frontend.bindingContext
@@ -67,6 +68,13 @@ class KotlinSensor(
.name(language.name + " Sensor")
}
+ override fun execute(sensorContext: SensorContext) {
+ sensorContext.config()[KOTLIN_LANGUAGE_VERSION].ifPresent { value ->
+ sensorContext.addTelemetryProperty("kotlin.languageVersion", value)
+ }
+ super.execute(sensorContext)
+ }
+
override fun getExecuteContext(
sensorContext: SensorContext,
filesToAnalyze: Iterable,