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 に適切なパラメーターを使用していないかどうかを知りたいです。
ありがとう