@Test void whenValidXmlGivenThenPmdRuleSetIsReturned() throws URISyntaxException, IOException { final Reader reader = createReader("/org/sonar/plugins/pmd/simple.xml"); final PmdRuleSet result = PmdRuleSets.parse(reader, messages); assertThat(result).isNotNull() .satisfies(this::hasRuleCouplingBetweenObjects) .satisfies(this::hasRuleExcessiveImports) .satisfies(this::hasRuleUseNotifyAllInsteadOfNotify) .satisfies(this::hasRuleUseCollectionIsEmptyRule); assertThat(result.getPmdRules()).hasSize(4); assertThatNoMessagesWritten(); }
public PmdRuleSet parse() throws JDOMException, IOException { final SAXBuilder parser = new SAXBuilder(); final Document dom = parser.build(reader); final Element eltResultset = dom.getRootElement(); final Namespace namespace = eltResultset.getNamespace(); final PmdRuleSet result = new PmdRuleSet(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); result.addRule(pmdRule); } return result; }
PmdRuleSets implements Closeable { public PmdRuleSet parse() throws JDOMException, IOException { final SAXBuilder parser = new SAXBuilder(); final Document dom = parser.build(reader); final Element eltResultset = dom.getRootElement(); final Namespace namespace = eltResultset.getNamespace(); final PmdRuleSet result = new PmdRuleSet(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); result.addRule(pmdRule); } return result; } }
PmdRuleSets implements Closeable { public PmdRuleSet parse() throws JDOMException, IOException { final SAXBuilder parser = new SAXBuilder(); final Document dom = parser.build(reader); final Element eltResultset = dom.getRootElement(); final Namespace namespace = eltResultset.getNamespace(); final PmdRuleSet result = new PmdRuleSet(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); result.addRule(pmdRule); } return result; } PmdRuleSets(Reader configReader); }
PmdRuleSets implements Closeable { public PmdRuleSet parse() throws JDOMException, IOException { final SAXBuilder parser = new SAXBuilder(); final Document dom = parser.build(reader); final Element eltResultset = dom.getRootElement(); final Namespace namespace = eltResultset.getNamespace(); final PmdRuleSet result = new PmdRuleSet(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); result.addRule(pmdRule); } return result; } PmdRuleSets(Reader configReader); PmdRuleSet parse(); static PmdRuleSet parse(Reader configReader, ValidationMessages messages); @Override void close(); }
PmdRuleSets implements Closeable { public PmdRuleSet parse() throws JDOMException, IOException { final SAXBuilder parser = new SAXBuilder(); final Document dom = parser.build(reader); final Element eltResultset = dom.getRootElement(); final Namespace namespace = eltResultset.getNamespace(); final PmdRuleSet result = new PmdRuleSet(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); result.addRule(pmdRule); } return result; } PmdRuleSets(Reader configReader); PmdRuleSet parse(); static PmdRuleSet parse(Reader configReader, ValidationMessages messages); @Override void close();  }