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;
@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();
tester.stop();
logs = new LogOutputRecorder();
}
-
+
private ImmutableMap.Builder<String, String> createBuilder() {
return ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
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();