本文整理汇总了Java中org.sonar.api.rule.RuleKey类的典型用法代码示例。如果您正苦于以下问题:Java RuleKey类的具体用法?Java RuleKey怎么用?Java RuleKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RuleKey类属于org.sonar.api.rule包,在下文中一共展示了RuleKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: active
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void active() {
final ActiveRules activeRules = Mockito.mock(ActiveRules.class);
sensorContext.setActiveRules(activeRules);
Mockito.when(activeRules.find(RuleKey.of("package-analyzer-test-no", "test"))).thenReturn(null);
Mockito.when(activeRules.find(RuleKey.of("package-analyzer-test-yes", "test"))).thenReturn(activeRule);
// Model
final Model<Location> model = new Model<>();
model.addPackage("packageA", location("packageA/package-info.java"));
// Check only no issue, because test-no:test is not active
subject.scanModel(sensorContext, "test-no", model);
Assert.assertEquals(0, sensorContext.allIssues().size());
// Check only one issue, because test-yes:test is active
subject.scanModel(sensorContext, "test-yes", model);
Assert.assertEquals(1, sensorContext.allIssues().size());
}
示例2: createRules
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
private static Rules createRules(StandaloneRuleDefinitionsLoader pluginRulesLoader) {
RulesBuilder builder = new RulesBuilder();
for (RulesDefinition.Repository repoDef : pluginRulesLoader.getContext().repositories()) {
for (org.sonar.api.server.rule.RulesDefinition.Rule ruleDef : repoDef.rules()) {
NewRule newRule = builder.add(RuleKey.of(ruleDef.repository().key(), ruleDef.key()))
.setInternalKey(ruleDef.internalKey())
.setDescription(ruleDef.htmlDescription() != null ? ruleDef.htmlDescription() : ruleDef.markdownDescription())
.setSeverity(ruleDef.severity())
.setType(ruleDef.type() != null ? ruleDef.type().toString() : null)
.setName(ruleDef.name());
for (Param p : ruleDef.params()) {
newRule.addParam(p.key())
.setDescription(p.description());
}
}
}
return builder.build();
}
示例3: should_optimize_on_repository
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void should_optimize_on_repository() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
ActiveRules activeRules = new ActiveRulesBuilder()
.create(RuleKey.of("repo1", "foo"))
.activate()
.build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
activeRules = new ActiveRulesBuilder()
.create(RuleKey.of("repo1", "foo"))
.activate()
.create(RuleKey.of("squid", "rule"))
.activate()
.build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
示例4: addIssue
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
private void addIssue(Project project, double coverage, double previousCoverage) {
Issuable issuable = perspectives.as(Issuable.class, (Resource) project);
if (issuable == null) {
LOGGER.warn("Could not get a perspective of Issuable to create an issue for {}, skipping",
project);
return;
}
Optional<RuleKey> ruleKey = CoverageRule.decreasingOverallLineCoverageRule(fileSystem);
if (ruleKey.isPresent()) {
LOGGER.debug("RuleKey: {}", ruleKey.get());
addIssue(issuable,
formatIssueMessage("the project", coverage, previousCoverage),
ruleKey.get());
} else {
LOGGER.warn("Could not determine the RuleKey for the project {}", project.getEffectiveKey());
}
}
示例5: createIssuesForMutants
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
private void createIssuesForMutants(List<MutantResult> mutantResults, SensorContext context, MutantStatus targetStatus, String ruleKey) throws IOException {
if (isRuleActive(ruleKey)) {
int count = 0;
for (MutantResult mutantResult : mutantResults) {
if (mutantResult.getStatus() == targetStatus) {
count++;
InputFile file = locateSourceFile(mutantResult.getSourceFilePath());
NewIssue issue = context.newIssue();
NewIssueLocation location = issue.newLocation()
.on(file)
.at(mutantResult.getLocation().getRange(file))
.message(formatIssueMessage(mutantResult));
issue.at(location);
issue.forRule(RuleKey.of(RULE_REPOSITORY_KEY, ruleKey));
issue.save();
}
}
log.info("Reported {} issue(s) as {}.", count, targetStatus);
} else {
log.info("Skip reporting {} mutant(s), because rule {} is inactive", targetStatus, ruleKey);
}
}
示例6: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.css");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createCssSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例7: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.less");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createLessSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例8: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.scss");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createScssSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例9: 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();
}
示例10: addErrorTest
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void addErrorTest() {
final Rule rule = setupRule("repo", "key");
final Issuable issuable = setupIssuable();
final IssueBuilder issueBuilder = mock(IssueBuilder.class);
final Issue issue = mock(Issue.class);
when(issuable.newIssueBuilder()).thenReturn(issueBuilder);
when(issueBuilder.ruleKey(RuleKey.of("repo", "key"))).thenReturn(issueBuilder);
when(issueBuilder.message(event.getMessage())).thenReturn(issueBuilder);
when(issueBuilder.line(event.getLine())).thenReturn(issueBuilder);
when(issueBuilder.build()).thenReturn(issue);
addErrorToListener();
verify(issuable).addIssue(issue);
verify(issueBuilder).ruleKey(RuleKey.of("repo", "key"));
verify(issueBuilder).message(event.getMessage());
verify(issueBuilder).line(event.getLine());
verify(rule).ruleKey();
}
示例11: consumeFor
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Override
void consumeFor(InputFile inputFile, FileIssues message) {
for (SonarAnalyzer.FileIssues.Issue issue : message.getIssueList()) {
NewIssue newIssue = context.newIssue();
NewIssueLocation location = newIssue
.newLocation()
.on(inputFile)
.message(issue.getMessage());
SonarAnalyzer.TextRange issueTextRange = issue.getLocation();
if (issueTextRange.getStartOffset() == issueTextRange.getEndOffset() &&
issueTextRange.getStartLine() == issueTextRange.getEndLine()) {
// file level issue
} else {
location = location.at(toTextRange(inputFile, issueTextRange));
}
newIssue.forRule(RuleKey.of(repositoryKey, issue.getId()))
.at(location)
.save();
}
}
示例12: onFileIssue
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Override
public void onFileIssue(String ruleId, String absolutePath, String message) {
String repositoryKey = repositoryKeyByRoslynRuleKey.get(ruleId);
if (repositoryKey == null) {
return;
}
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates()
.hasAbsolutePath(absolutePath));
if (inputFile == null) {
return;
}
NewIssue newIssue = context.newIssue();
newIssue
.forRule(RuleKey.of(repositoryKey, ruleId))
.at(newIssue.newLocation()
.on(inputFile)
.message(message))
.save();
}
示例13: escapesAnalysisInput
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
@Test
public void escapesAnalysisInput() throws Exception {
tester.setActiveRules(new ActiveRulesBuilder()
.create(RuleKey.of(REPOSITORY_KEY, "S1186"))
.setParam("param1", "value1")
.activate()
.create(RuleKey.of(REPOSITORY_KEY, "S9999"))
.setParam("param9", "value9")
.activate()
.build());
String sonarlint = AnalysisInputXml.generate(true, false, true, tester, REPOSITORY_KEY, LANGUAGE_KEY, "utf-8");
assertThat(
sonarlint
.replaceAll("\r?\n|\r", "")
.replaceAll("<File>.*?Program.cs</File>", "<File>Program.cs</File>"))
.isEqualTo(readFile("src/test/resources/AnalysisInputXmlTest/SonarLint-expected.xml").replaceAll("\r?\n|\r", ""));
}
示例14: 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();
}
示例15: saveIssues
import org.sonar.api.rule.RuleKey; //导入依赖的package包/类
/**
* Saves issues form input file and source file.
*
* @param sonarFile input file.
* @param squidFile source file.
*/
private void saveIssues(InputFile sonarFile, SourceFile squidFile) {
Collection<CheckMessage> messages = squidFile.getCheckMessages();
messages.forEach(message -> {
RuleKey ruleKey = checks.ruleKey((SquidAstVisitor<Grammar>) message.getCheck());
Issuable issuable = resourcePerspectives.as(Issuable.class, sonarFile);
if (issuable != null) {
Issue issue = issuable.newIssueBuilder()
.ruleKey(ruleKey)
.line(message.getLine())
.message(message.getText(Locale.ENGLISH))
.build();
issuable.addIssue(issue);
}
});
}