aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-09-25 13:51:00 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-09-25 13:51:57 +0200
commit6571831760ff04b098cdf8e6177fa4fff6f9fb11 (patch)
treec08ec821c359bd1ca743fbd6e3a6b3f1c9da8f42 /sonar-batch
parent0d7c71ee21a8d77948523fa1d331a12f61637a30 (diff)
downloadsonarqube-6571831760ff04b098cdf8e6177fa4fff6f9fb11.tar.gz
sonarqube-6571831760ff04b098cdf8e6177fa4fff6f9fb11.zip
SONAR-6835 Do not display system properties multiple times
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java43
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java22
2 files changed, 53 insertions, 12 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
index c4e396fd381..e7ba57a7c0f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/report/AnalysisContextReportPublisher.java
@@ -37,6 +37,7 @@ import org.sonar.core.platform.PluginInfo;
@BatchSide
public class AnalysisContextReportPublisher {
+ private static final String SONAR_PROP_PREFIX = "sonar.";
private final BatchPluginRepository pluginRepo;
private final AnalysisMode mode;
@@ -54,23 +55,38 @@ public class AnalysisContextReportPublisher {
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');
- }
+ writeEnvVariables(fileWriter);
+ writeSystemProps(fileWriter);
+ writePlugins(fileWriter);
} catch (IOException e) {
throw new IllegalStateException("Unable to write analysis log", e);
}
}
+ private void writePlugins(BufferedWriter fileWriter) throws IOException {
+ 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');
+ }
+ }
+
+ private void writeSystemProps(BufferedWriter fileWriter) throws IOException {
+ fileWriter.write("System properties:\n");
+ for (Map.Entry<Object, Object> env : System.getProperties().entrySet()) {
+ if (env.getKey().toString().startsWith(SONAR_PROP_PREFIX)) {
+ continue;
+ }
+ fileWriter.append(String.format(" - %s=%s", env.getKey(), env.getValue())).append('\n');
+ }
+ }
+
+ private static void writeEnvVariables(BufferedWriter fileWriter) throws IOException {
+ fileWriter.append("Environment variables:\n");
+ for (Map.Entry<String, String> env : System.getenv().entrySet()) {
+ fileWriter.append(String.format(" - %s=%s", env.getKey(), env.getValue())).append('\n');
+ }
+ }
+
public void dumpSettings(ProjectDefinition moduleDefinition, Settings settings) {
if (mode.isIssues()) {
return;
@@ -79,6 +95,9 @@ public class AnalysisContextReportPublisher {
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()) {
+ if (System.getProperties().containsKey(prop.getKey()) && !prop.getKey().startsWith(SONAR_PROP_PREFIX)) {
+ continue;
+ }
fileWriter.append(String.format(" - %s=%s", prop.getKey(), sensitive(prop.getKey()) ? "******" : prop.getValue())).append('\n');
}
} catch (IOException e) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java
index e7bdc1b66e4..f890b6ab725 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/AnalysisContextReportPublisherTest.java
@@ -74,6 +74,28 @@ public class AnalysisContextReportPublisherTest {
}
@Test
+ public void shouldNotDumpSQPropsInSystemProps() throws Exception {
+ BatchReportWriter writer = new BatchReportWriter(temp.newFolder());
+ System.setProperty("com.foo", "bar");
+ System.setProperty("sonar.skip", "true");
+ publisher.init(writer);
+
+ String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog());
+ assertThat(content).containsOnlyOnce("com.foo");
+ assertThat(content).doesNotContain("sonar.skip");
+
+ Settings settings = new Settings();
+ settings.setProperty("com.foo", "bar");
+ settings.setProperty("sonar.skip", "true");
+
+ publisher.dumpSettings(ProjectDefinition.create().setProperty("sonar.projectKey", "foo"), settings);
+
+ content = FileUtils.readFileToString(writer.getFileStructure().analysisLog());
+ assertThat(content).containsOnlyOnce("com.foo");
+ assertThat(content).containsOnlyOnce("sonar.skip");
+ }
+
+ @Test
public void shouldNotDumpSensitiveProperties() throws Exception {
BatchReportWriter writer = new BatchReportWriter(temp.newFolder());
publisher.init(writer);