Пример #1
0
 private void configureFields(ActiveRule activeRule, Object check) {
   for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
     Field field = getField(check, param.getKey());
     if (field == null) {
       throw new SonarException(
           "The field "
               + param.getKey()
               + " does not exist or is not annotated with @RuleProperty in the class "
               + check.getClass().getName());
     }
     if (StringUtils.isNotBlank(param.getValue())) {
       configureField(check, field, param.getValue());
     }
   }
 }
Пример #2
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;
  }
Пример #3
0
 private void appendRuleParameter(Writer writer, ActiveRuleParam activeRuleParam)
     throws IOException {
   if (StringUtils.isNotBlank(activeRuleParam.getValue())) {
     writer.append("<parameter><key>");
     StringEscapeUtils.escapeXml(writer, activeRuleParam.getKey());
     writer.append("</key><value>");
     StringEscapeUtils.escapeXml(writer, activeRuleParam.getValue());
     writer.append("</value>");
     writer.append("</parameter>");
   }
 }
Пример #4
0
 /** Important : the ruby controller has already create the profile */
 public ValidationMessages importProfile(
     String profileName, String language, String importerKey, String profileDefinition) {
   ValidationMessages messages = ValidationMessages.create();
   ProfileImporter importer = getProfileImporter(importerKey);
   RulesProfile profile = importer.importProfile(new StringReader(profileDefinition), messages);
   if (!messages.hasErrors()) {
     DatabaseSession session = sessionFactory.getSession();
     RulesProfile persistedProfile =
         session.getSingleResult(RulesProfile.class, "name", profileName, "language", language);
     for (ActiveRule activeRule : profile.getActiveRules()) {
       ActiveRule persistedActiveRule =
           persistedProfile.activateRule(activeRule.getRule(), activeRule.getSeverity());
       for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
         persistedActiveRule.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue());
       }
     }
     session.saveWithoutFlush(persistedProfile);
     session.commit();
   }
   return messages;
 }