Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-362 Enable SonarJaRED to consume SonarJS ASTs without SonarArmor #4878

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected void analyzeFile(InputFile file, @Nullable List<String> tsConfigs, @Nu
LOG.debug("Analyzing file: {}", file.uri());
progressReport.nextFile(file.toString());
var fileContent = contextUtils.shouldSendFileContent(file) ? file.contents() : null;
var skipAst = !consumers.hasConsumers() || !contextUtils.isSonarArmorEnabled();
var skipAst = !consumers.hasConsumers() || !(contextUtils.isSonarArmorEnabled() || contextUtils.isSonarJaredEnabled());
var request = getJsAnalysisRequest(file, fileContent, tsProgram, tsConfigs, skipAst);

var response = isJavaScript(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ContextUtils {
/* Internal property to enable Armor (disabled by default) */
private static final String ARMOR_INTERNAL_ENABLED = "sonar.armor.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 @@ -66,4 +69,8 @@ SensorContext context() {
boolean isSonarArmorEnabled() {
return context.config().getBoolean(ARMOR_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 @@ -401,6 +401,24 @@ 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();
}

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