Ejemplo 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;
  }
Ejemplo n.º 2
0
 private ProfileDefinition loadFromDeprecatedCheckProfile(CheckProfile cp) {
   DefaultProfileDefinition definition =
       DefaultProfileDefinition.create(cp.getName(), cp.getLanguage());
   for (Check check : cp.getChecks()) {
     RulePriority priority = null;
     if (check.getPriority() != null) {
       priority = RulePriority.fromCheckPriority(check.getPriority());
     }
     Rule rule = ruleFinder.findByKey(check.getRepositoryKey(), check.getTemplateKey());
     if (rule != null) {
       ActiveRule activeRule = definition.activateRule(rule, priority);
       for (Map.Entry<String, String> entry : check.getProperties().entrySet()) {
         activeRule.setParameter(entry.getKey(), entry.getValue());
       }
     }
   }
   return definition;
 }