aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-09-15 15:37:38 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-09-16 15:14:49 +0200
commit991c4b28ff79817a292f7a05845dd0f5cfae0842 (patch)
tree5ab4700c31f6a18d178279d823ba96ecea4b4b71 /sonar-batch/src/main
parentb48e0f8bc3787c8e73edb47503b345ace29d224c (diff)
downloadsonarqube-991c4b28ff79817a292f7a05845dd0f5cfae0842.tar.gz
sonarqube-991c4b28ff79817a292f7a05845dd0f5cfae0842.zip
SONAR-6835 Include batch analysis context in the report sent by the batch
Diffstat (limited to 'sonar-batch/src/main')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java92
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java2
5 files changed, 109 insertions, 15 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java
new file mode 100644
index 00000000000..c4e396fd381
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java
@@ -0,0 +1,92 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.report;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
+import java.util.Map;
+import org.sonar.api.batch.AnalysisMode;
+import org.sonar.api.batch.BatchSide;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.Settings;
+import org.sonar.batch.bootstrap.BatchPluginRepository;
+import org.sonar.batch.protocol.output.BatchReportWriter;
+import org.sonar.core.platform.PluginInfo;
+
+@BatchSide
+public class AnalysisContextReportPublisher {
+
+ private final BatchPluginRepository pluginRepo;
+ private final AnalysisMode mode;
+
+ private BatchReportWriter writer;
+
+ public AnalysisContextReportPublisher(AnalysisMode mode, BatchPluginRepository pluginRepo) {
+ this.mode = mode;
+ this.pluginRepo = pluginRepo;
+ }
+
+ public void init(BatchReportWriter writer) {
+ if (mode.isIssues()) {
+ return;
+ }
+ this.writer = writer;
+ File analysisLog = writer.getFileStructure().analysisLog();
+ try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8)) {
+ fileWriter.append("Environement variables:\n");
+ for (Map.Entry<String, String> env : System.getenv().entrySet()) {
+ fileWriter.append(String.format(" - %s=%s", env.getKey(), env.getValue())).append('\n');
+ }
+ fileWriter.write("System properties:\n");
+ for (Map.Entry<Object, Object> env : System.getProperties().entrySet()) {
+ fileWriter.append(String.format(" - %s=%s", env.getKey(), env.getValue())).append('\n');
+ }
+ fileWriter.write("SonarQube plugins:\n");
+ for (PluginInfo p : pluginRepo.getPluginInfos()) {
+ fileWriter.append(String.format(" - %s %s (%s)", p.getName(), p.getVersion(), p.getKey())).append('\n');
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to write analysis log", e);
+ }
+ }
+
+ public void dumpSettings(ProjectDefinition moduleDefinition, Settings settings) {
+ if (mode.isIssues()) {
+ return;
+ }
+ File analysisLog = writer.getFileStructure().analysisLog();
+ try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8, StandardOpenOption.WRITE, StandardOpenOption.APPEND)) {
+ fileWriter.append(String.format("Settings for module: %s", moduleDefinition.getKey())).append('\n');
+ for (Map.Entry<String, String> prop : settings.getProperties().entrySet()) {
+ fileWriter.append(String.format(" - %s=%s", prop.getKey(), sensitive(prop.getKey()) ? "******" : prop.getValue())).append('\n');
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to write analysis log", e);
+ }
+ }
+
+ private static boolean sensitive(String key) {
+ return key.contains(".password") || key.contains(".secured");
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
index 6638fbd4721..418703ae7fa 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
@@ -19,12 +19,8 @@
*/
package org.sonar.batch.report;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
-
-import org.sonar.batch.util.BatchUtils;
import com.github.kevinsawicki.http.HttpRequest;
import com.google.common.annotations.VisibleForTesting;
-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -32,7 +28,6 @@ import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
-
import org.apache.commons.io.FileUtils;
import org.picocontainer.Startable;
import org.slf4j.Logger;
@@ -44,9 +39,12 @@ import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
import org.sonar.api.utils.TempFolder;
import org.sonar.api.utils.ZipUtils;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.batch.scan.ImmutableProjectReactor;
+import org.sonar.batch.util.BatchUtils;
+
import static java.lang.String.format;
@BatchSide
@@ -62,16 +60,18 @@ public class ReportPublisher implements Startable {
private final ImmutableProjectReactor projectReactor;
private final DefaultAnalysisMode analysisMode;
private final TempFolder temp;
+ private final AnalysisContextReportPublisher contextPublisher;
private ReportPublisherStep[] publishers;
private File reportDir;
private BatchReportWriter writer;
- public ReportPublisher(Settings settings, ServerClient serverClient, Server server,
+ public ReportPublisher(Settings settings, ServerClient serverClient, Server server, AnalysisContextReportPublisher contextPublisher,
ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
this.serverClient = serverClient;
this.server = server;
+ this.contextPublisher = contextPublisher;
this.projectReactor = projectReactor;
this.settings = settings;
this.analysisMode = analysisMode;
@@ -83,6 +83,7 @@ public class ReportPublisher implements Startable {
public void start() {
reportDir = new File(projectReactor.getRoot().getWorkDir(), "batch-report");
writer = new BatchReportWriter(reportDir);
+ contextPublisher.init(writer);
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java
index b28bea91d20..f7652b22c72 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ImmutableProjectReactor.java
@@ -20,7 +20,7 @@
package org.sonar.batch.scan;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.BatchSide;
@@ -33,7 +33,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
public class ImmutableProjectReactor {
private ProjectDefinition root;
- private Map<String, ProjectDefinition> byKey = new HashMap<>();
+ private Map<String, ProjectDefinition> byKey = new LinkedHashMap<>();
public ImmutableProjectReactor(ProjectDefinition root) {
if (root.getParent() != null) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
index 00692d53cfa..43ca0dd6ac1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
@@ -19,18 +19,16 @@
*/
package org.sonar.batch.scan;
-import org.sonar.batch.repository.ProjectSettingsRepo;
-
-import org.sonar.batch.analysis.DefaultAnalysisMode;
import com.google.common.collect.Lists;
-
import java.util.List;
-
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.GlobalSettings;
+import org.sonar.batch.report.AnalysisContextReportPublisher;
+import org.sonar.batch.repository.ProjectSettingsRepo;
/**
* @since 2.12
@@ -38,16 +36,17 @@ import org.sonar.batch.bootstrap.GlobalSettings;
public class ModuleSettings extends Settings {
private final ProjectSettingsRepo projectSettingsRepo;
- private DefaultAnalysisMode analysisMode;
+ private final DefaultAnalysisMode analysisMode;
public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition moduleDefinition, ProjectSettingsRepo projectSettingsRepo,
- DefaultAnalysisMode analysisMode) {
+ DefaultAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
super(batchSettings.getDefinitions());
this.projectSettingsRepo = projectSettingsRepo;
this.analysisMode = analysisMode;
getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
init(moduleDefinition, batchSettings);
+ contextReportPublisher.dumpSettings(moduleDefinition, this);
}
private ModuleSettings init(ProjectDefinition moduleDefinition, GlobalSettings batchSettings) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 7d65aae8ab5..431b916ebff 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -72,6 +72,7 @@ import org.sonar.batch.mediumtest.ScanTaskObservers;
import org.sonar.batch.phases.PhasesTimeProfiler;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.report.ActiveRulesPublisher;
+import org.sonar.batch.report.AnalysisContextReportPublisher;
import org.sonar.batch.report.ComponentsPublisher;
import org.sonar.batch.report.CoveragePublisher;
import org.sonar.batch.report.DuplicationsPublisher;
@@ -192,6 +193,7 @@ public class ProjectScanContainer extends ComponentContainer {
// Report
ReportPublisher.class,
+ AnalysisContextReportPublisher.class,
MetadataPublisher.class,
ActiveRulesPublisher.class,
ComponentsPublisher.class,