diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2022-07-06 17:26:32 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-07-08 20:02:47 +0000 |
commit | e3fc4647925f88c6c5504350e39d4f60786682b9 (patch) | |
tree | 3b54ddb1b34245fb86a066c8d873b72890fa71d6 | |
parent | d2673b56781ac7d1f359a291f6294c015131fb6d (diff) | |
download | sonarqube-e3fc4647925f88c6c5504350e39d4f60786682b9.tar.gz sonarqube-e3fc4647925f88c6c5504350e39d4f60786682b9.zip |
SONAR-16598 Populate Generic concepts from sonar-plugin api
8 files changed, 34 insertions, 16 deletions
diff --git a/build.gradle b/build.gradle index d0d96d9824a..fd18ae77ed6 100644 --- a/build.gradle +++ b/build.gradle @@ -178,7 +178,7 @@ subprojects { dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.9.0.1147' dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.9.0.3429' dependency 'org.sonarsource.slang:sonar-scala-plugin:1.9.0.3429' - dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.7.0.160' + dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.8.0.184' dependency 'org.sonarsource.xml:sonar-xml-plugin:2.5.0.3376' dependency 'org.sonarsource.iac:sonar-iac-plugin:1.7.0.2012' dependency 'org.sonarsource.text:sonar-text-plugin:1.1.0.282' diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 38ed2bad0bf..51ad8f121e1 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -118,7 +118,8 @@ public class XooRulesDefinition implements RulesDefinition { addHowToFixSectionsWithContexts(oneIssuePerLine); oneIssuePerLine .setDebtRemediationFunction(oneIssuePerLine.debtRemediationFunctions().linear("1min")) - .setGapDescription("It takes about 1 minute to an experienced software craftsman to remove a line of code"); + .setGapDescription("It takes about 1 minute to an experienced software craftsman to remove a line of code") + .addGenericConceptKeys("defense_in_depth", "least_trust_principle"); NewRule oneQuickFixPerLine = repo.createRule(OneQuickFixPerLineSensor.RULE_KEY).setName("One Quick Fix Per Line") .setTags("line"); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java index fc3463987b6..b7324ab3a3a 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -396,7 +396,8 @@ public class RegisterRules implements Startable { .setIsExternal(ruleDef.repository().isExternal()) .setIsAdHoc(false) .setCreatedAt(system2.now()) - .setUpdatedAt(system2.now()); + .setUpdatedAt(system2.now()) + .setGenericConcepts(ruleDef.genericConceptKeys()); if (isNotEmpty(ruleDef.htmlDescription())) { ruleDto.setDescriptionFormat(Format.HTML); @@ -442,7 +443,8 @@ public class RegisterRules implements Startable { boolean debtDefinitionsMerged = mergeDebtDefinitions(ruleDef, ruleDto); boolean tagsMerged = mergeTags(ruleDef, ruleDto); boolean securityStandardsMerged = mergeSecurityStandards(ruleDef, ruleDto); - return ruleMerged || debtDefinitionsMerged || tagsMerged || securityStandardsMerged; + boolean genericConceptsMerged = mergeGenericConcepts(ruleDef, ruleDto); + return ruleMerged || debtDefinitionsMerged || tagsMerged || securityStandardsMerged || genericConceptsMerged; } private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) { @@ -681,6 +683,16 @@ public class RegisterRules implements Startable { return changed; } + private static boolean mergeGenericConcepts(RulesDefinition.Rule ruleDef, RuleDto dto) { + boolean changed = false; + if (dto.getGenericConcepts().size() != ruleDef.genericConceptKeys().size() || + !dto.getGenericConcepts().containsAll(ruleDef.genericConceptKeys())) { + dto.setGenericConcepts(ruleDef.genericConceptKeys()); + changed = true; + } + return changed; + } + private void processRemainingDbRules(RegisterRulesContext recorder, DbSession dbSession) { // custom rules check status of template, so they must be processed at the end List<RuleDto> customRules = new ArrayList<>(); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index fb6fb316b6c..e42dc236273 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -244,6 +244,7 @@ public class RegisterRulesTest { assertThat(rule.getType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); assertThat(rule.getPluginKey()).isEqualTo(FAKE_PLUGIN_KEY); assertThat(rule.isAdHoc()).isFalse(); + assertThat(rule.getGenericConcepts()).containsOnly("concept1", "concept2", "concept3"); } @Test @@ -413,6 +414,7 @@ public class RegisterRulesTest { assertThat(rule1.getType()).isEqualTo(RuleType.BUG.getDbConstant()); assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime()); assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2.getTime()); + assertThat(rule1.getGenericConcepts()).containsOnly("concept1","concept4"); } @Test @@ -663,7 +665,7 @@ public class RegisterRulesTest { @DataProvider public static Object[][] allRenamingCases() { - return new Object[][] { + return new Object[][]{ {"repo1", "rule1", "repo1", "rule2"}, {"repo1", "rule1", "repo2", "rule1"}, {"repo1", "rule1", "repo2", "rule2"}, @@ -744,10 +746,10 @@ public class RegisterRulesTest { system.setNow(DATE1.getTime()); RuleDescriptionSection section1context1 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx1 content", "CTX_1"); - RuleDescriptionSection section1context2 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY,"section1 ctx2 content", "CTX_2"); - RuleDescriptionSection section2context1 = createRuleDescriptionSection(RESOURCES_SECTION_KEY,"section2 content", "CTX_1"); - RuleDescriptionSection section3noContext = createRuleDescriptionSection(ASSESS_THE_PROBLEM_SECTION_KEY,"section3 content", null); - RuleDescriptionSection section4noContext = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY,"section4 content", null); + RuleDescriptionSection section1context2 = createRuleDescriptionSection(HOW_TO_FIX_SECTION_KEY, "section1 ctx2 content", "CTX_2"); + RuleDescriptionSection section2context1 = createRuleDescriptionSection(RESOURCES_SECTION_KEY, "section2 content", "CTX_1"); + RuleDescriptionSection section3noContext = createRuleDescriptionSection(ASSESS_THE_PROBLEM_SECTION_KEY, "section3 content", null); + RuleDescriptionSection section4noContext = createRuleDescriptionSection(ROOT_CAUSE_SECTION_KEY, "section4 content", null); execute(context -> { NewRepository repo = context.createRepository("fake", "java"); repo.createRule("rule") @@ -1202,7 +1204,8 @@ public class RegisterRulesTest { .setScope(RuleScope.ALL) .setType(RuleType.CODE_SMELL) .setStatus(RuleStatus.BETA) - .setGapDescription("java.S115.effortToFix"); + .setGapDescription("java.S115.effortToFix") + .addGenericConceptKeys("concept1", "concept2", "concept3"); rule1.setDebtRemediationFunction(rule1.debtRemediationFunctions().linearWithOffset("5d", "10h")); rule1.createParam("param1").setDescription("parameter one").setDefaultValue("default1"); @@ -1240,7 +1243,8 @@ public class RegisterRulesTest { .setTags("tag1", "tag4") .setType(RuleType.BUG) .setStatus(READY) - .setGapDescription("java.S115.effortToFix.v2"); + .setGapDescription("java.S115.effortToFix.v2") + .addGenericConceptKeys("concept1", "concept4"); rule1.setDebtRemediationFunction(rule1.debtRemediationFunctions().linearWithOffset("6d", "2h")); rule1.createParam("param1").setDescription("parameter one v2").setDefaultValue("default1 v2"); rule1.createParam("param2").setDescription("parameter two v2").setDefaultValue("default2 v2"); @@ -1279,7 +1283,8 @@ public class RegisterRulesTest { .setTags("tag1", "tag2", "tag3") .setScope(RuleScope.ALL) .setType(RuleType.CODE_SMELL) - .setStatus(RuleStatus.BETA); + .setStatus(RuleStatus.BETA) + .addGenericConceptKeys("concept1", "concept2", "concept3"); repo.createRule(EXTERNAL_HOTSPOT_RULE_KEY.rule()) .setName("Hotspot") diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/AddTagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/AddTagsActionTest.java index a7a75e6f2e0..e716d9b2e8a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/AddTagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/AddTagsActionTest.java @@ -67,6 +67,6 @@ public class AddTagsActionTest { underTest.execute(properties, context); }) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Tag 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); + .hasMessage("Entry 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java index 4a8d7573c6b..6c35531d6e4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java @@ -67,6 +67,6 @@ public class RemoveTagsActionTest { action.execute(properties, context); }) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Tag 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); + .hasMessage("Entry 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java index b4585b5b519..9dfd0f41558 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java @@ -175,7 +175,7 @@ public class SetTagsActionTest { assertThatThrownBy(() -> call(issueDto.getKey(), "pol op")) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Tags 'pol op' are invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); + .hasMessage("Entries 'pol op' are invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleTagHelperTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleTagHelperTest.java index ac406962493..77e12bf069b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleTagHelperTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/RuleTagHelperTest.java @@ -65,7 +65,7 @@ public class RuleTagHelperTest { RuleTagHelper.applyTags(rule, Sets.newHashSet("Java Eight")); fail(); } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).startsWith("Tag 'Java Eight' is invalid"); + assertThat(e.getMessage()).startsWith("Entry 'Java Eight' is invalid"); } } |