|
34 | 34 | import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction; |
35 | 35 | import org.sonar.api.server.rule.RuleParamType; |
36 | 36 | import org.sonar.api.server.rule.RulesDefinition; |
| 37 | +import org.sonar.plugins.checkstyle.metadata.SonarRulePropertyLoader.AdditionalRuleProperties; |
37 | 38 |
|
38 | 39 | import com.fasterxml.jackson.databind.DeserializationFeature; |
39 | 40 | import com.fasterxml.jackson.databind.ObjectMapper; |
@@ -95,44 +96,55 @@ public void createRulesWithMetadata() { |
95 | 96 |
|
96 | 97 | metadataRepo.entrySet().stream() |
97 | 98 | .filter(entry -> entry.getValue().getModuleType() == ModuleType.CHECK) |
98 | | - .forEach(check -> { |
99 | | - final ModuleDetails moduleDetails = check.getValue(); |
100 | | - final boolean isTemplate = isTemplateRule(moduleDetails); |
101 | | - final String fullCheckName = getFullCheckName(moduleDetails.getName()); |
102 | | - final String fullQualifiedName = moduleDetails.getFullQualifiedName(); |
103 | | - final RulesDefinition.NewRule rule; |
104 | | - if (isTemplate) { |
105 | | - rule = repository |
106 | | - .createRule(fullQualifiedName + "template") |
107 | | - .setName(fullCheckName + " Template"); |
108 | | - } |
109 | | - else { |
110 | | - rule = repository |
111 | | - .createRule(fullQualifiedName) |
112 | | - .setName(fullCheckName); |
113 | | - } |
114 | | - rule.setHtmlDescription(moduleDetails.getDescription()) |
115 | | - .setInternalKey(getInternalKey(moduleDetails)) |
116 | | - .setSeverity("MINOR") |
117 | | - .setStatus(RuleStatus.READY); |
118 | | - if (!NO_SQALE.contains(rule.key())) { |
119 | | - rule.setDebtRemediationFunction(debtRemediationFunction); |
120 | | - } |
121 | | - final String tag = getRuleTag(moduleDetails.getFullQualifiedName(), |
122 | | - additionalRuleData.get(check.getKey())); |
123 | | - if (tag != null) { |
124 | | - rule.setTags(tag); |
125 | | - } |
126 | | - if (isTemplate) { |
127 | | - rule.setTemplate(true); |
128 | | - } |
| 99 | + .forEach(check -> forEachCheck(check, additionalRuleData, debtRemediationFunction)); |
| 100 | + } |
129 | 101 |
|
130 | | - for (ModulePropertyDetails property : moduleDetails.getProperties()) { |
131 | | - constructParams(moduleDetails.getName(), |
132 | | - rule.createParam(property.getName()), |
133 | | - property); |
134 | | - } |
135 | | - }); |
| 102 | + /** |
| 103 | + * Processing to do when examining each check found. |
| 104 | + * |
| 105 | + * @param check The check to do processing on. |
| 106 | + * @param additionalRuleData The additional rule data to save. |
| 107 | + * @param debtRemediationFunction The remediation function to use. |
| 108 | + */ |
| 109 | + private void forEachCheck(Map.Entry<String, ModuleDetails> check, |
| 110 | + Map<String, AdditionalRuleProperties> additionalRuleData, |
| 111 | + DebtRemediationFunction debtRemediationFunction) { |
| 112 | + final ModuleDetails moduleDetails = check.getValue(); |
| 113 | + final boolean isTemplate = isTemplateRule(moduleDetails); |
| 114 | + final String fullCheckName = getFullCheckName(moduleDetails.getName()); |
| 115 | + final String fullQualifiedName = moduleDetails.getFullQualifiedName(); |
| 116 | + final RulesDefinition.NewRule rule; |
| 117 | + if (isTemplate) { |
| 118 | + rule = repository |
| 119 | + .createRule(fullQualifiedName + "template") |
| 120 | + .setName(fullCheckName + " Template"); |
| 121 | + } |
| 122 | + else { |
| 123 | + rule = repository |
| 124 | + .createRule(fullQualifiedName) |
| 125 | + .setName(fullCheckName); |
| 126 | + } |
| 127 | + rule.setHtmlDescription(moduleDetails.getDescription()) |
| 128 | + .setInternalKey(getInternalKey(moduleDetails)) |
| 129 | + .setSeverity("MINOR") |
| 130 | + .setStatus(RuleStatus.READY); |
| 131 | + if (!NO_SQALE.contains(rule.key())) { |
| 132 | + rule.setDebtRemediationFunction(debtRemediationFunction); |
| 133 | + } |
| 134 | + final String tag = getRuleTag(moduleDetails.getFullQualifiedName(), |
| 135 | + additionalRuleData.get(check.getKey())); |
| 136 | + if (tag != null) { |
| 137 | + rule.setTags(tag); |
| 138 | + } |
| 139 | + if (isTemplate) { |
| 140 | + rule.setTemplate(true); |
| 141 | + } |
| 142 | + |
| 143 | + for (ModulePropertyDetails property : moduleDetails.getProperties()) { |
| 144 | + constructParams(moduleDetails.getName(), |
| 145 | + rule.createParam(property.getName()), |
| 146 | + property); |
| 147 | + } |
136 | 148 | } |
137 | 149 |
|
138 | 150 | /** |
@@ -222,6 +234,7 @@ else if ("anyTokenTypesSet".equals(paramType)) { |
222 | 234 | /** |
223 | 235 | * This check is required since the PARAM_TYPE column has size 512, and exceeding it |
224 | 236 | * will result in an error in DB updates |
| 237 | + * |
225 | 238 | * @param values array of values |
226 | 239 | * @return true if the size has exceeded the limit |
227 | 240 | */ |
|
0 commit comments