From 85ceabacd698befe87f1bf657cdcdd9f9242d13b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 30 May 2013 12:02:57 +0200 Subject: [PATCH] Remove projectKey from Issues API as it's not always populated --- .../java/org/sonar/core/issue/DefaultIssueBuilder.java | 8 -------- .../org/sonar/core/issue/DefaultIssueQueryResult.java | 2 +- .../org/sonar/core/issue/DefaultIssueBuilderTest.java | 2 -- .../src/main/java/org/sonar/api/issue/Issue.java | 2 -- .../org/sonar/server/issue/DefaultIssueFinderTest.java | 3 ++- 5 files changed, 3 insertions(+), 14 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java index 1c4dcf208fb..a429333d19b 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java @@ -34,7 +34,6 @@ import java.util.UUID; public class DefaultIssueBuilder implements Issuable.IssueBuilder { private String componentKey; - private String projectKey; private RuleKey ruleKey; private Integer line; private String message; @@ -52,11 +51,6 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { return this; } - public DefaultIssueBuilder projectKey(String projectKey) { - this.projectKey = projectKey; - return this; - } - @Override public Issuable.IssueBuilder ruleKey(RuleKey ruleKey) { this.ruleKey = ruleKey; @@ -105,7 +99,6 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { @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(); @@ -113,7 +106,6 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder { 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); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java index 239d1b8d1e1..ad95980706c 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java @@ -128,7 +128,7 @@ public class DefaultIssueQueryResult implements IssueQueryResult { @Override public Component project(Issue issue) { - return projectsByKey.get(issue.projectKey()); + return projectsByKey.get(((DefaultIssue) issue).projectKey()); } @Override diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java index 61d3db092f9..eb55c784461 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java @@ -33,7 +33,6 @@ public class DefaultIssueBuilderTest { 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) @@ -65,7 +64,6 @@ public class DefaultIssueBuilderTest { 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(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java index 7f0fab7d2d2..9af4e5519a4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java @@ -55,8 +55,6 @@ public interface Issue extends Serializable { String componentKey(); - String projectKey(); - RuleKey ruleKey(); String severity(); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java index 0123c9f1083..b8b2f19841d 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java @@ -32,6 +32,7 @@ import org.sonar.api.user.User; 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; @@ -87,7 +88,7 @@ public class DefaultIssueFinderTest { 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"); -- 2.39.5