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) {
*/
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 {
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() {
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;
}
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;
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);
DbSession dbSession;
QProfileExporters exporters;
QProfileLoader loader;
+ ActiveRuleIndexer activeRuleIndexer;
@Before
public void before() {
dbSession = db.openSession(false);
exporters = tester.get(QProfileExporters.class);
loader = tester.get(QProfileLoader.class);
+ activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
+ activeRuleIndexer.setEnabled(true);
}
@After
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);