Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry #474

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1690,19 +1690,19 @@
<sha256 value="f31fc4ec929a3734b2d394edb4ea6dea50e24c95547dcad0ed137d7917f4052a" origin="Verified"/>
</artifact>
</component>
<component group="org.sonarsource.api.plugin" name="sonar-plugin-api" version="10.3.0.1951">
<artifact name="sonar-plugin-api-10.3.0.1951.jar">
<sha256 value="0d77abf571e335b0928592cc6184a695976ba3c351ec79f08c0094678533dbdb" origin="Verified"/>
<component group="org.sonarsource.api.plugin" name="sonar-plugin-api" version="10.11.0.2468">
<artifact name="sonar-plugin-api-10.11.0.2468.jar">
<sha256 value="ffc6f029c3802483eaca7fd1e670665647324052237909f2f136edb4b748b213" origin="Verified"/>
</artifact>
</component>
<component group="org.sonarsource.api.plugin" name="sonar-plugin-api" version="9.14.0.375">
<artifact name="sonar-plugin-api-9.14.0.375.jar">
<sha256 value="ca679099e12bb6a797b60ad35954f4d0cb0b87b136a96f74245745118256e3df" origin="Verified"/>
</artifact>
</component>
<component group="org.sonarsource.api.plugin" name="sonar-plugin-api-test-fixtures" version="10.3.0.1951">
<artifact name="sonar-plugin-api-test-fixtures-10.3.0.1951.jar">
<sha256 value="907f05af3824893f40b7c03a0f3b0b86371d92531c328f1810747696083af7c2" origin="Verified"/>
<component group="org.sonarsource.api.plugin" name="sonar-plugin-api-test-fixtures" version="10.11.0.2468">
<artifact name="sonar-plugin-api-test-fixtures-10.11.0.2468.jar">
<sha256 value="c2ff7f0da0d9aeb2d58dc629dbcdec78e0b7fde01431ef18c34da7ac8ef39188" origin="Verified"/>
</artifact>
</component>
<component group="org.sonarsource.orchestrator" name="sonar-orchestrator" version="5.0.0.2065">
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
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)
Expand Down Expand Up @@ -114,6 +115,9 @@ fun compilerConfiguration(
numberOfThreads: Int?,
): CompilerConfiguration {
val classpathFiles = classpath.map(::File)

println(version(classpathFiles))

val versionSettings = LanguageVersionSettingsImpl(
languageVersion,
ApiVersion.createByLanguageVersion(languageVersion),
Expand All @@ -128,3 +132,22 @@ fun compilerConfiguration(
}
}

fun version(classpathFiles: List<File>): String {
class Loader(classpath: List<File>) : 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<InputFile>,
Expand Down