]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Use Component#getProjectKey instead of Project#getKey
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 31 Aug 2017 07:44:44 +0000 (09:44 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:56 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java

index 64310f4b8f6a11a47eddaf64fa2012dc8cee0b31..8897c682e25eeb601b0ed54e5a2bdc5c1170d66a 100644 (file)
@@ -126,7 +126,7 @@ public class QualityGateEventsStep implements ComputationStep {
     Notification notification = new Notification("alerts")
       .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
       .setFieldValue("projectName", project.getName())
-      .setFieldValue("projectKey", getMainBranchProjectKey())
+      .setFieldValue("projectKey", project.getPublicKey())
       .setFieldValue("projectUuid", project.getUuid())
       .setFieldValue("alertName", label)
       .setFieldValue("alertText", rawStatus.getText())
@@ -145,7 +145,4 @@ public class QualityGateEventsStep implements ComputationStep {
     return "Generate Quality gate events";
   }
 
-  private String getMainBranchProjectKey() {
-    return analysisMetadataHolder.getProject().getKey();
-  }
 }
index fbfb35060eeb5b333aff3d3faca1bcefe19ed78a..95e83be4a2476131b067a378dc606ab51a360aa5 100644 (file)
@@ -106,7 +106,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     IssueChangeNotification changeNotification = new IssueChangeNotification();
     changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName());
     changeNotification.setIssue(issue);
-    changeNotification.setProject(getMainBranchProjectKey(), project.getName(), getBranchName());
+    changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName());
     service.deliver(changeNotification);
   }
 
@@ -114,7 +114,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     NewIssuesStatistics.Stats globalStatistics = statistics.globalStatistics();
     NewIssuesNotification notification = newIssuesNotificationFactory
       .newNewIssuesNotication()
-      .setProject(getMainBranchProjectKey(), project.getUuid(), project.getName(), getBranchName())
+      .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName())
       .setAnalysisDate(new Date(analysisDate))
       .setStatistics(project.getName(), globalStatistics)
       .setDebt(globalStatistics.debt());
@@ -130,7 +130,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
         .newMyNewIssuesNotification()
         .setAssignee(assignee);
       myNewIssuesNotification
-        .setProject(getMainBranchProjectKey(), project.getUuid(), project.getName(), getBranchName())
+        .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName())
         .setAnalysisDate(new Date(analysisDate))
         .setStatistics(project.getName(), assigneeStatistics)
         .setDebt(assigneeStatistics.debt());
@@ -148,8 +148,4 @@ public class SendIssueNotificationsStep implements ComputationStep {
     return analysisMetadataHolder.getBranch().filter(b -> !b.isMain()).map(Branch::getName).orElse(null);
   }
 
-  private String getMainBranchProjectKey() {
-    return analysisMetadataHolder.getProject().getKey();
-  }
-
 }
index 76dcf82762eb4542a1cbc6dc03ade6177f5972f3..72033929cd953be278ff1de09382c362b85747e6 100644 (file)
@@ -187,7 +187,7 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
     assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("branch")).isNull();
@@ -239,7 +239,7 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
     assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("branch")).isNull();
@@ -263,7 +263,7 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
     assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
     assertThat(notification.getFieldValue("branch")).isEqualTo(branchName);
index 9db49085e2f825a29ee87a048d3af65be82c69b2..6b3115688c0515018f6bbfd298a38e84970f344a 100644 (file)
@@ -30,11 +30,10 @@ import org.sonar.api.utils.Duration;
 import org.sonar.api.utils.System2;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
-import org.sonar.server.computation.task.projectanalysis.analysis.Project;
-import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
-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.Component.Type;
+import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
+import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.issue.IssueCache;
 import org.sonar.server.computation.task.projectanalysis.issue.RuleRepository;
 import org.sonar.server.computation.task.step.ComputationStep;
@@ -57,22 +56,21 @@ import static org.sonar.server.computation.task.projectanalysis.component.Report
 
 public class SendIssueNotificationsStepTest extends BaseStepTest {
 
-  static final String PROJECT_UUID = "PROJECT_UUID";
-  static final String PROJECT_KEY = "PROJECT_KEY";
-  static final String PROJECT_NAME = "PROJECT_NAME";
+  private static final String PROJECT_UUID = "PROJECT_UUID";
+  private static final String PROJECT_KEY = "PROJECT_KEY";
+  private static final String PROJECT_NAME = "PROJECT_NAME";
 
-  static final String BRANCH_COMPONENT_UUID = "BRANCH_UUID";
-  static final String BRANCH_COMPONENT_KEY = "BRANCH_KEY";
-  static final String BRANCH_COMPONENT_NAME = "BRANCH_NAME";
-  static final String BRANCH_NAME = "feature";
+  private static final String BRANCH_COMPONENT_UUID = "BRANCH_UUID";
+  private static final String BRANCH_COMPONENT_NAME = "BRANCH_NAME";
+  private static final String BRANCH_NAME = "feature";
 
-  static final long ANALYSE_DATE = 123L;
+  private static final long ANALYSE_DATE = 123L;
 
-  static final Duration ISSUE_DURATION = Duration.create(100L);
-  static final String ISSUE_ASSIGNEE = "John";
+  private static final Duration ISSUE_DURATION = Duration.create(100L);
+  private static final String ISSUE_ASSIGNEE = "John";
 
-  static final Component PROJECT = builder(Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).setName(PROJECT_NAME).build();
-  static final Component BRANCH = builder(Type.PROJECT, 2).setUuid(BRANCH_COMPONENT_UUID).setKey(BRANCH_COMPONENT_KEY).setName(BRANCH_COMPONENT_NAME).build();
+  private static final Component PROJECT = builder(Type.PROJECT, 1).setUuid(PROJECT_UUID).setPublicKey(PROJECT_KEY).setName(PROJECT_NAME).build();
+  private static final Component BRANCH = builder(Type.PROJECT, 2).setUuid(BRANCH_COMPONENT_UUID).setPublicKey(PROJECT_KEY).setName(BRANCH_COMPONENT_NAME).build();
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
@@ -80,7 +78,6 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
 
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
-    .setProject(new Project(PROJECT_UUID, PROJECT_KEY, PROJECT_NAME))
     .setBranch(new DefaultBranchImpl())
     .setAnalysisDate(new Date(ANALYSE_DATE));