]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Issue#componentKey should be the public key
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 30 Aug 2017 14:59:30 +0000 (16:59 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:55 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/TrackerRawInputFactory.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ReportComponent.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/MovedIssueVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/TrackerRawInputFactoryTest.java

index 38328b7ff15fbdac349d25e86203998a2be58659..efafe43e94129ceeb1587b5605c36d800351a38c 100644 (file)
@@ -59,7 +59,7 @@ public class MovedIssueVisitor extends IssueVisitor {
     // changes the issue's component uuid, add a change and set issue as changed to enforce it is persisted to DB
     issueUpdater.setIssueMoved(issue, component.getUuid(), IssueChangeContext.createUser(new Date(analysisMetadataHolder.getAnalysisDate()), null));
     // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only
-    issue.setComponentKey(component.getKey());
+    issue.setComponentKey(component.getPublicKey());
     issue.setModuleUuid(null);
     issue.setModuleUuidPath(null);
   }
index 9de67f6b6100779434e63780fcc57a59ef900342..f113a73a86b7b130d1cac3d31ffcfcb09942f3e2 100644 (file)
@@ -161,9 +161,9 @@ public class TrackerRawInputFactory {
       issue.setResolution(null);
       issue.setStatus(Issue.STATUS_OPEN);
       issue.setComponentUuid(component.getUuid());
-      issue.setComponentKey(component.getKey());
+      issue.setComponentKey(component.getPublicKey());
       issue.setProjectUuid(treeRootHolder.getRoot().getUuid());
-      issue.setProjectKey(treeRootHolder.getRoot().getKey());
+      issue.setProjectKey(treeRootHolder.getRoot().getPublicKey());
       return issue;
     }
 
index e3baec1c1882ad60b7674669d46fbd45cfea4b21..3ebeabcc6472ff78f7936b0bd0833dfe44ca79b3 100644 (file)
@@ -37,7 +37,13 @@ public class ReportComponent implements Component {
 
   private static final FileAttributes DEFAULT_FILE_ATTRIBUTES = new FileAttributes(false, null, 1);
 
-  public static final Component DUMB_PROJECT = builder(Type.PROJECT, 1).setKey("PROJECT_KEY").setUuid("PROJECT_UUID").setName("Project Name").setVersion("1.0-SNAPSHOT").build();
+  public static final Component DUMB_PROJECT = builder(Type.PROJECT, 1)
+    .setKey("PROJECT_KEY")
+    .setPublicKey("PUBLIC_PROJECT_KEY")
+    .setUuid("PROJECT_UUID")
+    .setName("Project Name")
+    .setVersion("1.0-SNAPSHOT")
+    .build();
 
   private final Type type;
   private final Status status;
@@ -170,7 +176,7 @@ public class ReportComponent implements Component {
   }
 
   public static Builder builder(Type type, int ref) {
-    return new Builder(type, ref).setKey("key_" + ref).setUuid("uuid_" + ref);
+    return new Builder(type, ref).setKey("key_" + ref).setPublicKey("public_" + ref).setUuid("uuid_" + ref);
   }
 
   public static final class Builder {
index 568fb90b02bbd42650b254c1e528a4a6e9ba3aaf..9328e9d7359c44adc15f4fab309552856c9a594e 100644 (file)
@@ -45,7 +45,11 @@ import static org.mockito.Mockito.when;
 public class MovedIssueVisitorTest {
   private static final long ANALYSIS_DATE = 894521;
   private static final String FILE_UUID = "file uuid";
-  private static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1).setUuid(FILE_UUID).build();
+  private static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1)
+    .setKey("key_1")
+    .setPublicKey("public_key_1")
+    .setUuid(FILE_UUID)
+    .build();
 
   @org.junit.Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -115,7 +119,7 @@ public class MovedIssueVisitorTest {
     underTest.onIssue(FILE, issue);
 
     verify(issue).setComponentUuid(FILE.getUuid());
-    verify(issue).setComponentKey(FILE.getKey());
+    verify(issue).setComponentKey(FILE.getPublicKey());
     verify(issue).setModuleUuid(null);
     verify(issue).setModuleUuidPath(null);
     verify(issue).setChanged(true);
index 0133505adb22896326f95f97f191e785cf54a128..dabb0922fa50f838e1a03fba40bcff03f0f7939e 100644 (file)
@@ -32,9 +32,9 @@ import org.sonar.scanner.protocol.Constants;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.TextRange;
 import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
+import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.issue.commonrule.CommonRuleEngine;
 import org.sonar.server.computation.task.projectanalysis.issue.filter.IssueFilter;
 import org.sonar.server.computation.task.projectanalysis.source.SourceLinesRepositoryRule;
@@ -49,10 +49,10 @@ import static org.mockito.Mockito.when;
 
 public class TrackerRawInputFactoryTest {
 
-  static int FILE_REF = 2;
+  private static int FILE_REF = 2;
 
-  static ReportComponent PROJECT = ReportComponent.builder(Component.Type.PROJECT, 1).setKey("PROJECT_KEY_2").setUuid("PROJECT_UUID_1").build();
-  static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, FILE_REF).setKey("FILE_KEY_2").setUuid("FILE_UUID_2").build();
+  private static ReportComponent PROJECT = ReportComponent.builder(Component.Type.PROJECT, 1).build();
+  private static ReportComponent FILE = ReportComponent.builder(Component.Type.FILE, FILE_REF).build();
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(PROJECT);
@@ -190,7 +190,8 @@ public class TrackerRawInputFactoryTest {
   }
 
   private void assertInitializedIssue(DefaultIssue issue) {
-    assertThat(issue.componentKey()).isEqualTo(FILE.getKey());
+    assertThat(issue.projectKey()).isEqualTo(PROJECT.getPublicKey());
+    assertThat(issue.componentKey()).isEqualTo(FILE.getPublicKey());
     assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid());
     assertThat(issue.resolution()).isNull();
     assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);