Search in sources :

Example 6 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method launch_forks_a_new_process.

@Test
public void launch_forks_a_new_process() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setJvmOptions(new JvmOptions<>().add("-Dfoo=bar").add("-Dfoo2=bar2"));
    command.setEsInstallation(createEsInstallation());
    ManagedProcess monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(processBuilder.started).isTrue();
    assertThat(processBuilder.commands.get(0)).endsWith("java");
    assertThat(processBuilder.commands).containsSubsequence("-Dfoo=bar", "-Dfoo2=bar2", "-cp", "lib/*.class" + System.getProperty("path.separator") + "lib/*.jar", "org.sonarqube.Main");
    assertThat(processBuilder.dir).isEqualTo(command.getWorkDir());
    assertThat(processBuilder.redirectErrorStream).isTrue();
    assertThat(processBuilder.environment).contains(entry("VAR1", "valueOfVar1")).containsAllEntriesOf(command.getEnvVariables());
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) File(java.io.File) ManagedProcess(org.sonar.application.process.ManagedProcess) Test(org.junit.Test)

Example 7 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method enabling_es_security_should_execute_keystore_cli_if_truststore_and_keystore_provided.

@Test
public void enabling_es_security_should_execute_keystore_cli_if_truststore_and_keystore_provided() throws Exception {
    File tempDir = temp.newFolder();
    File truststoreFile = temp.newFile("truststore.pk12");
    File keystoreFile = temp.newFile("keystore.pk12");
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    EsInstallation esInstallation = createEsInstallation(new Props(new Properties()).set("sonar.cluster.enabled", "true").set("sonar.cluster.search.password", "bootstrap-password").set("sonar.cluster.es.ssl.keystore", keystoreFile.getAbsolutePath()).set("sonar.cluster.es.ssl.keystorePassword", "keystore-password").set("sonar.cluster.es.ssl.truststore", truststoreFile.getAbsolutePath()).set("sonar.cluster.es.ssl.truststorePassword", "truststore-password"));
    JavaCommand<JvmOptions> command = new JavaCommand<>(ProcessId.ELASTICSEARCH, temp.newFolder());
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setJvmOptions(new JvmOptions<>().add("-Dfoo=bar").add("-Dfoo2=bar2"));
    command.setEsInstallation(esInstallation);
    ManagedProcess monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "truststore.pk12")).exists();
    assertThat(Paths.get(esInstallation.getConfDirectory().getAbsolutePath(), "keystore.pk12")).exists();
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) ManagedProcess(org.sonar.application.process.ManagedProcess) Test(org.junit.Test)

Example 8 with JavaCommand

use of org.sonar.application.command.JavaCommand in project sonarqube by SonarSource.

the class ProcessLauncherImplTest method temporary_properties_file_can_be_avoided.

@Test
public void temporary_properties_file_can_be_avoided() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    ProcessLauncher underTest = new ProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand<JvmOptions<?>> command = new JavaCommand<>(ProcessId.WEB_SERVER, temp.newFolder());
    command.setReadsArgumentsFromFile(false);
    command.setArgument("foo", "bar");
    command.setArgument("baz", "woo");
    command.setJvmOptions(new JvmOptions<>());
    underTest.launch(command);
    String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1);
    File file = new File(propsFilePath);
    assertThat(file).doesNotExist();
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsJvmOptions(org.sonar.application.command.EsJvmOptions) JvmOptions(org.sonar.application.command.JvmOptions) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaCommand (org.sonar.application.command.JavaCommand)8 File (java.io.File)7 Test (org.junit.Test)6 EsJvmOptions (org.sonar.application.command.EsJvmOptions)5 JvmOptions (org.sonar.application.command.JvmOptions)5 ManagedProcess (org.sonar.application.process.ManagedProcess)5 EsInstallation (org.sonar.application.es.EsInstallation)4 Properties (java.util.Properties)3 Props (org.sonar.process.Props)3 IOException (java.io.IOException)2 EsScriptCommand (org.sonar.application.command.EsScriptCommand)2 Logger (ch.qos.logback.classic.Logger)1 Before (org.junit.Before)1 EsConnectorImpl (org.sonar.application.es.EsConnectorImpl)1 EsManagedProcess (org.sonar.application.process.EsManagedProcess)1 ProcessCommandsManagedProcess (org.sonar.application.process.ProcessCommandsManagedProcess)1 ProcessId (org.sonar.process.ProcessId)1 ProcessCommands (org.sonar.process.sharedmemoryfile.ProcessCommands)1