/** {@inheritDoc} */
  @Override
  public RulesProfile importProfile(Reader reader, ValidationMessages messages) {
    RulesProfile profile = RulesProfile.create();
    profile.setLanguage(CSharpConstants.LANGUAGE_KEY);

    try {
      List<StyleCopRule> styleCopConfig = StyleCopRuleParser.parse(IOUtils.toString(reader));

      for (StyleCopRule styleCopRule : styleCopConfig) {
        if (styleCopRule.isEnabled()) {
          String ruleName = styleCopRule.getName();
          Rule rule =
              ruleFinder.find(RuleQuery.create().withRepositoryKey(getKey()).withKey(ruleName));

          if (rule != null) {
            String rawPriority = styleCopRule.getPriority();
            RulePriority rulePriority = RulePriority.MINOR;
            if (StringUtils.isNotEmpty(rawPriority)) {
              rulePriority = RulePriority.valueOfString(rawPriority);
            }
            profile.activateRule(rule, rulePriority);
          }
        }
      }
    } catch (IOException e) {
      messages.addErrorText("Failed to read the profile to import: " + e.getMessage());
    }

    return profile;
  }
  private RuleFinder newRuleFinder() {
    RuleFinder ruleFinder = mock(RuleFinder.class);
    when(ruleFinder.find(any(RuleQuery.class)))
        .thenAnswer(
            new Answer<Rule>() {
              public Rule answer(InvocationOnMock iom) throws Throwable {
                RuleQuery query = (RuleQuery) iom.getArguments()[0];
                Rule rule = null;
                if (StringUtils.equals(query.getConfigKey(), "Checker/JavadocPackage")) {
                  rule =
                      Rule.create(
                              query.getRepositoryKey(),
                              "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck",
                              "Javadoc Package")
                          .setConfigKey("Checker/JavadocPackage")
                          .setSeverity(RulePriority.MAJOR);
                  rule.createParameter("format");
                  rule.createParameter("ignore");

                } else if (StringUtils.equals(
                    query.getConfigKey(), "Checker/TreeWalker/EqualsHashCode")) {
                  rule =
                      Rule.create(
                              query.getRepositoryKey(),
                              "com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck",
                              "Equals HashCode")
                          .setConfigKey("Checker/TreeWalker/EqualsHashCode")
                          .setSeverity(RulePriority.BLOCKER);

                } else if (StringUtils.equals(
                    query.getKey(),
                    "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345")) {
                  rule =
                      Rule.create(
                              query.getRepositoryKey(),
                              "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345",
                              "Javadoc Package")
                          .setConfigKey("Checker/JavadocPackage")
                          .setSeverity(RulePriority.MAJOR);
                  rule.createParameter("format");
                  rule.createParameter("ignore");
                } else if (StringUtils.equals(
                    query.getConfigKey(), "Checker/TreeWalker/MissingOverride")) {
                  rule =
                      Rule.create(
                              query.getRepositoryKey(),
                              "com.puppycrawl.tools.checkstyle.checks.annotation.MissingOverrideCheck",
                              "Missing Override")
                          .setConfigKey("Checker/TreeWalker/MissingOverride")
                          .setSeverity(RulePriority.MINOR);
                  rule.createParameter("javaFiveCompatibility");
                }
                return rule;
              }
            });
    return ruleFinder;
  }
 private void parseStyleCopViolationsBloc(SMInputCursor violationsCursor)
     throws XMLStreamException {
   // Cursor in on <Violations>
   StringBuffer configKey = new StringBuffer();
   RuleQuery ruleQuery = RuleQuery.create().withRepositoryKey(StyleCopConstants.REPOSITORY_KEY);
   while (violationsCursor.getNext() != null) {
     configKey.setLength(0);
     configKey.append(violationsCursor.getAttrValue("RuleNamespace"));
     configKey.append("#");
     configKey.append(violationsCursor.getAttrValue("Rule"));
     Rule currentRule = ruleFinder.find(ruleQuery.withConfigKey(configKey.toString()));
     if (currentRule != null) {
       createViolation(violationsCursor, currentRule);
     } else {
       LOG.warn(
           "Could not find the following rule in the StyleCop rule repository: "
               + configKey.toString());
     }
   }
 }