aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-09-04 16:08:53 +0200
committerSonarTech <sonartech@sonarsource.com>2018-09-24 20:20:58 +0200
commitcfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2 (patch)
tree81398a80d0269b523e630495a580daf8ac144228 /server
parent326b30334f0f5c0bb6a9565a3f6b367695bb1087 (diff)
downloadsonarqube-cfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2.tar.gz
sonarqube-cfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2.zip
SONAR-11209 Allow sensors to provide ad hoc rule metadata for external issues
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java38
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java39
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java6
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java4
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java (renamed from server/sonar-server-common/src/main/java/org/sonar/server/rule/ExternalRuleCreator.java)17
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java (renamed from server/sonar-server-common/src/main/java/org/sonar/server/rule/NewExternalRule.java)8
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java (renamed from server/sonar-server-common/src/test/java/org/sonar/server/rule/ExternalRuleCreatorTest.java)6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/rule/NewAddHocRuleTest.java (renamed from server/sonar-server/src/test/java/org/sonar/server/rule/NewExternalRuleTest.java)8
14 files changed, 89 insertions, 89 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
index 123dc51d93c..a780920f733 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepository.java
@@ -23,7 +23,7 @@ import java.util.Optional;
import java.util.function.Supplier;
import org.sonar.api.rule.RuleKey;
import org.sonar.db.DbSession;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.NewAddHocRule;
/**
* Repository of every rule in DB (including manual rules) whichever their status.
@@ -48,8 +48,8 @@ public interface RuleRepository {
Optional<Rule> findById(int id);
- void insertNewExternalRuleIfAbsent(RuleKey ruleKey, Supplier<NewExternalRule> ruleSupplier);
+ void addNewAddHocRuleIfAbsent(RuleKey ruleKey, Supplier<NewAddHocRule> ruleSupplier);
- void persistNewExternalRules(DbSession dbSession);
+ void persistNewAddHocRules(DbSession dbSession);
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
index 65be96fdfa7..7a99e846c1c 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImpl.java
@@ -37,8 +37,8 @@ import org.sonar.db.DbSession;
import org.sonar.db.rule.DeprecatedRuleKeyDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.server.rule.ExternalRuleCreator;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.AddHocRuleCreator;
+import org.sonar.server.rule.NewAddHocRule;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
@@ -50,34 +50,34 @@ public class RuleRepositoryImpl implements RuleRepository {
@CheckForNull
private Map<Integer, Rule> rulesById;
- private final ExternalRuleCreator creator;
+ private final AddHocRuleCreator creator;
private final DbClient dbClient;
private final AnalysisMetadataHolder analysisMetadataHolder;
- public RuleRepositoryImpl(ExternalRuleCreator creator, DbClient dbClient, AnalysisMetadataHolder analysisMetadataHolder) {
+ public RuleRepositoryImpl(AddHocRuleCreator creator, DbClient dbClient, AnalysisMetadataHolder analysisMetadataHolder) {
this.creator = creator;
this.dbClient = dbClient;
this.analysisMetadataHolder = analysisMetadataHolder;
}
- public void insertNewExternalRuleIfAbsent(RuleKey ruleKey, Supplier<NewExternalRule> ruleSupplier) {
+ public void addNewAddHocRuleIfAbsent(RuleKey ruleKey, Supplier<NewAddHocRule> ruleSupplier) {
ensureInitialized();
if (!rulesByKey.containsKey(ruleKey)) {
- rulesByKey.computeIfAbsent(ruleKey, s -> new ExternalRuleWrapper(ruleSupplier.get()));
+ rulesByKey.computeIfAbsent(ruleKey, s -> new AdHocRuleWrapper(ruleSupplier.get()));
}
}
@Override
- public void persistNewExternalRules(DbSession dbSession) {
+ public void persistNewAddHocRules(DbSession dbSession) {
ensureInitialized();
rulesByKey.values().stream()
- .filter(ExternalRuleWrapper.class::isInstance)
- .forEach(extRule -> persistAndIndex(dbSession, (ExternalRuleWrapper) extRule));
+ .filter(AdHocRuleWrapper.class::isInstance)
+ .forEach(r -> persistAndIndex(dbSession, (AdHocRuleWrapper) r));
}
- private void persistAndIndex(DbSession dbSession, ExternalRuleWrapper external) {
+ private void persistAndIndex(DbSession dbSession, AdHocRuleWrapper external) {
Rule rule = new RuleImpl(creator.persistAndIndex(dbSession, external.getDelegate()));
rulesById.put(rule.getId(), rule);
rulesByKey.put(external.getKey(), rule);
@@ -145,15 +145,15 @@ public class RuleRepositoryImpl implements RuleRepository {
}
}
- private static class ExternalRuleWrapper implements Rule {
- private final NewExternalRule externalRule;
+ private static class AdHocRuleWrapper implements Rule {
+ private final NewAddHocRule addHocRule;
- private ExternalRuleWrapper(NewExternalRule externalRule) {
- this.externalRule = externalRule;
+ private AdHocRuleWrapper(NewAddHocRule addHocRule) {
+ this.addHocRule = addHocRule;
}
- public NewExternalRule getDelegate() {
- return externalRule;
+ public NewAddHocRule getDelegate() {
+ return addHocRule;
}
@Override
@@ -163,12 +163,12 @@ public class RuleRepositoryImpl implements RuleRepository {
@Override
public RuleKey getKey() {
- return externalRule.getKey();
+ return addHocRule.getKey();
}
@Override
public String getName() {
- return externalRule.getName();
+ return addHocRule.getName();
}
@Override
@@ -201,7 +201,7 @@ public class RuleRepositoryImpl implements RuleRepository {
@CheckForNull
@Override
public String getPluginKey() {
- return externalRule.getPluginKey();
+ return addHocRule.getPluginKey();
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
index 58801ef4de6..767627d6a79 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
@@ -40,14 +40,13 @@ import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.IssueType;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
import org.sonar.ce.task.projectanalysis.issue.commonrule.CommonRuleEngine;
import org.sonar.ce.task.projectanalysis.issue.filter.IssueFilter;
import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRulesHolder;
import org.sonar.ce.task.projectanalysis.source.SourceLinesHashRepository;
import org.sonar.server.rule.CommonRuleKeys;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.NewAddHocRule;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
@@ -182,30 +181,30 @@ public class TrackerRawInputFactory {
return issue;
}
- private DefaultIssue toExternalIssue(LineHashSequence lineHashSeq, ScannerReport.ExternalIssue reportIssue) {
+ private DefaultIssue toExternalIssue(LineHashSequence lineHashSeq, ScannerReport.ExternalIssue reportExternalIssue) {
DefaultIssue issue = new DefaultIssue();
init(issue);
- issue.setRuleKey(RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportIssue.getRuleRepository(), reportIssue.getRuleKey()));
- if (reportIssue.hasTextRange()) {
- int startLine = reportIssue.getTextRange().getStartLine();
+ issue.setRuleKey(RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportExternalIssue.getEngineId(), reportExternalIssue.getRuleId()));
+ if (reportExternalIssue.hasTextRange()) {
+ int startLine = reportExternalIssue.getTextRange().getStartLine();
issue.setLine(startLine);
issue.setChecksum(lineHashSeq.getHashForLine(startLine));
} else {
issue.setChecksum("");
}
- if (isNotEmpty(reportIssue.getMsg())) {
- issue.setMessage(reportIssue.getMsg());
+ if (isNotEmpty(reportExternalIssue.getMsg())) {
+ issue.setMessage(reportExternalIssue.getMsg());
}
- if (reportIssue.getSeverity() != Severity.UNSET_SEVERITY) {
- issue.setSeverity(reportIssue.getSeverity().name());
+ if (reportExternalIssue.getSeverity() != Severity.UNSET_SEVERITY) {
+ issue.setSeverity(reportExternalIssue.getSeverity().name());
}
- issue.setEffort(Duration.create(reportIssue.getEffort() != 0 ? reportIssue.getEffort() : DEFAULT_EXTERNAL_ISSUE_EFFORT));
+ issue.setEffort(Duration.create(reportExternalIssue.getEffort() != 0 ? reportExternalIssue.getEffort() : DEFAULT_EXTERNAL_ISSUE_EFFORT));
DbIssues.Locations.Builder dbLocationsBuilder = DbIssues.Locations.newBuilder();
- if (reportIssue.hasTextRange()) {
- dbLocationsBuilder.setTextRange(convertTextRange(reportIssue.getTextRange()));
+ if (reportExternalIssue.hasTextRange()) {
+ dbLocationsBuilder.setTextRange(convertTextRange(reportExternalIssue.getTextRange()));
}
- for (ScannerReport.Flow flow : reportIssue.getFlowList()) {
+ for (ScannerReport.Flow flow : reportExternalIssue.getFlowList()) {
if (flow.getLocationCount() > 0) {
DbIssues.Flow.Builder dbFlowBuilder = DbIssues.Flow.newBuilder();
for (ScannerReport.IssueLocation location : flow.getLocationList()) {
@@ -216,16 +215,16 @@ public class TrackerRawInputFactory {
}
issue.setIsFromExternalRuleEngine(true);
issue.setLocations(dbLocationsBuilder.build());
- issue.setType(toRuleType(reportIssue.getType()));
+ issue.setType(toRuleType(reportExternalIssue.getType()));
- ruleRepository.insertNewExternalRuleIfAbsent(issue.getRuleKey(), () -> toExternalRule(reportIssue));
+ ruleRepository.addNewAddHocRuleIfAbsent(issue.getRuleKey(), () -> toAdHocRule(reportExternalIssue));
return issue;
}
- private NewExternalRule toExternalRule(ScannerReport.ExternalIssue reportIssue) {
- NewExternalRule.Builder builder = new NewExternalRule.Builder()
- .setName(RuleKey.of(reportIssue.getRuleRepository(), reportIssue.getRuleKey()).toString())
- .setKey(RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportIssue.getRuleRepository(), reportIssue.getRuleKey()));
+ private NewAddHocRule toAdHocRule(ScannerReport.ExternalIssue reportIssue) {
+ NewAddHocRule.Builder builder = new NewAddHocRule.Builder()
+ .setName(reportIssue.getEngineId() + " " + reportIssue.getRuleId())
+ .setKey(RuleKey.of(RuleKey.EXTERNAL_RULE_REPO_PREFIX + reportIssue.getEngineId(), reportIssue.getRuleId()));
return builder.build();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java
index 67baee66f5c..28c871d75fa 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStep.java
@@ -37,7 +37,7 @@ public class PersistExternalRulesStep implements ComputationStep {
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
- ruleRepository.persistNewExternalRules(dbSession);
+ ruleRepository.persistNewAddHocRules(dbSession);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
index 623c082f094..c359b6919d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryImplTest.java
@@ -37,8 +37,8 @@ import org.sonar.db.rule.DeprecatedRuleKeyDto;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
-import org.sonar.server.rule.ExternalRuleCreator;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.AddHocRuleCreator;
+import org.sonar.server.rule.NewAddHocRule;
import org.sonar.server.rule.index.RuleIndexer;
import static org.assertj.core.api.Assertions.assertThat;
@@ -78,8 +78,8 @@ public class RuleRepositoryImplTest {
private RuleDao ruleDao = mock(RuleDao.class);
private RuleIndexer ruleIndexer = mock(RuleIndexer.class);
- private ExternalRuleCreator externalRuleCreator = new ExternalRuleCreator(db.getDbClient(), System2.INSTANCE, ruleIndexer);
- private RuleRepositoryImpl underTest = new RuleRepositoryImpl(externalRuleCreator, dbClient, analysisMetadataHolder);
+ private AddHocRuleCreator addHocRuleCreator = new AddHocRuleCreator(db.getDbClient(), System2.INSTANCE, ruleIndexer);
+ private RuleRepositoryImpl underTest = new RuleRepositoryImpl(addHocRuleCreator, dbClient, analysisMetadataHolder);
@Before
public void setUp() throws Exception {
@@ -270,7 +270,7 @@ public class RuleRepositoryImplTest {
public void accept_new_externally_defined_Rules() {
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
- underTest.insertNewExternalRuleIfAbsent(ruleKey, () -> new NewExternalRule.Builder()
+ underTest.addNewAddHocRuleIfAbsent(ruleKey, () -> new NewAddHocRule.Builder()
.setKey(ruleKey)
.setPluginKey("eslint")
.build());
@@ -286,15 +286,15 @@ public class RuleRepositoryImplTest {
@Test
public void persist_new_externally_defined_Rules() {
- underTest = new RuleRepositoryImpl(externalRuleCreator, db.getDbClient(), analysisMetadataHolder);
+ underTest = new RuleRepositoryImpl(addHocRuleCreator, db.getDbClient(), analysisMetadataHolder);
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
- underTest.insertNewExternalRuleIfAbsent(ruleKey, () -> new NewExternalRule.Builder()
+ underTest.addNewAddHocRuleIfAbsent(ruleKey, () -> new NewAddHocRule.Builder()
.setKey(ruleKey)
.setPluginKey("eslint")
.build());
- underTest.persistNewExternalRules(db.getSession());
+ underTest.persistNewAddHocRules(db.getSession());
db.commit();
Optional<RuleDefinitionDto> ruleDefinitionDto = db.getDbClient().ruleDao().selectDefinitionByKey(db.getSession(), ruleKey);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
index 5044fcd2c77..ee875f21287 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/RuleRepositoryRule.java
@@ -26,7 +26,7 @@ import java.util.function.Supplier;
import org.junit.rules.ExternalResource;
import org.sonar.api.rule.RuleKey;
import org.sonar.db.DbSession;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.NewAddHocRule;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
@@ -35,7 +35,7 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
private final Map<RuleKey, Rule> rulesByKey = new HashMap<>();
private final Map<Integer, Rule> rulesById = new HashMap<>();
- private final Map<RuleKey, NewExternalRule> newExternalRulesById = new HashMap<>();
+ private final Map<RuleKey, NewAddHocRule> newExternalRulesById = new HashMap<>();
@Override
protected void after() {
@@ -68,7 +68,7 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
}
@Override
- public void persistNewExternalRules(DbSession dbSession) {
+ public void persistNewAddHocRules(DbSession dbSession) {
throw new UnsupportedOperationException();
}
@@ -87,7 +87,7 @@ public class RuleRepositoryRule extends ExternalResource implements RuleReposito
}
@Override
- public void insertNewExternalRuleIfAbsent(RuleKey ruleKey, Supplier<NewExternalRule> ruleSupplier) {
+ public void addNewAddHocRuleIfAbsent(RuleKey ruleKey, Supplier<NewAddHocRule> ruleSupplier) {
newExternalRulesById.computeIfAbsent(ruleKey, k -> ruleSupplier.get());
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java
index c977257a543..390f6d8035f 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java
@@ -191,8 +191,8 @@ public class TrackerRawInputFactoryTest {
ScannerReport.ExternalIssue reportIssue = ScannerReport.ExternalIssue.newBuilder()
.setTextRange(TextRange.newBuilder().setStartLine(2).build())
.setMsg("the message")
- .setRuleRepository("eslint")
- .setRuleKey("S001")
+ .setEngineId("eslint")
+ .setRuleId("S001")
.setSeverity(Constants.Severity.BLOCKER)
.setEffort(20l)
.setType(ScannerReport.IssueType.SECURITY_HOTSPOT)
@@ -224,8 +224,8 @@ public class TrackerRawInputFactoryTest {
ScannerReport.ExternalIssue reportIssue = ScannerReport.ExternalIssue.newBuilder()
.setTextRange(TextRange.newBuilder().setStartLine(2).build())
.setMsg("the message")
- .setRuleRepository("eslint")
- .setRuleKey("S001")
+ .setEngineId("eslint")
+ .setRuleId("S001")
.setSeverity(Constants.Severity.BLOCKER)
.setType(ScannerReport.IssueType.BUG)
.build();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java
index 87d44ddb343..2832628b193 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistExternalRulesStepTest.java
@@ -34,8 +34,8 @@ import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.server.es.EsTester;
-import org.sonar.server.rule.ExternalRuleCreator;
-import org.sonar.server.rule.NewExternalRule;
+import org.sonar.server.rule.AddHocRuleCreator;
+import org.sonar.server.rule.NewAddHocRule;
import org.sonar.server.rule.index.RuleIndexDefinition;
import org.sonar.server.rule.index.RuleIndexer;
@@ -59,7 +59,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest {
public EsTester es = EsTester.create();
private RuleIndexer indexer = new RuleIndexer(es.client(), dbClient);
- private ExternalRuleCreator externalRuleCreator = new ExternalRuleCreator(dbClient, System2.INSTANCE, indexer);
+ private AddHocRuleCreator addHocRuleCreator = new AddHocRuleCreator(dbClient, System2.INSTANCE, indexer);
@Override
protected ComputationStep step() {
@@ -68,7 +68,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest {
@Before
public void setup() {
- ruleRepository = new RuleRepositoryImpl(externalRuleCreator, dbClient, analysisMetadataHolder);
+ ruleRepository = new RuleRepositoryImpl(addHocRuleCreator, dbClient, analysisMetadataHolder);
underTest = new PersistExternalRulesStep(dbClient, ruleRepository);
}
@@ -76,7 +76,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest {
public void persist_and_index_new_external_rules() {
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
- ruleRepository.insertNewExternalRuleIfAbsent(ruleKey, () -> new NewExternalRule.Builder()
+ ruleRepository.addNewAddHocRuleIfAbsent(ruleKey, () -> new NewAddHocRule.Builder()
.setKey(ruleKey)
.setPluginKey("eslint")
.setName("eslint:no-cond-assign")
@@ -105,7 +105,7 @@ public class PersistExternalRulesStepTest extends BaseStepTest {
public void do_not_persist_existing_external_rules() {
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
db.rules().insert(ruleKey, r -> r.setIsExternal(true));
- ruleRepository.insertNewExternalRuleIfAbsent(ruleKey, () -> new NewExternalRule.Builder()
+ ruleRepository.addNewAddHocRuleIfAbsent(ruleKey, () -> new NewAddHocRule.Builder()
.setKey(ruleKey)
.setPluginKey("eslint")
.build());
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
index a5a7552b0ac..e5cdb6f6a12 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistIssuesStepTest.java
@@ -53,7 +53,7 @@ import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.server.issue.IssueStorage;
-import org.sonar.server.rule.ExternalRuleCreator;
+import org.sonar.server.rule.AddHocRuleCreator;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -85,7 +85,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
private IssueCache issueCache;
private ComputationStep underTest;
- private ExternalRuleCreator externalRuleCreator = mock(ExternalRuleCreator.class);
+ private AddHocRuleCreator addHocRuleCreator = mock(AddHocRuleCreator.class);
@Override
protected ComputationStep step() {
@@ -99,7 +99,7 @@ public class PersistIssuesStepTest extends BaseStepTest {
when(system2.now()).thenReturn(NOW);
reportReader.setMetadata(ScannerReport.Metadata.getDefaultInstance());
- underTest = new PersistIssuesStep(dbClient, system2, new UpdateConflictResolver(), new RuleRepositoryImpl(externalRuleCreator, dbClient, analysisMetadataHolder), issueCache,
+ underTest = new PersistIssuesStep(dbClient, system2, new UpdateConflictResolver(), new RuleRepositoryImpl(addHocRuleCreator, dbClient, analysisMetadataHolder), issueCache,
new IssueStorage());
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
index 6a70c5d6b79..dacec29f0b0 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
@@ -141,7 +141,7 @@ import org.sonar.server.qualitygate.QualityGateEvaluatorImpl;
import org.sonar.server.qualitygate.QualityGateFinder;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.DefaultRuleFinder;
-import org.sonar.server.rule.ExternalRuleCreator;
+import org.sonar.server.rule.AddHocRuleCreator;
import org.sonar.server.rule.index.RuleIndex;
import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.setting.DatabaseSettingLoader;
@@ -370,7 +370,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
XMLRuleParser.class,
DefaultRuleFinder.class,
RulesDefinitionXmlLoader.class,
- ExternalRuleCreator.class,
+ AddHocRuleCreator.class,
RuleIndexer.class,
// languages
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/ExternalRuleCreator.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java
index 9044ebff3a1..a2f938f9e7a 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/ExternalRuleCreator.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/AddHocRuleCreator.java
@@ -30,35 +30,36 @@ import org.sonar.server.rule.index.RuleIndexer;
import static org.sonar.api.rule.RuleStatus.READY;
import static org.sonar.db.rule.RuleDto.Scope.ALL;
-public class ExternalRuleCreator {
+public class AddHocRuleCreator {
private final DbClient dbClient;
private final System2 system2;
private final RuleIndexer ruleIndexer;
- public ExternalRuleCreator(DbClient dbClient, System2 system2, RuleIndexer ruleIndexer) {
+ public AddHocRuleCreator(DbClient dbClient, System2 system2, RuleIndexer ruleIndexer) {
this.dbClient = dbClient;
this.system2 = system2;
this.ruleIndexer = ruleIndexer;
}
/**
- * Persists a rule in the DB and indexes it.
+ * Persists a new add hoc rule in the DB and indexes it.
* @return the rule that was inserted in the DB, which <b>includes the generated ID</b>.
*/
- public RuleDto persistAndIndex(DbSession dbSession, NewExternalRule external) {
+ public RuleDto persistAndIndex(DbSession dbSession, NewAddHocRule adHoc) {
RuleDao dao = dbClient.ruleDao();
dao.insert(dbSession, new RuleDefinitionDto()
- .setRuleKey(external.getKey())
- .setPluginKey(external.getPluginKey())
+ .setRuleKey(adHoc.getKey())
+ .setPluginKey(adHoc.getPluginKey())
.setIsExternal(true)
- .setName(external.getName())
+ .setName(adHoc.getName())
+ .setIsAdHoc(true)
.setScope(ALL)
.setStatus(READY)
.setCreatedAt(system2.now())
.setUpdatedAt(system2.now()));
- RuleDto ruleDto = dao.selectOrFailByKey(dbSession, external.getKey());
+ RuleDto ruleDto = dao.selectOrFailByKey(dbSession, adHoc.getKey());
ruleIndexer.commitAndIndex(dbSession, ruleDto.getId());
return ruleDto;
}
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewExternalRule.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java
index a968a43d7ac..c84896b7791 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewExternalRule.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/NewAddHocRule.java
@@ -24,12 +24,12 @@ import javax.annotation.concurrent.Immutable;
import org.sonar.api.rule.RuleKey;
@Immutable
-public class NewExternalRule {
+public class NewAddHocRule {
private final RuleKey key;
private final String name;
private final String pluginKey;
- private NewExternalRule(Builder builder) {
+ private NewAddHocRule(Builder builder) {
Objects.requireNonNull(builder.key, "'key' not expected to be null for an external rule");
this.key = builder.key;
this.pluginKey = builder.pluginKey;
@@ -67,8 +67,8 @@ public class NewExternalRule {
return name;
}
- public NewExternalRule build() {
- return new NewExternalRule(this);
+ public NewAddHocRule build() {
+ return new NewAddHocRule(this);
}
public Builder setPluginKey(String pluginKey) {
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/ExternalRuleCreatorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java
index 59d4d28fcfe..db5269e1b4b 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/ExternalRuleCreatorTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/AddHocRuleCreatorTest.java
@@ -30,7 +30,7 @@ import org.sonar.server.rule.index.RuleIndexer;
import static org.assertj.core.api.Assertions.assertThat;
-public class ExternalRuleCreatorTest {
+public class AddHocRuleCreatorTest {
@org.junit.Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -38,13 +38,13 @@ public class ExternalRuleCreatorTest {
public EsTester es = EsTester.create();
private RuleIndexer indexer = new RuleIndexer(es.client(), dbTester.getDbClient());
- private ExternalRuleCreator underTest = new ExternalRuleCreator(dbTester.getDbClient(), System2.INSTANCE, indexer);
+ private AddHocRuleCreator underTest = new AddHocRuleCreator(dbTester.getDbClient(), System2.INSTANCE, indexer);
private DbSession dbSession = dbTester.getSession();
@Test
public void create_external_rule() {
RuleKey ruleKey = RuleKey.of("eslint", "no-cond-assign");
- NewExternalRule externalRule = new NewExternalRule.Builder()
+ NewAddHocRule externalRule = new NewAddHocRule.Builder()
.setKey(ruleKey)
.setPluginKey("eslint")
.setName("name")
diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/NewExternalRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/NewAddHocRuleTest.java
index 85816da9e6b..11917668f11 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/rule/NewExternalRuleTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/rule/NewAddHocRuleTest.java
@@ -25,20 +25,20 @@ import org.sonar.api.rule.RuleKey;
import static org.assertj.core.api.Assertions.assertThat;
-public class NewExternalRuleTest {
+public class NewAddHocRuleTest {
@org.junit.Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void should_build_new_external_rule() {
- NewExternalRule.Builder builder = new NewExternalRule.Builder()
+ NewAddHocRule.Builder builder = new NewAddHocRule.Builder()
.setKey(RuleKey.of("repo", "rule"))
.setPluginKey("repo")
.setName("name");
assertThat(builder.name()).isEqualTo("name");
- NewExternalRule rule = builder.build();
+ NewAddHocRule rule = builder.build();
assertThat(rule.getName()).isEqualTo("name");
assertThat(rule.getPluginKey()).isEqualTo("repo");
@@ -49,7 +49,7 @@ public class NewExternalRuleTest {
exception.expect(NullPointerException.class);
exception.expectMessage("'key' not expected to be null for an external rule");
- new NewExternalRule.Builder()
+ new NewAddHocRule.Builder()
.build();
}
}