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或检查样式规则的问题时,它会起作用。
但是,当我尝试添加引用手动规则的问题时,例如问题"issue2",它不起作用。我已经手动创建了规则" performance“,因此规则performance存在于声纳的手动规则列表中。
我想知道是不是不可能添加涉及手动规则的问题,或者我是否没有为方法RuleKey.of使用正确的参数。
谢谢
发布于 2013-08-13 20:06:36
你的自定义问题没有显示在Sonar中的一个原因可能是你没有启用它的规则。
选择设置-质量配置文件,单击您的质量配置文件,选择选项卡“编码规则”,将激活设置为“任意”,单击搜索并检查您的规则是否显示在此处。
如果是,请选中其旁边的复选框,然后选择严重性。现在,违反规则的情况将显示在Sonar中。
https://stackoverflow.com/questions/17973054
复制相似问题