-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TelemetryData at KotlinSensor level, passed to the MetricVisitor
- Loading branch information
1 parent
ba412e6
commit 0ff8570
Showing
8 changed files
with
169 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
sonar-kotlin-api/src/main/java/org/sonarsource/kotlin/api/telemetry/TelemetryData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* SonarSource Kotlin | ||
* Copyright (C) 2018-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.kotlin.api.telemetry | ||
|
||
import org.sonar.api.batch.sensor.SensorContext | ||
import org.sonar.api.utils.Version | ||
|
||
private object VersionConstants { | ||
val MIN_SQS_SUPPORTED: Version = Version.create(10, 9) | ||
} | ||
|
||
class TelemetryData { | ||
var hasAndroidImports = false | ||
var hasAndroidImportsReportedAsTrue = false | ||
|
||
fun report(sensorContext: SensorContext) { | ||
if (hasAndroidImportsReportedAsTrue) return | ||
val isTelemetrySupported = sensorContext.runtime().apiVersion.isGreaterThanOrEqual(VersionConstants.MIN_SQS_SUPPORTED) | ||
if (!isTelemetrySupported) return | ||
sensorContext.addTelemetryProperty("kotlin.android", if (hasAndroidImports) "1" else "0") | ||
hasAndroidImportsReportedAsTrue = hasAndroidImports | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
sonar-kotlin-api/src/test/java/org/sonarsource/kotlin/api/telemetry/TelemetryDataTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SonarSource Kotlin | ||
* Copyright (C) 2018-2025 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the Sonar Source-Available License for more details. | ||
* | ||
* You should have received a copy of the Sonar Source-Available License | ||
* along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
*/ | ||
package org.sonarsource.kotlin.api.telemetry | ||
|
||
import io.mockk.every | ||
import io.mockk.spyk | ||
import org.junit.jupiter.api.Test | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.sonar.api.batch.sensor.SensorContext | ||
import org.sonar.api.batch.sensor.internal.SensorContextTester | ||
import java.nio.file.Path | ||
|
||
class TelemetryDataTest { | ||
@Test | ||
fun hasAndroidImportsReportedAsTrue() { | ||
val data = TelemetryData() | ||
assertFalse(data.hasAndroidImports) | ||
assertFalse(data.hasAndroidImportsReportedAsTrue) | ||
data.hasAndroidImports = false | ||
assertFalse(data.hasAndroidImportsReportedAsTrue) | ||
val sensorContext = SensorContextTester.create(Path.of(".")) | ||
data.report(sensorContext) | ||
assertFalse(data.hasAndroidImportsReportedAsTrue) | ||
data.hasAndroidImports = true | ||
data.report(sensorContext) | ||
assertTrue(data.hasAndroidImportsReportedAsTrue) | ||
data.hasAndroidImports = false | ||
data.report(sensorContext) | ||
assertTrue(data.hasAndroidImportsReportedAsTrue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters