本文整理汇总了Java中org.sonar.api.rule.RuleKey.of方法的典型用法代码示例。如果您正苦于以下问题:Java RuleKey.of方法的具体用法?Java RuleKey.of怎么用?Java RuleKey.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sonar.api.rule.RuleKey
的用法示例。
在下文中一共展示了RuleKey.of方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveIssue
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private void saveIssue(final SensorContext context, final InputFile inputFile, String lineString, final String externalRuleKey, final String message) {
RuleKey ruleKey = RuleKey.of(FramaCRulesDefinition.getRepositoryKeyForLanguage(), externalRuleKey);
LOGGER.info("externalRuleKey: "+externalRuleKey);
LOGGER.info("Repo: "+FramaCRulesDefinition.getRepositoryKeyForLanguage());
LOGGER.info("RuleKey: "+ruleKey);
NewIssue newIssue = context.newIssue()
.forRule(ruleKey);
NewIssueLocation primaryLocation = newIssue.newLocation()
.on(inputFile)
.message(message);
int maxLine = inputFile.lines();
int iLine = getLineAsInt(lineString, maxLine);
if (iLine > 0) {
primaryLocation.at(inputFile.selectLine(iLine));
}
newIssue.at(primaryLocation);
newIssue.save();
}
示例2: saveIssue
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
void saveIssue(InputFile inputFile, int line, String externalRuleKey, String message) {
RuleKey rule = RuleKey.of(PerlCriticRulesDefinition.getRepositoryKey(), externalRuleKey);
if (activeRules.find(rule) == null) {
log.info("Ignoring unknown or deactivated issue of type {}", rule);
return;
}
log.debug("Saving an issue of type {} on file {}", rule, inputFile);
NewIssue issue = this.context.newIssue().forRule(rule);
NewIssueLocation location = issue.newLocation().message(message).on(inputFile);
if (line > 0) {
location.at(inputFile.selectLine(line));
}
issue.at(location);
issue.save();
}
示例3: testSingleActiveRule
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
@Test
public void testSingleActiveRule() {
final String reportFile = new File(resourcesDirectory,
"webgoat/webgoat-Findings-List-all.xml").getAbsolutePath();
settings.setProperty(XanitizerSonarQubePlugin.XAN_XML_REPORT_FILE, reportFile);
final ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (GeneratedProblemType problemType : GeneratedProblemType.values()) {
final RuleKey ruleKey = RuleKey.of(XanitizerRulesDefinition.REPOSITORY_KEY,
problemType.name());
final NewActiveRule activeRule = builder.create(ruleKey);
if (problemType.getPresentationName().equals("SQL Injection")) {
activeRule.activate();
}
}
final XanitizerSensor sensor = new XanitizerSensor(mock(JavaResourceLocator.class),
builder.build(), context);
sensor.execute(context);
assertEquals(26, createdIssues);
}
示例4: analyse
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
public void analyse(Project project, SensorContext sensorContext) {
if (CodeReviewInitialize.reviewResult == null || CodeReviewInitialize.reviewResult.getProjectBasedir() == null) return;
logger.debug("Project basedir : " + CodeReviewInitialize.reviewResult.getProjectBasedir());
File projectBasedir = new File(CodeReviewInitialize.reviewResult.getProjectBasedir());
for (RuleType rule : CodeReviewInitialize.reviewResult.getRule()) {
if (rule.getResult().size() > 0) {
logger.debug("Found one non conformity : " + rule.getRule().getKey());
RuleKey ruleKey = RuleKey.of("FCCodeReviewRepository", rule.getRule().getKey());
for (Result result : rule.getResult()) {
File resourceToFind = new File(projectBasedir.getAbsolutePath() + result.getResource());
InputFile resource = fs.inputFile(fs.predicates().hasPath(projectBasedir.getAbsolutePath() + result.getResource()));
if (resource != null) {
logger.debug("Resource found : " + resourceToFind.getAbsolutePath());
Issuable issuable = perspectives.as(Issuable.class, resource);
issuable.addIssue(issuable.newIssueBuilder().ruleKey(ruleKey).line(1).build());
} else {
logger.debug("Resource not found : " + resourceToFind.getAbsolutePath());
}
}
}
}
}
示例5: getActiveRules
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private ActiveRules getActiveRules() {
final ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (GeneratedProblemType problemType : GeneratedProblemType.values()) {
final RuleKey ruleKey = RuleKey.of(XanitizerRulesDefinition.REPOSITORY_KEY,
problemType.name());
final NewActiveRule activeRule = builder.create(ruleKey);
activeRule.activate();
}
return builder.build();
}
示例6: fill
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
@Override
public void fill(final SensorContext context, final InputFile inputFile,
final TsqlIssue... issues) {
for (final TsqlIssue error : issues) {
InputFile file = inputFile;
try {
if (error.getLine() < 1) {
LOGGER.warn(
format("Can't add issue %s on file %s as line is 0", error.getType(), error.getFilePath()));
continue;
}
if (file == null){
final FileSystem fileSystem = context.fileSystem();
file = fileSystem.inputFile(fileSystem.predicates().and(error.getPredicate()));
if (file == null) {
LOGGER.debug(format("Cound not find file %s to add issue %s at line %d.", error.getFilePath(),
error.getType(), error.getLine()));
continue;
}
}
final RuleKey rule = RuleKey.of(error.getRepositoryKey(), error.getType());
final NewIssue issue = context.newIssue().forRule(rule);
final NewIssueLocation loc = issue.newLocation().on(file).at(file.selectLine(error.getLine()));
if (error.getDescription() != null) {
loc.message(error.getDescription());
}
issue.at(loc).save();
} catch (final Throwable e) {
LOGGER.warn(format("Can't add issue %s on file %s at line %d.", error.getType(), file.absolutePath(),
error.getLine()), e);
}
}
}
示例7: decreasingLineCoverageRule
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
public static RuleKey decreasingLineCoverageRule(String language) {
return RuleKey.of(getRepositoryName(language), decreasingLineCoverageRule);
}
示例8: ruleKey
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private RuleKey ruleKey() {
return RuleKey.of(MyRpgRulesDefinition.REPOSITORY_KEY, RULE_KEY);
}
开发者ID:SonarSource,项目名称:sonar-custom-rules-examples,代码行数:4,代码来源:DataStructureNamingConventionCheck.java
示例9: createSpellCheckIssues
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private void createSpellCheckIssues(SensorContext sensorContext, InputFile inputFile, Feature feature) throws IOException {
// TODO: Don't hardcode the ruleKey
RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "SpellCheck");
ActiveRule activeRule = sensorContext.activeRules().find(ruleKey);
if (activeRule == null) {
LOG.debug("SpellCheck rule is deactivated. RuleKey: " + ruleKey);
return;
}
List<ScenarioDefinition> scenarioDefinitions = feature.getChildren();
String featureLanguage = feature.getLanguage();
if ("en".equals(featureLanguage)) {
featureLanguage = "en-US";
}
Language language = Languages.getLanguageForShortName(featureLanguage);
JLanguageTool langTool = new JLanguageTool(language);
String disabledRules = activeRule.param("disabledRules");
String[] disabledRulesArray = new String[0];
if (disabledRules != null) {
disabledRulesArray = disabledRules.split(",");
}
for (String disabledRuleKey : disabledRulesArray) {
langTool.disableRule(disabledRuleKey);
}
checkNodeSpelling(sensorContext, inputFile, langTool, feature, feature.getName());
checkNodeSpelling(sensorContext, inputFile, langTool, feature, feature.getDescription());
for (ScenarioDefinition scenario: scenarioDefinitions ) {
checkNodeSpelling(sensorContext, inputFile, langTool, scenario, scenario.getName());
List<Step> steps = scenario.getSteps();
for (Step step : steps) {
checkNodeSpelling(sensorContext, inputFile, langTool, step, step.getText());
}
}
}
示例10: createParserErrorIssue
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private void createParserErrorIssue(SensorContext sensorContext, InputFile inputFile, ParserException pe) {
RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "ParserError");
ActiveRule activeRule = sensorContext.activeRules().find(ruleKey);
if (activeRule == null) {
LOG.debug("Parser Error rule is deactivated. RuleKey: " + ruleKey);
return;
}
TextRange textRange = inputFile.newRange(1,1,1,1);
//TODO Parser error message contains an address - add it
NewIssue newIssue = sensorContext.newIssue();
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(pe.getMessage())
.on(inputFile)
.at(textRange);
newIssue.forRule(ruleKey).at(primaryLocation);
newIssue.save();
}
示例11: createSpellCheckIssueObject
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private void createSpellCheckIssueObject(SensorContext sensorContext,
InputFile inputFile,
Node node,
RuleMatch match) {
// TODO: Don't hardcode the ruleKey
RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "SpellCheck");
try {
TextRange textRange = inputFile.newRange(
node.getLocation().getLine(),
match.getColumn(),
node.getLocation().getLine(),
match.getEndColumn()
);
NewIssue newIssue = sensorContext.newIssue();
String suggestedReplace = "";
if (!match.getSuggestedReplacements().isEmpty()) {
suggestedReplace = " - replace it with:";
for (String suggest: match.getSuggestedReplacements()
) {
suggestedReplace = suggestedReplace + " " + suggest + ";";
}
}
NewIssueLocation primaryLocation = newIssue.newLocation()
.message(match.getMessage() + suggestedReplace)
.on(inputFile)
.at(textRange);
newIssue.forRule(ruleKey).at(primaryLocation);
newIssue.save();
} catch (IllegalArgumentException iarg) {
LOG.error("SpellCheck rule is an error when create issue: \n" +
"file is: " + inputFile.relativePath() + "\n" +
"match is:" + match.getMessage() + "\n" +
"line is:" + node.getLocation().getLine() + "\n" +
"offsets is: start - " + match.getColumn() + " to " + match.getEndColumn(),
iarg);
}
}
示例12: createNewIssue
import org.sonar.api.rule.RuleKey; //导入方法依赖的package包/类
private boolean createNewIssue(final InputFile inputFile, final XMLReportFinding xanFinding,
final SensorContext sensorContext) {
final GeneratedProblemType pt = xanFinding.getProblemType();
final RuleKey ruleKey = RuleKey.of(XanitizerRulesDefinition.REPOSITORY_KEY, pt.name());
final int lineNo = normalizeLineNo(xanFinding.getLocation().getLineNoOrMinus1());
final Severity severity = SensorUtil.mkSeverity(xanFinding);
final String issueKey = mkIssueKey(ruleKey, inputFile, lineNo);
final NewIssue alreadyCreatedIssue = alreadyCreatedIssues.get(issueKey);
if (alreadyCreatedIssue != null) {
addSecondaryLocation(alreadyCreatedIssue, xanFinding, sensorContext);
LOG.debug("Issue already exists: " + inputFile + ":" + lineNo + " - "
+ pt.getPresentationName());
return false;
}
final NewIssue newIssue = sensorContext.newIssue();
newIssue.forRule(ruleKey);
newIssue.overrideSeverity(severity);
final NewIssueLocation newIssueLocation = newIssue.newLocation();
newIssueLocation.on(inputFile);
// If line number exceeds the current length of the file,
// SonarQube will crash. So check length for robustness.
if (lineNo <= inputFile.lines()) {
final TextRange textRange = inputFile.selectLine(lineNo);
newIssueLocation.at(textRange);
}
newIssueLocation.message(pt.getMessage());
newIssue.at(newIssueLocation);
addSecondaryLocation(newIssue, xanFinding, sensorContext);
alreadyCreatedIssues.put(issueKey, newIssue);
LOG.debug("Issue saved: " + inputFile + ":" + lineNo + " - " + pt.getPresentationName());
return true;
}