use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.
the class QProfileExporters method toRuleActivation.
private static RuleActivation toRuleActivation(org.sonar.api.rules.ActiveRule activeRule) {
RuleActivation ruleActivation = new RuleActivation(activeRule.getRule().ruleKey());
ruleActivation.setSeverity(activeRule.getSeverity().name());
for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
ruleActivation.setParameter(activeRuleParam.getKey(), activeRuleParam.getValue());
}
return ruleActivation;
}
use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.
the class XMLProfileSerializer method appendRuleParameters.
private static void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException {
if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
writer.append("<parameters>");
for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
appendRuleParameter(writer, activeRuleParam);
}
writer.append("</parameters>");
}
}
use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.
the class QProfileReset method resetLanguage.
/**
* Reset built-in profiles for the given language. Missing profiles are created and
* existing ones are updated.
*/
public void resetLanguage(String language) {
DbSession dbSession = db.openSession(false);
try {
ListMultimap<QProfileName, RulesProfile> profilesByName = loadDefinitionsGroupedByName(language);
for (Map.Entry<QProfileName, Collection<RulesProfile>> entry : profilesByName.asMap().entrySet()) {
QProfileName profileName = entry.getKey();
QualityProfileDto profile = factory.getOrCreate(dbSession, profileName);
List<RuleActivation> activations = Lists.newArrayList();
for (RulesProfile def : entry.getValue()) {
for (ActiveRule activeRule : def.getActiveRules()) {
RuleActivation activation = new RuleActivation(RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()));
activation.setSeverity(activeRule.getSeverity().name());
if (!activeRule.getActiveRuleParams().isEmpty()) {
for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
activation.setParameter(param.getParamKey(), param.getValue());
}
} else {
for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(dbSession, activeRule.getRule().ruleKey())) {
activation.setParameter(param.getName(), param.getDefaultValue());
}
}
activations.add(activation);
}
}
doReset(dbSession, profile, activations);
}
} finally {
dbSession.close();
}
}
use of org.sonar.api.rules.ActiveRuleParam in project sonarqube by SonarSource.
the class RegisterQualityProfiles method register.
private List<ActiveRuleChange> register(QProfileName name, Collection<RulesProfile> profiles, DbSession session) {
LOGGER.info("Register profile " + name);
List<ActiveRuleChange> changes = new ArrayList<>();
QualityProfileDto profileDto = dbClient.qualityProfileDao().selectByNameAndLanguage(name.getName(), name.getLanguage(), session);
if (profileDto != null) {
changes.addAll(profileFactory.delete(session, profileDto.getKey(), true));
}
profileFactory.create(session, name);
for (RulesProfile profile : profiles) {
for (org.sonar.api.rules.ActiveRule activeRule : profile.getActiveRules()) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(activeRule.getSeverity() != null ? activeRule.getSeverity().name() : null);
for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
activation.setParameter(param.getKey(), param.getValue());
}
changes.addAll(ruleActivator.activate(session, activation, name));
}
}
LoadedTemplateDto template = new LoadedTemplateDto(templateKey(name), LoadedTemplateDto.QUALITY_PROFILE_TYPE);
dbClient.loadedTemplateDao().insert(template, session);
session.commit();
return changes;
}
Aggregations