aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-main
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2018-06-08 10:36:23 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-08 20:20:51 +0200
commite6d7fdb0d12d1ebe9212a941b71736c20969c434 (patch)
treed21d9663abf45e7a521866aca8954187a7a0a2d9 /server/sonar-main
parentb61ddb3f840fbc36e6aade3a51c4d36a30862521 (diff)
downloadsonarqube-e6d7fdb0d12d1ebe9212a941b71736c20969c434.tar.gz
sonarqube-e6d7fdb0d12d1ebe9212a941b71736c20969c434.zip
SONAR-SONAR-10294 Ignore ES_JAVA_OPTS env variable
Diffstat (limited to 'server/sonar-main')
-rw-r--r--server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java14
-rw-r--r--server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java19
2 files changed, 29 insertions, 4 deletions
diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
index fdf1937b95d..d448a1a9403 100644
--- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
+++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java
@@ -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() {
diff --git a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
index e6fb71a2548..1e6cb8f1e5c 100644
--- a/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
+++ b/server/sonar-main/src/test/java/org/sonar/application/command/CommandFactoryImplTest.java
@@ -96,6 +96,21 @@ public class CommandFactoryImplTest {
}
@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);
expectedException.expectMessage("Cannot find elasticsearch binary");
@@ -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