public String getKey() { return ruleParam.getKey(); }
/** * @deprecated visibility should be decreased to protected or package */ @Deprecated public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String value) { this.activeRule = activeRule; this.ruleParam = ruleParam; this.value = value; this.paramKey = ruleParam.getKey(); }
public RuleParam getParam(String key) { for (RuleParam param : params) { if (StringUtils.equals(key, param.getKey())) { return param; } } return null; }
@CheckForNull private String paramDescription(String repositoryKey, String ruleKey, RuleParam param) { String desc = StringUtils.defaultIfEmpty( i18n.getParamDescription(repositoryKey, ruleKey, param.getKey()), param.getDescription()); return StringUtils.defaultIfBlank(desc, null); }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (StringUtils.isEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }
@Test public void rule_with_property() { List<Rule> rules = parseAnnotatedClass(RuleWithProperty.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo("foo"); assertThat(rule.getName()).isEqualTo("bar"); assertThat(rule.getDescription()).isEqualTo("Foo Bar"); assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER); assertThat(rule.getStatus()).isEqualTo(Rule.STATUS_READY); assertThat(rule.getParams()).hasSize(1); RuleParam prop = rule.getParam("property"); assertThat(prop.getKey()).isEqualTo("property"); assertThat(prop.getDescription()).isEqualTo("Ignore ?"); assertThat(prop.getDefaultValue()).isEqualTo("false"); assertThat(prop.getType()).isEqualTo(PropertyType.STRING.name()); }
private void verifyRule(Rule rule, RuleDefinitionDto ruleDefinition, RuleParamDto ruleParam) { assertThat(rule).isNotNull(); assertThat(rule.getName()).isEqualTo(ruleDefinition.getName()); assertThat(rule.getLanguage()).isEqualTo(ruleDefinition.getLanguage()); assertThat(rule.getKey()).isEqualTo(ruleDefinition.getRuleKey()); assertThat(rule.getConfigKey()).isEqualTo(ruleDefinition.getConfigKey()); assertThat(rule.isTemplate()).isEqualTo(ruleDefinition.isTemplate()); assertThat(rule.getCreatedAt().getTime()).isEqualTo(ruleDefinition.getCreatedAt()); assertThat(rule.getUpdatedAt().getTime()).isEqualTo(ruleDefinition.getUpdatedAt()); assertThat(rule.getRepositoryKey()).isEqualTo(ruleDefinition.getRepositoryKey()); assertThat(rule.getSeverity().name()).isEqualTo(ruleDefinition.getSeverityString()); assertThat(rule.getSystemTags()).isEqualTo(ruleDefinition.getSystemTags().stream().toArray(String[]::new)); assertThat(rule.getTags()).isEmpty(); assertThat(rule.getId()).isEqualTo(ruleDefinition.getId()); assertThat(rule.getDescription()).isEqualTo(ruleDefinition.getDescription()); assertThat(rule.getParams()).hasSize(1); org.sonar.api.rules.RuleParam param = rule.getParams().iterator().next(); assertThat(param.getRule()).isSameAs(rule); assertThat(param.getKey()).isEqualTo(ruleParam.getName()); assertThat(param.getDescription()).isEqualTo(ruleParam.getDescription()); assertThat(param.getType()).isEqualTo(ruleParam.getType()); assertThat(param.getDefaultValue()).isEqualTo(ruleParam.getDefaultValue()); } }
newRule.setTags(rule.getTags()); for (RuleParam param : rule.getParams()) { RulesDefinition.NewParam newParam = newRule.createParam(param.getKey()); newParam.setDefaultValue(param.getDefaultValue()); newParam.setDescription(paramDescription(repository.getKey(), rule.getKey(), param));
public String getKey() { return ruleParam.getKey(); }
public String getKey() { return ruleParam.getKey(); }
/** * @deprecated visibility should be decreased to protected or package */ @Deprecated public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String value) { this.activeRule = activeRule; this.ruleParam = ruleParam; this.value = value; this.paramKey = ruleParam.getKey(); }
public RuleParam getParam(String key) { for (RuleParam param : params) { if (StringUtils.equals(key, param.getKey())) { return param; } } return null; }
/** * @deprecated visibility should be decreased to protected or package */ @Deprecated public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String value) { this.activeRule = activeRule; this.ruleParam = ruleParam; this.value = value; this.paramKey = ruleParam.getKey(); }
public RuleParam getParam(String key) { for (RuleParam param : params) { if (StringUtils.equals(key, param.getKey())) { return param; } } return null; }
private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
private static void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { final String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
@CheckForNull private String paramDescription(String repositoryKey, String ruleKey, RuleParam param) { String desc = StringUtils.defaultIfEmpty( i18n.getParamDescription(repositoryKey, ruleKey, param.getKey()), param.getDescription()); return StringUtils.defaultIfBlank(desc, null); }
private static void addRuleProperties(ActiveRule activeRule, PmdRule pmdRule) { if ((activeRule.getActiveRuleParams() != null) && !activeRule.getActiveRuleParams().isEmpty()) { List<PmdProperty> properties = new ArrayList<>(); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { properties.add(new PmdProperty(activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue())); } pmdRule.setProperties(properties); } }
static List<ActiveRuleParam> buildActiveRuleParams(DelphiRule delphiRule, Rule repositoryRule, ActiveRule activeRule) { List<ActiveRuleParam> activeRuleParams = new ArrayList<ActiveRuleParam>(); if (delphiRule.getProperties() != null) { for (Property property : delphiRule.getProperties()) { if (repositoryRule.getParams() != null) { for (RuleParam ruleParam : repositoryRule.getParams()) { if (ruleParam.getKey().equals(property.getName())) { activeRuleParams.add(new ActiveRuleParam(activeRule, ruleParam, property.getValue())); } } } } } return activeRuleParams; }