]> source.dussan.org Git - sonarqube.git/commitdiff
Remove projectKey from Issues API as it's not always populated
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 30 May 2013 10:02:57 +0000 (12:02 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 30 May 2013 10:02:57 +0000 (12:02 +0200)
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueQueryResult.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java

index 1c4dcf208fb2e087fb72bc038fbc3ab72498a7ae..a429333d19b6eac5ff3fe310bb6e1aea595a5935 100644 (file)
@@ -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);
index 239d1b8d1e1072412223bbe69525d694f5030ee3..ad95980706c8cf69fedbc298af875bc6a1bfdb2a 100644 (file)
@@ -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
index 61d3db092f9424b69aab7187db0b51b9e7414959..eb55c784461bf89442352044d3c8cb5e4271273a 100644 (file)
@@ -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();
 
index 7f0fab7d2d270d8dfecfa3a61a4d23165c86e9e0..9af4e5519a496b7db1b07c990a9494c37601151c 100644 (file)
@@ -55,8 +55,6 @@ public interface Issue extends Serializable {
 
   String componentKey();
 
-  String projectKey();
-
   RuleKey ruleKey();
 
   String severity();
index 0123c9f1083b3391aede81669702a89f96ad18e8..b8b2f19841d0f6bbfd147a81f1af21f32407aacd 100644 (file)
@@ -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");