Skip to content

Commit cfa2fee

Browse files
GabinL21sonartech
authored andcommitted
SONARTEXT-623 Make automatic test files detection toggleable in the cli (#1151)
GitOrigin-RevId: 7294899a0ac0060e4ba9be3f01a7b75e62af948b
1 parent 5c2a0f1 commit cfa2fee

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sonar-text-plugin/src/main/java/org/sonar/plugins/common/TextAndSecretsSensor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Optional;
2323
import java.util.function.Consumer;
2424
import java.util.stream.StreamSupport;
25+
import javax.annotation.Nullable;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728
import org.sonar.api.SonarEdition;
@@ -88,6 +89,8 @@ public class TextAndSecretsSensor implements Sensor {
8889
protected final AnalysisWarningsWrapper analysisWarnings;
8990
private final SecretsSpecificationContainer secretsSpecificationContainer;
9091
private final CheckContainer checkContainer;
92+
@Nullable
93+
private final Boolean overrideAutomaticTestFileDetection;
9194
protected DurationStatistics durationStatistics;
9295
protected TelemetryReporter telemetryReporter;
9396
protected MemoryMonitor memoryMonitor;
@@ -106,11 +109,22 @@ public TextAndSecretsSensor(
106109
AnalysisWarningsWrapper analysisWarnings,
107110
SecretsSpecificationContainer secretsSpecificationContainer,
108111
CheckContainer checkContainer) {
112+
this(sonarRuntime, checkFactory, analysisWarnings, secretsSpecificationContainer, checkContainer, null);
113+
}
114+
115+
public TextAndSecretsSensor(
116+
SonarRuntime sonarRuntime,
117+
CheckFactory checkFactory,
118+
AnalysisWarningsWrapper analysisWarnings,
119+
SecretsSpecificationContainer secretsSpecificationContainer,
120+
CheckContainer checkContainer,
121+
@Nullable Boolean overrideAutomaticTestFileDetection) {
109122
this.sonarRuntime = sonarRuntime;
110123
this.checkFactory = checkFactory;
111124
this.analysisWarnings = analysisWarnings;
112125
this.secretsSpecificationContainer = secretsSpecificationContainer;
113126
this.checkContainer = checkContainer;
127+
this.overrideAutomaticTestFileDetection = overrideAutomaticTestFileDetection;
114128
}
115129

116130
@Override
@@ -148,7 +162,10 @@ public void execute(SensorContext sensorContext) {
148162
return;
149163
}
150164

151-
initializeChecks(activeChecks, new SpecificationConfiguration(enableAutomaticTestFileDetection(sensorContext)));
165+
var automaticTestFileDetection = overrideAutomaticTestFileDetection != null
166+
? overrideAutomaticTestFileDetection
167+
: enableAutomaticTestFileDetection(sensorContext);
168+
initializeChecks(activeChecks, new SpecificationConfiguration(automaticTestFileDetection));
152169

153170
runAnalysis(sensorContext, activeChecks);
154171

0 commit comments

Comments
 (0)