@Override @CheckForNull public Rule findByKey(RuleKey key) { return delegate.findByKey(key); }
@Override @CheckForNull public Rule find(RuleQuery query) { return delegate.find(query); }
@Override public Collection<Rule> findAll(RuleQuery query) { return delegate.findAll(query); }
@Override @CheckForNull @Deprecated public Rule findById(int ruleId) { return delegate.findById(ruleId); }
@Override @CheckForNull @Deprecated public Rule findById(int ruleId) { return delegate.findById(ruleId); }
@Override @CheckForNull public Rule findByKey(String repositoryKey, String key) { return delegate.findByKey(repositoryKey, key); }
@Override @CheckForNull public Rule find(RuleQuery query) { return delegate.find(query); }
@Override public Collection<Rule> findAll(RuleQuery query) { return delegate.findAll(query); }
@CheckForNull protected Integer getRuleId(Issue issue) { Rule rule = ruleFinder.findByKey(issue.ruleKey()); return rule != null ? rule.getId() : null; } }
private void createActiveRule(SMInputCursor rulesCursor, Map<String, ActiveRule> activeRules, String gendarmeCategory, RulesProfile profile, RulePriority rulePriority) throws XMLStreamException { String[] includedRules = StringUtils.split(rulesCursor.getAttrValue("include"), '|'); for (int i = 0; i < includedRules.length; i++) { String configKey = includedRules[i].trim() + "@" + gendarmeCategory; ActiveRule activeRule = activeRules.get(configKey); if (activeRule == null) { Rule rule = ruleFinder.find(ruleQuery.withConfigKey(configKey)); if (rule != null) { activeRule = profile.activateRule(rule, rulePriority); activeRules.put(configKey, activeRule); } } else if (activeRule.getSeverity().equals(RulePriority.MAJOR)) { // MAJOR is the default one: maybe another priority has been defined and we must set it activeRule.setSeverity(rulePriority); } } }
private Iterable<Rule> rules() { return Iterables.concat( ruleFinder.findAll(RuleQuery.create().withRepositoryKey(FindbugsRulesDefinition.REPOSITORY_KEY)), ruleFinder.findAll(RuleQuery.create().withRepositoryKey(FbContribRulesDefinition.REPOSITORY_KEY)), ruleFinder.findAll(RuleQuery.create().withRepositoryKey(FindSecurityBugsRulesDefinition.REPOSITORY_KEY)), ruleFinder.findAll(RuleQuery.create().withRepositoryKey(FindSecurityBugsJspRulesDefinition.REPOSITORY_KEY))); }
private RuleFinder newRuleFinder() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock iom) throws Throwable { Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); rule.createParameter("format"); rule.createParameter("message"); return rule; } }); return ruleFinder; } }
private void processRule(RulesProfile profile, String path, String moduleName, Map<String, String> properties, ValidationMessages messages) throws XMLStreamException { Rule rule; String id = properties.get("id"); String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { String configKey = path + moduleName; rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
Rule rule = ruleFinder.findByKey(repositoryKey, key); if (rule == null) { messages.addWarningText("Rule not found: " + ruleToString(repositoryKey, key));
messages.addWarningText(message.toString()); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PHPMD_REPOSITORY_KEY).withConfigKey(configKey)); if (rule == null) { StringBuilder message = new StringBuilder("Unable to import unknown PMD rule '");
@Test public void shouldParseOnlyWantedProfile() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock iom) throws Throwable { return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); } }); ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages); assertThat(profile.getActiveRule("squid", "fake")).isNotNull(); assertThat(profile.getActiveRule("squid", "other")).isNull(); } }
private void processRule(RulesProfile profile, String path, String moduleName, SMInputCursor moduleCursor, ValidationMessages messages) throws XMLStreamException { Map<String, String> properties = processProps(moduleCursor); Rule rule; String id = properties.get("id"); String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { String configKey = path + moduleName; rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
@Test public void shouldParseAnnotatedClasses() { RuleFinder ruleFinder = mock(RuleFinder.class); when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { public Rule answer(InvocationOnMock iom) throws Throwable { return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]); } }); ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages); assertThat(profile.getName()).isEqualTo("Foo way"); assertThat(profile.getLanguage()).isEqualTo("java"); assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER); assertThat(messages.hasErrors()).isFalse(); }
private void processRule(RulesProfile profile, String path, String moduleName, Map<String, String> properties, ValidationMessages messages) { final Rule rule; final String id = properties.get("id"); final String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create() .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { final String configKey = path + moduleName; rule = ruleFinder .find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY) .withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { final ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
private void addRule(Class aClass, BelongsToProfile annotation, RulesProfile profile, String repositoryKey, ValidationMessages messages) { if ((annotation != null) && StringUtils.equals(annotation.title(), profile.getName())) { String ruleKey = RuleAnnotationUtils.getRuleKey(aClass); Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey); if (rule == null) { messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + ruleKey + "]"); } else { RulePriority priority = null; if (annotation.priority() != null) { priority = RulePriority.fromCheckPriority(annotation.priority()); } profile.activateRule(rule, priority); } } } }