/** * @return the list of active rules */ public List<ActiveRule> getActiveRules() { return getActiveRules(false); }
private static void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }
@Override public void exportProfile(RulesProfile profile, Writer writer) { try { writer.write("xoo -> " + profile.getName() + " -> " + profile.getActiveRules().size()); } catch (IOException e) { throw new IllegalStateException(e); } } }
private List<ActiveRuleChange> importProfile(QProfileDto profile, RulesProfile definition, DbSession dbSession) { Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = dbClient.ruleDao().selectAllDefinitions(dbSession) .stream() .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey)); List<ActiveRule> activeRules = definition.getActiveRules(); List<RuleActivation> activations = activeRules.stream() .map(activeRule -> toRuleActivation(activeRule, rulesByRuleKey)) .filter(Objects::nonNull) .collect(MoreCollectors.toArrayList(activeRules.size())); return qProfileRules.activateAndCommit(dbSession, profile, activations); }
@Override public void exportProfile(RulesProfile profile, Writer writer) { try { writer.write("xoo -> " + profile.getName() + " -> " + profile.getActiveRules().size()); } catch (IOException e) { throw new IllegalStateException(e); } } }
@Override public void exportProfile(RulesProfile profile, Writer writer) { try { writer.write("standard -> " + profile.getName() + " -> " + profile.getActiveRules().size()); } catch (IOException e) { throw new IllegalStateException(e); } } }
private static void define(Context context, RulesProfile profile) { NewBuiltInQualityProfile newQp = context.createBuiltInQualityProfile(profile.getName(), profile.getLanguage()) .setDefault(profile.getDefaultProfile().booleanValue()); for (org.sonar.api.rules.ActiveRule ar : profile.getActiveRules()) { NewBuiltInActiveRule newActiveRule = newQp.activateRule(ar.getRepositoryKey(), ar.getRuleKey()); RulePriority overriddenSeverity = ar.getOverriddenSeverity(); if (overriddenSeverity != null) { newActiveRule.overrideSeverity(overriddenSeverity.name()); } for (ActiveRuleParam param : ar.getActiveRuleParams()) { newActiveRule.overrideParam(param.getKey(), param.getValue()); } } newQp.done(); }
/** * @return the list of active rules */ public List<ActiveRule> getActiveRules() { return getActiveRules(false); }
/** * @return the list of active rules */ public List<ActiveRule> getActiveRules() { return getActiveRules(false); }
@Override public List<ActiveRule> getActiveRules() { List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); for (RulesProfile profile : profiles) { activeRules.addAll(profile.getActiveRules()); } return activeRules; }
@Override public List<ActiveRule> getActiveRules(boolean acceptDisabledRules) { List<ActiveRule> activeRules = new ArrayList<ActiveRule>(); for (RulesProfile profile : profiles) { activeRules.addAll(profile.getActiveRules(acceptDisabledRules)); } return activeRules; }
@Override public List<ActiveRule> getActiveRules() { List<ActiveRule> activeRules = new ArrayList<>(); for (RulesProfile profile : profiles) { activeRules.addAll(profile.getActiveRules()); } return activeRules; }
@Override public List<ActiveRule> getActiveRules(boolean acceptDisabledRules) { List<ActiveRule> activeRules = new ArrayList<>(); for (RulesProfile profile : profiles) { activeRules.addAll(profile.getActiveRules(acceptDisabledRules)); } return activeRules; }
private void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }
private static void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }
@Override public void exportProfile(RulesProfile profile, Writer writer) { try { writer.write("xoo -> " + profile.getName() + " -> " + profile.getActiveRules().size()); } catch (IOException e) { throw new IllegalStateException(e); } } }
@Override public void exportProfile(RulesProfile profile, Writer writer) { try { writer.write("xoo -> " + profile.getName() + " -> " + profile.getActiveRules().size()); } catch (IOException e) { throw new IllegalStateException(e); } } }
private List<ActiveRuleChange> importProfile(QProfileDto profile, RulesProfile definition, DbSession dbSession) { Map<RuleKey, RuleDefinitionDto> rulesByRuleKey = dbClient.ruleDao().selectAllDefinitions(dbSession) .stream() .collect(MoreCollectors.uniqueIndex(RuleDefinitionDto::getKey)); List<ActiveRule> activeRules = definition.getActiveRules(); List<RuleActivation> activations = activeRules.stream() .map(activeRule -> toRuleActivation(activeRule, rulesByRuleKey)) .filter(Objects::nonNull) .collect(MoreCollectors.toArrayList(activeRules.size())); return qProfileRules.activateAndCommit(dbSession, profile, activations); }
@Override public void define(Context context) { LOGGER.info("Creating Tailor Profile"); NewBuiltInQualityProfile nbiqp = context.createBuiltInQualityProfile(TailorRulesDefinition.REPOSITORY_KEY, Swift.KEY); try(Reader config = new InputStreamReader(getClass().getResourceAsStream(PROFILE_PATH))) { RulesProfile ocLintRulesProfile = profileImporter.importProfile(config, ValidationMessages.create()); for (ActiveRule rule : ocLintRulesProfile.getActiveRules()) { nbiqp.activateRule(rule.getRepositoryKey(), rule.getRuleKey()); } } catch (IOException ex){ LOGGER.error("Error Creating Tailor Profile",ex); } nbiqp.done(); } }
@Test public void should_create_perlcritic_profile() { ValidationMessages validation = ValidationMessages.create(); SonarWayProfile definition = new SonarWayProfile(new XMLProfileParser(ruleFinder())); RulesProfile profile = definition.createProfile(validation); assertThat(profile.getLanguage()).isEqualTo(PerlLanguage.KEY); assertThat(profile.getName()).isEqualTo("Sonar way"); assertThat(profile.getActiveRules()).extracting("repositoryKey").containsOnly("PerlCritic", "common-perl"); assertThat(validation.hasErrors()).isFalse(); assertThat(profile.getActiveRules().size()).isGreaterThan(87); }