/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
@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(); } }
@Test public void importProfile() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfile.xml", validation); assertThat(profile.getLanguage()).isEqualTo("java"); assertThat(profile.getName()).isEqualTo("sonar way"); assertThat(validation.hasErrors()).isFalse(); assertThat(profile).isNotNull(); assertThat(profile.getActiveRule("checkstyle", "IllegalRegexp").getSeverity()).isEqualTo(RulePriority.CRITICAL); }
@Test public void importProfileWithRuleParameters() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfileWithRuleParameters.xml", validation); assertThat(validation.hasErrors()).isFalse(); assertThat(validation.hasWarnings()).isFalse(); ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp"); assertThat(rule.getParameter("format")).isEqualTo("foo"); assertThat(rule.getParameter("message")).isEqualTo("with special characters < > &"); }
@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(); }
@Test public void importProfileWithUnknownRuleParameter() { ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = parse("importProfileWithUnknownRuleParameter.xml", validation); assertThat(validation.getWarnings()).hasSize(1); ActiveRule rule = profile.getActiveRule("checkstyle", "IllegalRegexp"); assertThat(rule.getParameter("unknown")).isNull(); }
@Test public void activateRuleWithDefaultPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, null); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.CRITICAL); }
@Test public void activateRuleWithSpecificPriority() { RulesProfile profile = RulesProfile.create(); Rule rule = Rule.create("repo", "key1", "name1").setSeverity(RulePriority.CRITICAL); profile.activateRule(rule, RulePriority.MINOR); assertThat(profile.getActiveRule("repo", "key1").getSeverity()).isEqualTo(RulePriority.MINOR); }
@Override public ActiveRule getActiveRule(Rule rule) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { return activeRule; } } return null; }
@Override public ActiveRule getActiveRule(String repositoryKey, String ruleKey) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey); if (activeRule != null) { return activeRule; } } return null; }
@Override public ActiveRule getActiveRule(String repositoryKey, String ruleKey) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(repositoryKey, ruleKey); if (activeRule != null) { return activeRule; } } return null; }
@Override public ActiveRule getActiveRule(Rule rule) { for (RulesProfile profile : profiles) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { return activeRule; } } return null; }
/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
/** * Note: disabled rules are excluded. */ @CheckForNull public ActiveRule getActiveRule(Rule rule) { return getActiveRule(rule.getRepositoryKey(), rule.getKey()); }
private void initSetOfDirs(Project project) { dirsWithoutPackageInfo = Sets.newHashSet(); ActiveRule activeRule = rulesProfile.getActiveRule(CheckList.REPOSITORY_KEY, PackageInfoCheck.RULE_KEY); if (activeRule != null) { CodeVisitor check = checkInstanceOf(activeRule.getRule().ruleKey()); if (check != null) { Set<File> dirs = ((PackageInfoCheck) check).getDirectoriesWithoutPackageFile(); for (File dir : dirs) { dirsWithoutPackageInfo.add(Directory.fromIOFile(dir, project)); } } } } }
private void updateUnmatchedIssue(DefaultIssue issue, boolean forceEndOfLife) { issue.setNew(false); boolean manualIssue = !Strings.isNullOrEmpty(issue.reporter()); Rule rule = ruleFinder.findByKey(issue.ruleKey()); if (manualIssue) { // Manual rules are not declared in Quality profiles, so no need to check ActiveRule boolean isRemovedRule = rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus()); issue.setEndOfLife(forceEndOfLife || isRemovedRule); issue.setOnDisabledRule(isRemovedRule); } else { ActiveRule activeRule = rulesProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule()); issue.setEndOfLife(true); issue.setOnDisabledRule(activeRule == null || rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus())); } }