private List<ActiveRuleChange> removeActiveRulesOnStillExistingRepositories(DbSession dbSession, RegisterRulesContext recorder,
    List<RulesDefinition.ExtendedRepository> context) {
    List<String> repositoryKeys = context.stream()
      .map(RulesDefinition.ExtendedRepository::key)
      .collect(MoreCollectors.toList(context.size()));

    List<ActiveRuleChange> changes = new ArrayList<>();
    Profiler profiler = Profiler.create(Loggers.get(getClass()));
    recorder.getRemoved().forEach(rule -> {
      // SONAR-4642 Remove active rules only when repository still exists
      if (repositoryKeys.contains(rule.getRepositoryKey())) {
        profiler.start();
        changes.addAll(qProfileRules.deleteRule(dbSession, rule));
        profiler.stopDebug(format("Remove active rule for rule %s", rule.getKey()));
      }
    });
    return changes;
  }
private List < ActiveRuleChange > removeActiveRulesOnStillExistingRepositories ( DbSession dbSession , RegisterRulesContext recorder , List < RulesDefinition . ExtendedRepository > context ) { List < String > repositoryKeys = context . stream ( ) . map ( RulesDefinition . ExtendedRepository :: key ) . collect ( MoreCollectors . toList ( context . size ( ) ) ) ; List < ActiveRuleChange > changes = new ArrayList < > ( ) ; Profiler profiler = Profiler . create ( Loggers . get ( getClass ( ) ) ) ; recorder . getRemoved ( ) . forEach ( rule -> { if ( repositoryKeys . contains ( rule . getRepositoryKey ( ) ) ) { profiler . start ( ) ; changes . addAll ( qProfileRules . deleteRule ( dbSession , rule ) ) ; profiler . stopDebug ( format ( "Remove active rule for rule %s" , rule . getKey ( ) ) ) ; } } ) ; return changes ; }
SONAR-4642
<p/>
Remove active rules on repositories that still exists.
<p/>
For instance, if the javascript repository do not provide anymore some rules, active rules related to this rules will be removed.
But if the javascript repository do not exists anymore, then related active rules will not be removed.
<p/>
The side effect of this approach is that extended repositories will not be managed the same way.
If an extended repository do not exists anymore, then related active rules will be removed.