]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9883 Project name is 'null' if not specified and branch is used
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 29 Sep 2017 14:54:11 +0000 (16:54 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 2 Oct 2017 07:45:47 +0000 (09:45 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java

index 0c1af1a91d7925251bcefdc10b4c2383de2ee3b8..7995b30cd1be396f1c6d525e053e9c7b19d766a3 100644 (file)
@@ -258,7 +258,7 @@ public class ComponentsPublisher implements ReportPublisherStep {
   @CheckForNull
   private static String getName(DefaultInputModule module) {
     if (StringUtils.isNotEmpty(module.definition().getBranch())) {
-      return module.definition().getOriginalName() + " " + module.definition().getBranch();
+      return module.definition().getName() + " " + module.definition().getBranch();
     } else {
       return module.definition().getOriginalName();
     }
index 528aa5b968c6782f5c612fb08fb6e13ae8f7a387..00c496be9aba0bb69dc91d64729ba62e4b29a041 100644 (file)
@@ -154,6 +154,30 @@ public class ComponentsPublisherTest {
     assertThat(reader.readComponent(7).getStatus()).isEqualTo(FileStatus.ADDED);
   }
 
+  @Test
+  public void should_set_modified_name_with_branch() throws IOException {
+    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
+    when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
+
+    ProjectDefinition rootDef = ProjectDefinition.create()
+      .setKey("foo")
+      .setDescription("Root description")
+      .setBaseDir(temp.newFolder())
+      .setWorkDir(temp.newFolder())
+      .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch");
+
+    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
+
+    moduleHierarchy = mock(InputModuleHierarchy.class);
+    when(moduleHierarchy.root()).thenReturn(root);
+
+    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree, branchConfiguration);
+    publisher.publish(writer);
+    Component rootProtobuf = reader.readComponent(1);
+    assertThat(rootProtobuf.getKey()).isEqualTo("foo");
+    assertThat(rootProtobuf.getName()).isEqualTo("foo my_branch");
+  }
+
   @Test
   public void should_skip_dir_without_published_files() throws IOException {
     ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);