@Override
  public JavaCommand<EsServerCliJvmOptions> createEsCommand() {
    EsInstallation esInstallation = createEsInstallation();
    String esHomeDirectoryAbsolutePath = esInstallation.getHomeDirectory().getAbsolutePath();
    return new JavaCommand<EsServerCliJvmOptions>(ProcessId.ELASTICSEARCH, esInstallation.getHomeDirectory())
      .setEsInstallation(esInstallation)
      .setJvmOptions(new EsServerCliJvmOptions(esInstallation))
      .setEnvVariable("ES_JAVA_HOME", System.getProperties().getProperty("java.home"))
      .setClassName("org.elasticsearch.launcher.CliToolLauncher")
      .addClasspath(Paths.get(esHomeDirectoryAbsolutePath, "lib").toAbsolutePath() + File.separator + "*")
      .addClasspath(Paths.get(esHomeDirectoryAbsolutePath, "lib", "cli-launcher").toAbsolutePath() + File.separator + "*");
  }
@Test
  public void createEsCommand_for_unix_returns_command_for_default_settings() throws Exception {
    when(system2.isOsWindows()).thenReturn(false);
    prepareEsFileSystem();

    Properties props = new Properties();
    props.setProperty("sonar.search.host", "localhost");

    JavaCommand<?> esCommand = newFactory(props, system2).createEsCommand();
    EsInstallation esConfig = esCommand.getEsInstallation();

    assertThat(esConfig.getHost()).isNotEmpty();
    assertThat(esConfig.getHttpPort()).isEqualTo(9001);
    assertThat(esConfig.getEsJvmOptions().getAll())
      // enforced values
      .contains("-XX:+UseG1GC")
      .contains("-Dfile.encoding=UTF-8")
      // default settings
      .contains("-Xms512m", "-Xmx512m", "-XX:+HeapDumpOnOutOfMemoryError");
    assertThat(esConfig.getEsYmlSettings()).isNotNull();
    assertThat(esConfig.getLog4j2Properties())
      .contains(entry("appender.file_es.fileName", new File(logsDir, "es.log").getAbsolutePath()));

    assertThat(esCommand.getEnvVariables())
      .containsKey("ES_JAVA_HOME");

    assertThat(esCommand.getJvmOptions().getAll())
      .contains("-Xms4m", "-Xmx64m", "-XX:+UseSerialGC", "-Dcli.name=server", "-Dcli.script=./bin/elasticsearch",
        "-Dcli.libs=lib/tools/server-cli", "-Des.path.home=" + esConfig.getHomeDirectory().getAbsolutePath(),
        "-Des.path.conf=" + esConfig.getConfDirectory().getAbsolutePath(), "-Des.distribution.type=tar");
  }