Search in sources :

Example 71 with RuleKey

use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.

the class OneIssuePerModuleSensor method analyse.

private void analyse(SensorContext context, String language, String repo) {
    RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
    NewIssue newIssue = context.newIssue();
    newIssue.forRule(ruleKey).at(newIssue.newLocation().on(context.module()).message("This issue is generated on each module")).save();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 72 with RuleKey

use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.

the class OneIssuePerUnknownFileSensor method execute.

@Override
public void execute(SensorContext context) {
    RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
    FilePredicate unknownFilesPredicate = context.fileSystem().predicates().matchesPathPattern("**/*.unknown");
    Iterable<InputFile> unknownFiles = context.fileSystem().inputFiles(unknownFilesPredicate);
    unknownFiles.forEach(inputFile -> {
        NewIssue newIssue = context.newIssue();
        newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputFile).message("This issue is generated on each file with extension 'unknown'")).save();
    });
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilePredicate(org.sonar.api.batch.fs.FilePredicate) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue) InputFile(org.sonar.api.batch.fs.InputFile)

Example 73 with RuleKey

use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.

the class OneVulnerabilityIssuePerModuleSensor method analyse.

private void analyse(SensorContext context, String repo) {
    RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
    NewIssue newIssue = context.newIssue();
    newIssue.forRule(ruleKey).at(newIssue.newLocation().on(context.module()).message("This issue is generated on each module")).save();
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) NewIssue(org.sonar.api.batch.sensor.issue.NewIssue)

Example 74 with RuleKey

use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.

the class ActiveRuleKeyTest method of.

@Test
public void of() {
    RuleKey ruleKey = RuleKey.of("xoo", "R1");
    ActiveRuleKey key = ActiveRuleKey.of("P1", ruleKey);
    assertThat(key.qProfile()).isEqualTo("P1");
    assertThat(key.ruleKey()).isSameAs(ruleKey);
    assertThat(key.toString()).isEqualTo("P1:xoo:R1");
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) Test(org.junit.Test)

Example 75 with RuleKey

use of org.sonar.api.rule.RuleKey in project sonarqube by SonarSource.

the class CommonRule method processFile.

@CheckForNull
public DefaultIssue processFile(Component file, String fileLanguage) {
    DefaultIssue issue = null;
    RuleKey ruleKey = RuleKey.of(commonRepositoryForLang(fileLanguage), key);
    Optional<ActiveRule> activeRule = activeRulesHolder.get(ruleKey);
    if (activeRule.isPresent()) {
        CommonRuleIssue cri = doProcessFile(file, activeRule.get());
        if (cri != null) {
            issue = new DefaultIssue();
            issue.setGap(cri.effortToFix);
            issue.setMessage(cri.message);
            issue.setRuleKey(ruleKey);
            issue.setSeverity(activeRule.get().getSeverity());
            issue.setLine(null);
            issue.setChecksum("");
        }
    }
    return issue;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) ActiveRule(org.sonar.server.computation.task.projectanalysis.qualityprofile.ActiveRule) DefaultIssue(org.sonar.core.issue.DefaultIssue) CheckForNull(javax.annotation.CheckForNull)

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