|
|
@ -6,6 +6,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.keyware.sonar.cxx; |
|
|
|
package com.keyware.sonar.cxx; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.keyware.sonar.cxx.rules.SecurityDesignRuleRepository; |
|
|
|
import com.sonar.cxx.sslr.api.Grammar; |
|
|
|
import com.sonar.cxx.sslr.api.Grammar; |
|
|
|
import org.sonar.api.PropertyType; |
|
|
|
import org.sonar.api.PropertyType; |
|
|
|
import org.sonar.api.batch.fs.InputFile; |
|
|
|
import org.sonar.api.batch.fs.InputFile; |
|
|
@ -98,6 +99,7 @@ public class CxxSquidSensor implements ProjectSensor { |
|
|
|
@Nullable CustomCxxRulesDefinition[] customRulesDefinition) { |
|
|
|
@Nullable CustomCxxRulesDefinition[] customRulesDefinition) { |
|
|
|
this.checks = CxxChecks.createCxxCheck(checkFactory) |
|
|
|
this.checks = CxxChecks.createCxxCheck(checkFactory) |
|
|
|
.addChecks(CheckList.REPOSITORY_KEY, CheckList.getChecks()) |
|
|
|
.addChecks(CheckList.REPOSITORY_KEY, CheckList.getChecks()) |
|
|
|
|
|
|
|
.addChecks(SecurityDesignRuleRepository.REPOSITORY_KEY, SecurityDesignRuleRepository.RULE_CHECKERS) |
|
|
|
.addCustomChecks(customRulesDefinition); |
|
|
|
.addCustomChecks(customRulesDefinition); |
|
|
|
this.fileLinesContextFactory = fileLinesContextFactory; |
|
|
|
this.fileLinesContextFactory = fileLinesContextFactory; |
|
|
|
this.noSonarFilter = noSonarFilter; |
|
|
|
this.noSonarFilter = noSonarFilter; |
|
|
@ -456,14 +458,20 @@ public class CxxSquidSensor implements ProjectSensor { |
|
|
|
if (message.getLine() != null && message.getLine() > 0) { |
|
|
|
if (message.getLine() != null && message.getLine() > 0) { |
|
|
|
line = message.getLine(); |
|
|
|
line = message.getLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 增加对规则库的判断
|
|
|
|
|
|
|
|
var checker = (SquidAstVisitor<Grammar>) message.getCheck(); |
|
|
|
|
|
|
|
var repositoryKey = CheckList.REPOSITORY_KEY; |
|
|
|
|
|
|
|
if (checker.getClass().getPackageName().startsWith("com.keyware.sonar.cxx.rules.checkers")) { |
|
|
|
|
|
|
|
repositoryKey = SecurityDesignRuleRepository.REPOSITORY_KEY; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck()); |
|
|
|
RuleKey ruleKey = checks.ruleKey(checker); |
|
|
|
if (ruleKey != null) { |
|
|
|
if (ruleKey != null) { |
|
|
|
var newIssue = context.newIssue().forRule(RuleKey.of(CheckList.REPOSITORY_KEY, ruleKey.rule())); |
|
|
|
var newIssue = context.newIssue().forRule(RuleKey.of(repositoryKey, ruleKey.rule())); |
|
|
|
var location = newIssue.newLocation() |
|
|
|
var location = newIssue.newLocation() |
|
|
|
.on(inputFile) |
|
|
|
.on(inputFile) |
|
|
|
.at(inputFile.selectLine(line)) |
|
|
|
.at(inputFile.selectLine(line)) |
|
|
|
.message(message.getText(Locale.ENGLISH)); |
|
|
|
.message(message.getText(Locale.CHINA)); |
|
|
|
|
|
|
|
|
|
|
|
newIssue.at(location); |
|
|
|
newIssue.at(location); |
|
|
|
newIssue.save(); |
|
|
|
newIssue.save(); |
|
|
|