From 2278146794b220eb8b859759527a8578370bb0fa Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 29 Sep 2017 16:54:11 +0200 Subject: [PATCH] SONAR-9883 Project name is 'null' if not specified and branch is used --- .../scanner/report/ComponentsPublisher.java | 2 +- .../report/ComponentsPublisherTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index 0c1af1a91d7..7995b30cd1b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -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(); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java index 528aa5b968c..00c496be9ab 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java @@ -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); -- 2.39.5