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
*/
.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
.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() {
.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() {
"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);
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
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