Exemplo n.º 1
0
  private List<ProfileDefinition> loadFromDeprecatedRepository(RulesRepository repository) {
    List<ProfileDefinition> result = new ArrayList<ProfileDefinition>();

    for (int index = 0; index < repository.getProvidedProfiles().size(); index++) {
      RulesProfile deprecated = (RulesProfile) repository.getProvidedProfiles().get(index);
      DefaultProfileDefinition providedProfile =
          DefaultProfileDefinition.create(deprecated.getName(), repository.getLanguage().getKey());
      for (ActiveRule deprecatedActiveRule : deprecated.getActiveRules(true)) {
        String repositoryKey = deprecatedActiveRule.getRepositoryKey();
        if (StringUtils.isBlank(repositoryKey)) {
          repositoryKey = getPluginKey(repository);
        }
        Rule rule = ruleFinder.findByKey(repositoryKey, deprecatedActiveRule.getRuleKey());
        if (rule != null) {
          ActiveRule activeRule =
              providedProfile.activateRule(rule, deprecatedActiveRule.getSeverity());
          for (ActiveRuleParam arp : deprecatedActiveRule.getActiveRuleParams()) {
            activeRule.setParameter(arp.getKey(), arp.getValue());
          }
        }
      }
      result.add(providedProfile);
    }
    return result;
  }
Exemplo n.º 2
0
 /**
  * Get the active rules of a specific repository. Only enabled rules are selected. Disabled rules
  * are excluded.
  */
 public List<ActiveRule> getActiveRulesByRepository(String repositoryKey) {
   List<ActiveRule> result = new ArrayList<>();
   for (ActiveRule activeRule : activeRules) {
     if (repositoryKey.equals(activeRule.getRepositoryKey()) && activeRule.isEnabled()) {
       result.add(activeRule);
     }
   }
   return result;
 }
Exemplo n.º 3
0
 /** Note: disabled rules are excluded. */
 @CheckForNull
 public ActiveRule getActiveRuleByConfigKey(String repositoryKey, String configKey) {
   for (ActiveRule activeRule : activeRules) {
     if (StringUtils.equals(activeRule.getRepositoryKey(), repositoryKey)
         && StringUtils.equals(activeRule.getConfigKey(), configKey)
         && activeRule.isEnabled()) {
       return activeRule;
     }
   }
   return null;
 }
Exemplo n.º 4
0
 private void appendRule(ActiveRule activeRule, Writer writer) throws IOException {
   writer.append("<rule><repositoryKey>");
   writer.append(activeRule.getRepositoryKey());
   writer.append("</repositoryKey><key>");
   StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey());
   writer.append("</key>");
   if (activeRule.getSeverity() != null) {
     writer.append("<priority>");
     writer.append(activeRule.getSeverity().name());
     writer.append("</priority>");
   }
   appendRuleParameters(activeRule, writer);
   writer.append("</rule>");
 }