org.sonar.api.rules.XMLRuleParser类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中org.sonar.api.rules.XMLRuleParser类的一些代码示例,展示了XMLRuleParser类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLRuleParser类的具体详情如下:
包路径:org.sonar.api.rules.XMLRuleParser
类名称:XMLRuleParser

XMLRuleParser介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

/**
 * 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);
 }
}

代码示例来源:origin: SonarSource/sonarqube

processParameter(rule, cursor);

代码示例来源:origin: SonarSource/sonarqube

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);
 }
}

代码示例来源:origin: SonarSource/sonarqube

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>");
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet/sonar-dotnet-gendarme-plugin

public GendarmeRuleRepositoryProvider(ServerFileSystem fileSystem, Settings settings) {
 this.fileSystem = fileSystem;
 this.xmlRuleParser = new XMLRuleParser();
 this.settings = settings;
}

代码示例来源:origin: org.codehaus.sonar/sonar-deprecated

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>");
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet/sonar-dotnet-fxcop-plugin

public FxCopRuleRepositoryProvider(ServerFileSystem fileSystem, Settings settings) {
 this.fileSystem = fileSystem;
 this.xmlRuleParser = new XMLRuleParser();
 this.settings = settings;
}

代码示例来源:origin: SonarSource/sonarqube

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);
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-deprecated

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);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

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>");
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-deprecated

processParameter(rule, cursor);

代码示例来源:origin: org.codehaus.sonar-plugins.java/sonar-checkstyle-plugin

@Override
 public List<Rule> createRules() {
  return xmlRuleParser.parse(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml"));
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

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);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-plugin-api

processParameter(rule, cursor);

代码示例来源:origin: org.codehaus.sonar.plugins/sonar-pmd-plugin

@Override
 public List<Rule> createRules() {
  InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules-unit-tests.xml");
  return xmlRuleParser.parse(input);
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet/sonar-dotnet-fxcop-plugin

@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;
 }
}

代码示例来源:origin: org.codehaus.sonar.plugins/sonar-pmd-plugin

@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;
 }
}

代码示例来源:origin: org.codehaus.sonar.plugins/sonar-checkstyle-plugin

@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;
 }
}

代码示例来源:origin: org.codehaus.sonar-plugins.dotnet/sonar-dotnet-gendarme-plugin

@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;
 }
}

代码示例来源:origin: org.codehaus.sonar/sonar-deprecated

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);
 }
}

相关文章