]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8769 Display project and organization keys in the analysis logs
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 10 Feb 2017 11:06:04 +0000 (12:06 +0100)
committerdbmeneses <duarte.meneses@sonarsource.com>
Fri, 10 Feb 2017 13:53:39 +0000 (14:53 +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 d9ddca72dbf5c360bee6cced7d408fa0188cbc02..85450419f41b94d1c1819ff725e8eba3c2afb98b 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.scanner.scan;
 
 import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.commons.lang.StringUtils;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.InstantiationStrategy;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -228,9 +230,16 @@ public class ProjectScanContainer extends ComponentContainer {
   @Override
   protected void doAfterStart() {
     DefaultAnalysisMode analysisMode = getComponentByType(DefaultAnalysisMode.class);
+    InputModuleHierarchy tree = getComponentByType(InputModuleHierarchy.class);
+
     analysisMode.printMode();
+    LOG.info("Project key: {}", tree.root().key());
+    String organization = props.property("sonar.organization");
+    if (StringUtils.isNotEmpty(organization)) {
+      LOG.info("Organization key: {}", organization);
+    }
+
     LOG.debug("Start recursive analysis of project modules");
-    InputModuleHierarchy tree = getComponentByType(InputModuleHierarchy.class);
     scanRecursively(tree, tree.root());
     if (analysisMode.isMediumTest()) {
       getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask();
index aa095aa5c2e81a451f58ca23157e20b3689336d8..61b6747508618a67ce6613925b57ecc6116e96db 100644 (file)
@@ -86,7 +86,7 @@ public class FileSystemMediumTest {
     tester.stop();
     logs = new LogOutputRecorder();
   }
-  
+
   private ImmutableMap.Builder<String, String> createBuilder() {
     return ImmutableMap.<String, String>builder()
       .put("sonar.task", "scan")
@@ -131,6 +131,45 @@ public class FileSystemMediumTest {
     assertThat(result.getReportComponent(file.key())).isNotNull();
   }
 
+  @Test
+  public void logProjectKeyAndOrganizationKey() throws IOException {
+    builder = createBuilder();
+    builder.put("sonar.organization", "my org");
+    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("Organization key: my org");
+  }
+  
+  @Test
+  public void dontLogInvalidOrganization() throws IOException {
+    builder = createBuilder();
+    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()).doesNotContain("Organization key");
+  }
+
   @Test
   public void onlyGenerateMetadataIfNeeded() throws IOException {
     builder = createBuilder();