/** * Loads rules by reading the XML input stream. The input stream is not always closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, InputStream input, String encoding) { load(repo, input, Charset.forName(encoding)); }
name = nodeValue(cursor); type = nodeValue(cursor); description = nodeValue(cursor); descriptionFormat = nodeValue(cursor); key = nodeValue(cursor); internalKey = nodeValue(cursor); internalKey = nodeValue(cursor); severity = nodeValue(cursor); template = Cardinality.MULTIPLE == Cardinality.valueOf(nodeValue(cursor)); gapDescription = nodeValue(cursor); debtRemediationFunction = nodeValue(cursor); debtRemediationFunctionGapMultiplier = nodeValue(cursor); debtRemediationFunctionBaseEffort = nodeValue(cursor); String s = nodeValue(cursor); if (s != null) { status = RuleStatus.valueOf(s);
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, 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> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
@Override public void define(Context context) { NewRepository repositoryJsp = context .createRepository(REPOSITORY_KEY, Jsp.KEY) .setName(REPOSITORY_JSP_NAME); RulesDefinitionXmlLoader ruleLoaderJsp = new RulesDefinitionXmlLoader(); ruleLoaderJsp.load(repositoryJsp, FindSecurityBugsRulesDefinition.class.getResourceAsStream("/org/sonar/plugins/findbugs/rules-jsp.xml"), "UTF-8"); repositoryJsp.done(); } }
params.add(processParameter(cursor));
static void extractRulesData(NewRepository repository, String xmlRulesFilePath, String htmlDescriptionFolder) { RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load(repository, PmdRulesDefinition.class.getResourceAsStream(xmlRulesFilePath), "UTF-8"); ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder); PropertyFileLoader.loadNames(repository, PmdRulesDefinition.class.getResourceAsStream("/org/sonar/l10n/pmd.properties")); SqaleXmlLoader.load(repository, "/com/sonar/sqale/pmd-model.xml"); } }
@Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, Java.KEY) .setName(REPOSITORY_NAME); RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load(repository, FindSecurityBugsRulesDefinition.class.getResourceAsStream("/org/sonar/plugins/findbugs/rules-findsecbugs.xml"), "UTF-8"); repository.done(); } }
/** * @since 5.1 */ public void load(RulesDefinition.NewRepository repo, InputStream input, Charset charset) { try (Reader reader = new InputStreamReader(input, charset)) { load(repo, reader); } catch (IOException e) { throw new IllegalStateException("Error while reading XML rules definition for repository " + repo.key(), e); } }
name = nodeValue(cursor); type = nodeValue(cursor); description = nodeValue(cursor); descriptionFormat = nodeValue(cursor); key = nodeValue(cursor); internalKey = nodeValue(cursor); internalKey = nodeValue(cursor); severity = nodeValue(cursor); template = Cardinality.MULTIPLE == Cardinality.valueOf(nodeValue(cursor)); gapDescription = nodeValue(cursor); debtRemediationFunction = nodeValue(cursor); debtRemediationFunctionGapMultiplier = nodeValue(cursor); debtRemediationFunctionBaseEffort = nodeValue(cursor); String s = nodeValue(cursor); if (s != null) { status = RuleStatus.valueOf(s);
public void load(RulesDefinition.NewRepository repo, 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> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
@Override public void define(Context context) { NewRepository repository = context .createRepository(REPOSITORY_KEY, Java.KEY) .setName(REPOSITORY_NAME); RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load(repository, FbContribRulesDefinition.class.getResourceAsStream("/org/sonar/plugins/findbugs/rules-fbcontrib.xml"), "UTF-8"); repository.done(); }
private RulesDefinition.Repository load(String xml) { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); underTest.load(newRepository, new StringReader(xml)); newRepository.done(); return context.repository("squid"); } }
/** * Loads rules by reading the XML input stream. The reader is not closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, 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> SMInputCursor rulesC = rootC.childElementCursor("rule"); while (rulesC.getNext() != null) { // <rule> processRule(repo, rulesC); } } catch (XMLStreamException e) { throw new IllegalStateException("XML is not valid", e); } }
@Override public void define(Context context) { NewRepository repository = context.createRepository(REPOSITORY_KEY, Java.KEY).setName(REPOSITORY_NAME); RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); ruleLoader.load( repository, FindBugsSlf4jRulesDefinition.class.getResourceAsStream( "/jp/skypencil/findbugs/slf4j/sonar/rules.xml"), "UTF-8"); repository.done(); } }
private RulesDefinition.Repository load(InputStream input, String encoding) { RulesDefinition.Context context = new RulesDefinition.Context(); RulesDefinition.NewRepository newRepository = context.createRepository("squid", "java"); underTest.load(newRepository, input, encoding); newRepository.done(); return context.repository("squid"); }
@VisibleForTesting static void extractRulesData(NewRepository repository, String xmlRulesFilePath, String htmlDescriptionFolder) throws IOException { final RulesDefinitionXmlLoader ruleLoader = new RulesDefinitionXmlLoader(); try (InputStream resource = CheckstyleRulesDefinition.class .getResourceAsStream(xmlRulesFilePath)) { ruleLoader.load(repository, resource, "UTF-8"); } ExternalDescriptionLoader.loadHtmlDescriptions(repository, htmlDescriptionFolder); try (InputStream resource = CheckstyleRulesDefinition.class .getResourceAsStream("/org/sonar/l10n/checkstyle.properties")) { loadNames(repository, resource); } SqaleXmlLoader.load(repository, "/com/sonar/sqale/checkstyle-model.xml"); }
/** * Loads rules by reading the XML input stream. The input stream is not always closed by the method, so it * should be handled by the caller. * @since 4.3 */ public void load(RulesDefinition.NewRepository repo, InputStream input, String encoding) { load(repo, input, Charset.forName(encoding)); }
private void defineRulesForLanguage(Context context, String repositoryKey, String repositoryName, String languageKey) { NewRepository repository = context.createRepository(repositoryKey, languageKey).setName(repositoryName); InputStream rulesXml = this.getClass().getResourceAsStream(rulesDefinitionFilePath()); if (rulesXml != null) { RulesDefinitionXmlLoader rulesLoader = new RulesDefinitionXmlLoader(); rulesLoader.load(repository, rulesXml, StandardCharsets.UTF_8.name()); } repository.done(); }
public void load(RulesDefinition.NewRepository repo, InputStream input, String encoding) { load(repo, input, Charset.forName(encoding)); }
@Override public void define(Context context) { NewRepository repository = context.createRepository(REPOSITORY_KEY, LANGUAGE_KEY); try (InputStream inputStream = PmdExtensionRepository.class.getResourceAsStream("/org/sonar/examples/pmd/extensions.xml")) { new RulesDefinitionXmlLoader() .load( repository, inputStream, StandardCharsets.UTF_8 ); } catch (IOException e) { LOGGER.error("Failed to load PMD RuleSet.", e); } repository.done(); } }