use of org.sonar.server.qualityprofile.ActiveRuleChange in project sonarqube by SonarSource.
the class RegisterRules method start.
@Override
public void start() {
Profiler profiler = Profiler.create(LOG).startInfo("Register rules");
DbSession session = dbClient.openSession(false);
try {
Map<RuleKey, RuleDto> allRules = loadRules(session);
RulesDefinition.Context context = defLoader.load();
for (RulesDefinition.ExtendedRepository repoDef : getRepositories(context)) {
if (languages.get(repoDef.language()) != null) {
for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
registerRule(ruleDef, allRules, session);
}
session.commit();
}
}
List<RuleDto> activeRules = processRemainingDbRules(allRules.values(), session);
List<ActiveRuleChange> changes = removeActiveRulesOnStillExistingRepositories(session, activeRules, context);
session.commit();
persistRepositories(session, context.repositories());
ruleIndexer.index();
activeRuleIndexer.index(changes);
profiler.stopDebug();
} finally {
session.close();
}
}
use of org.sonar.server.qualityprofile.ActiveRuleChange in project sonarqube by SonarSource.
the class RegisterRules method removeActiveRulesOnStillExistingRepositories.
/**
* 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.
*/
private List<ActiveRuleChange> removeActiveRulesOnStillExistingRepositories(DbSession session, Collection<RuleDto> removedRules, RulesDefinition.Context context) {
List<String> repositoryKeys = newArrayList(Iterables.transform(context.repositories(), new Function<RulesDefinition.Repository, String>() {
@Override
public String apply(@Nonnull RulesDefinition.Repository input) {
return input.key();
}
}));
List<ActiveRuleChange> changes = new ArrayList<>();
for (RuleDto rule : removedRules) {
// SONAR-4642 Remove active rules only when repository still exists
if (repositoryKeys.contains(rule.getRepositoryKey())) {
changes.addAll(ruleActivator.deactivate(session, rule));
}
}
return changes;
}
Aggregations