public class DefaultIssueBuilder implements Issuable.IssueBuilder {
private String componentKey;
- private String projectKey;
private RuleKey ruleKey;
private Integer line;
private String message;
return this;
}
- public DefaultIssueBuilder projectKey(String projectKey) {
- this.projectKey = projectKey;
- return this;
- }
-
@Override
public Issuable.IssueBuilder ruleKey(RuleKey ruleKey) {
this.ruleKey = ruleKey;
@Override
public DefaultIssue build() {
Preconditions.checkNotNull(componentKey, "Component key must be set");
- Preconditions.checkNotNull(projectKey, "Project key must be set");
Preconditions.checkNotNull(ruleKey, "Rule key must be set");
DefaultIssue issue = new DefaultIssue();
Preconditions.checkState(!Strings.isNullOrEmpty(key), "Fail to generate issue key");
issue.setKey(key);
issue.setComponentKey(componentKey);
- issue.setProjectKey(projectKey);
issue.setRuleKey(ruleKey);
issue.setMessage(message);
issue.setSeverity(severity);
@Override
public Component project(Issue issue) {
- return projectsByKey.get(issue.projectKey());
+ return projectsByKey.get(((DefaultIssue) issue).projectKey());
}
@Override
String componentKey = "org.apache.struts:struts-core:Action.java";
DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder()
.componentKey(componentKey)
- .projectKey("org.apache.struts:struts-parent")
.message("the message")
.line(123)
.effortToFix(10000.0)
public void should_not_set_default_severity() {
DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder()
.componentKey("Action.java")
- .projectKey("org.apache.struts:struts-parent")
.ruleKey(RuleKey.of("squid", "NullDereference"))
.build();
String componentKey();
- String projectKey();
-
RuleKey ruleKey();
String severity();
import org.sonar.api.user.UserFinder;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.DefaultActionPlan;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.db.IssueChangeDao;
import org.sonar.core.issue.db.IssueDao;
import org.sonar.core.issue.db.IssueDto;
verify(issueDao).selectIssues(eq(query), anyInt(), any(SqlSession.class));
assertThat(results.issues()).hasSize(2);
- Issue issue = results.issues().iterator().next();
+ DefaultIssue issue = (DefaultIssue) results.issues().iterator().next();
assertThat(issue.componentKey()).isEqualTo("Action.java");
assertThat(issue.projectKey()).isEqualTo("struts");
assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");