Search in sources :

Example 31 with RuleKey

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);
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) RuleActivation(org.sonar.server.qualityprofile.RuleActivation)

Example 32 with RuleKey

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));
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey)

Example 33 with 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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ShowResponse(org.sonarqube.ws.Rules.ShowResponse) RuleKey(org.sonar.api.rule.RuleKey) RuleDto(org.sonar.db.rule.RuleDto) ArrayList(java.util.ArrayList) RuleParamDto(org.sonar.db.rule.RuleParamDto)

Example 34 with RuleKey

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();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Example 35 with RuleKey

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();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) DefaultIssue(org.sonar.core.issue.DefaultIssue) Test(org.junit.Test)

Aggregations

RuleKey (org.sonar.api.rule.RuleKey)95 Test (org.junit.Test)48 RuleDto (org.sonar.db.rule.RuleDto)24 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)22 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)17 SearchOptions (org.sonar.server.es.SearchOptions)14 RuleParamDto (org.sonar.db.rule.RuleParamDto)10 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)9 ArrayList (java.util.ArrayList)5 DbSession (org.sonar.db.DbSession)5 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 ComponentDto (org.sonar.db.component.ComponentDto)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)4 Rule (org.sonar.api.batch.rule.Rule)3 WildcardPattern (org.sonar.api.utils.WildcardPattern)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)3 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)3 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)3 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)3