Browse Source

SONAR-10313 remove dead interface ActiveRule

it was only used to "host" enum Inheritance which is now at upper level and renamed to ActiveRuleInheritance
tags/7.5
Sébastien Lesaint 6 years ago
parent
commit
af9cd8be6d

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleChange.java View File

@@ -42,7 +42,7 @@ public class ActiveRuleChange {
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) {
@@ -80,13 +80,13 @@ public class ActiveRuleChange {
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;
}


server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java → server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRuleInheritance.java View File

@@ -19,22 +19,6 @@
*/
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();

public enum ActiveRuleInheritance {
NONE, OVERRIDES, INHERITED
}

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java View File

@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
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

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java View File

@@ -96,7 +96,7 @@ public class RuleActivator {
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
@@ -107,7 +107,7 @@ public class RuleActivator {
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());
@@ -117,7 +117,7 @@ public class RuleActivator {
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)) {
@@ -263,7 +263,7 @@ public class RuleActivator {
if (severity != null) {
activeRule.setSeverity(severity);
}
ActiveRule.Inheritance inheritance = change.getInheritance();
ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null) {
activeRule.setInheritance(inheritance.name());
}
@@ -290,7 +290,7 @@ public class RuleActivator {
if (severity != null) {
activeRule.get().setSeverity(severity);
}
ActiveRule.Inheritance inheritance = change.getInheritance();
ActiveRuleInheritance inheritance = change.getInheritance();
if (inheritance != null) {
activeRule.get().setInheritance(inheritance.name());
}
@@ -427,7 +427,7 @@ public class RuleActivator {
}

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;
}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java View File

@@ -23,7 +23,7 @@ import com.google.common.collect.Maps;
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;
@@ -85,15 +85,15 @@ public class ActiveRuleDoc extends BaseDoc {
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");
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexer.java View File

@@ -46,8 +46,8 @@ import org.sonar.server.es.IndexingListener;
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;
@@ -212,7 +212,7 @@ public class ActiveRuleIndexer implements ResilientIndexer {
.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())

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java View File

@@ -49,7 +49,7 @@ import org.sonar.db.qualityprofile.OrgActiveRuleDto;
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;
@@ -164,7 +164,7 @@ public class ActiveRuleCompleter {
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();

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java View File

@@ -52,7 +52,7 @@ import org.sonar.db.rule.RuleParamDto;
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;
@@ -275,11 +275,11 @@ public class SearchAction implements RulesWsAction {
.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)

+ 10
- 10
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java View File

@@ -68,7 +68,7 @@ import static org.sonar.api.rule.Severity.CRITICAL;
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 {

@@ -490,7 +490,7 @@ 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);
}

@@ -514,7 +514,7 @@ public class QProfileRuleImplTest {

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);
}

@@ -538,7 +538,7 @@ public class QProfileRuleImplTest {

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);
}

@@ -556,7 +556,7 @@ public class QProfileRuleImplTest {
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);
}

@@ -644,7 +644,7 @@ public class QProfileRuleImplTest {

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());
@@ -670,7 +670,7 @@ public class QProfileRuleImplTest {

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);

@@ -678,7 +678,7 @@ public class QProfileRuleImplTest {
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);

@@ -894,7 +894,7 @@ public class QProfileRuleImplTest {
}

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()))
@@ -929,7 +929,7 @@ public class QProfileRuleImplTest {
}

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()))

+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java View File

@@ -50,7 +50,7 @@ import static java.util.Collections.emptyMap;
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 {

@@ -167,7 +167,7 @@ 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);
@@ -211,7 +211,7 @@ public class QProfileTreeImplTest {
}

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()))
@@ -246,7 +246,7 @@ public class QProfileTreeImplTest {
}

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()))

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java View File

@@ -44,8 +44,8 @@ import org.sonar.db.user.UserDto;
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;
@@ -291,7 +291,7 @@ public class ChangelogActionTest {
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);

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/rule/index/RuleIndexTest.java View File

@@ -76,8 +76,8 @@ import static org.sonar.db.rule.RuleTesting.setTags;
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;

Loading…
Cancel
Save