Skip to content

Commit b21c5c7

Browse files
committed
Clean-up obsolete config flags for plugins using Java AST API
1 parent 54727bc commit b21c5c7

3 files changed

Lines changed: 6 additions & 96 deletions

File tree

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/AbstractAnalysis.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,12 @@ protected void analyzeFile(
109109
LOG.debug("Analyzing file: {}", file.uri());
110110
progressReport.nextFile(file.toString());
111111
var fileContent = contextUtils.shouldSendFileContent(file) ? file.contents() : null;
112-
var skipAst =
113-
!consumers.hasConsumers() ||
114-
!(contextUtils.isSonarArmorEnabled() ||
115-
contextUtils.isSonarJasminEnabled() ||
116-
contextUtils.isSonarJaredEnabled());
117112
var request = getJsAnalysisRequest(
118113
file,
119114
fileContent,
120115
tsProgram,
121116
tsConfigs,
122-
skipAst,
117+
shouldSkipAstProduction(),
123118
dirtyPackageJSONCache
124119
);
125120

@@ -144,6 +139,11 @@ protected void analyzeFile(
144139
}
145140
}
146141

142+
private boolean shouldSkipAstProduction() {
143+
// we don't need to produce AST if there are no consumers
144+
return !consumers.hasConsumers();
145+
}
146+
147147
private void acceptAstResponse(BridgeServer.AnalysisResponse response, InputFile file) {
148148
Node responseAst = response.ast();
149149
if (responseAst != null) {

sonar-plugin/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/analysis/ContextUtils.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,6 @@
2424

2525
public class ContextUtils {
2626

27-
/**
28-
* Internal property to enable SonarArmor (disabled by default), now called Jasmin
29-
* @deprecated Kept for backwards compatibility until SonarArmor has been renamed to Jasmin, to allow for a smooth transition. Roadmap:
30-
* 1. Merge this
31-
* 2. Rename SonarArmor to Jasmin on SonarArmor repository, this includes renaming the flag
32-
* 3. Once Jasmin renaming is on master, change the flags in the Peachee jobs
33-
* 4. Finally, remove this flag here
34-
*/
35-
@Deprecated(forRemoval = true)
36-
private static final String ARMOR_INTERNAL_ENABLED = "sonar.armor.internal.enabled";
37-
38-
/* Internal property to enable Jasmin (disabled by default) */
39-
private static final String JASMIN_INTERNAL_ENABLED = "sonar.jasmin.internal.enabled";
40-
41-
/* Internal property to enable JaRED (disabled by default) */
42-
private static final String JARED_INTERNAL_ENABLED = "sonar.jared.internal.enabled";
43-
4427
private final SensorContext context;
4528

4629
ContextUtils(SensorContext context) {
@@ -73,17 +56,4 @@ boolean failFast() {
7356
SensorContext context() {
7457
return context;
7558
}
76-
77-
@Deprecated(forRemoval = true)
78-
boolean isSonarArmorEnabled() {
79-
return context.config().getBoolean(ARMOR_INTERNAL_ENABLED).orElse(false);
80-
}
81-
82-
boolean isSonarJasminEnabled() {
83-
return context.config().getBoolean(JASMIN_INTERNAL_ENABLED).orElse(false);
84-
}
85-
86-
boolean isSonarJaredEnabled() {
87-
return context.config().getBoolean(JARED_INTERNAL_ENABLED).orElse(false);
88-
}
8959
}

sonar-plugin/sonar-javascript-plugin/src/test/java/org/sonar/plugins/javascript/analysis/JsTsSensorTest.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -409,66 +409,6 @@ void should_not_send_the_skipAst_flag_when_there_are_consumers() throws Exceptio
409409
assertThat(captor.getValue().skipAst()).isFalse();
410410
}
411411

412-
@Test
413-
void should_not_send_the_skipAst_flag_when_jared_is_enabled() throws Exception {
414-
var ctx = createSensorContext(baseDir);
415-
ctx.setSettings(new MapSettings().setProperty("sonar.jared.internal.enabled", "true"));
416-
var inputFile = createInputFile(ctx);
417-
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
418-
var consumer = createConsumer();
419-
var sensor = createSensorWithConsumer(consumer);
420-
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
421-
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
422-
sensor.execute(ctx);
423-
424-
createSensor().execute(context);
425-
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
426-
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
427-
assertThat(captor.getValue().skipAst()).isFalse();
428-
}
429-
430-
/**
431-
* @deprecated Should be removed when the sonar.armor.internal.enabled is removed, see comments in ContextUtils#ARMOR_INTERNAL_ENABLED
432-
*/
433-
@Deprecated(forRemoval = true)
434-
@Test
435-
void should_send_the_skipAst_flag_when_there_are_consumers_but_armor_is_disabled()
436-
throws Exception {
437-
var ctx = createSensorContext(baseDir);
438-
ctx.setSettings(new MapSettings().setProperty("sonar.armor.internal.enabled", "false"));
439-
var inputFile = createInputFile(ctx);
440-
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
441-
var consumer = createConsumer();
442-
var sensor = createSensorWithConsumer(consumer);
443-
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
444-
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
445-
sensor.execute(ctx);
446-
447-
createSensor().execute(context);
448-
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
449-
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
450-
assertThat(captor.getValue().skipAst()).isTrue();
451-
}
452-
453-
@Test
454-
void should_send_the_skipAst_flag_when_there_are_consumers_but_jasmin_is_disabled()
455-
throws Exception {
456-
var ctx = createSensorContext(baseDir);
457-
ctx.setSettings(new MapSettings().setProperty("sonar.jasmin.internal.enabled", "false"));
458-
var inputFile = createInputFile(ctx);
459-
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
460-
var consumer = createConsumer();
461-
var sensor = createSensorWithConsumer(consumer);
462-
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
463-
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
464-
sensor.execute(ctx);
465-
466-
createSensor().execute(context);
467-
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
468-
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
469-
assertThat(captor.getValue().skipAst()).isTrue();
470-
}
471-
472412
@Test
473413
void should_send_content_when_not_utf8() throws Exception {
474414
var ctx = createSensorContext(baseDir);

0 commit comments

Comments
 (0)