import org.sonar.api.component.ResourcePerspectives;
public class MySensor extends Sensor {
private final ResourcePerspectives perspectives;
public MySensor(ResourcePerspectives p) {
this.perspectives = p;
}
public void analyse(Project project, SensorContext context) {
Resource myResource; // to be set
Issuable issuable = perspectives.as(Issuable.class, myResource);
if (issuable != null) {
// can be used
Issue issue = issuable.newIssueBuilder()
//repository : pmd, key : AvoidArrayLoops
.setRuleKey(RuleKey.of("pmd", "AvoidArrayLoops"))
.setLine(10)
.build();
//works
issuable.addIssue(issue);
Issue issue2 = issuable.newIssueBuilder()
//repository : manual, key : performance
.setRuleKey(RuleKey.of("manual", "performance"))
.setLine(10)
.build();
// doesn't work
issuable.addIssue(issue2);
}
}
}
当我尝试添加引用 pmd 规则 AvoidArrayLoops 的问题“问题”时,它可以工作。更一般地说,当我尝试添加引用 pmd 或 checkstyle 规则的问题时,它会起作用。
但是,当我尝试添加涉及手动规则的问题时,例如问题“issue2”,它不起作用。我手动创建了规则“性能”,因此规则性能存在于声纳的手动规则列表中。
我想知道是否无法添加引用手动规则的问题,或者我是否没有为 RuleKey.of 方法使用正确的参数。
谢谢