aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api
diff options
context:
space:
mode:
authorLéo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com>2022-04-22 14:13:59 +0200
committersonartech <sonartech@sonarsource.com>2022-05-06 20:02:43 +0000
commit6e2ed638eeb353c4048575e9ba16c968455d3142 (patch)
tree8cc600e82076e13a06b8124d8101884711316fe7 /server/sonar-webserver-api
parent988512fbbf60d11ec53c2add9a277f4c04c163f8 (diff)
downloadsonarqube-6e2ed638eeb353c4048575e9ba16c968455d3142.tar.gz
sonarqube-6e2ed638eeb353c4048575e9ba16c968455d3142.zip
SONAR-16302 adapt RuleDto, RuleDefinitionDto and introduce RuleSectionDescriptionDto to prepare for multiple section support
Diffstat (limited to 'server/sonar-webserver-api')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java15
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java3
2 files changed, 5 insertions, 13 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
index 17199eb9ce1..43f6fdb03c6 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
@@ -41,9 +41,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
-import org.sonar.markdown.Markdown;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
@@ -147,8 +145,6 @@ public class CachingRuleFinder implements ServerRuleFinder {
private static Rule toRule(RuleDefinitionDto ruleDefinition, List<RuleParamDto> params) {
String severity = ruleDefinition.getSeverityString();
- String description = ruleDefinition.getDescription();
- RuleDto.Format descriptionFormat = ruleDefinition.getDescriptionFormat();
Rule apiRule = new Rule();
apiRule
@@ -163,14 +159,9 @@ public class CachingRuleFinder implements ServerRuleFinder {
.setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
.setStatus(ruleDefinition.getStatus().name())
.setSystemTags(ruleDefinition.getSystemTags().toArray(new String[ruleDefinition.getSystemTags().size()]))
- .setTags(new String[0]);
- if (description != null && descriptionFormat != null) {
- if (RuleDto.Format.HTML.equals(descriptionFormat)) {
- apiRule.setDescription(description);
- } else {
- apiRule.setDescription(Markdown.convertToHtml(description));
- }
- }
+ .setTags(new String[0])
+ .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDefinition));
+
List<org.sonar.api.rules.RuleParam> apiParams = new ArrayList<>();
for (RuleParamDto param : params) {
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
index 0d37e1221fe..cd2c2235981 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
@@ -46,6 +46,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection;
public class CachingRuleFinderTest {
@org.junit.Rule
@@ -422,7 +423,7 @@ public class CachingRuleFinderTest {
assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString());
assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().toArray(new String[0]));
assertThat(rule.getTags()).isEmpty();
- assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription());
+ assertThat(rule.getDescription()).isEqualTo(createDefaultRuleDescriptionSection(randomAlphabetic(5)).getDescription());
assertThat(rule.getParams()).hasSize(1);
org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next();