aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-25 11:16:21 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-29 13:26:54 +0100
commitfd857e7077277194c59af15f77f381ef0bd35443 (patch)
tree4bdd2920b84588da69949e952bf353fc57380558 /server
parent57ef40dfa4071de478bfc184cc7f7846e76836b8 (diff)
downloadsonarqube-fd857e7077277194c59af15f77f381ef0bd35443.tar.gz
sonarqube-fd857e7077277194c59af15f77f381ef0bd35443.zip
SONAR-7330 QProfileExporters is now using ActiveRuleIndexer
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java23
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java20
3 files changed, 37 insertions, 15 deletions
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 192349dba9a..3f30e0f3feb 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
@@ -166,15 +166,18 @@ public class QProfileExporters {
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
RulesProfile rulesProfile = importer.importProfile(xml, messages);
- importProfile(profileDto, rulesProfile, dbSession);
+ List<ActiveRuleChange> changes = importProfile(profileDto, rulesProfile, dbSession);
+ result.addChanges(changes);
processValidationMessages(messages, result);
return result;
}
- private void importProfile(QualityProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
+ private List<ActiveRuleChange> importProfile(QualityProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
+ List<ActiveRuleChange> changes = new ArrayList<>();
for (org.sonar.api.rules.ActiveRule activeRule : rulesProfile.getActiveRules()) {
- ruleActivator.activate(dbSession, toRuleActivation(activeRule), profileDto);
+ changes.addAll(ruleActivator.activate(dbSession, toRuleActivation(activeRule), profileDto));
}
+ return changes;
}
private ProfileImporter getProfileImporter(String importerKey) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
index 34b90e34e75..24d0b23caf7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
@@ -19,11 +19,9 @@
*/
package org.sonar.server.qualityprofile;
-import org.sonar.db.qualityprofile.QualityProfileDto;
-
+import java.util.ArrayList;
import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
+import org.sonar.db.qualityprofile.QualityProfileDto;
public class QProfileResult {
@@ -32,9 +30,12 @@ public class QProfileResult {
private QualityProfileDto profile;
+ private List<ActiveRuleChange> changes;
+
public QProfileResult() {
- warnings = newArrayList();
- infos = newArrayList();
+ warnings = new ArrayList<>();
+ infos = new ArrayList<>();
+ changes = new ArrayList<>();
}
public List<String> warnings() {
@@ -64,9 +65,19 @@ public class QProfileResult {
return this;
}
+ public List<ActiveRuleChange> getChanges() {
+ return changes;
+ }
+
+ public QProfileResult addChanges(List<ActiveRuleChange> changes) {
+ this.changes.addAll(changes);
+ return this;
+ }
+
public QProfileResult add(QProfileResult result) {
warnings.addAll(result.warnings());
infos.addAll(result.infos());
+ changes.addAll(result.getChanges());
return this;
}
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 35ef9aba34c..37639fcb1dc 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
@@ -39,12 +39,13 @@ import org.sonar.api.rules.RulePriority;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.utils.ValidationMessages;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.server.db.DbClient;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.index.ActiveRuleDoc;
+import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -54,10 +55,13 @@ import static org.junit.Assert.fail;
public class QProfileExportersTest {
@ClassRule
- public static ServerTester tester = new ServerTester().withStartupTasks().addXoo().addComponents(
- XooRulesDefinition.class, XooProfileDefinition.class,
- XooExporter.class, StandardExporter.class,
- XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
+ public static ServerTester tester = new ServerTester()
+ .withEsIndexes()
+ .withStartupTasks()
+ .addXoo()
+ .addComponents(XooRulesDefinition.class, XooProfileDefinition.class, XooExporter.class, StandardExporter.class,
+ XooProfileImporter.class, XooProfileImporterWithMessages.class, XooProfileImporterWithError.class);
+
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
@@ -65,6 +69,7 @@ public class QProfileExportersTest {
DbSession dbSession;
QProfileExporters exporters;
QProfileLoader loader;
+ ActiveRuleIndexer activeRuleIndexer;
@Before
public void before() {
@@ -72,6 +77,8 @@ public class QProfileExportersTest {
dbSession = db.openSession(false);
exporters = tester.get(QProfileExporters.class);
loader = tester.get(QProfileLoader.class);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
}
@After
@@ -135,8 +142,9 @@ public class QProfileExportersTest {
assertThat(loader.findActiveRulesByProfile(profileDto.getKey())).isEmpty();
- exporters.importXml(profileDto, "XooProfileImporter", "<xml/>", dbSession);
+ QProfileResult result = exporters.importXml(profileDto, "XooProfileImporter", "<xml/>", dbSession);
dbSession.commit();
+ activeRuleIndexer.index(result.getChanges());
List<ActiveRuleDoc> activeRules = Lists.newArrayList(loader.findActiveRulesByProfile(profileDto.getKey()));
assertThat(activeRules).hasSize(1);