@Test public void should_import_pmd_ruleset() { Reader reader = read("/org/sonar/plugins/pmd/simple.xml"); PmdRuleset pmdRuleset = importer.parsePmdRuleset(reader, messages); assertThat(pmdRuleset.getPmdRules()).hasSize(4); }
protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = 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); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } }
PmdProfileImporter extends ProfileImporter { protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = 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); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } } }
PmdProfileImporter extends ProfileImporter { protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = 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); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } } PmdProfileImporter(RuleFinder ruleFinder); }
PmdProfileImporter extends ProfileImporter { protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = 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); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } } PmdProfileImporter(RuleFinder ruleFinder); @Override RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages); }
PmdProfileImporter extends ProfileImporter { protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = 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); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } } PmdProfileImporter(RuleFinder ruleFinder); @Override RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages);  }