aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-29 16:54:11 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-10-02 09:45:47 +0200
commit2278146794b220eb8b859759527a8578370bb0fa (patch)
tree918a6dc5aa4c2fe51189dbc296e8c55405a4310a /sonar-scanner-engine
parent3b41bd6846e1ca604a1e4042ff7d40a5392b9bf7 (diff)
downloadsonarqube-2278146794b220eb8b859759527a8578370bb0fa.tar.gz
sonarqube-2278146794b220eb8b859759527a8578370bb0fa.zip
SONAR-9883 Project name is 'null' if not specified and branch is used
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java24
2 files changed, 25 insertions, 1 deletions
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
@@ -155,6 +155,30 @@ public class ComponentsPublisherTest {
}
@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);
when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));