it was only used to "host" enum Inheritance which is now at upper level and renamed to ActiveRuleInheritance
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.qualityprofile;
-
-import org.sonar.db.qualityprofile.ActiveRuleKey;
-
-public interface ActiveRule {
-
- enum Inheritance {
- NONE, OVERRIDES, INHERITED
- }
-
- long createdAt();
-
- long updatedAt();
-
- ActiveRuleKey key();
-
- String severity();
-
- Inheritance inheritance();
-
-}
private final ActiveRuleKey key;
private final int ruleId;
private String severity = null;
- private ActiveRule.Inheritance inheritance = null;
+ private ActiveRuleInheritance inheritance = null;
private final Map<String, String> parameters = new HashMap<>();
public ActiveRuleChange(Type type, ActiveRuleDto activeRule, RuleDefinitionDto ruleDefinition) {
return this;
}
- public ActiveRuleChange setInheritance(@Nullable ActiveRule.Inheritance i) {
+ public ActiveRuleChange setInheritance(@Nullable ActiveRuleInheritance i) {
this.inheritance = i;
return this;
}
@CheckForNull
- public ActiveRule.Inheritance getInheritance() {
+ public ActiveRuleInheritance getInheritance() {
return inheritance;
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.qualityprofile;
+
+public enum ActiveRuleInheritance {
+ NONE, OVERRIDES, INHERITED
+}
import org.sonar.db.qualityprofile.RulesProfileDto;
import static java.lang.String.format;
-import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.NONE;
+import static org.sonar.server.qualityprofile.ActiveRuleInheritance.NONE;
/**
* Synchronize Quality profiles during server startup
change = new ActiveRuleChange(ActiveRuleChange.Type.ACTIVATED, activeRuleKey, rule);
applySeverityAndParamToChange(activation, context, change);
if (context.isCascading() || isSameAsParent(change, context)) {
- change.setInheritance(ActiveRule.Inheritance.INHERITED);
+ change.setInheritance(ActiveRuleInheritance.INHERITED);
}
} else {
// already activated
change = new ActiveRuleChange(ActiveRuleChange.Type.UPDATED, activeRuleKey, rule);
if (context.isCascading() && activeRule.get().getInheritance() == null) {
// activate on child, then on parent -> mark child as overriding parent
- change.setInheritance(ActiveRule.Inheritance.OVERRIDES);
+ change.setInheritance(ActiveRuleInheritance.OVERRIDES);
change.setSeverity(activeRule.get().getSeverityString());
for (ActiveRuleParamDto activeParam : activeRule.getParams()) {
change.setParameter(activeParam.getKey(), activeParam.getValue());
applySeverityAndParamToChange(activation, context, change);
if (!context.isCascading() && context.getParentActiveRule() != null) {
// override rule which is already declared on parents
- change.setInheritance(isSameAsParent(change, context) ? ActiveRule.Inheritance.INHERITED : ActiveRule.Inheritance.OVERRIDES);
+ change.setInheritance(isSameAsParent(change, context) ? ActiveRuleInheritance.INHERITED : ActiveRuleInheritance.OVERRIDES);
}
}
if (isSame(change, activeRule)) {
if (severity != null) {
activeRule.setSeverity(severity);
}
- ActiveRule.Inheritance inheritance = change.getInheritance();
+ ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null) {
activeRule.setInheritance(inheritance.name());
}
if (severity != null) {
activeRule.get().setSeverity(severity);
}
- ActiveRule.Inheritance inheritance = change.getInheritance();
+ ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null) {
activeRule.get().setInheritance(inheritance.name());
}
}
private static boolean isSame(ActiveRuleChange change, ActiveRuleWrapper activeRule) {
- ActiveRule.Inheritance inheritance = change.getInheritance();
+ ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null && !inheritance.name().equals(activeRule.get().getInheritance())) {
return false;
}
import java.util.Map;
import javax.annotation.Nullable;
import org.sonar.server.es.BaseDoc;
-import org.sonar.server.qualityprofile.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ID;
return this;
}
- ActiveRule.Inheritance getInheritance() {
+ ActiveRuleInheritance getInheritance() {
String inheritance = getNullableField(FIELD_ACTIVE_RULE_INHERITANCE);
if (inheritance == null || inheritance.isEmpty() ||
containsIgnoreCase(inheritance, "none")) {
- return ActiveRule.Inheritance.NONE;
+ return ActiveRuleInheritance.NONE;
} else if (containsIgnoreCase(inheritance, "herit")) {
- return ActiveRule.Inheritance.INHERITED;
+ return ActiveRuleInheritance.INHERITED;
} else if (containsIgnoreCase(inheritance, "over")) {
- return ActiveRule.Inheritance.OVERRIDES;
+ return ActiveRuleInheritance.OVERRIDES;
} else {
throw new IllegalStateException("Value \"" + inheritance + "\" is not valid for rule's inheritance");
}
import org.sonar.server.es.IndexingResult;
import org.sonar.server.es.OneToOneResilientIndexingListener;
import org.sonar.server.es.ResilientIndexer;
-import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.qualityprofile.ActiveRuleChange;
+import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import org.sonar.server.rule.index.RuleIndexDefinition;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
.setSeverity(SeverityUtil.getSeverityFromOrdinal(dto.getSeverity()));
// all the fields must be present, even if value is null
String inheritance = dto.getInheritance();
- doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);
+ doc.setInheritance(inheritance == null ? ActiveRuleInheritance.NONE.name() : inheritance);
return new IndexRequest(INDEX_TYPE_ACTIVE_RULE.getIndex(), INDEX_TYPE_ACTIVE_RULE.getType())
.id(doc.getId())
.parent(doc.getParent())
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
-import org.sonar.server.qualityprofile.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import org.sonar.server.rule.index.RuleQuery;
import org.sonarqube.ws.Rules;
import org.sonarqube.ws.Rules.SearchResponse;
Rules.Active.Builder builder = Rules.Active.newBuilder();
builder.setQProfile(activeRule.getProfileUuid());
String inheritance = activeRule.getInheritance();
- builder.setInherit(inheritance != null ? inheritance : ActiveRule.Inheritance.NONE.name());
+ builder.setInherit(inheritance != null ? inheritance : ActiveRuleInheritance.NONE.name());
builder.setSeverity(activeRule.getSeverityString());
builder.setCreatedAt(DateUtils.formatDateTime(activeRule.getCreatedAt()));
Rules.Active.Param.Builder paramBuilder = Rules.Active.Param.newBuilder();
import org.sonar.server.es.Facets;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
-import org.sonar.server.qualityprofile.ActiveRule;
+import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleIndexDefinition;
import org.sonar.server.rule.index.RuleQuery;
.createParam(PARAM_INHERITANCE)
.setDescription("Comma-separated list of values of inheritance for a rule within a quality profile. Used only if the parameter '" +
PARAM_ACTIVATION + "' is set.")
- .setPossibleValues(ActiveRule.Inheritance.NONE.name(),
- ActiveRule.Inheritance.INHERITED.name(),
- ActiveRule.Inheritance.OVERRIDES.name())
- .setExampleValue(ActiveRule.Inheritance.INHERITED.name() + "," +
- ActiveRule.Inheritance.OVERRIDES.name());
+ .setPossibleValues(ActiveRuleInheritance.NONE.name(),
+ ActiveRuleInheritance.INHERITED.name(),
+ ActiveRuleInheritance.OVERRIDES.name())
+ .setExampleValue(ActiveRuleInheritance.INHERITED.name() + "," +
+ ActiveRuleInheritance.OVERRIDES.name());
action
.createParam(PARAM_ACTIVE_SEVERITIES)
import static org.sonar.api.rule.Severity.MAJOR;
import static org.sonar.api.rule.Severity.MINOR;
import static org.sonar.db.rule.RuleTesting.newCustomRule;
-import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.INHERITED;
+import static org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED;
public class QProfileRuleImplTest {
assertThatProfileHasNoActiveRules(parentProfile);
assertThatRuleIsUpdated(childProfile, rule, MAJOR, null, of(param.getName(), "foo"));
- assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRule.Inheritance.OVERRIDES, of(param.getName(), "bar"));
+ assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar"));
assertThat(changes).hasSize(1);
}
assertThatProfileHasNoActiveRules(parentProfile);
assertThatRuleIsUpdated(childProfile, rule, BLOCKER, null, of(param.getName(), "baz"));
- assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRule.Inheritance.OVERRIDES, of(param.getName(), "bar"));
+ assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar"));
assertThat(changes).hasSize(1);
}
assertThatRuleIsUpdated(parentProfile, rule, rule.getSeverityString(), null, of(param.getName(), param.getDefaultValue()));
assertThatRuleIsUpdated(childProfile, rule, rule.getSeverityString(), INHERITED, of(param.getName(), param.getDefaultValue()));
- assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRule.Inheritance.OVERRIDES, of(param.getName(), "bar"));
+ assertThatRuleIsUpdated(grandChildProfile, rule, CRITICAL, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "bar"));
assertThat(changes).hasSize(2);
}
List<ActiveRuleChange> changes = activate(parentProfile, parentActivation);
assertThatRuleIsUpdated(parentProfile, rule, CRITICAL, null, of(param.getName(), "bar"));
- assertThatRuleIsUpdated(childProfile, rule, MAJOR, ActiveRule.Inheritance.OVERRIDES, of(param.getName(), "foo"));
+ assertThatRuleIsUpdated(childProfile, rule, MAJOR, ActiveRuleInheritance.OVERRIDES, of(param.getName(), "foo"));
assertThat(changes).hasSize(2);
}
RuleActivation childActivation = RuleActivation.create(rule.getId(), BLOCKER, null);
changes = activate(childProfile, childActivation);
- assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
+ assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThat(changes).hasSize(1);
RuleActivation resetActivation = RuleActivation.createReset(rule.getId());
RuleActivation childActivation = RuleActivation.create(rule.getId(), BLOCKER, null);
changes = activate(childProfile, childActivation);
- assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
+ assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThatRuleIsUpdated(grandChildProfile, rule, BLOCKER, INHERITED, emptyMap());
assertThat(changes).hasSize(2);
RuleActivation resetActivation = RuleActivation.createReset(rule.getId());
changes = activate(baseProfile, resetActivation);
assertThatRuleIsUpdated(baseProfile, rule, rule.getSeverityString(), null, emptyMap());
- assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
+ assertThatRuleIsUpdated(childProfile, rule, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThatRuleIsUpdated(grandChildProfile, rule, BLOCKER, INHERITED, emptyMap());
assertThat(changes).hasSize(1);
}
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes,
- String expectedSeverity, @Nullable ActiveRule.Inheritance expectedInheritance, Map<String, String> expectedParams) {
+ String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)
.stream()
.filter(ar -> ar.getRuleKey().equals(rule.getKey()))
}
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule,
- String expectedSeverity, @Nullable ActiveRule.Inheritance expectedInheritance, Map<String, String> expectedParams) {
+ String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)
.stream()
.filter(ar -> ar.getRuleKey().equals(rule.getKey()))
import static java.util.Collections.singleton;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.rule.Severity.BLOCKER;
-import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.INHERITED;
+import static org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED;
public class QProfileTreeImplTest {
RuleActivation activation = RuleActivation.create(rule1.getId(), BLOCKER, null);
changes = activate(profile2, activation);
assertThat(changes).hasSize(1);
- assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRule.Inheritance.OVERRIDES, emptyMap());
+ assertThatRuleIsUpdated(profile2, rule1, BLOCKER, ActiveRuleInheritance.OVERRIDES, emptyMap());
assertThatRuleIsActivated(profile2, rule2, null, rule2.getSeverityString(), null, emptyMap());
changes = underTest.removeParentAndCommit(db.getSession(), profile2);
}
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes,
- String expectedSeverity, @Nullable ActiveRule.Inheritance expectedInheritance, Map<String, String> expectedParams) {
+ String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)
.stream()
.filter(ar -> ar.getRuleKey().equals(rule.getKey()))
}
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule,
- String expectedSeverity, @Nullable ActiveRule.Inheritance expectedInheritance, Map<String, String> expectedParams) {
+ String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) {
OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile)
.stream()
.filter(ar -> ar.getRuleKey().equals(rule.getKey()))
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
-import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.qualityprofile.ActiveRuleChange;
+import org.sonar.server.qualityprofile.ActiveRuleInheritance;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
Map<String, Object> data = ImmutableMap.of(
"ruleId", valueOf(rule1.getId()),
"severity", "MINOR",
- "inheritance", ActiveRule.Inheritance.INHERITED.name(),
+ "inheritance", ActiveRuleInheritance.INHERITED.name(),
"param_foo", "foo_value",
"param_bar", "bar_value");
QProfileChangeDto change = insertChange(profile, ActiveRuleChange.Type.ACTIVATED, "theLogin", data);
import static org.sonar.db.rule.RuleTesting.setTemplateId;
import static org.sonar.db.rule.RuleTesting.setType;
import static org.sonar.db.rule.RuleTesting.setUpdatedAt;
-import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.INHERITED;
-import static org.sonar.server.qualityprofile.ActiveRule.Inheritance.OVERRIDES;
+import static org.sonar.server.qualityprofile.ActiveRuleInheritance.INHERITED;
+import static org.sonar.server.qualityprofile.ActiveRuleInheritance.OVERRIDES;
import static org.sonar.server.rule.index.RuleIndex.FACET_LANGUAGES;
import static org.sonar.server.rule.index.RuleIndex.FACET_REPOSITORIES;
import static org.sonar.server.rule.index.RuleIndex.FACET_TAGS;