@Override public Object clone() { final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity()); clone.setInheritance(getInheritance()); if (activeRuleParams != null && !activeRuleParams.isEmpty()) { clone.setActiveRuleParams(activeRuleParams .stream() .map(input -> { ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) input.clone(); activeRuleParamClone.setActiveRule(clone); return activeRuleParamClone; }) .collect(Collectors.toList())); } return clone; }
private void appendModule(Writer writer, ActiveRule activeRule) throws IOException { String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/"); writer.append("<module name=\""); StringEscapeUtils.escapeXml(writer, moduleName); writer.append("\">"); if (activeRule.getRule().getTemplate() != null) { appendModuleProperty(writer, "id", activeRule.getRuleKey()); } appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity())); appendRuleParameters(writer, activeRule); writer.append("</module>"); }
private void appendModule(Writer writer, ActiveRule activeRule) throws IOException { String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/"); writer.append("<module name=\""); StringEscapeUtils.escapeXml(writer, moduleName); writer.append("\">"); if (activeRule.getRule().getParent() != null) { appendModuleProperty(writer, "id", activeRule.getRuleKey()); } appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity())); appendRuleParameters(writer, activeRule); writer.append("</module>"); }
/** * @param optionalSeverity if null, then the default rule severity is used */ public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) { if (activeRules.stream().anyMatch(ar -> ar.getRule().equals(rule))) { throw MessageException.of(String.format( "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.", getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey())); } ActiveRule activeRule = new ActiveRule(this, rule, optionalSeverity); activeRules.add(activeRule); return activeRule; }
private static void appendModule(Writer writer, ActiveRule activeRule) throws IOException { final String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/"); writer.append("<module name=\""); StringEscapeUtils.escapeXml(writer, moduleName); writer.append("\">"); if (activeRule.getRule().getTemplate() != null) { appendModuleProperty(writer, "id", activeRule.getRuleKey()); } appendModuleProperty(writer, "severity", CheckstyleSeverityUtils.toSeverity(activeRule.getSeverity())); appendRuleParameters(writer, activeRule); writer.append(CLOSE_MODULE); }
@CheckForNull private static RuleActivation toRuleActivation(ActiveRule activeRule, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) { RuleKey ruleKey = activeRule.getRule().ruleKey(); RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); if (ruleDefinition == null) { return null; } String severity = activeRule.getSeverity().name(); Map<String, String> params = activeRule.getActiveRuleParams().stream() .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue)); return RuleActivation.create(ruleDefinition.getId(), severity, params); }
private static void registerProfile(ActiveRulesBuilder builder, String language, Map.Entry<String, Collection<RulesProfile>> entry) { for (RulesProfile rp : entry.getValue()) { for (ActiveRule ar : rp.getActiveRules()) { Builder newAr = new NewActiveRule.Builder() .setRuleKey(RuleKey.of(ar.getRepositoryKey(), ar.getRuleKey())) .setLanguage(language) .setName(ar.getRule().getName()) .setSeverity(ar.getSeverity().name()) .setInternalKey(ar.getConfigKey()); for (ActiveRuleParam param : ar.getActiveRuleParams()) { newAr.setParam(param.getKey(), param.getValue()); } builder.addRule(newAr.build()); } } }
@Override public boolean apply(ActiveRule input) { return input.getRule().equals(rule); } })) {
public static Violation create(ActiveRule activeRule, Resource resource) { return new Violation(activeRule.getRule()).setResource(resource); }
/** * @param optionalSeverity if null, then the default rule severity is used */ public ActiveRule activateRule(final Rule rule, @Nullable RulePriority optionalSeverity) { if (activeRules.stream().anyMatch(ar -> ar.getRule().equals(rule))) { throw MessageException.of(String.format( "The definition of the profile '%s' (language '%s') contains multiple occurrences of the '%s:%s' rule. The plugin which declares this profile should fix this.", getName(), getLanguage(), rule.getRepositoryKey(), rule.getKey())); } ActiveRule activeRule = new ActiveRule(this, rule, optionalSeverity); activeRules.add(activeRule); return activeRule; }
@CheckForNull private static RuleActivation toRuleActivation(ActiveRule activeRule, Map<RuleKey, RuleDefinitionDto> rulesByRuleKey) { RuleKey ruleKey = activeRule.getRule().ruleKey(); RuleDefinitionDto ruleDefinition = rulesByRuleKey.get(ruleKey); if (ruleDefinition == null) { return null; } String severity = activeRule.getSeverity().name(); Map<String, String> params = activeRule.getActiveRuleParams().stream() .collect(MoreCollectors.uniqueIndex(ActiveRuleParam::getKey, ActiveRuleParam::getValue)); return RuleActivation.create(ruleDefinition.getId(), severity, params); }
private void initSetOfDirs(Project project) { dirsWithoutPackageInfo = Sets.newHashSet(); ActiveRule activeRule = rulesProfile.getActiveRule(CheckList.REPOSITORY_KEY, PackageInfoCheck.RULE_KEY); if (activeRule != null) { CodeVisitor check = checkInstanceOf(activeRule.getRule().ruleKey()); if (check != null) { Set<File> dirs = ((PackageInfoCheck) check).getDirectoriesWithoutPackageFile(); for (File dir : dirs) { dirsWithoutPackageInfo.add(Directory.fromIOFile(dir, project)); } } } } }
private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
private static void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { final String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException { for (RuleParam ruleParam : activeRule.getRule().getParams()) { String value = activeRule.getParameter(ruleParam.getKey()); if (StringUtils.isNotBlank(value)) { appendModuleProperty(writer, ruleParam.getKey(), value); } } }
@SuppressWarnings({"rawtypes", "unchecked"}) public void decorate(Resource resource, DecoratorContext context) { // assume that all checks relate to files, not directories nor modules if (ResourceUtils.isEntity(resource) && resource.getLanguage() != null && resource.getLanguage().getKey().equals(language)) { for (CommonCheck check : activeChecks) { check.checkResource(resource, context, checkFactory.getActiveRule(check).getRule()); } } }
/** * Create PageScanner with Visitors. */ private HtmlAstScanner setupScanner() { HtmlAstScanner scanner = new HtmlAstScanner(ImmutableList.of(new PageCountLines(), new ComplexityVisitor(), new NoSonarScanner(noSonarFilter))); for (AbstractPageCheck check : (Collection<AbstractPageCheck>) annotationCheckFactory.getChecks()) { scanner.addVisitor(check); check.setRule(annotationCheckFactory.getActiveRule(check).getRule()); } return scanner; }