Skip to content

Commit d9b1b7b

Browse files
SONARJAVA-6205 Remove reflection to load DBD rule keys
DBD registers rules using ProfileRegistrar defined in the sonar-java API and is therefore automatically loaded into all built-in quality profiles.
1 parent bc0490c commit d9b1b7b

2 files changed

Lines changed: 0 additions & 21 deletions

File tree

sonar-java-plugin/src/main/java/org/sonar/plugins/java/BuiltInJavaQualityProfile.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ abstract class BuiltInJavaQualityProfile implements BuiltInQualityProfilesDefini
4141
static final String SECURITY_RULES_CLASS_NAME = "com.sonar.plugins.security.api.JavaRules";
4242
static final String DBD_RULES_CLASS_NAME = "com.sonarsource.plugins.dbd.api.JavaRules";
4343
static final String SECURITY_RULE_KEYS_METHOD_NAME = "getSecurityRuleKeys";
44-
static final String DBD_RULE_KEYS_METHOD_NAME = "getDataflowBugDetectionRuleKeys";
4544
static final String GET_REPOSITORY_KEY = "getRepositoryKey";
4645
static final String SECURITY_REPOSITORY_KEY = "javasecurity";
47-
static final String DBD_REPOSITORY_KEY = "javabugs";
4846

4947

5048
protected final ProfileRegistrar[] profileRegistrars;
@@ -74,9 +72,6 @@ public void define(Context context) {
7472
if (ruleKeys.stream().noneMatch(rule -> SECURITY_REPOSITORY_KEY.equals(rule.repository()))) {
7573
ruleKeys.addAll(getSecurityRuleKeys());
7674
}
77-
if (ruleKeys.stream().noneMatch(rule -> DBD_REPOSITORY_KEY.equals(rule.repository()))) {
78-
ruleKeys.addAll(getDataflowBugDetectionRuleKeys());
79-
}
8075

8176
ruleKeys.forEach(ruleKey -> profile.activateRule(ruleKey.repository(), ruleKey.rule()));
8277
profile.setDefault(isDefault());
@@ -105,11 +100,6 @@ Set<RuleKey> getSecurityRuleKeys() {
105100
return getExternalRuleKeys(SECURITY_RULES_CLASS_NAME, SECURITY_RULE_KEYS_METHOD_NAME, "security");
106101
}
107102

108-
@VisibleForTesting
109-
Set<RuleKey> getDataflowBugDetectionRuleKeys() {
110-
return getExternalRuleKeys(DBD_RULES_CLASS_NAME, DBD_RULE_KEYS_METHOD_NAME, "dataflow bug detection");
111-
}
112-
113103
@VisibleForTesting
114104
Set<RuleKey> getExternalRuleKeys(String className, String ruleKeysMethod, String rulesCategory) {
115105
try {

sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaSonarWayProfileTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,6 @@ void should_contains_security_rules_if_present() {
103103
assertThat(new JavaSonarWayProfile().getSecurityRuleKeys()).containsOnly(RuleKey.of("security-repo-key", "S3649"));
104104
}
105105

106-
@Test
107-
void should_contains_dataflow_bug_detection_rules_if_present() {
108-
// no dataflow bug detection rules available
109-
com.sonarsource.plugins.dbd.api.JavaRules.ruleKeys = new HashSet<>();
110-
assertThat(new JavaSonarWayProfile().getDataflowBugDetectionRuleKeys()).isEmpty();
111-
112-
// one dataflow bug detection rule available
113-
com.sonarsource.plugins.dbd.api.JavaRules.ruleKeys = new HashSet<>(Arrays.asList("S6322"));
114-
assertThat(new JavaSonarWayProfile().getDataflowBugDetectionRuleKeys()).containsOnly(RuleKey.of("dbd-repo-key", "S6322"));
115-
}
116-
117106
@Test
118107
void external_rule_keys_missing_class() {
119108
new JavaSonarWayProfile().getExternalRuleKeys("silly.name", "getDataflowBugDetectionRuleKeys", "ruleCategory");

0 commit comments

Comments
 (0)