3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.rule;
22 import java.util.EnumSet;
24 import org.sonar.api.rules.RuleType;
25 import org.sonar.api.server.rule.RulesDefinition;
26 import org.sonar.core.util.UuidFactory;
27 import org.sonar.db.rule.RuleDescriptionSectionDto;
29 import static java.util.Collections.emptySet;
30 import static java.util.Collections.singleton;
31 import static org.apache.commons.lang.StringUtils.isNotEmpty;
32 import static org.sonar.api.rules.RuleType.BUG;
33 import static org.sonar.api.rules.RuleType.CODE_SMELL;
34 import static org.sonar.api.rules.RuleType.VULNERABILITY;
35 import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection;
37 public class LegacyIssueRuleDescriptionSectionsGenerator implements RuleDescriptionSectionsGenerator {
38 private static final Set<RuleType> ISSUE_RULE_TYPES = EnumSet.of(CODE_SMELL, BUG, VULNERABILITY);
40 private final UuidFactory uuidFactory;
42 public LegacyIssueRuleDescriptionSectionsGenerator(UuidFactory uuidFactory) {
43 this.uuidFactory = uuidFactory;
47 public boolean isGeneratorForRule(RulesDefinition.Rule rule) {
48 return ISSUE_RULE_TYPES.contains(rule.type()) && rule.ruleDescriptionSections().isEmpty();
52 public Set<RuleDescriptionSectionDto> generateSections(RulesDefinition.Rule rule) {
53 if (isNotEmpty(rule.htmlDescription())) {
54 return singleton(createDefaultRuleDescriptionSection(uuidFactory.create(), rule.htmlDescription()));
55 } else if (isNotEmpty(rule.markdownDescription())) {
56 return singleton(createDefaultRuleDescriptionSection(uuidFactory.create(), rule.markdownDescription()));