]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16303 Change RuleDescriptionFormatter from a static helper to regular bean
authorZipeng WU <zipeng.wu@sonarsource.com>
Tue, 10 May 2022 13:49:14 +0000 (15:49 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 11 May 2022 20:02:59 +0000 (20:02 +0000)
35 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-server-common/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java
server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/rule/RuleDescriptionFormatter.java
server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java
server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndexer.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/DefaultRuleFinderTest.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/RuleDescriptionFormatterTest.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleDocTest.java
server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java
server/sonar-webserver-api/src/main/java/org/sonar/server/rule/CachingRuleFinder.java
server/sonar-webserver-api/src/main/java/org/sonar/server/rule/WebServerRuleFinderImpl.java
server/sonar-webserver-api/src/test/java/org/sonar/server/rule/CachingRuleFinderTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/rule/WebServerRuleFinderImplTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java
server/sonar-webserver-es/src/test/java/org/sonar/server/es/RecoveryIndexerTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleMapper.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/WebIssueStorageTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/IssueUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/RegisterQualityProfilesNotificationTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileInsertImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/builtin/BuiltInQProfileRepositoryImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/UpdateActionTest.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java

index 7a83f3db85b871f7db2c268c2d1bd984c25e5a25..8193be28b6516bd7e758ef246a921112c2af0e71 100644 (file)
@@ -138,6 +138,7 @@ import org.sonar.server.qualitygate.notification.QGChangeEmailTemplate;
 import org.sonar.server.qualitygate.notification.QGChangeNotificationHandler;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.setting.DatabaseSettingLoader;
@@ -353,6 +354,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
 
   private static void populateLevel4(Container container, Props props) {
     container.add(
+      RuleDescriptionFormatter.class,
       ResourceTypes.class,
       DefaultResourceTypes.get(),
 
index 84edc168bdb9f750a1b9f4aff74bdc8da6d9fd96..f813a76572dbdd84732d054bc5494334dfc8d691 100644 (file)
@@ -40,8 +40,6 @@ import org.sonar.db.rule.RuleDao;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleParamDto;
 
-import static org.sonar.server.rule.RuleDescriptionFormatter.getDescriptionAsHtml;
-
 /**
  * Will be removed in the future.
  */
@@ -49,10 +47,12 @@ public class DefaultRuleFinder implements ServerRuleFinder {
 
   private final DbClient dbClient;
   private final RuleDao ruleDao;
+  private final RuleDescriptionFormatter ruleDescriptionFormatter;
 
-  public DefaultRuleFinder(DbClient dbClient) {
+  public DefaultRuleFinder(DbClient dbClient, RuleDescriptionFormatter ruleDescriptionFormatter) {
     this.dbClient = dbClient;
     this.ruleDao = dbClient.ruleDao();
+    this.ruleDescriptionFormatter = ruleDescriptionFormatter;
   }
 
   @Override
@@ -131,7 +131,7 @@ public class DefaultRuleFinder implements ServerRuleFinder {
     return rules;
   }
 
-  private static org.sonar.api.rules.Rule toRule(RuleDto rule, List<RuleParamDto> params) {
+  private org.sonar.api.rules.Rule toRule(RuleDto rule, List<RuleParamDto> params) {
     String severity = rule.getSeverityString();
 
     org.sonar.api.rules.Rule apiRule = new org.sonar.api.rules.Rule();
@@ -147,9 +147,9 @@ public class DefaultRuleFinder implements ServerRuleFinder {
       .setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
       .setStatus(rule.getStatus().name())
       .setSystemTags(rule.getSystemTags().toArray(new String[rule.getSystemTags().size()]))
-      .setTags(rule.getTags().toArray(new String[rule.getTags().size()]))
-      .setDescription(getDescriptionAsHtml(rule));
+      .setTags(rule.getTags().toArray(new String[rule.getTags().size()]));
 
+    Optional.ofNullable(ruleDescriptionFormatter.getDescriptionAsHtml(rule)).ifPresent(apiRule::setDescription);
 
     List<org.sonar.api.rules.RuleParam> apiParams = new ArrayList<>();
     for (RuleParamDto param : params) {
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/HotspotRuleDescription.java
deleted file mode 100644 (file)
index 82b0917..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.rule;
-
-import java.util.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.sonar.db.rule.RuleDto;
-
-import static java.util.Optional.ofNullable;
-
-/***
- * Temporary rule split before we have a better
- * solution to specify security hotspot.
- */
-public class HotspotRuleDescription {
-  private static final HotspotRuleDescription NO_DESCRIPTION = new HotspotRuleDescription(null, null, null);
-
-  @CheckForNull
-  private final String risk;
-  @CheckForNull
-  private final String vulnerable;
-  @CheckForNull
-  private final String fixIt;
-
-  private HotspotRuleDescription(@Nullable String risk, @Nullable String vulnerable, @Nullable String fixIt) {
-    this.risk = risk;
-    this.vulnerable = vulnerable;
-    this.fixIt = fixIt;
-  }
-
-  public static HotspotRuleDescription from(RuleDto dto) {
-    String description = RuleDescriptionFormatter.getDescriptionAsHtml(dto);
-    return from(description);
-  }
-
-  private static HotspotRuleDescription from(@Nullable String description) {
-    if (description == null) {
-      return NO_DESCRIPTION;
-    }
-
-    String[] split = extractSection("", description);
-    description = split[0];
-    String ruleDescriptionSection = split[1];
-
-    split = extractSection("<h2>Exceptions</h2>", description);
-    description = split[0];
-    String exceptions = split[1];
-
-    split = extractSection("<h2>Ask Yourself Whether</h2>", description);
-    description = split[0];
-    String askSection = split[1];
-
-    split = extractSection("<h2>Sensitive Code Example</h2>", description);
-    description = split[0];
-    String sensitiveSection = split[1];
-
-    split = extractSection("<h2>Noncompliant Code Example</h2>", description);
-    description = split[0];
-    String noncompliantSection = split[1];
-
-    split = extractSection("<h2>Recommended Secure Coding Practices</h2>", description);
-    description = split[0];
-    String recommendedSection = split[1];
-
-    split = extractSection("<h2>Compliant Solution</h2>", description);
-    description = split[0];
-    String compliantSection = split[1];
-
-    split = extractSection("<h2>See</h2>", description);
-    description = split[0];
-    String seeSection = split[1];
-
-    return new HotspotRuleDescription(
-      trimToNull(ruleDescriptionSection + exceptions + description),
-      trimToNull(askSection + sensitiveSection + noncompliantSection),
-      trimToNull(recommendedSection + compliantSection + seeSection));
-  }
-
-  private static String trimToNull(String input) {
-    return input.isEmpty() ? null : input;
-  }
-
-  private static String[] extractSection(String beginning, String description) {
-    String endSection = "<h2>";
-    int beginningIndex = description.indexOf(beginning);
-    if (beginningIndex != -1) {
-      int endIndex = description.indexOf(endSection, beginningIndex + beginning.length());
-      if (endIndex == -1) {
-        endIndex = description.length();
-      }
-      return new String[]{
-        description.substring(0, beginningIndex) + description.substring(endIndex),
-        description.substring(beginningIndex, endIndex)
-      };
-    } else {
-      return new String[]{description, ""};
-    }
-
-  }
-
-  public Optional<String> getRisk() {
-    return ofNullable(risk);
-  }
-
-  public Optional<String> getVulnerable() {
-    return ofNullable(vulnerable);
-  }
-
-  public Optional<String> getFixIt() {
-    return ofNullable(fixIt);
-  }
-
-  public boolean isComplete() {
-    return risk != null && vulnerable != null && fixIt != null;
-  }
-
-  @Override
-  public String toString() {
-    return "HotspotRuleDescription{" +
-      "risk='" + risk + '\'' +
-      ", vulnerable='" + vulnerable + '\'' +
-      ", fixIt='" + fixIt + '\'' +
-      '}';
-  }
-
-}
index 0b78ff94321c3a4805c764a981b41a771aefe683..39107e39de476ccacfbb4c8aeff27205c3d266cd 100644 (file)
@@ -61,10 +61,8 @@ public class RuleDescriptionFormatter {
     RESOURCES_SECTION_KEY, "Resources"
   );
 
-  private RuleDescriptionFormatter() { /* static helpers */ }
-
   @CheckForNull
-  public static String getDescriptionAsHtml(RuleDto ruleDto) {
+  public String getDescriptionAsHtml(RuleDto ruleDto) {
     if (ruleDto.getDescriptionFormat() == null) {
       return null;
     }
index e9cc6b74875ae2812a34b18a6273d38c61c050a7..0fa670dcfe048a34f6885f536d7f6c8b5f91996c 100644 (file)
@@ -295,7 +295,7 @@ public class RuleDoc extends BaseDoc {
     return ReflectionToStringBuilder.toString(this);
   }
 
-  public static RuleDoc of(RuleForIndexingDto dto, SecurityStandards securityStandards) {
+  public static RuleDoc createFrom(RuleForIndexingDto dto, SecurityStandards securityStandards) {
     return new RuleDoc()
       .setUuid(dto.getUuid())
       .setKey(dto.getRuleKey().toString())
index da9fa447957b19d6129a75a9d87a5a9852fe27ba..9da22bebdaff11cba04d9516b87cfc37644e634d 100644 (file)
@@ -160,7 +160,7 @@ public class RuleIndexer implements ResilientIndexer {
           .sorted(SQ_CATEGORY_KEYS_ORDERING)
           .collect(joining(", ")));
     }
-    return RuleDoc.of(dto, securityStandards);
+    return RuleDoc.createFrom(dto, securityStandards);
   }
 
 
index 8b83e2d58119d76a09aac1da13f79144e16a44e3..a4286390138be1dd7b314ceaabbe8d9cc1d66847 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.db.rule.RuleDto.Scope;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
 
 public class DefaultRuleFinderTest {
 
@@ -80,7 +81,7 @@ public class DefaultRuleFinderTest {
     .setScope(Scope.MAIN)
     .setStatus(RuleStatus.READY);
 
-  private final DefaultRuleFinder underTest = new DefaultRuleFinder(dbClient);
+  private final DefaultRuleFinder underTest = new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class));
 
   @Before
   public void setup() {
index ab79c311530df9388039462c14d3c83bbbd7da2a..b0aaeb8a38ff7e51109356b1dab782ee9126f202 100644 (file)
@@ -34,18 +34,19 @@ public class RuleDescriptionFormatterTest {
 
   private static final RuleDescriptionSectionDto HTML_SECTION = createDefaultRuleDescriptionSection("uuid", "<span class=\"example\">*md* ``description``</span>");
   private static final RuleDescriptionSectionDto MARKDOWN_SECTION = createDefaultRuleDescriptionSection("uuid", "*md* ``description``");
+  private static final RuleDescriptionFormatter ruleDescriptionFormatter = new RuleDescriptionFormatter();
 
   @Test
   public void getMarkdownDescriptionAsHtml() {
     RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.MARKDOWN).addRuleDescriptionSectionDto(MARKDOWN_SECTION).setType(RuleType.BUG);
-    String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
+    String html = ruleDescriptionFormatter.getDescriptionAsHtml(rule);
     assertThat(html).isEqualTo("<strong>md</strong> <code>description</code>");
   }
 
   @Test
   public void getHtmlDescriptionAsIs() {
     RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.HTML).addRuleDescriptionSectionDto(HTML_SECTION).setType(RuleType.BUG);
-    String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
+    String html = ruleDescriptionFormatter.getDescriptionAsHtml(rule);
     assertThat(html).isEqualTo(HTML_SECTION.getContent());
   }
 
@@ -59,7 +60,7 @@ public class RuleDescriptionFormatterTest {
       .addRuleDescriptionSectionDto(section1)
       .addRuleDescriptionSectionDto(section2)
       .addRuleDescriptionSectionDto(section3);
-    String html = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
+    String html = ruleDescriptionFormatter.getDescriptionAsHtml(rule);
     assertThat(html)
       .contains(
         "<h2>What is the risk?</h2>"
@@ -74,7 +75,7 @@ public class RuleDescriptionFormatterTest {
   @Test
   public void handleEmptyDescription() {
     RuleDto rule = new RuleDto().setDescriptionFormat(RuleDto.Format.HTML).setType(RuleType.BUG);
-    String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
+    String result = ruleDescriptionFormatter.getDescriptionAsHtml(rule);
     assertThat(result).isNull();
   }
 
@@ -82,7 +83,7 @@ public class RuleDescriptionFormatterTest {
   public void handleNullDescriptionFormat() {
     RuleDescriptionSectionDto sectionWithNullFormat = createDefaultRuleDescriptionSection("uuid", "whatever");
     RuleDto rule = new RuleDto().addRuleDescriptionSectionDto(sectionWithNullFormat).setType(RuleType.BUG);
-    String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
+    String result = ruleDescriptionFormatter.getDescriptionAsHtml(rule);
     assertThat(result).isNull();
   }
 
index 93d4a1e35306db74be79ab20300e9cd7787649ea..af46148f9642708e76600e2ee570468c5868a759 100644 (file)
@@ -40,7 +40,7 @@ public class RuleDocTest {
     ruleForIndexingDto.setTemplateRepository("repoKey");
     SecurityStandards securityStandards = fromSecurityStandards(ruleDto.getSecurityStandards());
 
-    RuleDoc ruleDoc = RuleDoc.of(ruleForIndexingDto, securityStandards);
+    RuleDoc ruleDoc = RuleDoc.createFrom(ruleForIndexingDto, securityStandards);
 
     assertThat(ruleDoc.getId()).isEqualTo(ruleDto.getUuid());
     assertThat(ruleDoc.key()).isEqualTo(ruleForIndexingDto.getRuleKey());
@@ -75,7 +75,7 @@ public class RuleDocTest {
     RuleForIndexingDto ruleForIndexingDto = RuleForIndexingDto.fromRuleDto(ruleDto);
     SecurityStandards securityStandards = fromSecurityStandards(ruleDto.getSecurityStandards());
 
-    RuleDoc ruleDoc = RuleDoc.of(ruleForIndexingDto, securityStandards);
+    RuleDoc ruleDoc = RuleDoc.createFrom(ruleForIndexingDto, securityStandards);
     assertThat(ruleDoc.htmlDescription()).isEmpty();
   }
 
@@ -92,7 +92,7 @@ public class RuleDocTest {
     RuleForIndexingDto ruleForIndexingDto = RuleForIndexingDto.fromRuleDto(ruleDto);
     SecurityStandards securityStandards = fromSecurityStandards(ruleDto.getSecurityStandards());
 
-    RuleDoc ruleDoc = RuleDoc.of(ruleForIndexingDto, securityStandards);
+    RuleDoc ruleDoc = RuleDoc.createFrom(ruleForIndexingDto, securityStandards);
     assertThat(ruleDoc.htmlDescription())
       .contains(section1.getContent())
       .contains(section2.getContent())
@@ -112,7 +112,7 @@ public class RuleDocTest {
     RuleForIndexingDto ruleForIndexingDto = RuleForIndexingDto.fromRuleDto(ruleDto);
     SecurityStandards securityStandards = fromSecurityStandards(ruleDto.getSecurityStandards());
 
-    RuleDoc ruleDoc = RuleDoc.of(ruleForIndexingDto, securityStandards);
+    RuleDoc ruleDoc = RuleDoc.createFrom(ruleForIndexingDto, securityStandards);
     assertThat(ruleDoc.htmlDescription())
       .contains(convertToHtml(section1.getContent()))
       .contains(convertToHtml(section2.getContent()))
index f276fb08843ccb30e10f61253b03ce39c5a52972..2b3003993603fad0dbf40d9b5df824f63cc47a14 100644 (file)
@@ -106,7 +106,7 @@ public class RuleIndexTest {
 
   private RuleIndex underTest = new RuleIndex(es.client(), system2);
   private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-  
+
   @Test
   public void search_all_rules() {
     createRule();
index c66e48d1bc35a1a0fe32708ca002d727b7bdafa9..4e3d57d58dcd2591bada9879f46b3b7ce77dd796 100644 (file)
@@ -59,8 +59,10 @@ public class CachingRuleFinder implements ServerRuleFinder {
   private final Map<String, RuleDto> ruleDtosByUuid;
   private final Map<RuleDto, Rule> ruleByRuleDto;
   private final Map<RuleKey, Rule> rulesByKey;
+  private final RuleDescriptionFormatter ruleDescriptionFormatter;
 
-  public CachingRuleFinder(DbClient dbClient) {
+  public CachingRuleFinder(DbClient dbClient, RuleDescriptionFormatter ruleDescriptionFormatter) {
+    this.ruleDescriptionFormatter = ruleDescriptionFormatter;
     try (DbSession dbSession = dbClient.openSession(false)) {
       List<RuleDto> dtos = dbClient.ruleDao().selectAll(dbSession);
       this.ruleDtosByKey = dtos.stream().collect(Collectors.toMap(RuleDto::getKey, d -> d));
@@ -71,7 +73,7 @@ public class CachingRuleFinder implements ServerRuleFinder {
     }
   }
 
-  private static Map<RuleDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List<RuleDto> dtos) {
+  private Map<RuleDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient, DbSession dbSession, List<RuleDto> dtos) {
     Map<String, List<RuleParamDto>> ruleParamsByRuleUuid = retrieveRuleParameters(dbClient, dbSession);
     Map<RuleDto, Rule> rulesByDefinition = new HashMap<>(dtos.size());
     for (RuleDto definition : dtos) {
@@ -143,7 +145,7 @@ public class CachingRuleFinder implements ServerRuleFinder {
     return configKey == null || configKey.equals(ruleDto.getConfigKey());
   }
 
-  private static Rule toRule(RuleDto ruleDto, List<RuleParamDto> params) {
+  private Rule toRule(RuleDto ruleDto, List<RuleParamDto> params) {
     String severity = ruleDto.getSeverityString();
 
     Rule apiRule = Rule.create()
@@ -157,9 +159,9 @@ public class CachingRuleFinder implements ServerRuleFinder {
       .setSeverity(severity != null ? RulePriority.valueOf(severity) : null)
       .setStatus(ruleDto.getStatus().name())
       .setSystemTags(ruleDto.getSystemTags().toArray(new String[ruleDto.getSystemTags().size()]))
-      .setTags(new String[0])
-      .setDescription(RuleDescriptionFormatter.getDescriptionAsHtml(ruleDto));
+      .setTags(new String[0]);
 
+    Optional.ofNullable(ruleDescriptionFormatter.getDescriptionAsHtml(ruleDto)).ifPresent(apiRule::setDescription);
     Optional.ofNullable(ruleDto.getLanguage()).ifPresent(apiRule::setLanguage);
 
     List<org.sonar.api.rules.RuleParam> apiParams = new ArrayList<>();
index 1a79d6528a32f3a6a9923c53412fffb5781d6072..20f023bf7e12e1be333a05bbd4bad13098a7a0e4 100644 (file)
@@ -32,18 +32,20 @@ import org.sonar.db.rule.RuleDto;
 public class WebServerRuleFinderImpl implements WebServerRuleFinder {
   private final DbClient dbClient;
   private final ServerRuleFinder defaultFinder;
+  private final RuleDescriptionFormatter ruleDescriptionFormatter;
   @VisibleForTesting
   ServerRuleFinder delegate;
 
-  public WebServerRuleFinderImpl(DbClient dbClient) {
+  public WebServerRuleFinderImpl(DbClient dbClient, RuleDescriptionFormatter ruleDescriptionFormatter) {
     this.dbClient = dbClient;
-    this.defaultFinder = new DefaultRuleFinder(dbClient);
+    this.ruleDescriptionFormatter = ruleDescriptionFormatter;
+    this.defaultFinder = new DefaultRuleFinder(dbClient, ruleDescriptionFormatter);
     this.delegate = this.defaultFinder;
   }
 
   @Override
   public void startCaching() {
-    this.delegate = new CachingRuleFinder(dbClient);
+    this.delegate = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
   }
 
   @Override
index b7b555a8b949f2decb27a1d1ef00fe725051d202..c1f6e2a4f8ee5c7ff6b2f45390c2ee3f725f7316 100644 (file)
@@ -56,6 +56,7 @@ public class CachingRuleFinderTest {
   private RuleDto[] ruleDtos;
   private RuleParamDto[] ruleParams;
   private CachingRuleFinder underTest;
+  private RuleDescriptionFormatter ruleDescriptionFormatter = new RuleDescriptionFormatter();
 
   @Before()
   public void setUp() {
@@ -72,7 +73,7 @@ public class CachingRuleFinderTest {
       .map(rule -> dbTester.rules().insertRuleParam(rule))
       .toArray(RuleParamDto[]::new);
 
-    underTest = new CachingRuleFinder(dbClient);
+    underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     // delete all data from DB to ensure tests rely on cache exclusively
     dbTester.executeUpdateSql("delete from rules");
@@ -89,7 +90,7 @@ public class CachingRuleFinderTest {
     when(dbClient.openSession(anyBoolean())).thenReturn(dbSession);
     when(dbClient.ruleDao()).thenReturn(ruleDao);
 
-    new CachingRuleFinder(dbClient);
+    new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     verify(dbClient).openSession(anyBoolean());
     verify(ruleDao).selectAll(dbSession);
@@ -107,7 +108,7 @@ public class CachingRuleFinderTest {
     List<RuleKey> ruleKeys = Arrays.asList(RuleKey.of("A", "B"), RuleKey.of("C", "D"), RuleKey.of("E", "F"));
     when(ruleDao.selectAll(dbSession)).thenReturn(ruleKeys.stream().map(RuleTesting::newRule).collect(toList()));
 
-    new CachingRuleFinder(dbClient);
+    new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     verify(ruleDao).selectAllRuleParams(dbSession);
   }
@@ -166,7 +167,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(toRuleKey(underTest.find(RuleQuery.create().withRepositoryKey(repoKey))))
       .isEqualTo(sameRepoKey[1].getKey());
@@ -187,7 +188,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(toRuleKey(underTest.find(RuleQuery.create().withKey(ruleKey))))
       .isEqualTo(sameRuleKey[1].getKey());
@@ -208,7 +209,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(toRuleKey(underTest.find(RuleQuery.create().withConfigKey(configKey))))
       .isEqualTo(sameConfigKey[1].getKey());
@@ -239,7 +240,7 @@ public class CachingRuleFinderTest {
     RuleQuery ruleKeyQuery = RuleQuery.create().withKey(ruleKey);
     RuleQuery repoKeyQuery = RuleQuery.create().withRepositoryKey(repoKey);
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(toRuleKey(underTest.find(allQuery))).isEqualTo(rules[0].getKey());
     assertThat(toRuleKey(underTest.find(ruleAndConfigKeyQuery))).isEqualTo(rules[1].getKey());
@@ -272,7 +273,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(currentTimeMillis + system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey(repoKey)))
       .extracting(CachingRuleFinderTest::toRuleKey)
@@ -295,7 +296,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(underTest.findAll(RuleQuery.create().withKey(ruleKey)))
       .extracting(CachingRuleFinderTest::toRuleKey)
@@ -318,7 +319,7 @@ public class CachingRuleFinderTest {
     };
     RuleDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(underTest.findAll(RuleQuery.create().withConfigKey(configKey)))
       .extracting(CachingRuleFinderTest::toRuleKey)
@@ -351,7 +352,7 @@ public class CachingRuleFinderTest {
     RuleQuery ruleKeyQuery = RuleQuery.create().withKey(ruleKey);
     RuleQuery repoKeyQuery = RuleQuery.create().withRepositoryKey(repoKey);
 
-    CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
+    CachingRuleFinder underTest = new CachingRuleFinder(dbClient, ruleDescriptionFormatter);
 
     assertThat(underTest.findAll(allQuery))
       .extracting(CachingRuleFinderTest::toRuleKey)
index 28b999c045cb7d33b396c04c606febea965e9c0b..929d72c5c848e5531389a7e0c7c718c4649524ff 100644 (file)
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.when;
 public class WebServerRuleFinderImplTest {
 
   private DbClient dbClient = mock(DbClient.class);
-  private WebServerRuleFinderImpl underTest = new WebServerRuleFinderImpl(dbClient);
+  private WebServerRuleFinderImpl underTest = new WebServerRuleFinderImpl(dbClient, mock(RuleDescriptionFormatter.class));
 
   @Before
   public void setUp() {
index 3aa93a6af1e774cff7102449e1be0c8452a50b02..39795de074fc1ef060e96453193aafd043927419 100644 (file)
@@ -141,7 +141,6 @@ public class RegisterRulesTest {
       return Set.of(builder().uuid(UuidFactoryFast.getInstance().create()).key("default").content(description).build());
     });
 
-
     when(ruleDescriptionSectionsGenerator.isGeneratorForRule(any())).thenReturn(true);
   }
 
@@ -202,7 +201,6 @@ public class RegisterRulesTest {
     verifyHotspot(hotspotRule);
   }
 
-
   private void verifyRule(RuleDto rule) {
     assertThat(rule.getName()).isEqualTo("One");
     assertThat(rule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One");
index c4c0c81d58c9c1dd089796a59bfd69748a555038..0a4d57447e2a6c0926008c77f03aed6aa9299611 100644 (file)
@@ -36,8 +36,8 @@ import org.junit.rules.TestRule;
 import org.junit.rules.Timeout;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.internal.MapSettings;
-import org.sonar.api.utils.MessageException;
 import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.api.utils.MessageException;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.db.DbSession;
index 21202d076db626ec4a80e7a986301d8bcefdad24..9756754118f69437ab59de5e53b1b78c19f957aa 100644 (file)
@@ -89,10 +89,12 @@ public class RuleMapper {
 
   private final Languages languages;
   private final MacroInterpreter macroInterpreter;
+  private final RuleDescriptionFormatter ruleDescriptionFormatter;
 
-  public RuleMapper(final Languages languages, final MacroInterpreter macroInterpreter) {
+  public RuleMapper(final Languages languages, final MacroInterpreter macroInterpreter, RuleDescriptionFormatter ruleDescriptionFormatter) {
     this.languages = languages;
     this.macroInterpreter = macroInterpreter;
+    this.ruleDescriptionFormatter = ruleDescriptionFormatter;
   }
 
   public Rules.Rule toWsRule(RuleDto ruleDefinitionDto, SearchResult result, Set<String> fieldsToReturn) {
@@ -328,7 +330,7 @@ public class RuleMapper {
 
   private void setDescriptionFields(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
     if (shouldReturnField(fieldsToReturn, FIELD_HTML_DESCRIPTION)) {
-      String htmlDescription = RuleDescriptionFormatter.getDescriptionAsHtml(ruleDto);
+      String htmlDescription = ruleDescriptionFormatter.getDescriptionAsHtml(ruleDto);
       if (htmlDescription != null) {
         ruleResponse.setHtmlDesc(macroInterpreter.interpret(htmlDescription));
       }
index b72c2687c8a6fa3620d9464107d831a8ec0fe57b..9c1af5b3601d0120f85ec775b835dd8598005565 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.db.issue.IssueDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -58,7 +59,7 @@ public class WebIssueStorageTest {
 
   private final DbClient dbClient = db.getDbClient();
   private final IssueIndexer issueIndexer = mock(IssueIndexer.class);
-  private final WebIssueStorage underTest = new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(db.getDbClient()), issueIndexer,
+  private final WebIssueStorage underTest = new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(db.getDbClient(), mock(RuleDescriptionFormatter.class)), issueIndexer,
     new SequenceUuidFactory());
 
   @Test
index 86143f0b91856ce36fcfe307decec89aa4d7054f..9db8356c600e927ca77e3dafc1aff90a4c9771ce 100644 (file)
@@ -50,6 +50,7 @@ import org.sonar.server.issue.index.IssueIteratorFactory;
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -89,7 +90,7 @@ public class AddCommentActionTest {
   private IssueDbTester issueDbTester = new IssueDbTester(dbTester);
 
   private IssueIndexer issueIndexer = new IssueIndexer(es.client(), dbClient, new IssueIteratorFactory(dbClient), null);
-  private WebIssueStorage serverIssueStorage = new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer,
+  private WebIssueStorage serverIssueStorage = new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer,
     new SequenceUuidFactory());
   private TestIssueChangePostProcessor issueChangePostProcessor = new TestIssueChangePostProcessor();
   private IssueUpdater issueUpdater = new IssueUpdater(dbClient, serverIssueStorage, mock(NotificationManager.class), issueChangePostProcessor,
index 3d0c732ff4e15ab813ffccff97a2284f40729604..94b5be2ad46ee2be7a79550e3b928904d31e89e7 100644 (file)
@@ -45,6 +45,7 @@ import org.sonar.server.issue.notification.IssuesChangesNotification;
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -85,7 +86,7 @@ public class AssignActionTest {
   private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer();
   private AssignAction underTest = new AssignAction(system2, userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
     new IssueUpdater(dbClient,
-      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()),
+      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
       notificationManager, issueChangePostProcessor, issuesChangesSerializer),
     responseWriter);
   private WsActionTester ws = new WsActionTester(underTest);
index 07d0d2af52f21a23c06fce9ca96bf6ffc6598694..9797f60a958392c15e96102506926b3dc2933519 100644 (file)
@@ -60,6 +60,7 @@ import org.sonar.server.issue.workflow.FunctionExecutor;
 import org.sonar.server.issue.workflow.IssueWorkflow;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -115,7 +116,7 @@ public class BulkChangeActionTest {
   private IssueFieldsSetter issueFieldsSetter = new IssueFieldsSetter();
   private IssueWorkflow issueWorkflow = new IssueWorkflow(new FunctionExecutor(issueFieldsSetter), issueFieldsSetter);
   private WebIssueStorage issueStorage = new WebIssueStorage(system2, dbClient,
-    new DefaultRuleFinder(dbClient),
+    new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)),
     new IssueIndexer(es.client(), dbClient, new IssueIteratorFactory(dbClient), null), new SequenceUuidFactory());
   private NotificationManager notificationManager = mock(NotificationManager.class);
   private TestIssueChangePostProcessor issueChangePostProcessor = new TestIssueChangePostProcessor();
index c9d8180ca8befc4c80a1e05f36bd7e7260189ac2..8fefd3eaa062bf7124fbb00b7d692785ee4bf15c 100644 (file)
@@ -51,6 +51,7 @@ import org.sonar.server.issue.workflow.FunctionExecutor;
 import org.sonar.server.issue.workflow.IssueWorkflow;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -96,7 +97,7 @@ public class DoTransitionActionTest {
   private TestIssueChangePostProcessor issueChangePostProcessor = new TestIssueChangePostProcessor();
   private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer();
   private IssueUpdater issueUpdater = new IssueUpdater(dbClient,
-    new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()),
+    new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
     mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer);
   private ArgumentCaptor<SearchResponseData> preloadedSearchResponseDataCaptor = ArgumentCaptor.forClass(SearchResponseData.class);
 
index a819ec58b3c1fac99a2abd067a950444ff653d46..e334d80a7a373a0f0a282b806932c96b7cc2f3ed 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -84,7 +85,7 @@ public class IssueUpdaterTest {
   private TestIssueChangePostProcessor issueChangePostProcessor = new TestIssueChangePostProcessor();
   private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer();
   private IssueUpdater underTest = new IssueUpdater(dbClient,
-    new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()), notificationManager,
+    new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()), notificationManager,
     issueChangePostProcessor, issuesChangesSerializer);
 
   @Test
index 7ba6e06b1561a3d8631adbb1e96aad40731c17fa..3936efae996a40819cc1269dc1757f8e3046f643 100644 (file)
@@ -50,6 +50,7 @@ import org.sonar.server.issue.index.IssueIteratorFactory;
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -88,7 +89,7 @@ public class SetSeverityActionTest {
   private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer();
   private WsActionTester tester = new WsActionTester(new SetSeverityAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
     new IssueUpdater(dbClient,
-      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()),
+      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
       mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer),
     responseWriter));
 
index 63d70c9305ea36abcb35c4d6aa900e82c7e81e51..b4585b5b519fe1bb64bf361d87be606960d1cbca 100644 (file)
@@ -53,6 +53,7 @@ import org.sonar.server.issue.index.IssueIteratorFactory;
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -90,7 +91,7 @@ public class SetTagsActionTest {
 
   private WsActionTester ws = new WsActionTester(new SetTagsAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
     new IssueUpdater(dbClient,
-      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()),
+      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
       mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer),
     responseWriter));
 
index 04418f2a76011c03bcf72e5f282af0cc36211dce..d4b0cfb5cabb6ce57c11cee8c1ae96bd93c2b1c0 100644 (file)
@@ -58,6 +58,7 @@ import org.sonar.server.issue.index.IssueIteratorFactory;
 import org.sonar.server.issue.notification.IssuesChangesNotificationSerializer;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
@@ -101,7 +102,7 @@ public class SetTypeActionTest {
   private IssuesChangesNotificationSerializer issuesChangesSerializer = new IssuesChangesNotificationSerializer();
   private WsActionTester tester = new WsActionTester(new SetTypeAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
     new IssueUpdater(dbClient,
-      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient), issueIndexer, new SequenceUuidFactory()),
+      new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
       mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer), responseWriter, system2));
 
   @Test
index 0a188fbfe2ef8f721f1951564421e574b2075fbb..f1bd898e541cefeb895aa9c114f463342d576acb 100644 (file)
@@ -44,6 +44,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -65,7 +66,7 @@ public class QProfileExportersTest {
   @org.junit.Rule
   public DbTester db = DbTester.create(system2);
 
-  private final RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
+  private final RuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient(), mock(RuleDescriptionFormatter.class));
   private final ProfileExporter[] exporters = new ProfileExporter[] {
     new StandardExporter(), new XooExporter()};
   private final ProfileImporter[] importers = new ProfileImporter[] {
index 729ded73f01c588f9522b4118bfc3f459240c879..6de9225db6fd06e710b552d7e4021cd2d0a27169 100644 (file)
@@ -57,6 +57,7 @@ import org.sonar.server.qualityprofile.builtin.QProfileName;
 import org.sonar.server.qualityprofile.builtin.RuleActivator;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.ServerRuleFinder;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.tester.UserSessionRule;
@@ -100,7 +101,7 @@ public class RegisterQualityProfilesNotificationTest {
   private TypeValidations typeValidations = mock(TypeValidations.class);
   private ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
   private QualityProfileChangeEventService qualityProfileChangeEventService = mock(QualityProfileChangeEventService.class);
-  private ServerRuleFinder ruleFinder = new DefaultRuleFinder(dbClient);
+  private ServerRuleFinder ruleFinder = new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class));
   private BuiltInQProfileInsert builtInQProfileInsert = new BuiltInQProfileInsertImpl(dbClient, ruleFinder, system2, UuidFactoryFast.getInstance(),
     typeValidations, activeRuleIndexer);
   private RuleActivator ruleActivator = new RuleActivator(system2, dbClient, typeValidations, userSessionRule);
index 300cdd7ba695097e3c125fb90b42ccbad9ed68d8..b35d37403d632fef57fa5280ee8f37794d2d2fde 100644 (file)
@@ -45,6 +45,7 @@ import org.sonar.db.rule.RuleParamDto;
 import org.sonar.server.qualityprofile.ActiveRuleChange;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.ServerRuleFinder;
 import org.sonar.server.util.StringTypeValidation;
 import org.sonar.server.util.TypeValidations;
@@ -65,7 +66,7 @@ public class BuiltInQProfileInsertImplTest {
   private final TypeValidations typeValidations = new TypeValidations(singletonList(new StringTypeValidation()));
   private final DbSession dbSession = db.getSession();
   private final DbSession batchDbSession = db.getDbClient().openSession(true);
-  private final ServerRuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient());
+  private final ServerRuleFinder ruleFinder = new DefaultRuleFinder(db.getDbClient(), mock(RuleDescriptionFormatter.class));
   private final ActiveRuleIndexer activeRuleIndexer = mock(ActiveRuleIndexer.class);
   private final BuiltInQProfileInsertImpl underTest = new BuiltInQProfileInsertImpl(db.getDbClient(), ruleFinder, system2, uuidFactory, typeValidations, activeRuleIndexer);
 
index 4eb4ab9bc5ea3f65a40e24660906eb8d68b758bf..41a929b8c57672793238595e88ae947638d88d68 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.server.language.LanguageTesting;
 import org.sonar.server.qualityprofile.builtin.BuiltInQProfile.ActiveRule;
 import org.sonar.server.rule.DefaultRuleFinder;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.ServerRuleFinder;
 
 import static java.util.Arrays.asList;
@@ -52,7 +53,7 @@ public class BuiltInQProfileRepositoryImplTest {
   public DbTester db = DbTester.create();
 
   private final DbClient dbClient = db.getDbClient();
-  private final ServerRuleFinder ruleFinder = new DefaultRuleFinder(dbClient);
+  private final ServerRuleFinder ruleFinder = new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class));
 
   @Test
   public void create_qprofile_with_rule() {
index 9f9d9d7bbb91c6b31e90d73d1ee1f78f4f7d6128..57f92598018f5d6864197f2c2ebe4a538f8b09df 100644 (file)
@@ -34,6 +34,7 @@ import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.rule.RuleCreator;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.text.MacroInterpreter;
@@ -60,7 +61,6 @@ public class CreateActionTest {
 
   private System2 system2 = mock(System2.class);
 
-
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
@@ -74,7 +74,7 @@ public class CreateActionTest {
 
   private WsActionTester ws = new WsActionTester(new CreateAction(db.getDbClient(),
     new RuleCreator(system2, new RuleIndexer(es.client(), db.getDbClient()), db.getDbClient(), newFullTypeValidations(), uuidFactory),
-    new RuleMapper(new Languages(), createMacroInterpreter()),
+    new RuleMapper(new Languages(), createMacroInterpreter(), new RuleDescriptionFormatter()),
     new RuleWsSupport(db.getDbClient(), userSession)));
 
   @Test
index 161e06d44a334bfc383ac2232deba2a236c10b89..12aa783dcb4804e1e55acbebfd34c1e5cbec3c0b 100644 (file)
@@ -54,6 +54,7 @@ import org.sonar.server.qualityprofile.QProfileRulesImpl;
 import org.sonar.server.qualityprofile.RuleActivation;
 import org.sonar.server.qualityprofile.builtin.RuleActivator;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.index.RuleIndex;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.tester.UserSessionRule;
@@ -110,7 +111,7 @@ public class SearchActionTest {
   private final RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(db.getDbClient());
   private final MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
   private final QualityProfileChangeEventService qualityProfileChangeEventService = mock(QualityProfileChangeEventService.class);
-  private final RuleMapper ruleMapper = new RuleMapper(languages, macroInterpreter);
+  private final RuleMapper ruleMapper = new RuleMapper(languages, macroInterpreter, new RuleDescriptionFormatter());
   private final SearchAction underTest = new SearchAction(ruleIndex, activeRuleCompleter, ruleQueryFactory, db.getDbClient(), ruleMapper,
     new RuleWsSupport(db.getDbClient(), userSession));
   private final TypeValidations typeValidations = new TypeValidations(asList(new StringTypeValidation(), new IntegerTypeValidation()));
index 5d5949263aa496d5922236f7e871e55bdf7f4db5..6da5721cfd28e0a6aec0dde1aba1cda50d34600c 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleMetadataDto;
 import org.sonar.db.rule.RuleParamDto;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.text.MacroInterpreter;
 import org.sonar.server.ws.WsActionTester;
@@ -82,7 +83,7 @@ public class ShowActionTest {
   private final MacroInterpreter macroInterpreter = mock(MacroInterpreter.class);
   private final Languages languages = new Languages(newLanguage("xoo", "Xoo"));
   private final WsActionTester ws = new WsActionTester(
-    new ShowAction(db.getDbClient(), new RuleMapper(languages, macroInterpreter),
+    new ShowAction(db.getDbClient(), new RuleMapper(languages, macroInterpreter, new RuleDescriptionFormatter()),
       new ActiveRuleCompleter(db.getDbClient(), languages),
       new RuleWsSupport(db.getDbClient(), userSession)));
 
index 4e1818d62f672ade62d9d921c595de314812b76e..ef3ed9d90320dbda5bd3009d56cb88d5061c55b8 100644 (file)
@@ -29,14 +29,15 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleDescriptionSectionDto;
+import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleMetadataDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.es.EsClient;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.RuleUpdater;
 import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.tester.UserSessionRule;
@@ -81,9 +82,10 @@ public class UpdateActionTest {
 
   private DbClient dbClient = db.getDbClient();
   private EsClient esClient = es.client();
+  private RuleDescriptionFormatter ruleDescriptionFormatter = new RuleDescriptionFormatter();
 
   private Languages languages = new Languages();
-  private RuleMapper mapper = new RuleMapper(languages, createMacroInterpreter());
+  private RuleMapper mapper = new RuleMapper(languages, createMacroInterpreter(), ruleDescriptionFormatter);
   private RuleIndexer ruleIndexer = new RuleIndexer(esClient, dbClient);
   private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
 
index 467040683db0b1781fb50f194ac0e23801da11a9..6ccdff45a30fc7c97cf268fd2b5caf6c896d0421 100644 (file)
@@ -210,6 +210,7 @@ import org.sonar.server.root.ws.RootWsModule;
 import org.sonar.server.rule.CommonRuleDefinitionsImpl;
 import org.sonar.server.rule.RuleCreator;
 import org.sonar.server.rule.RuleDefinitionsLoader;
+import org.sonar.server.rule.RuleDescriptionFormatter;
 import org.sonar.server.rule.RuleUpdater;
 import org.sonar.server.rule.WebServerRuleFinderImpl;
 import org.sonar.server.rule.index.RuleIndexDefinition;
@@ -285,6 +286,7 @@ public class PlatformLevel4 extends PlatformLevel {
     addIfStandalone(StandaloneRuleActivatorEventsDistributor.class);
 
     add(
+      RuleDescriptionFormatter.class,
       ClusterVerification.class,
       LogServerId.class,
       LogOAuthWarning.class,