diff options
author | Damien Urruty <damien.urruty@sonarsource.com> | 2022-03-01 10:45:57 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-03 09:54:42 +0000 |
commit | 78386839d860c20b5cfca0f572f21dc52721f81b (patch) | |
tree | 6b1f6c0b9e1587e85eb5407e88b076d6f93a3640 /server/sonar-webserver-pushapi/src | |
parent | 042825ec38a115983cbdced7a8b5b1d56aa05e74 (diff) | |
download | sonarqube-78386839d860c20b5cfca0f572f21dc52721f81b.tar.gz sonarqube-78386839d860c20b5cfca0f572f21dc52721f81b.zip |
SONAR-15919 Use long-form rule key in events
Diffstat (limited to 'server/sonar-webserver-pushapi/src')
4 files changed, 23 insertions, 21 deletions
diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/qualityprofile/QualityProfileChangeEventServiceImpl.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/qualityprofile/QualityProfileChangeEventServiceImpl.java index 75cd84956f5..568dc5eb9f3 100644 --- a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/qualityprofile/QualityProfileChangeEventServiceImpl.java +++ b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/qualityprofile/QualityProfileChangeEventServiceImpl.java @@ -121,7 +121,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang List<RuleDto> ruleDtos = dbClient.ruleDao().selectByUuids(dbSession, ruleUuids); for (RuleDto ruleDto : ruleDtos) { - ruleKeys.add(ruleDto.getRuleKey()); + ruleKeys.add(ruleDto.getKey().toString()); } } return ruleKeys; @@ -130,7 +130,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang @NotNull private RuleChange toRuleChange(RuleDto ruleDto, List<ActiveRuleParamDto> activeRuleParamDtos) { RuleChange ruleChange = new RuleChange(); - ruleChange.setKey(ruleDto.getRuleKey()); + ruleChange.setKey(ruleDto.getKey().toString()); ruleChange.setLanguage(ruleDto.getLanguage()); ruleChange.setSeverity(ruleDto.getSeverityString()); @@ -145,7 +145,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang 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()); + ruleChange.setTemplateKey(templateRule.getKey().toString()); } } @@ -166,7 +166,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang } RuleChange ruleChange = new RuleChange(); - ruleChange.setKey(activeRule.getRuleKey().rule()); + ruleChange.setKey(activeRule.getRuleKey().toString()); ruleChange.setSeverity(arc.getSeverity()); ruleChange.setLanguage(language); @@ -190,7 +190,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang .map(ActiveRuleChange::getActiveRule) .filter(not(Objects::isNull)) .map(ActiveRuleDto::getRuleKey) - .map(RuleKey::rule) + .map(RuleKey::toString) .collect(Collectors.toSet()); Set<String> projectKeys = getProjectKeys(profiles); @@ -213,7 +213,7 @@ public class QualityProfileChangeEventServiceImpl implements QualityProfileChang if (StringUtils.isNotEmpty(templateUuid)) { RuleDto templateRule = dbClient.ruleDao().selectByUuid(templateUuid, dbSession) .orElseThrow(() -> new IllegalStateException(String.format("Unknown Template Rule '%s'", templateUuid))); - return Optional.of(templateRule.getRuleKey()); + return Optional.of(templateRule.getKey().toString()); } } return Optional.empty(); diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java index f423dd7096b..2147bf50ecf 100644 --- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java +++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintClientsRegistryTest.java @@ -104,7 +104,7 @@ public class SonarLintClientsRegistryTest { RuleChange javaRule = createRuleChange(); RuleChange[] activatedRules = {javaRule}; - String[] deactivatedRules = {"rule-key"}; + String[] deactivatedRules = {"repo2:rule-key2"}; RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules, "java"); underTest.listen(ruleSetChangedEvent); @@ -126,7 +126,7 @@ public class SonarLintClientsRegistryTest { underTest.registerClient(sonarLintClient); RuleChange[] activatedRules = {}; - String[] deactivatedRules = {"rule-key"}; + String[] deactivatedRules = {"repo:rule-key"}; RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules, "java"); underTest.listen(ruleSetChangedEvent); @@ -144,7 +144,7 @@ public class SonarLintClientsRegistryTest { underTest.registerClient(sonarLintClient); RuleChange[] activatedRules = {}; - String[] deactivatedRules = {"rule-key"}; + String[] deactivatedRules = {"repo:rule-key"}; RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(eventProjectKeys.toArray(String[]::new), activatedRules, deactivatedRules, "java"); underTest.listen(ruleSetChangedEvent); @@ -156,7 +156,7 @@ public class SonarLintClientsRegistryTest { @Test public void listen_givenUserNotPermittedToReceiveEvent_closeConnection() { RuleChange[] activatedRules = {}; - String[] deactivatedRules = {"rule-key"}; + String[] deactivatedRules = {"repo:rule-key"}; RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules, "java"); SonarLintClient sonarLintClient = createSampleSLClient(); @@ -171,7 +171,7 @@ public class SonarLintClientsRegistryTest { @Test public void listen_givenUnregisteredClient_closeConnection() throws IOException { RuleChange[] activatedRules = {}; - String[] deactivatedRules = {"rule-key"}; + String[] deactivatedRules = {"repo:rule-key"}; RuleSetChangedEvent ruleSetChangedEvent = new RuleSetChangedEvent(exampleKeys.toArray(String[]::new), activatedRules, deactivatedRules, "java"); SonarLintClient sonarLintClient = createSampleSLClient(); @@ -226,9 +226,9 @@ public class SonarLintClientsRegistryTest { RuleChange javaRule = new RuleChange(); javaRule.setLanguage("java"); javaRule.setParams(new ParamChange[]{new ParamChange("param-key", "param-value")}); - javaRule.setTemplateKey("template-key"); + javaRule.setTemplateKey("repo:template-key"); javaRule.setSeverity(Severity.CRITICAL); - javaRule.setKey("rule-key"); + javaRule.setKey("repo:rule-key"); return javaRule; } } diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java index 79900642530..1e12fda35ca 100644 --- a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java +++ b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/qualityprofile/builtin/QualityProfileChangeEventServiceImplTest.java @@ -71,6 +71,8 @@ public class QualityProfileChangeEventServiceImplTest { // Custom rule RuleDefinitionDto rule1 = newCustomRule(templateRule.getDefinition()) .setLanguage("xoo") + .setRepositoryKey("repo") + .setRuleKey("ruleKey") .setDescription("<div>line1\nline2</div>") .setDescriptionFormat(MARKDOWN); db.rules().insert(rule1); @@ -99,7 +101,7 @@ public class QualityProfileChangeEventServiceImplTest { assertThat(ruleSetChangedEvent.getActivatedRules()) .extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey) - .containsExactly(tuple(rule1.getRuleKey(), "xoo", null, "template-key")); + .containsExactly(tuple("repo:ruleKey", "xoo", null, "xoo:template-key")); assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1); ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0]; @@ -117,7 +119,7 @@ public class QualityProfileChangeEventServiceImplTest { QProfileDto activatedQualityProfile = QualityProfileTesting.newQualityProfileDto(); activatedQualityProfile.setLanguage("xoo"); db.qualityProfiles().insert(activatedQualityProfile); - RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo").setRuleKey("ruleKey")); RuleParamDto rule1Param = db.rules().insertRuleParam(rule1); ActiveRuleDto activeRule1 = db.qualityProfiles().activateRule(activatedQualityProfile, rule1); @@ -127,7 +129,7 @@ public class QualityProfileChangeEventServiceImplTest { QProfileDto deactivatedQualityProfile = QualityProfileTesting.newQualityProfileDto(); db.qualityProfiles().insert(deactivatedQualityProfile); - RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo")); + RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage("xoo").setRepositoryKey("repo2").setRuleKey("ruleKey2")); RuleParamDto rule2Param = db.rules().insertRuleParam(rule2); ActiveRuleDto activeRule2 = db.qualityProfiles().activateRule(deactivatedQualityProfile, rule2); @@ -150,7 +152,7 @@ public class QualityProfileChangeEventServiceImplTest { assertThat(ruleSetChangedEvent.getActivatedRules()) .extracting(RuleChange::getKey, RuleChange::getLanguage, RuleChange::getSeverity, RuleChange::getTemplateKey) - .containsExactly(tuple(rule1.getRuleKey(), "xoo", rule1.getSeverityString(), null)); + .containsExactly(tuple("repo:ruleKey", "xoo", rule1.getSeverityString(), null)); assertThat(ruleSetChangedEvent.getActivatedRules()[0].getParams()).hasSize(1); ParamChange actualParamChange = ruleSetChangedEvent.getActivatedRules()[0].getParams()[0]; @@ -160,7 +162,7 @@ public class QualityProfileChangeEventServiceImplTest { // deactivated rule assertThat(ruleSetChangedEvent.getDeactivatedRules()) - .containsExactly(rule2.getRuleKey()); + .containsExactly("repo2:ruleKey2"); } } diff --git a/server/sonar-webserver-pushapi/src/test/resources/org/sonar/server/pushapi/sonarlint/rule-change-event-data.json b/server/sonar-webserver-pushapi/src/test/resources/org/sonar/server/pushapi/sonarlint/rule-change-event-data.json index 9f157f28479..81d1dc7920b 100644 --- a/server/sonar-webserver-pushapi/src/test/resources/org/sonar/server/pushapi/sonarlint/rule-change-event-data.json +++ b/server/sonar-webserver-pushapi/src/test/resources/org/sonar/server/pushapi/sonarlint/rule-change-event-data.json @@ -6,8 +6,8 @@ ], "activatedRules": [ { - "key": "rule-key", - "templateKey": "template-key", + "key": "repo:rule-key", + "templateKey": "repo:template-key", "severity": "CRITICAL", "language": "java", "params": [ @@ -19,6 +19,6 @@ } ], "deactivatedRules": [ - "rule-key" + "repo2:rule-key2" ] } |