org.sonar.api.rule.RuleStatus Java Examples
The following examples show how to use
org.sonar.api.rule.RuleStatus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApexRulesDefinition.java From enforce-sonarqube-plugin with MIT License | 6 votes |
/** * Adds checks necessary information from JSON file. * * @param rule the new rule to add the information. * @param metadataKey rule key. */ private void addMetadata(NewRule rule, String metadataKey) { URL resource = ExternalDescriptionLoader.class.getResource(String.format("%s/%s.json", RESOURCE_BASE_PATH, metadataKey)); if (resource != null) { RuleMetatada metadata = gson.fromJson(readResource(resource), RuleMetatada.class); rule.setName(metadata.title); rule.setSeverity(metadata.defaultSeverity.toUpperCase()); rule.addTags(metadata.tags); rule.setStatus(RuleStatus.valueOf(metadata.status.toUpperCase())); rule.setDebtSubCharacteristic(metadata.sqaleSubCharacteristic); if (metadata.remediation != null) { rule.setDebtRemediationFunction(metadata.remediation.remediationFunction(rule.debtRemediationFunctions())); rule.setEffortToFixDescription(metadata.remediation.linearDesc); } } }
Example #2
Source File: RulesLoader.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 6 votes |
private RulesDefinition.NewRule createRule(RulesDefinition.NewExtendedRepository repo, Class clazz, Rule ruleAnnotation) { String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName()); String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null); String description = StringUtils.defaultIfEmpty(loadDescription(ruleKey), "No description yet."); RulesDefinition.NewRule rule = repo.createRule(ruleKey); rule.setName(ruleName).setMarkdownDescription(description); rule.setSeverity(ruleAnnotation.priority().name()); rule.setStatus(RuleStatus.valueOf(ruleAnnotation.status())); rule.setTags(ruleAnnotation.tags()); setMetadata(rule, clazz); List<Field> fields = FieldUtils2.getFields(clazz, true); for (Field field : fields) { loadParameters(rule, field); } return rule; }
Example #3
Source File: SmellRulesDefinition.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 6 votes |
private void addMetadata(final NewRule rule, final String metadataKey) { final String json = readRuleDefinitionResource(metadataKey + ".json"); if (json != null) { final RuleMetadata metadata = this.gson.fromJson(json, RuleMetadata.class); rule.setSeverity(metadata.defaultSeverity.toUpperCase(Locale.US)); rule.setName(metadata.title); rule.setTags(metadata.tags); rule.setStatus(RuleStatus.valueOf(metadata.status.toUpperCase(Locale.US))); rule.setType(RuleType.valueOf(metadata.type)); if (metadata.remediation != null) { // metadata.remediation is null for template rules rule.setDebtRemediationFunction(metadata.remediation.remediationFunction(rule.debtRemediationFunctions())); rule.setGapDescription(metadata.remediation.linearDesc); } } }
Example #4
Source File: WebDriverRulesDefinition.java From sonar-webdriver-plugin with MIT License | 5 votes |
private void addMetadata(NewRule rule, String metadataKey) { URL resource = WebDriverRulesDefinition.class.getResource(RESOURCE_BASE_PATH + "/" + metadataKey + "_java.json"); if (resource != null) { RuleMetadata metadata = gson.fromJson(readResource(resource), RuleMetadata.class); rule.setSeverity(metadata.defaultSeverity.toUpperCase(Locale.US)); rule.setName(metadata.title); rule.addTags(metadata.tags); rule.setType(RuleType.valueOf(metadata.type)); rule.setStatus(RuleStatus.valueOf(metadata.status.toUpperCase(Locale.US))); if (metadata.remediation != null) { rule.setDebtRemediationFunction(metadata.remediation.remediationFunction(rule.debtRemediationFunctions())); rule.setGapDescription(metadata.remediation.linearDesc); } } }
Example #5
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 5 votes |
private void addMetadata(NewRule rule, String metadataKey) { URL resource = SonarDefinition.class.getResource(RESOURCE_BASE_PATH + "/" + metadataKey + "_java.json"); if (resource != null) { RuleMetatada metatada = gson.fromJson(readResource(resource), RuleMetatada.class); rule.setSeverity(metatada.defaultSeverity.toUpperCase(Locale.US)); rule.setName(metatada.title); rule.addTags(metatada.tags); rule.setType(RuleType.valueOf(metatada.type)); rule.setStatus(RuleStatus.valueOf(metatada.status.toUpperCase(Locale.US))); if (metatada.remediation != null) { rule.setDebtRemediationFunction(metatada.remediation.remediationFunction(rule.debtRemediationFunctions())); rule.setGapDescription(metatada.remediation.linearDesc); } } }
Example #6
Source File: SonarDefinition.java From vjtools with Apache License 2.0 | 5 votes |
private void addMetadata(NewRule rule, String metadataKey) { URL resource = SonarDefinition.class.getResource(RESOURCE_BASE_PATH + "/" + metadataKey + "_java.json"); if (resource != null) { RuleMetatada metatada = gson.fromJson(readResource(resource), RuleMetatada.class); rule.setSeverity(metatada.defaultSeverity.toUpperCase(Locale.US)); rule.setName(metatada.title); rule.addTags(metatada.tags); rule.setType(RuleType.valueOf(metatada.type)); rule.setStatus(RuleStatus.valueOf(metatada.status.toUpperCase(Locale.US))); if (metatada.remediation != null) { rule.setDebtRemediationFunction(metatada.remediation.remediationFunction(rule.debtRemediationFunctions())); rule.setGapDescription(metatada.remediation.linearDesc); } } }
Example #7
Source File: RubyRulesDefinition.java From sonar-ruby-plugin with MIT License | 5 votes |
private void createRule(NewRepository repository, RubocopRule rubocopRule) { repository .createRule(rubocopRule.key) .setName(rubocopRule.name) .setSeverity(rubocopRule.severity) .setHtmlDescription(rubocopRule.htmlDescription) .setStatus(RuleStatus.READY) .setType(rubocopRule.debtType); }
Example #8
Source File: SmellRulesDefinitionTest.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void define_should_createRepositoryAndRegisterAllSmellPluginChecks() { Mockito.when(this.repository.key()) .thenReturn(EXPECTED_REPOSITORY_KEY); Mockito.when(this.rule.key()) .thenReturn(LAST_RULE_KEY); // Some plumbering... Mockito.when(this.context.createRepository(Matchers.anyString(), Matchers.anyString())) .thenReturn(this.repository); Mockito.when(this.repository.setName(Matchers.anyString())) .thenReturn(this.repository); Mockito.when(this.repository.rules()) .thenReturn(ImmutableList.<NewRule> of(this.rule)); Mockito.when(this.repository.createRule(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.repository.rule(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setName(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setHtmlDescription(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setSeverity(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setTemplate(Matchers.anyBoolean())) .thenReturn(this.rule); Mockito.when(this.rule.setStatus(Matchers.any(RuleStatus.class))) .thenReturn(this.rule); Mockito.when(this.rule.setTags(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setDebtSubCharacteristic(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setDebtRemediationFunction(Matchers.any(DebtRemediationFunction.class))) .thenReturn(this.rule); Mockito.when(this.rule.debtRemediationFunctions()) .thenReturn(this.functions); Mockito.when(this.rule.setEffortToFixDescription(Matchers.anyString())) .thenReturn(this.rule); // Execute final SmellRulesDefinition sut = new SmellRulesDefinition(); sut.define(this.context); // Verify behavior Mockito.verify(this.context, Mockito.times(1)) .createRepository(Matchers.eq(EXPECTED_REPOSITORY_KEY), Matchers.eq(Java.KEY)); Mockito.verify(this.repository, Mockito.times(1)) .setName(Matchers.eq(EXPECTED_REPOSITORY_NAME)); Mockito.verify(this.repository, Mockito.times(27)) .createRule(this.captor.capture()); Assertions.assertThat(this.captor.getValue()) .isEqualTo(LAST_RULE_KEY); Mockito.verify(this.rule, Mockito.times(28)) .key(); Mockito.verify(this.rule, Mockito.times(1)) .setInternalKey(Matchers.eq(LAST_RULE_KEY)); Mockito.verify(this.repository, Mockito.times(1)) .done(); }
Example #9
Source File: TsRulesDefinition.java From SonarTsPlugin with MIT License | 4 votes |
private void createRule(NewRepository repository, TsLintRule tsRule) { NewRule sonarRule = repository .createRule(tsRule.key) .setName(tsRule.name) .setSeverity(tsRule.severity) .setHtmlDescription(tsRule.htmlDescription) .setStatus(RuleStatus.READY); if (tsRule.hasDebtRemediation) { DebtRemediationFunction debtRemediationFn = null; DebtRemediationFunctions funcs = sonarRule.debtRemediationFunctions(); switch (tsRule.debtRemediationFunction) { case LINEAR: debtRemediationFn = funcs.linear(tsRule.debtRemediationScalar); break; case LINEAR_OFFSET: debtRemediationFn = funcs.linearWithOffset(tsRule.debtRemediationScalar, tsRule.debtRemediationOffset); break; case CONSTANT_ISSUE: debtRemediationFn = funcs.constantPerIssue(tsRule.debtRemediationScalar); break; } sonarRule.setDebtRemediationFunction(debtRemediationFn); } RuleType type = null; if (tsRule.debtType != null && RuleType.names().contains(tsRule.debtType)) { // Try and parse it as a new-style rule type (since 5.5 SQALE's been replaced // with something simpler, and there's really only three buckets) type = RuleType.valueOf(tsRule.debtType); } if (type == null) { type = RuleType.CODE_SMELL; } sonarRule.setType(type); }