Skip to content

Commit

Permalink
Clean-up obsolete config flags for plugins using Java AST API
Browse files Browse the repository at this point in the history
  • Loading branch information
saberduck committed Jan 30, 2025
1 parent 54727bc commit b21c5c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,12 @@ protected void analyzeFile(
LOG.debug("Analyzing file: {}", file.uri());
progressReport.nextFile(file.toString());
var fileContent = contextUtils.shouldSendFileContent(file) ? file.contents() : null;
var skipAst =
!consumers.hasConsumers() ||
!(contextUtils.isSonarArmorEnabled() ||
contextUtils.isSonarJasminEnabled() ||
contextUtils.isSonarJaredEnabled());
var request = getJsAnalysisRequest(
file,
fileContent,
tsProgram,
tsConfigs,
skipAst,
shouldSkipAstProduction(),
dirtyPackageJSONCache
);

Expand All @@ -144,6 +139,11 @@ protected void analyzeFile(
}
}

private boolean shouldSkipAstProduction() {
// we don't need to produce AST if there are no consumers
return !consumers.hasConsumers();
}

private void acceptAstResponse(BridgeServer.AnalysisResponse response, InputFile file) {
Node responseAst = response.ast();
if (responseAst != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@

public class ContextUtils {

/**
* Internal property to enable SonarArmor (disabled by default), now called Jasmin
* @deprecated Kept for backwards compatibility until SonarArmor has been renamed to Jasmin, to allow for a smooth transition. Roadmap:
* 1. Merge this
* 2. Rename SonarArmor to Jasmin on SonarArmor repository, this includes renaming the flag
* 3. Once Jasmin renaming is on master, change the flags in the Peachee jobs
* 4. Finally, remove this flag here
*/
@Deprecated(forRemoval = true)
private static final String ARMOR_INTERNAL_ENABLED = "sonar.armor.internal.enabled";

/* Internal property to enable Jasmin (disabled by default) */
private static final String JASMIN_INTERNAL_ENABLED = "sonar.jasmin.internal.enabled";

/* Internal property to enable JaRED (disabled by default) */
private static final String JARED_INTERNAL_ENABLED = "sonar.jared.internal.enabled";

private final SensorContext context;

ContextUtils(SensorContext context) {
Expand Down Expand Up @@ -73,17 +56,4 @@ boolean failFast() {
SensorContext context() {
return context;
}

@Deprecated(forRemoval = true)
boolean isSonarArmorEnabled() {
return context.config().getBoolean(ARMOR_INTERNAL_ENABLED).orElse(false);
}

boolean isSonarJasminEnabled() {
return context.config().getBoolean(JASMIN_INTERNAL_ENABLED).orElse(false);
}

boolean isSonarJaredEnabled() {
return context.config().getBoolean(JARED_INTERNAL_ENABLED).orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,66 +409,6 @@ void should_not_send_the_skipAst_flag_when_there_are_consumers() throws Exceptio
assertThat(captor.getValue().skipAst()).isFalse();
}

@Test
void should_not_send_the_skipAst_flag_when_jared_is_enabled() throws Exception {
var ctx = createSensorContext(baseDir);
ctx.setSettings(new MapSettings().setProperty("sonar.jared.internal.enabled", "true"));
var inputFile = createInputFile(ctx);
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
var consumer = createConsumer();
var sensor = createSensorWithConsumer(consumer);
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
sensor.execute(ctx);

createSensor().execute(context);
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
assertThat(captor.getValue().skipAst()).isFalse();
}

/**
* @deprecated Should be removed when the sonar.armor.internal.enabled is removed, see comments in ContextUtils#ARMOR_INTERNAL_ENABLED
*/
@Deprecated(forRemoval = true)
@Test
void should_send_the_skipAst_flag_when_there_are_consumers_but_armor_is_disabled()
throws Exception {
var ctx = createSensorContext(baseDir);
ctx.setSettings(new MapSettings().setProperty("sonar.armor.internal.enabled", "false"));
var inputFile = createInputFile(ctx);
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
var consumer = createConsumer();
var sensor = createSensorWithConsumer(consumer);
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
sensor.execute(ctx);

createSensor().execute(context);
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
assertThat(captor.getValue().skipAst()).isTrue();
}

@Test
void should_send_the_skipAst_flag_when_there_are_consumers_but_jasmin_is_disabled()
throws Exception {
var ctx = createSensorContext(baseDir);
ctx.setSettings(new MapSettings().setProperty("sonar.jasmin.internal.enabled", "false"));
var inputFile = createInputFile(ctx);
var tsProgram = new TsProgram("1", List.of(inputFile.absolutePath()), List.of());
var consumer = createConsumer();
var sensor = createSensorWithConsumer(consumer);
when(bridgeServerMock.createProgram(any())).thenReturn(tsProgram);
when(bridgeServerMock.analyzeTypeScript(any())).thenReturn(new AnalysisResponse());
sensor.execute(ctx);

createSensor().execute(context);
var captor = ArgumentCaptor.forClass(JsAnalysisRequest.class);
verify(bridgeServerMock).analyzeTypeScript(captor.capture());
assertThat(captor.getValue().skipAst()).isTrue();
}

@Test
void should_send_content_when_not_utf8() throws Exception {
var ctx = createSensorContext(baseDir);
Expand Down

0 comments on commit b21c5c7

Please sign in to comment.