/** * Warning : the input stream is closed in this method */ public List<Rule> parse(InputStream input) { try (Reader reader = new InputStreamReader(input, UTF_8)) { return parse(reader); } catch (IOException e) { throw new SonarException("Fail to load the xml stream", e); } }
processParameter(rule, cursor);
public List<Rule> parse(Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<>(); SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> Rule rule = Rule.create(); rules.add(rule); processRule(rule, rulesC); } return rules; } catch (XMLStreamException e) { throw new SonarException("XML is not valid", e); } }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (StringUtils.isEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }
public GendarmeRuleRepositoryProvider(ServerFileSystem fileSystem, Settings settings) { this.fileSystem = fileSystem; this.xmlRuleParser = new XMLRuleParser(); this.settings = settings; }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (Strings.isNullOrEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }
public FxCopRuleRepositoryProvider(ServerFileSystem fileSystem, Settings settings) { this.fileSystem = fileSystem; this.xmlRuleParser = new XMLRuleParser(); this.settings = settings; }
public List<Rule> parse(File file) { try (Reader reader = new InputStreamReader(FileUtils.openInputStream(file), UTF_8)) { return parse(reader); } catch (IOException e) { throw new SonarException("Fail to load the file: " + file, e); } }
public List<Rule> parse(Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<Rule>(); SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> Rule rule = Rule.create(); rules.add(rule); processRule(rule, rulesC); } return rules; } catch (XMLStreamException e) { throw new SonarException("XML is not valid", e); } }
private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException { RuleParam param = rule.createParameter(); String keyAttribute = ruleC.getAttrValue("key"); if (StringUtils.isNotBlank(keyAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setKey(StringUtils.trim(keyAttribute)); } String typeAttribute = ruleC.getAttrValue("type"); if (StringUtils.isNotBlank(typeAttribute)) { /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */ param.setType(type(StringUtils.trim(typeAttribute))); } SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); String propText = StringUtils.trim(paramC.collectDescendantText(false)); if (StringUtils.equalsIgnoreCase("key", propNodeName)) { param.setKey(propText); } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) { param.setDescription(propText); } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) { param.setType(type(propText)); } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) { param.setDefaultValue(propText); } } if (StringUtils.isEmpty(param.getKey())) { throw new SonarException("Node <key> is missing in <param>"); } }
processParameter(rule, cursor);
@Override public List<Rule> createRules() { return xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml")); } }
public List<Rule> parse(Reader reader) { XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE); xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // just so it won't try to load DTD in if there's DOCTYPE xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); SMInputFactory inputFactory = new SMInputFactory(xmlFactory); try { SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader); rootC.advance(); // <rules> List<Rule> rules = new ArrayList<>(); SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> Rule rule = Rule.create(); rules.add(rule); processRule(rule, rulesC); } return rules; } catch (XMLStreamException e) { throw new SonarException("XML is not valid", e); } }
@Override public List<Rule> createRules() { InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules-unit-tests.xml"); return xmlRuleParser.parse(input); } }
@Override public List<Rule> createRules() { List<Rule> rules = new ArrayList<Rule>(); rules.addAll(xmlRuleParser.parse(FxCopUnitTestsRuleRepository.class.getResourceAsStream("/org/sonar/plugins/csharp/fxcop/rules/rules-unit-tests.xml"))); for (File userExtensionXml : fileSystem.getExtensions(FxCopConstants.TEST_REPOSITORY_KEY, "xml")) { rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } }
@Override public List<Rule> createRules() { List<Rule> rules = Lists.newArrayList(); rules.addAll(xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml"))); for (File userExtensionXml : fileSystem.getExtensions(PmdConstants.REPOSITORY_KEY, "xml")) { rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } }
@Override public List<Rule> createRules() { List<Rule> rules = Lists.newArrayList(); rules.addAll(xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml"))); for (File userExtensionXml : fileSystem.getExtensions(CheckstyleConstants.REPOSITORY_KEY, "xml")) { rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } }
@Override public List<Rule> createRules() { List<Rule> rules = new ArrayList<Rule>(); rules .addAll(xmlRuleParser.parse(GendarmeUnitTestsRuleRepository.class.getResourceAsStream("/org/sonar/plugins/csharp/gendarme/rules/rules.xml"))); for (File userExtensionXml : fileSystem.getExtensions(GendarmeConstants.TEST_REPOSITORY_KEY, "xml")) { rules.addAll(xmlRuleParser.parse(userExtensionXml)); } return rules; } }
public List<Rule> parse(File file) { Reader reader = null; try { reader = new InputStreamReader(FileUtils.openInputStream(file), CharEncoding.UTF_8); return parse(reader); } catch (IOException e) { throw new SonarException("Fail to load the file: " + file, e); } finally { Closeables.closeQuietly(reader); } }