/**
  * Materialize the current active rule set for the profile
  *
  * @param activeRules
  * @param profileName
  * @return
  */
 protected PmdRuleset createRuleset(List<ActiveRule> activeRules, String profileName) {
   PmdRuleset ruleset = new PmdRuleset(profileName);
   for (ActiveRule activeRule : activeRules) {
     if (activeRule
         .getRule()
         .getPluginName()
         .equals(PhpCodeSnifferRuleRepository.PHPCS_REPOSITORY_KEY)) {
       String configKey = activeRule.getRule().getKey();
       PmdRule rule = new PmdRule(configKey, mapper.to(activeRule.getPriority()));
       List<PmdProperty> properties = null;
       List<ActiveRuleParam> activeRuleParams = activeRule.getActiveRuleParams();
       if (activeRuleParams != null && !activeRuleParams.isEmpty()) {
         properties = new ArrayList<PmdProperty>();
         for (ActiveRuleParam activeRuleParam : activeRuleParams) {
           properties.add(
               new PmdProperty(
                   activeRuleParam.getRuleParam().getKey(), activeRuleParam.getValue()));
         }
       }
       rule.setProperties(properties);
       ruleset.addRule(rule);
       processXPathRule(activeRule.getRuleKey(), rule);
     }
   }
   return ruleset;
 }
예제 #2
0
 private void importActiveRules(RulesDao rulesDao, RulesProfile profile) {
   for (Iterator<ActiveRule> iar = profile.getActiveRules(true).iterator(); iar.hasNext(); ) {
     ActiveRule activeRule = iar.next();
     Rule unMarshalledRule = activeRule.getRule();
     Rule matchingRuleInDb =
         rulesDao.getRuleByKey(unMarshalledRule.getRepositoryKey(), unMarshalledRule.getKey());
     if (matchingRuleInDb == null) {
       LoggerFactory.getLogger(getClass())
           .error(
               "Unable to find active rule "
                   + unMarshalledRule.getRepositoryKey()
                   + ":"
                   + unMarshalledRule.getKey());
       iar.remove();
       continue;
     }
     activeRule.setRule(matchingRuleInDb);
     activeRule.setRulesProfile(profile);
     activeRule.getActiveRuleParams();
     for (Iterator<ActiveRuleParam> irp = activeRule.getActiveRuleParams().iterator();
         irp.hasNext(); ) {
       ActiveRuleParam activeRuleParam = irp.next();
       RuleParam unMarshalledRP = activeRuleParam.getRuleParam();
       RuleParam matchingRPInDb = rulesDao.getRuleParam(matchingRuleInDb, unMarshalledRP.getKey());
       if (matchingRPInDb == null) {
         LoggerFactory.getLogger(getClass())
             .error("Unable to find active rule parameter " + unMarshalledRP.getKey());
         irp.remove();
         continue;
       }
       activeRuleParam.setActiveRule(activeRule);
       activeRuleParam.setRuleParam(matchingRPInDb);
     }
   }
 }