use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivationActions method activate.
private void activate(Request request, Response response) {
RuleKey ruleKey = readRuleKey(request);
RuleActivation activation = new RuleActivation(ruleKey);
activation.setSeverity(request.param(SEVERITY));
String params = request.param(PARAMS);
if (params != null) {
activation.setParameters(KeyValueFormat.parse(params));
}
activation.setReset(Boolean.TRUE.equals(request.paramAsBoolean(RESET)));
service.activate(request.mandatoryParam(PROFILE_KEY), activation);
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class RuleActivationActions method deactivate.
private void deactivate(Request request, Response response) {
RuleKey ruleKey = readRuleKey(request);
service.deactivate(ActiveRuleKey.of(request.mandatoryParam(PROFILE_KEY), ruleKey));
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY));
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<RuleDto> optionalRule = dbClient.ruleDao().selectByKey(dbSession, key);
checkFoundWithOptional(optionalRule, "Rule not found: " + key);
RuleDto rule = optionalRule.get();
List<RuleDto> templateRules = new ArrayList<>();
if (rule.getTemplateId() != null) {
Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(rule.getTemplateId(), dbSession);
if (templateRule.isPresent()) {
templateRules.add(templateRule.get());
}
}
List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleIds(dbSession, singletonList(rule.getId()));
ShowResponse showResponse = buildResponse(dbSession, request, new SearchAction.SearchResult().setRules(singletonList(rule)).setTemplateRules(templateRules).setRuleParameters(ruleParameters).setTotal(1L));
writeProtobuf(showResponse, request, response);
}
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IntegrateIssuesVisitorTest method process_existing_issue.
@Test
public void process_existing_issue() throws Exception {
componentsWithUnprocessedIssues.setUuids(newHashSet(FILE_UUID));
RuleKey ruleKey = RuleTesting.XOO_X1;
// Issue from db has severity major
addBaseIssue(ruleKey);
// Issue from report has severity blocker
ScannerReport.Issue reportIssue = ScannerReport.Issue.newBuilder().setMsg("the message").setRuleRepository(ruleKey.repository()).setRuleKey(ruleKey.rule()).setSeverity(Constants.Severity.BLOCKER).build();
reportReader.putIssues(FILE_REF, asList(reportIssue));
fileSourceRepository.addLine(FILE_REF, "line1");
underTest.visitAny(FILE);
ArgumentCaptor<DefaultIssue> rawIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
ArgumentCaptor<DefaultIssue> baseIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
verify(issueLifecycle).mergeExistingOpenIssue(rawIssueCaptor.capture(), baseIssueCaptor.capture());
assertThat(rawIssueCaptor.getValue().severity()).isEqualTo(Severity.BLOCKER);
assertThat(baseIssueCaptor.getValue().severity()).isEqualTo(Severity.MAJOR);
verify(issueLifecycle).doAutomaticTransition(defaultIssueCaptor.capture());
assertThat(defaultIssueCaptor.getValue().ruleKey()).isEqualTo(ruleKey);
List<DefaultIssue> issues = newArrayList(issueCache.traverse());
assertThat(issues).hasSize(1);
assertThat(issues.get(0).severity()).isEqualTo(Severity.BLOCKER);
assertThat(componentsWithUnprocessedIssues.getUuids()).isEmpty();
}
use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.
the class IntegrateIssuesVisitorTest method close_unmatched_base_issue.
@Test
public void close_unmatched_base_issue() throws Exception {
componentsWithUnprocessedIssues.setUuids(newHashSet(FILE_UUID));
RuleKey ruleKey = RuleTesting.XOO_X1;
addBaseIssue(ruleKey);
// No issue in the report
underTest.visitAny(FILE);
verify(issueLifecycle).doAutomaticTransition(defaultIssueCaptor.capture());
assertThat(defaultIssueCaptor.getValue().isBeingClosed()).isTrue();
List<DefaultIssue> issues = newArrayList(issueCache.traverse());
assertThat(issues).hasSize(1);
assertThat(componentsWithUnprocessedIssues.getUuids()).isEmpty();
}
Aggregations