RuleSet implements ChecksumAware { public boolean applies(File file) { return file == null || filter.filter(file); } private  RuleSet(final RuleSetBuilder builder);  RuleSet(final RuleSet rs); @Deprecated List<String> getExcludePatterns(); int size(); Collection<Rule> getRules(); Rule getRuleByName(String ruleName); boolean applies(File file); void start(RuleContext ctx); void apply(List<? extends Node> acuList, RuleContext ctx); static boolean applies(Rule rule, LanguageVersion languageVersion); void end(RuleContext ctx); @Override boolean equals(Object o); @Override int hashCode(); String getFileName(); String getName(); String getDescription(); @Deprecated List<String> getIncludePatterns(); List<Pattern> getFileExclusions(); List<Pattern> getFileInclusions(); @Deprecated boolean usesDFA(Language language); @Deprecated boolean usesTypeResolution(Language language); @Deprecated boolean usesMultifile(Language language); void removeDysfunctionalRules(Collection<Rule> collector); @Override long getChecksum();  }
@Test public void testLanguageApplies() { Rule rule = new MockRule(); rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME)); assertFalse("Different languages should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(Dummy2LanguageModule.NAME).getDefaultVersion())); rule.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME)); assertTrue("Same language with no min/max should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5"))); rule.setMinimumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5")); assertTrue("Same language with valid min only should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5"))); rule.setMaximumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.6")); assertTrue("Same language with valid min and max should apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.5"))); assertFalse("Same language with outside range of min/max should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.4"))); assertFalse("Same language with outside range of min/max should not apply", RuleSet.applies(rule, LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.7"))); }
@Test public void testIncludeExcludeApplies() { File file = new File("C:\\myworkspace\\project\\some\\random\\package\\RandomClass.java"); RuleSet ruleSet = createRuleSetBuilder("ruleset").build(); assertTrue("No patterns", ruleSet.applies(file)); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) .build(); assertTrue("Non-matching exclude", ruleSet.applies(file)); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch"), Pattern.compile(".*/package/.*")) .build(); assertFalse("Matching exclude", ruleSet.applies(file)); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) .withFileExclusions(Pattern.compile(".*/package/.*")) .withFileInclusions(Pattern.compile(".*/randomX/.*")) .build(); assertFalse("Non-matching include", ruleSet.applies(file)); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) .withFileExclusions(Pattern.compile(".*/package/.*")) .withFileInclusions(Pattern.compile(".*/randomX/.*")) .withFileInclusions(Pattern.compile(".*/random/.*")) .build(); assertTrue("Matching include", ruleSet.applies(file)); }