aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-02-24 13:41:27 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-02-24 13:49:39 +0100
commit841cfd567ca37afb94b948b8a3b7b74f781a641a (patch)
tree97e8b8f27c0fcf4e29b70fb4379850872bdcd755 /server
parent5ac06f760d8d80d5073074e7a11e780d9663f47b (diff)
downloadsonarqube-841cfd567ca37afb94b948b8a3b7b74f781a641a.tar.gz
sonarqube-841cfd567ca37afb94b948b8a3b7b74f781a641a.zip
SONAR-6009 Instead of loading active rules then iterate on rules, load rules and then iterate on active rules
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java56
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java33
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java46
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java19
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java16
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java19
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java6
14 files changed, 108 insertions, 119 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java
index c6fff9eff4e..50576f75bf4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectRepositoryLoader.java
@@ -28,6 +28,8 @@ import org.sonar.api.ServerComponent;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.api.web.UserRole;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectRepositories;
@@ -61,6 +63,8 @@ import static com.google.common.collect.Maps.newHashMap;
public class ProjectRepositoryLoader implements ServerComponent {
+ private static final Logger LOG = Loggers.get(ProjectRepositoryLoader.class);
+
private final DbClient dbClient;
private final QProfileFactory qProfileFactory;
private final QProfileLoader qProfileLoader;
@@ -224,36 +228,42 @@ public class ProjectRepositoryLoader implements ServerComponent {
private void addActiveRules(ProjectRepositories ref) {
for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
- Map<RuleKey, ActiveRule> activeRules = activeRuleByRuleKey(qProfileLoader.findActiveRulesByProfile(qProfile.key()));
- Iterator<Rule> rules = ruleService.search(new RuleQuery().setQProfileKey(qProfile.key()).setActivation(true),
- new QueryContext().setFieldsToReturn(newArrayList(
+ // Load all rules of the profile language (only needed fields are loaded)
+ Map<RuleKey, Rule> languageRules = ruleByRuleKey(ruleService.search(new RuleQuery().setLanguages(newArrayList(qProfile.language())),
+ new QueryContext().setLimit(100).setFieldsToReturn(newArrayList(
RuleNormalizer.RuleField.KEY.field(), RuleNormalizer.RuleField.NAME.field(), RuleNormalizer.RuleField.INTERNAL_KEY.field(), RuleNormalizer.RuleField.TEMPLATE_KEY.field()
- )).setScroll(true)).scroll();
- while (rules.hasNext()) {
- Rule rule = rules.next();
- RuleKey templateKey = rule.templateKey();
- ActiveRule activeRule = activeRules.get(rule.key());
- org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
- activeRule.key().ruleKey().repository(),
- activeRule.key().ruleKey().rule(),
- templateKey != null ? templateKey.rule() : null,
- rule.name(),
- activeRule.severity(),
- rule.internalKey(),
- qProfile.language());
- for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
- inputActiveRule.addParam(entry.getKey(), entry.getValue());
+ )).setScroll(true))
+ .scroll());
+ for (Iterator<ActiveRule> activeRuleIterator = qProfileLoader.findActiveRulesByProfile(qProfile.key()); activeRuleIterator.hasNext();) {
+ ActiveRule activeRule = activeRuleIterator.next();
+ Rule rule = languageRules.get(activeRule.key().ruleKey());
+ if (rule == null) {
+ // It should never happen, but we need some log in case it happens
+ LOG.warn("Rule could not be found on active rule '{}'", activeRule.key());
+ } else {
+ RuleKey templateKey = rule.templateKey();
+ org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
+ activeRule.key().ruleKey().repository(),
+ activeRule.key().ruleKey().rule(),
+ templateKey != null ? templateKey.rule() : null,
+ rule.name(),
+ activeRule.severity(),
+ rule.internalKey(),
+ qProfile.language());
+ for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
+ inputActiveRule.addParam(entry.getKey(), entry.getValue());
+ }
+ ref.addActiveRule(inputActiveRule);
}
- ref.addActiveRule(inputActiveRule);
}
}
}
- private Map<RuleKey, ActiveRule> activeRuleByRuleKey(List<ActiveRule> activeRules) {
- return Maps.uniqueIndex(activeRules, new Function<ActiveRule, RuleKey>() {
+ private Map<RuleKey, Rule> ruleByRuleKey(Iterator<Rule> rules) {
+ return Maps.uniqueIndex(rules, new Function<Rule, RuleKey>() {
@Override
- public RuleKey apply(@Nullable ActiveRule input) {
- return input != null ? input.key().ruleKey() : null;
+ public RuleKey apply(@Nullable Rule input) {
+ return input != null ? input.key() : null;
}
});
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
index 9d3389cb8b2..e8f29e64d73 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
@@ -41,6 +41,7 @@ import javax.xml.stream.XMLStreamException;
import java.io.Reader;
import java.io.Writer;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -64,17 +65,18 @@ public class QProfileBackuper implements ServerComponent {
} finally {
dbSession.close();
}
- List<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile.getKey());
+ Iterator<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile.getKey());
writeXml(writer, profile, activeRules);
}
- private void writeXml(Writer writer, QualityProfileDto profile, List<ActiveRule> activeRules) {
+ private void writeXml(Writer writer, QualityProfileDto profile, Iterator<ActiveRule> activeRules) {
XmlWriter xml = XmlWriter.of(writer).declaration();
xml.begin("profile");
xml.prop("name", profile.getName());
xml.prop("language", profile.getLanguage());
xml.begin("rules");
- for (ActiveRule activeRule : activeRules) {
+ while (activeRules.hasNext()) {
+ ActiveRule activeRule = activeRules.next();
xml.begin("rule");
xml.prop("repositoryKey", activeRule.key().ruleKey().repository());
xml.prop("key", activeRule.key().ruleKey().rule());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
index 0651346fcd4..46107c149bb 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
@@ -39,6 +39,7 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -97,7 +98,8 @@ public class QProfileExporters implements ServerComponent {
private RulesProfile wrap(QualityProfileDto profile) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
- for (ActiveRule activeRule : loader.findActiveRulesByProfile(profile.getKey())) {
+ for (Iterator<ActiveRule> activeRuleIterator = loader.findActiveRulesByProfile(profile.getKey()); activeRuleIterator.hasNext();) {
+ ActiveRule activeRule = activeRuleIterator.next();
Rule rule = ruleFinder.findByKey(activeRule.key().ruleKey());
org.sonar.api.rules.ActiveRule wrappedActiveRule = target.activateRule(rule, RulePriority.valueOf(activeRule.severity()));
for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java
index 20b689a13b9..2e0ad3010e6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLoader.java
@@ -38,6 +38,7 @@ import org.sonar.server.search.QueryContext;
import javax.annotation.CheckForNull;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -93,7 +94,7 @@ public class QProfileLoader implements ServerComponent {
return index.get(ActiveRuleIndex.class).findByRule(key);
}
- public List<ActiveRule> findActiveRulesByProfile(String key) {
+ public Iterator<ActiveRule> findActiveRulesByProfile(String key) {
return index.get(ActiveRuleIndex.class).findByProfile(key);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
index 4febac9339d..1cc6fee6c32 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java
@@ -23,6 +23,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchType;
+import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
@@ -37,10 +39,7 @@ import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.rule.index.RuleNormalizer;
import org.sonar.server.search.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, ActiveRuleKey> {
@@ -121,22 +120,20 @@ public class ActiveRuleIndex extends BaseIndex<ActiveRule, ActiveRuleDto, Active
return activeRules;
}
- public List<ActiveRule> findByProfile(String key) {
+ public Iterator<ActiveRule> findByProfile(String key) {
SearchRequestBuilder request = getClient().prepareSearch(getIndexName())
- .setQuery(QueryBuilders.filteredQuery(
- QueryBuilders.termsQuery(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key),
- FilterBuilders.boolFilter()
- .mustNot(FilterBuilders.hasParentFilter(this.getParentType(),
- FilterBuilders.termFilter(RuleNormalizer.RuleField.STATUS.field(), RuleStatus.REMOVED.name())))))
- .setRouting(key)
- // TODO replace by scrolling
- .setSize(Integer.MAX_VALUE);
+ .setTypes(IndexDefinition.ACTIVE_RULE.getIndexType())
+ .setSearchType(SearchType.SCAN)
+ .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES))
+ .setSize(100)
+ .setQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.boolFilter()
+ .must(FilterBuilders.termFilter(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), key))
+ .mustNot(FilterBuilders.hasParentFilter(this.getParentType(),
+ FilterBuilders.termFilter(RuleNormalizer.RuleField.STATUS.field(), RuleStatus.REMOVED.name())))))
+ .setRouting(key);
+
SearchResponse response = request.get();
- List<ActiveRule> activeRules = new ArrayList<ActiveRule>();
- for (SearchHit hit : response.getHits()) {
- activeRules.add(toDoc(hit.getSource()));
- }
- return activeRules;
+ return scroll(response.getScrollId());
}
private String getParentType() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
index 963ada73730..d3432183f19 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndex.java
@@ -308,7 +308,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> {
}
// ActiveRule Filter (profile and inheritance)
- BoolFilterBuilder childrenFilter = FilterBuilders.boolFilter().cache(false);
+ BoolFilterBuilder childrenFilter = FilterBuilders.boolFilter();
this.addTermFilter(childrenFilter, ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY.field(), query.getQProfileKey());
this.addTermFilter(childrenFilter, ActiveRuleNormalizer.ActiveRuleField.INHERITANCE.field(), query.getInheritance());
this.addTermFilter(childrenFilter, ActiveRuleNormalizer.ActiveRuleField.SEVERITY.field(), query.getActiveSeverities());
diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
index 4492b24a937..0e69a9feca1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java
@@ -26,23 +26,14 @@ import com.google.common.collect.Multimap;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.count.CountRequestBuilder;
import org.elasticsearch.action.count.CountResponse;
-import org.elasticsearch.action.get.GetRequestBuilder;
-import org.elasticsearch.action.get.GetResponse;
-import org.elasticsearch.action.get.MultiGetItemResponse;
-import org.elasticsearch.action.get.MultiGetRequest;
-import org.elasticsearch.action.get.MultiGetRequestBuilder;
-import org.elasticsearch.action.get.MultiGetResponse;
+import org.elasticsearch.action.get.*;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.BoolFilterBuilder;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.FilterBuilders;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -62,23 +53,15 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.io.Serializable;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Queue;
+import java.util.*;
public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serializable>
implements Index<DOMAIN, DTO, KEY> {
private static final Logger LOG = Loggers.get(BaseIndex.class);
+ public static final int SCROLL_TIME_IN_MINUTES = 3;
+
private final SearchClient client;
private final BaseNormalizer<DTO, KEY> normalizer;
private final IndexDefinition indexDefinition;
@@ -126,31 +109,20 @@ public abstract class BaseIndex<DOMAIN, DTO extends Dto<KEY>, KEY extends Serial
public Iterator<DOMAIN> scroll(final String scrollId) {
return new Iterator<DOMAIN>() {
- private final Queue<SearchHit> hits = new ArrayDeque<SearchHit>();
-
- private void fillQueue() {
- try {
- SearchScrollRequestBuilder esRequest = client.prepareSearchScroll(scrollId)
- .setScroll(TimeValue.timeValueMinutes(3));
- Collections.addAll(hits, esRequest.get().getHits().getHits());
- } catch (Exception e) {
- throw new IllegalStateException("Error while filling in the scroll buffer", e);
- }
- }
+ private final Queue<SearchHit> hits = new ArrayDeque<>();
@Override
public boolean hasNext() {
if (hits.isEmpty()) {
- fillQueue();
+ SearchScrollRequestBuilder esRequest = client.prepareSearchScroll(scrollId)
+ .setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES));
+ Collections.addAll(hits, esRequest.get().getHits().getHits());
}
return !hits.isEmpty();
}
@Override
public DOMAIN next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
return toDoc(hits.poll().getSource());
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
index 8d0d44d89c7..4abb34861d6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleBackendMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.junit.After;
import org.junit.Before;
@@ -233,16 +234,16 @@ public class ActiveRuleBackendMediumTest {
assertThat(activeRules).isEmpty();
// 2. find by profile
- activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile1.getKey());
+ activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profile1.getKey()));
assertThat(activeRules).hasSize(2);
assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile1.getKey());
assertThat(activeRules.get(1).key().qProfile()).isEqualTo(profile1.getKey());
- activeRules = index.get(ActiveRuleIndex.class).findByProfile(profile2.getKey());
+ activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profile2.getKey()));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile2.getKey());
- activeRules = index.get(ActiveRuleIndex.class).findByProfile("unknown");
+ activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile("unknown"));
assertThat(activeRules).isEmpty();
}
@@ -263,7 +264,7 @@ public class ActiveRuleBackendMediumTest {
dbSession.clearCache();
// verify index
- Collection<ActiveRule> activeRules = index.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey());
+ Collection<ActiveRule> activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey()));
assertThat(activeRules).hasSize(nb);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
index 035026141f2..0debd26b199 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.qualityprofile;
import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
@@ -116,7 +117,7 @@ public class QProfileBackuperMediumTest {
QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage("P1", "xoo");
assertThat(profile).isNotNull();
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(profile.getKey());
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(profile.getKey()));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("BLOCKER");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
@@ -143,7 +144,7 @@ public class QProfileBackuperMediumTest {
tester.get(QProfileBackuper.class).restore(new StringReader(
Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), Charsets.UTF_8)), null);
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY);
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("BLOCKER");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
@@ -171,14 +172,14 @@ public class QProfileBackuperMediumTest {
Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-child.xml"), Charsets.UTF_8)), null);
// parent profile is unchanged
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY);
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("INFO");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
assertThat(activeRules.get(0).params().get("max")).isEqualTo("10");
// child profile overrides parent
- activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY);
+ activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("BLOCKER");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.OVERRIDES);
@@ -206,14 +207,14 @@ public class QProfileBackuperMediumTest {
Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-parent.xml"), Charsets.UTF_8)), null);
// parent profile is updated
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY);
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("BLOCKER");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.NONE);
assertThat(activeRules.get(0).params().get("max")).isEqualTo("7");
// child profile is inherited
- activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY);
+ activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY));
assertThat(activeRules).hasSize(1);
assertThat(activeRules.get(0).severity()).isEqualTo("BLOCKER");
assertThat(activeRules.get(0).inheritance()).isEqualTo(ActiveRule.Inheritance.INHERITED);
@@ -241,7 +242,7 @@ public class QProfileBackuperMediumTest {
Resources.toString(getClass().getResource("QProfileBackuperMediumTest/keep_other_inherited_rules.xml"), Charsets.UTF_8)), QProfileTesting.XOO_P2_NAME);
// x1 and x2
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY);
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY));
assertThat(activeRules).hasSize(2);
}
@@ -274,12 +275,12 @@ public class QProfileBackuperMediumTest {
Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), Charsets.UTF_8)),
QProfileTesting.XOO_P3_NAME);
- List<ActiveRule> activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY);
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY));
assertThat(activeRules).hasSize(0);
QualityProfileDto target = db.qualityProfileDao().getByNameAndLanguage("P3", "xoo");
assertThat(target).isNotNull();
- activeRules = tester.get(QProfileLoader.class).findActiveRulesByProfile(target.getKey());
+ activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(target.getKey()));
assertThat(activeRules).hasSize(1);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
index 814d5095bff..3f5575b3f48 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -173,7 +174,7 @@ public class QProfileCopierMediumTest {
private void verifyOneActiveRule(String profileKey, String expectedSeverity,
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
- List<ActiveRule> activeRules = index.findByProfile(profileKey);
+ List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
assertThat(activeRules).hasSize(1);
ActiveRule activeRule = activeRules.get(0);
assertThat(activeRule.severity()).isEqualTo(expectedSeverity);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
index e9ebde65167..dbb5983b2b1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.qualityprofile;
+import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -134,7 +135,7 @@ public class QProfileExportersTest {
exporters.importXml(profileDto, "XooProfileImporter", "<xml/>", dbSession);
dbSession.commit();
- List<ActiveRule> activeRules = loader.findActiveRulesByProfile(profileDto.getKey());
+ List<ActiveRule> activeRules = Lists.newArrayList(loader.findActiveRulesByProfile(profileDto.getKey()));
assertThat(activeRules).hasSize(1);
ActiveRule activeRule = activeRules.get(0);
assertThat(activeRule.key().ruleKey()).isEqualTo(RuleKey.of("xoo", "R1"));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
index aa59c62aacd..2015af9ab51 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileServiceMediumTest.java
@@ -21,6 +21,7 @@ package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import org.junit.After;
import org.junit.Before;
@@ -122,7 +123,7 @@ public class QProfileServiceMediumTest {
assertThat(loader.getByKey(profile.getKey()).getLanguage()).isEqualTo("xoo");
assertThat(loader.getByKey(profile.getKey()).getName()).isEqualTo("New Profile");
- List<ActiveRule> activeRules = loader.findActiveRulesByProfile(profile.getKey());
+ List<ActiveRule> activeRules = Lists.newArrayList(loader.findActiveRulesByProfile(profile.getKey()));
assertThat(activeRules).hasSize(1);
}
@@ -190,7 +191,7 @@ public class QProfileServiceMediumTest {
ActiveRuleChange.createFor(ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1))
.setSeverity(Severity.MAJOR)
.setParameter("max", "10")
- );
+ );
dbSession.commit();
Result<QProfileActivity> activities = service.searchActivities(new QProfileActivityQuery(), new QueryContext());
@@ -219,7 +220,7 @@ public class QProfileServiceMediumTest {
tester.get(ActivityService.class).write(dbSession, Activity.Type.QPROFILE,
ActiveRuleChange.createFor(ActiveRuleChange.Type.UPDATED, ActiveRuleKey.of(XOO_P1_KEY, ruleKey))
.setParameter("max", "10")
- );
+ );
dbSession.commit();
Result<QProfileActivity> activities = service.searchActivities(new QProfileActivityQuery(), new QueryContext());
@@ -242,7 +243,7 @@ public class QProfileServiceMediumTest {
ActiveRuleChange.createFor(ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1))
.setSeverity(Severity.MAJOR)
.setParameter("max", "10")
- );
+ );
dbSession.commit();
Result<QProfileActivity> activities = service.searchActivities(new QProfileActivityQuery(), new QueryContext());
@@ -263,7 +264,7 @@ public class QProfileServiceMediumTest {
ActiveRuleChange.createFor(ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, ruleKey))
.setSeverity(Severity.MAJOR)
.setParameter("max", "10")
- );
+ );
dbSession.commit();
Result<QProfileActivity> activities = service.searchActivities(new QProfileActivityQuery(), new QueryContext());
@@ -333,7 +334,6 @@ public class QProfileServiceMediumTest {
assertThat(service.getDefault("xoo").getKey()).isEqualTo(XOO_P1_KEY);
}
-
public static class XooExporter extends ProfileExporter {
public XooExporter() {
super("xootool", "Xoo Tool");
@@ -341,7 +341,7 @@ public class QProfileServiceMediumTest {
@Override
public String[] getSupportedLanguages() {
- return new String[]{"xoo"};
+ return new String[] {"xoo"};
}
@Override
@@ -366,7 +366,7 @@ public class QProfileServiceMediumTest {
@Override
public String[] getSupportedLanguages() {
- return new String[]{"xoo"};
+ return new String[] {"xoo"};
}
@Override
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
index 8df38ef8ef2..927bcbedbf2 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/RuleActivatorMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.qualityprofile;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -163,7 +164,7 @@ public class RuleActivatorMediumTest {
@Test
public void activate_with_empty_parameter_having_no_default_value() throws Exception {
activate(new RuleActivation(RuleTesting.XOO_X1)
- .setParameter("min", ""),
+ .setParameter("min", ""),
XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
@@ -178,7 +179,7 @@ public class RuleActivatorMediumTest {
@Test
public void activate_with_empty_parameters() throws Exception {
activate(new RuleActivation(RuleTesting.XOO_X1)
- .setParameters(ImmutableMap.of("max", "", "min", "")),
+ .setParameters(ImmutableMap.of("max", "", "min", "")),
XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
@@ -193,7 +194,7 @@ public class RuleActivatorMediumTest {
@Test
public void activate_rule_with_negative_integer_value_on_parameter_having_no_default_value() throws Exception {
activate(new RuleActivation(RuleTesting.XOO_X1)
- .setParameter("min", "-10"),
+ .setParameter("min", "-10"),
XOO_P1_KEY);
assertThat(countActiveRules(XOO_P1_KEY)).isEqualTo(1);
@@ -1031,24 +1032,24 @@ public class RuleActivatorMediumTest {
private int countActiveRules(String profileKey) {
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, profileKey);
- List<ActiveRule> activeRules = index.findByProfile(profileKey);
+ List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(profileKey));
assertThat(activeRuleDtos.size()).as("Not same active rules between db and index").isEqualTo(activeRules.size());
return activeRuleDtos.size();
}
private void verifyOneActiveRule(String profileKey, RuleKey ruleKey, String expectedSeverity,
- @Nullable String expectedInheritance, Map<String, String> expectedParams) {
+ @Nullable String expectedInheritance, Map<String, String> expectedParams) {
assertThat(countActiveRules(profileKey)).isEqualTo(1);
verifyHasActiveRule(profileKey, ruleKey, expectedSeverity, expectedInheritance, expectedParams);
}
private void verifyHasActiveRule(String profileKey, RuleKey ruleKey, String expectedSeverity,
- @Nullable String expectedInheritance, Map<String, String> expectedParams) {
+ @Nullable String expectedInheritance, Map<String, String> expectedParams) {
verifyHasActiveRule(ActiveRuleKey.of(profileKey, ruleKey), expectedSeverity, expectedInheritance, expectedParams);
}
private void verifyHasActiveRule(ActiveRuleKey activeRuleKey, String expectedSeverity,
- @Nullable String expectedInheritance, Map<String, String> expectedParams) {
+ @Nullable String expectedInheritance, Map<String, String> expectedParams) {
// verify db
boolean found = false;
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, activeRuleKey.qProfile());
@@ -1073,7 +1074,7 @@ public class RuleActivatorMediumTest {
assertThat(found).as("Rule is not activated in db").isTrue();
// verify es
- List<ActiveRule> activeRules = index.findByProfile(activeRuleKey.qProfile());
+ List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(activeRuleKey.qProfile()));
found = false;
for (ActiveRule activeRule : activeRules) {
if (activeRule.key().equals(activeRuleKey)) {
@@ -1116,7 +1117,7 @@ public class RuleActivatorMediumTest {
assertThat(activeRuleDtos).isEmpty();
// verify es
- List<ActiveRule> activeRules = index.findByProfile(key);
+ List<ActiveRule> activeRules = Lists.newArrayList(index.findByProfile(key));
assertThat(activeRules).isEmpty();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
index 8043f0838e8..76510d1872a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleDeleterMediumTest.java
@@ -20,8 +20,7 @@
package org.sonar.server.rule;
-import org.sonar.server.search.BaseIndex;
-
+import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -40,6 +39,7 @@ import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.server.rule.index.RuleIndex;
+import org.sonar.server.search.BaseIndex;
import org.sonar.server.tester.ServerTester;
import java.util.List;
@@ -96,7 +96,7 @@ public class RuleDeleterMediumTest {
assertThat(customRuleReloaded.status()).isEqualTo(RuleStatus.REMOVED);
// Verify there's no more active rule from custom rule
- List<ActiveRule> activeRules = tester.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey());
+ List<ActiveRule> activeRules = Lists.newArrayList(tester.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey()));
assertThat(activeRules).isEmpty();
}