]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8769 Display project and organization keys in the analysis logs 1683/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 16 Feb 2017 16:48:34 +0000 (17:48 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 17 Feb 2017 13:04:21 +0000 (14:04 +0100)
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java

index 7bbb1247828efa58e25a253a7277a5df891eccf0..332a976d76cf18ea105b5beedd853c3ca2c24c7f 100644 (file)
@@ -238,6 +238,10 @@ public class ProjectScanContainer extends ComponentContainer {
     if (StringUtils.isNotEmpty(organization)) {
       LOG.info("Organization key: {}", organization);
     }
+    String branch = tree.root().definition().getBranch();
+    if (branch != null) {
+      LOG.info("Branch key: {}", branch);
+    }
 
     LOG.debug("Start recursive analysis of project modules");
     scanRecursively(tree, tree.root());
index 64a3018c6a3a077180b78ceeb182d6661db6674b..96e8df3f64d3f03267ed443959b308c559d4ac59 100644 (file)
@@ -135,6 +135,7 @@ public class FileSystemMediumTest {
   public void logProjectKeyAndOrganizationKey() throws IOException {
     builder = createBuilder();
     builder.put("sonar.organization", "my org");
+    builder.put("sonar.branch", "");
     File srcDir = new File(baseDir, "src");
     srcDir.mkdir();
 
@@ -149,8 +150,29 @@ public class FileSystemMediumTest {
 
     assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
     assertThat(logs.getAllAsString()).contains("Organization key: my org");
+    assertThat(logs.getAllAsString()).doesNotContain("Branch key");
   }
-  
+
+  @Test
+  public void logBranchKey() throws IOException {
+    builder = createBuilder();
+    builder.put("sonar.branch", "my-branch");
+    File srcDir = new File(baseDir, "src");
+    srcDir.mkdir();
+
+    File xooFile = new File(srcDir, "sample.xoo");
+    FileUtils.write(xooFile, "Sample xoo\ncontent");
+
+    tester.newTask()
+      .properties(builder
+        .put("sonar.sources", "src")
+        .build())
+      .start();
+
+    assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
+    assertThat(logs.getAllAsString()).contains("Branch key: my-branch");
+  }
+
   @Test
   public void dontLogInvalidOrganization() throws IOException {
     builder = createBuilder();
@@ -168,6 +190,7 @@ public class FileSystemMediumTest {
 
     assertThat(logs.getAllAsString()).contains("Project key: com.foo.project");
     assertThat(logs.getAllAsString()).doesNotContain("Organization key");
+    assertThat(logs.getAllAsString()).doesNotContain("Branch key");
   }
 
   @Test