Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bfe027f

Browse filesBrowse files
Seppli11sonartech
authored andcommitted
SONARPY-2651 Create a separate sensor for dependency telemetry (SonarSource#90)
GitOrigin-RevId: 3fc49656c2a74accbc0e4a0ff42bca426b04154c
1 parent 608ba5a commit bfe027f
Copy full SHA for bfe027f

File tree

Expand file treeCollapse file tree

5 files changed

+92
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+92
-6
lines changed
Open diff view settings
Collapse file
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2011-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
package org.sonar.plugins.python;
18+
19+
import org.sonar.api.batch.sensor.Sensor;
20+
import org.sonar.api.batch.sensor.SensorContext;
21+
import org.sonar.api.batch.sensor.SensorDescriptor;
22+
import org.sonar.plugins.python.dependency.DependencyTelemetry;
23+
24+
public class DependencyTelemetrySensor implements Sensor {
25+
private static final String TXT_LANGUAGE = "txt";
26+
private static final String TOML_LANGUAGE = "toml";
27+
28+
private final SensorTelemetryStorage sensorTelemetryStorage = new SensorTelemetryStorage();
29+
30+
@Override
31+
public void describe(SensorDescriptor descriptor) {
32+
descriptor
33+
.onlyOnLanguages(TXT_LANGUAGE, TOML_LANGUAGE)
34+
.name("Python Dependency Sensor");
35+
}
36+
37+
@Override
38+
public void execute(SensorContext context) {
39+
new DependencyTelemetry(sensorTelemetryStorage, context.fileSystem()).process();
40+
sensorTelemetryStorage.send(context);
41+
}
42+
}
Collapse file

‎python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java‎

Copy file name to clipboardExpand all lines: python-commons/src/main/java/org/sonar/plugins/python/PythonExtensions.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public static void addCommonExtensions(Plugin.Context context) {
7777
IPynbProfile.class,
7878
IPynbSensor.class,
7979
IPynbRuleRepository.class,
80-
OpenSourceRepositoryInfoProvider.class
80+
OpenSourceRepositoryInfoProvider.class,
81+
DependencyTelemetrySensor.class
8182
);
8283

8384
SonarRuntime sonarRuntime = context.getRuntime();
Collapse file

‎python-commons/src/main/java/org/sonar/plugins/python/PythonSensor.java‎

Copy file name to clipboardExpand all lines: python-commons/src/main/java/org/sonar/plugins/python/PythonSensor.java
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.sonar.plugins.python.api.PythonVersionUtils;
4040
import org.sonar.plugins.python.api.SonarLintCache;
4141
import org.sonar.plugins.python.api.caching.CacheContext;
42-
import org.sonar.plugins.python.dependency.DependencyTelemetry;
4342
import org.sonar.plugins.python.editions.OpenSourceRepositoryInfoProvider;
4443
import org.sonar.plugins.python.editions.RepositoryInfoProvider;
4544
import org.sonar.plugins.python.editions.RepositoryInfoProvider.RepositoryInfo;
@@ -155,9 +154,7 @@ public void execute(SensorContext context) {
155154
PythonScanner scanner = new PythonScanner(context, checks, fileLinesContextFactory, noSonarFilter, PythonParser.create(), pythonIndexer);
156155
scanner.execute(pythonFiles, context);
157156

158-
159157
updateDatabricksTelemetry(scanner);
160-
new DependencyTelemetry(sensorTelemetryStorage, context.fileSystem()).process();
161158

162159
sensorTelemetryStorage.send(context);
163160
durationReport.stop();
Collapse file
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2011-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
package org.sonar.plugins.python;
18+
19+
import java.nio.file.Paths;
20+
import org.junit.jupiter.api.Test;
21+
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
22+
import org.sonar.api.batch.sensor.internal.SensorContextTester;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.mockito.Mockito.spy;
26+
import static org.mockito.Mockito.verify;
27+
28+
class DependencyTelemetrySensorTest {
29+
@Test
30+
void testDescribe() {
31+
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor();
32+
new DependencyTelemetrySensor().describe(descriptor);
33+
34+
assertThat(descriptor.name()).isEqualTo("Python Dependency Sensor");
35+
assertThat(descriptor.languages()).containsOnly("txt", "toml");
36+
assertThat(descriptor.type()).isNull();
37+
}
38+
39+
@Test
40+
void testExecute() {
41+
SensorContextTester context = spy(SensorContextTester.create(Paths.get(".")));
42+
new DependencyTelemetrySensor().execute(context);
43+
verify(context).addTelemetryProperty(TelemetryMetricKey.PYTHON_DEPENDENCIES.key(), "");
44+
}
45+
46+
}
Collapse file

‎python-commons/src/test/java/org/sonar/plugins/python/PythonExtensionsTest.java‎

Copy file name to clipboardExpand all lines: python-commons/src/test/java/org/sonar/plugins/python/PythonExtensionsTest.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class PythonExtensionsTest {
4343
void testGetExtensions() {
4444
Version v79 = Version.create(7, 9);
4545
SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(v79, SonarQubeSide.SERVER, SonarEdition.DEVELOPER);
46-
assertThat(extensions(runtime)).hasSize(34);
46+
assertThat(extensions(runtime)).hasSize(35);
4747
assertThat(extensions(runtime)).contains(AnalysisWarningsWrapper.class);
4848
assertThat(extensions(SonarRuntimeImpl.forSonarLint(v79)))
49-
.hasSize(15)
49+
.hasSize(16)
5050
.contains(SonarLintCache.class);
5151
}
5252

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.