You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IssueExclusionProperties.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. package org.sonar.core.config;
  21. import com.google.common.collect.ImmutableList;
  22. import java.util.List;
  23. import org.sonar.api.CoreProperties;
  24. import org.sonar.api.PropertyType;
  25. import org.sonar.api.config.PropertyDefinition;
  26. import org.sonar.api.config.PropertyFieldDefinition;
  27. import org.sonar.api.resources.Qualifiers;
  28. public final class IssueExclusionProperties {
  29. public static final String SUB_CATEGORY_IGNORE_ISSUES = "issues";
  30. public static final String EXCLUSION_KEY_PREFIX = "sonar.issue.ignore";
  31. public static final String INCLUSION_KEY_PREFIX = "sonar.issue.enforce";
  32. public static final String MULTICRITERIA_SUFFIX = ".multicriteria";
  33. public static final String PATTERNS_MULTICRITERIA_EXCLUSION_KEY = EXCLUSION_KEY_PREFIX + MULTICRITERIA_SUFFIX;
  34. public static final String PATTERNS_MULTICRITERIA_INCLUSION_KEY = INCLUSION_KEY_PREFIX + MULTICRITERIA_SUFFIX;
  35. public static final String RESOURCE_KEY = "resourceKey";
  36. private static final String PROPERTY_FILE_PATH_PATTERN = "File Path Pattern";
  37. public static final String RULE_KEY = "ruleKey";
  38. private static final String PROPERTY_RULE_KEY_PATTERN = "Rule Key Pattern";
  39. private static final String PROPERTY_RULE_KEY_PATTERN_HELP = "<br/>A rule key pattern consists of the rule repository name, followed by a colon, followed by a rule key "
  40. + "or rule name fragment. For example:"
  41. + "<ul><li>squid:S1195</li><li>squid:*Naming*</li></ul>";
  42. public static final String BLOCK_SUFFIX = ".block";
  43. public static final String PATTERNS_BLOCK_KEY = EXCLUSION_KEY_PREFIX + BLOCK_SUFFIX;
  44. public static final String BEGIN_BLOCK_REGEXP = "beginBlockRegexp";
  45. public static final String END_BLOCK_REGEXP = "endBlockRegexp";
  46. public static final String ALLFILE_SUFFIX = ".allfile";
  47. public static final String PATTERNS_ALLFILE_KEY = EXCLUSION_KEY_PREFIX + ALLFILE_SUFFIX;
  48. public static final String FILE_REGEXP = "fileRegexp";
  49. public static final int LARGE_SIZE = 40;
  50. private IssueExclusionProperties() {
  51. // only static
  52. }
  53. public static List<PropertyDefinition> all() {
  54. return ImmutableList.of(
  55. PropertyDefinition.builder(PATTERNS_MULTICRITERIA_EXCLUSION_KEY)
  56. .category(CoreProperties.CATEGORY_EXCLUSIONS)
  57. .subCategory(SUB_CATEGORY_IGNORE_ISSUES)
  58. .name("Ignore Issues on Multiple Criteria")
  59. .description("Patterns to ignore issues on certain components and for certain coding rules." + PROPERTY_RULE_KEY_PATTERN_HELP)
  60. .onQualifiers(Qualifiers.PROJECT)
  61. .index(3)
  62. .fields(
  63. PropertyFieldDefinition.build(RULE_KEY)
  64. .name(PROPERTY_RULE_KEY_PATTERN)
  65. .description("Pattern to match rules which should be ignored.")
  66. .type(PropertyType.STRING)
  67. .build(),
  68. PropertyFieldDefinition.build(RESOURCE_KEY)
  69. .name(PROPERTY_FILE_PATH_PATTERN)
  70. .description("Pattern to match files which should be ignored.")
  71. .type(PropertyType.STRING)
  72. .build()
  73. )
  74. .build(),
  75. PropertyDefinition.builder(PATTERNS_BLOCK_KEY)
  76. .category(CoreProperties.CATEGORY_EXCLUSIONS)
  77. .subCategory(SUB_CATEGORY_IGNORE_ISSUES)
  78. .name("Ignore Issues in Blocks")
  79. .description("Patterns to ignore all issues (except the ones from the common repository) on specific blocks of code, " +
  80. "while continuing to scan and mark issues on the remainder of the file.")
  81. .onQualifiers(Qualifiers.PROJECT)
  82. .index(2)
  83. .fields(
  84. PropertyFieldDefinition.build(BEGIN_BLOCK_REGEXP)
  85. .name("Regular Expression for Start of Block")
  86. .description("If this regular expression is found in a file, then following lines are ignored until end of block.")
  87. .type(PropertyType.STRING)
  88. .build(),
  89. PropertyFieldDefinition.build(END_BLOCK_REGEXP)
  90. .name("Regular Expression for End of Block")
  91. .description("If specified, this regular expression is used to determine the end of code blocks to ignore. If not, then block ends at the end of file.")
  92. .type(PropertyType.STRING)
  93. .build()
  94. )
  95. .build(),
  96. PropertyDefinition.builder(PATTERNS_ALLFILE_KEY)
  97. .category(CoreProperties.CATEGORY_EXCLUSIONS)
  98. .subCategory(SUB_CATEGORY_IGNORE_ISSUES)
  99. .name("Ignore Issues on Files")
  100. .description("Patterns to ignore all issues (except the ones from the common repository) on files that contain a block of code matching a given regular expression.")
  101. .onQualifiers(Qualifiers.PROJECT)
  102. .index(1)
  103. .fields(
  104. PropertyFieldDefinition.build(FILE_REGEXP)
  105. .name("Regular Expression")
  106. .description("If this regular expression is found in a file, then the whole file is ignored.")
  107. .type(PropertyType.STRING)
  108. .build()
  109. )
  110. .build(),
  111. PropertyDefinition.builder(PATTERNS_MULTICRITERIA_INCLUSION_KEY)
  112. .category(CoreProperties.CATEGORY_EXCLUSIONS)
  113. .subCategory(SUB_CATEGORY_IGNORE_ISSUES)
  114. .name("Restrict Scope of Coding Rules")
  115. .description("Patterns to restrict the application of a rule to only certain components, ignoring all others." + PROPERTY_RULE_KEY_PATTERN_HELP)
  116. .onQualifiers(Qualifiers.PROJECT)
  117. .index(4)
  118. .fields(
  119. PropertyFieldDefinition.build(RULE_KEY)
  120. .name(PROPERTY_RULE_KEY_PATTERN)
  121. .description("Pattern used to match rules which should be restricted.")
  122. .type(PropertyType.STRING)
  123. .build(),
  124. PropertyFieldDefinition.build(RESOURCE_KEY)
  125. .name(PROPERTY_FILE_PATH_PATTERN)
  126. .description("Pattern used to match files to which the rules should be restricted.")
  127. .type(PropertyType.STRING)
  128. .build()
  129. )
  130. .build()
  131. );
  132. }
  133. }