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;
private static void populateLevel4(Container container, Props props) {
container.add(
+ RuleDescriptionFormatter.class,
ResourceTypes.class,
DefaultResourceTypes.get(),
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.
*/
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
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();
.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) {
+++ /dev/null
-/*
- * 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 + '\'' +
- '}';
- }
-
-}
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;
}
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())
.sorted(SQ_CATEGORY_KEYS_ORDERING)
.collect(joining(", ")));
}
- return RuleDoc.of(dto, securityStandards);
+ return RuleDoc.createFrom(dto, securityStandards);
}
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 {
.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() {
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());
}
.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>"
@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();
}
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();
}
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());
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();
}
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())
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()))
private RuleIndex underTest = new RuleIndex(es.client(), system2);
private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
-
+
@Test
public void search_all_rules() {
createRule();
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));
}
}
- 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) {
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()
.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<>();
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
private RuleDto[] ruleDtos;
private RuleParamDto[] ruleParams;
private CachingRuleFinder underTest;
+ private RuleDescriptionFormatter ruleDescriptionFormatter = new RuleDescriptionFormatter();
@Before()
public void setUp() {
.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");
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);
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);
}
};
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());
};
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());
};
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());
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());
};
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)
};
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)
};
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)
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)
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() {
return Set.of(builder().uuid(UuidFactoryFast.getInstance().create()).key("default").content(description).build());
});
-
when(ruleDescriptionSectionsGenerator.isGeneratorForRule(any())).thenReturn(true);
}
verifyHotspot(hotspotRule);
}
-
private void verifyRule(RuleDto rule) {
assertThat(rule.getName()).isEqualTo("One");
assertThat(rule.getDefaultRuleDescriptionSection().getContent()).isEqualTo("Description of One");
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;
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) {
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));
}
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;
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
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;
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,
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;
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);
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;
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();
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;
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);
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;
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
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;
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));
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;
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));
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;
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
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;
@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[] {
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;
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);
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;
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);
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;
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() {
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;
private System2 system2 = mock(System2.class);
-
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
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
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;
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()));
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;
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)));
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;
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();
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;
addIfStandalone(StandaloneRuleActivatorEventsDistributor.class);
add(
+ RuleDescriptionFormatter.class,
ClusterVerification.class,
LogServerId.class,
LogOAuthWarning.class,