use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImpl method publishRuleActivationToSonarLintClients.
@Override
public void publishRuleActivationToSonarLintClients(ProjectDto project, @Nullable QProfileDto activatedProfile, @Nullable QProfileDto deactivatedProfile) {
List<RuleChange> activatedRules = new ArrayList<>();
List<RuleChange> deactivatedRules = new ArrayList<>();
if (activatedProfile != null) {
activatedRules.addAll(createRuleChanges(activatedProfile));
}
if (deactivatedProfile != null) {
deactivatedRules.addAll(createRuleChanges(deactivatedProfile));
}
if (activatedRules.isEmpty() && deactivatedRules.isEmpty()) {
return;
}
RuleSetChangedEvent event = new RuleSetChangedEvent(new String[] { project.getKey() }, activatedRules.toArray(new RuleChange[0]), deactivatedRules.toArray(new RuleChange[0]));
eventsDistributor.pushEvent(event);
}
use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.
the class SonarLintClientsRegistryTest method createRuleChange.
private RuleChange createRuleChange() {
RuleChange javaRule = new RuleChange();
javaRule.setLanguage("java");
javaRule.setParams(new ParamChange[] { new ParamChange("param-key", "param-value") });
javaRule.setTemplateKey("template-key");
javaRule.setSeverity(Severity.CRITICAL);
javaRule.setKey("rule-key");
return javaRule;
}
use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.
the class SonarLintClientsRegistryTest method listen_givenUserNotPermittedToReceiveEvent_closeConnection.
@Test
public void listen_givenUserNotPermittedToReceiveEvent_closeConnection() {
RuleChange javaRuleChange = createRuleChange();
RuleChange[] activatedRules = {};
RuleChange[] deactivatedRules = { javaRuleChange };
RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules);
SonarLintClient sonarLintClient = createSampleSLClient();
underTest.registerClient(sonarLintClient);
doThrow(new ForbiddenException("Access forbidden")).when(permissionsValidator).validateUserCanReceivePushEventForProjects(anyString(), anySet());
underTest.listen(ruleSetChangedEvent);
verify(sonarLintClient).close();
}
use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.
the class SonarLintClientsRegistryTest method listen_givenUnregisteredClient_closeConnection.
@Test
public void listen_givenUnregisteredClient_closeConnection() throws IOException {
RuleChange javaRuleChange = createRuleChange();
RuleChange[] activatedRules = {};
RuleChange[] deactivatedRules = { javaRuleChange };
RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules);
SonarLintClient sonarLintClient = createSampleSLClient();
underTest.registerClient(sonarLintClient);
doThrow(new IOException("Broken pipe")).when(sonarLintClient).writeAndFlush(anyString());
underTest.listen(ruleSetChangedEvent);
underTest.registerClient(sonarLintClient);
doThrow(new IllegalStateException("Things went wrong")).when(sonarLintClient).writeAndFlush(anyString());
underTest.listen(ruleSetChangedEvent);
verify(sonarLintClient, times(2)).close();
}
use of org.sonar.core.util.RuleChange in project sonarqube by SonarSource.
the class QualityProfileChangeEventServiceImpl method toRuleChange.
@NotNull
private RuleChange toRuleChange(RuleDto ruleDto, List<ActiveRuleParamDto> activeRuleParamDtos) {
RuleChange ruleChange = new RuleChange();
ruleChange.setKey(ruleDto.getRuleKey());
ruleChange.setLanguage(ruleDto.getLanguage());
ruleChange.setSeverity(ruleDto.getSeverityString());
List<ParamChange> paramChanges = new ArrayList<>();
for (ActiveRuleParamDto activeRuleParam : activeRuleParamDtos) {
paramChanges.add(new ParamChange(activeRuleParam.getKey(), activeRuleParam.getValue()));
}
ruleChange.setParams(paramChanges.toArray(new ParamChange[0]));
String templateUuid = ruleDto.getTemplateUuid();
if (templateUuid != null && !"".equals(templateUuid)) {
try (DbSession dbSession = dbClient.openSession(false)) {
RuleDto templateRule = dbClient.ruleDao().selectByUuid(templateUuid, dbSession).orElseThrow(() -> new IllegalStateException(String.format("Unknown Template Rule '%s'", templateUuid)));
ruleChange.setTemplateKey(templateRule.getRuleKey());
}
}
return ruleChange;
}
Aggregations