]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-SONAR-10294 Ignore ES_JAVA_OPTS env variable
authorEric Hartmann <hartmann.eric@gmail.com>
Fri, 8 Jun 2018 08:36:23 +0000 (10:36 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 8 Jun 2018 18:20:51 +0000 (20:20 +0200)
server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java

index fdf1937b95de5c7902dfef83ec719a40f95a2199..d448a1a940315f93f52f8351bb3ea432762f65a6 100644 (file)
@@ -51,6 +51,7 @@ import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_OPTS;
 
 public class CommandFactoryImpl implements CommandFactory {
   private static final String ENV_VAR_JAVA_TOOL_OPTIONS = "JAVA_TOOL_OPTIONS";
+  private static final String ENV_VAR_ES_JAVA_OPTS = "ES_JAVA_OPTS";
   /**
    * Properties about proxy that must be set as system properties
    */
@@ -78,6 +79,13 @@ public class CommandFactoryImpl implements CommandFactory {
         .warn("JAVA_TOOL_OPTIONS is defined but will be ignored. " +
           "Use properties sonar.*.javaOpts and/or sonar.*.javaAdditionalOpts in sonar.properties to change SQ JVM processes options");
     }
+    String esJavaOpts = system2.getenv(ENV_VAR_ES_JAVA_OPTS);
+    if (esJavaOpts != null && !esJavaOpts.trim().isEmpty()) {
+      LoggerFactory.getLogger(CommandFactoryImpl.class)
+        .warn("ES_JAVA_OPTS is defined but will be ignored. " +
+          "Use properties sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to change SQ JVM processes options");
+    }
+
   }
 
   @Override
@@ -95,7 +103,8 @@ public class CommandFactoryImpl implements CommandFactory {
       .addOption("-Epath.conf=" + esInstallation.getConfDirectory().getAbsolutePath())
       .setEnvVariable("ES_JVM_OPTIONS", esInstallation.getJvmOptions().getAbsolutePath())
       .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home"))
-      .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS);
+      .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS)
+      .suppressEnvVariable(ENV_VAR_ES_JAVA_OPTS);
   }
 
   private JavaCommand createEsCommandForWindows() {
@@ -113,7 +122,8 @@ public class CommandFactoryImpl implements CommandFactory {
       .setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home"))
       .setClassName("org.elasticsearch.bootstrap.Elasticsearch")
       .addClasspath("lib/*")
-      .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS);
+      .suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS)
+      .suppressEnvVariable(ENV_VAR_ES_JAVA_OPTS);
   }
 
   private EsInstallation createEsInstallation() {
index e6fb71a2548e05c275a79b376de5ce1a63404345..1e6cb8f1e5c01526e86a315475d4fba33d074f9f 100644 (file)
@@ -95,6 +95,21 @@ public class CommandFactoryImplTest {
           "Use properties sonar.*.javaOpts and/or sonar.*.javaAdditionalOpts in sonar.properties to change SQ JVM processes options");
   }
 
+  @Test
+  public void constructor_logs_warning_if_env_variable_ES_JAVA_OPTS_is_set() {
+    System2 system2 = Mockito.mock(System2.class);
+    when(system2.getenv("ES_JAVA_OPTS")).thenReturn("xyz");
+    attachMemoryAppenderToLoggerOf(CommandFactoryImpl.class);
+
+    new CommandFactoryImpl(new Props(new Properties()), tempDir, system2);
+
+    assertThat(listAppender.getLogs())
+      .extracting(ILoggingEvent::getMessage)
+      .containsOnly(
+        "ES_JAVA_OPTS is defined but will be ignored. " +
+          "Use properties sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to change SQ JVM processes options");
+  }
+
   @Test
   public void createEsCommand_throws_ISE_if_es_binary_is_not_found() {
     expectedException.expect(IllegalStateException.class);
@@ -133,7 +148,7 @@ public class CommandFactoryImplTest {
     assertThat(esConfig.getLog4j2Properties())
       .contains(entry("appender.file_es.fileName", new File(logsDir, "es.log").getAbsolutePath()));
 
-    assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS");
+    assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
   }
 
   @Test
@@ -166,7 +181,7 @@ public class CommandFactoryImplTest {
     assertThat(esConfig.getLog4j2Properties())
       .contains(entry("appender.file_es.fileName", new File(logsDir, "es.log").getAbsolutePath()));
 
-    assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS");
+    assertThat(esCommand.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS", "ES_JAVA_OPTS");
   }
 
   @Test