@Override @CheckForNull public Rule find(RuleQuery query) { return delegate.find(query); }
@Override @CheckForNull public Rule find(RuleQuery query) { return delegate.find(query); }
private void createActiveRule(SMInputCursor rulesCursor, Map<String, ActiveRule> activeRules, String gendarmeCategory, RulesProfile profile, RulePriority rulePriority) throws XMLStreamException { String[] includedRules = StringUtils.split(rulesCursor.getAttrValue("include"), '|'); for (int i = 0; i < includedRules.length; i++) { String configKey = includedRules[i].trim() + "@" + gendarmeCategory; ActiveRule activeRule = activeRules.get(configKey); if (activeRule == null) { Rule rule = ruleFinder.find(ruleQuery.withConfigKey(configKey)); if (rule != null) { activeRule = profile.activateRule(rule, rulePriority); activeRules.put(configKey, activeRule); } } else if (activeRule.getSeverity().equals(RulePriority.MAJOR)) { // MAJOR is the default one: maybe another priority has been defined and we must set it activeRule.setSeverity(rulePriority); } } }
private void processRule(RulesProfile profile, String path, String moduleName, Map<String, String> properties, ValidationMessages messages) throws XMLStreamException { Rule rule; String id = properties.get("id"); String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { String configKey = path + moduleName; rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
private void processRule(RulesProfile profile, String path, String moduleName, SMInputCursor moduleCursor, ValidationMessages messages) throws XMLStreamException { Map<String, String> properties = processProps(moduleCursor); Rule rule; String id = properties.get("id"); String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { String configKey = path + moduleName; rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
messages.addWarningText(message.toString()); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PHPMD_REPOSITORY_KEY).withConfigKey(configKey)); if (rule == null) { StringBuilder message = new StringBuilder("Unable to import unknown PMD rule '");
private void processRule(RulesProfile profile, String path, String moduleName, Map<String, String> properties, ValidationMessages messages) { final Rule rule; final String id = properties.get("id"); final String warning; if (StringUtils.isNotBlank(id)) { rule = ruleFinder.find(RuleQuery.create() .withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).withKey(id)); warning = "Checkstyle rule with key '" + id + "' not found"; } else { final String configKey = path + moduleName; rule = ruleFinder .find(RuleQuery.create().withRepositoryKey(CheckstyleConstants.REPOSITORY_KEY) .withConfigKey(configKey)); warning = "Checkstyle rule with config key '" + configKey + "' not found"; } if (rule == null) { messages.addWarningText(warning); } else { final ActiveRule activeRule = profile.activateRule(rule, null); activateProperties(activeRule, properties); } }
private void createViolationFromMessageAtProjectLevel(SMInputCursor messagesCursor) throws XMLStreamException { Rule currentRule = ruleFinder.find(RuleQuery.create().withRepositoryKey(repositoryKey) .withKey(messagesCursor.getAttrValue(TYPENAME))); if (currentRule != null) { // the violation is saved at project level, not on a specific resource Violation violation = Violation.create(currentRule, project); violation.setMessage(messagesCursor.collectDescendantText().trim()); violation.setSeverity(currentRule.getSeverity()); context.saveViolation(violation); } else { LOG.debug("Could not find the following rule in the FxCop rule repository: " + messagesCursor.getAttrValue(TYPENAME)); } }
/** * @param pmdRuleset * @param messages * @return */ protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(pmdRuleset.getName(), Php.KEY); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { boolean isRuleValid = true; String key = pmdRule.getRef(); if (key == null) { messages.addWarningText("A rule without 'ref' attribute can't be imported. see '" + pmdRule.getClazz() + "'"); isRuleValid = false; } // Attention: rule is retrieved using the key field which different of what is done on PmdImporter that uses configKey. Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PHPCS_REPOSITORY_KEY).withKey(key)); if (rule == null) { StringBuilder message = new StringBuilder("Unable to import unknown PMD rule '"); message.append(key).append("' consider adding an extension in sonar extenions directory"); messages.addWarningText(message.toString()); isRuleValid = false; } ActiveRule activeRule = profile.activateRule(rule, mapper.from(pmdRule.getPriority())); if (isRuleValid && pmdRule.getProperties() != null) { createRule(messages, pmdRule, key, rule, activeRule); } } return profile; }
Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(getKey()).withKey(ruleName));
private void parseRuleBlocs(SMInputCursor cursor) throws XMLStreamException { RuleQuery ruleQuery = RuleQuery.create().withRepositoryKey(repositoryKey); // Cursor is on <rule> while (cursor.getNext() != null) { if (cursor.getCurrEvent().equals(SMEvent.START_ELEMENT)) { Rule currentRule = ruleFinder.find(ruleQuery.withKey(cursor.getAttrValue("Name"))); if (currentRule != null) { String type = cursor.getAttrValue("Type"); if (StringUtils.isEmpty(type)) { parseRuleDefects(cursor, currentRule); } else { gendarmeViolationMaker.registerRuleType(currentRule, type); } } } } }
private void parseTypeBloc(String namespaceName, SMInputCursor cursor) throws XMLStreamException { // Cursor on <Type> String typeName = cursor.getAttrValue(NAME); Resource<?> typeResource = resourceBridge.getFromTypeName(namespaceName, typeName); SMInputCursor messagesCursor = cursor.descendantElementCursor(MESSAGE); while (messagesCursor.getNext() != null) { // Cursor on <Message> if (messagesCursor.getCurrEvent() == SMEvent.START_ELEMENT) { Rule currentRule = ruleFinder.find(RuleQuery.create().withRepositoryKey(repositoryKey) .withKey(messagesCursor.getAttrValue(TYPENAME))); if (currentRule != null) { // look for all potential issues searchForViolations(messagesCursor, typeResource, currentRule); } else { LOG.warn("Could not find the following rule in the FxCop rule repository: " + messagesCursor.getAttrValue(TYPENAME)); } } } }
protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; }
@Override public RulesProfile importProfile(Reader pmdConfigurationFile, ValidationMessages messages) { PmdRuleSet pmdRuleset = PmdRuleSets.parse(pmdConfigurationFile, messages); RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { String ruleClassName = pmdRule.getClazz(); if (PmdConstants.XPATH_CLASS.equals(ruleClassName)) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the SonarQube web interface."); } else { String ruleRef = pmdRule.getRef(); if (ruleRef == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + ruleClassName + "'"); } else { Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(ruleRef)); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); setParameters(activeRule, pmdRule, rule, messages); } else { messages.addWarningText("Unable to import unknown PMD rule '" + ruleRef + "'"); } } } } return profile; } }
protected RulesProfile createRuleProfile(PmdRuleset pmdRuleset, ValidationMessages messages) { RulesProfile profile = RulesProfile.create(); for (PmdRule pmdRule : pmdRuleset.getPmdRules()) { if (PmdConstants.XPATH_CLASS.equals(pmdRule.getClazz())) { messages.addWarningText("PMD XPath rule '" + pmdRule.getName() + "' can't be imported automatically. The rule must be created manually through the Sonar web interface."); continue; } if (pmdRule.getRef() == null) { messages.addWarningText("A PMD rule without 'ref' attribute can't be imported. see '" + pmdRule.getClazz() + "'"); continue; } Rule rule = ruleFinder.find(RuleQuery.create().withRepositoryKey(PmdConstants.REPOSITORY_KEY).withConfigKey(pmdRule.getRef())); if (rule != null) { ActiveRule activeRule = profile.activateRule(rule, PmdLevelUtils.fromLevel(pmdRule.getPriority())); if (pmdRule.getProperties() != null) { for (PmdProperty prop : pmdRule.getProperties()) { if (rule.getParam(prop.getName()) == null) { messages.addWarningText("The property '" + prop.getName() + "' is not supported in the pmd rule: " + pmdRule.getRef()); continue; } activeRule.setParameter(prop.getName(), prop.getValue()); } } } else { messages.addWarningText("Unable to import unknown PMD rule '" + pmdRule.getRef() + "'"); } } return profile; }