Search in sources :

Example 1 with JavaProcessLauncher

use of org.sonar.application.process.JavaProcessLauncher in project sonarqube by SonarSource.

the class JavaProcessLauncherImplTest method properties_are_passed_to_command_via_a_temporary_properties_file.

@Test
public void properties_are_passed_to_command_via_a_temporary_properties_file() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH);
    command.setArgument("foo", "bar");
    command.setArgument("baz", "woo");
    underTest.launch(command);
    String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1);
    File file = new File(propsFilePath);
    assertThat(file).exists().isFile();
    try (FileReader reader = new FileReader(file)) {
        Properties props = new Properties();
        props.load(reader);
        assertThat(props).containsOnly(entry("foo", "bar"), entry("baz", "woo"), entry("process.terminationTimeout", "60000"), entry("process.key", ProcessId.ELASTICSEARCH.getKey()), entry("process.index", String.valueOf(ProcessId.ELASTICSEARCH.getIpcIndex())), entry("process.sharedDir", tempDir.getAbsolutePath()));
    }
}
Also used : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) FileReader(java.io.FileReader) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 2 with JavaProcessLauncher

use of org.sonar.application.process.JavaProcessLauncher in project sonarqube by SonarSource.

the class JavaProcessLauncherImplTest method launch_forks_a_new_process.

@Test
public void launch_forks_a_new_process() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH);
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setWorkDir(temp.newFolder());
    ProcessMonitor monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(processBuilder.started).isTrue();
    assertThat(processBuilder.commands.get(0)).endsWith("java");
    assertThat(processBuilder.commands).containsSequence("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-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 : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) ProcessMonitor(org.sonar.application.process.ProcessMonitor) File(java.io.File) Test(org.junit.Test)

Example 3 with JavaProcessLauncher

use of org.sonar.application.process.JavaProcessLauncher in project sonarqube by SonarSource.

the class JavaProcessLauncherImplTest method throw_ISE_if_command_fails.

@Test
public void throw_ISE_if_command_fails() throws IOException {
    File tempDir = temp.newFolder();
    JavaProcessLauncher.SystemProcessBuilder processBuilder = mock(JavaProcessLauncher.SystemProcessBuilder.class, RETURNS_MOCKS);
    when(processBuilder.start()).thenThrow(new IOException("error"));
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Fail to launch process [es]");
    underTest.launch(new JavaCommand(ProcessId.ELASTICSEARCH));
}
Also used : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 4 with JavaProcessLauncher

use of org.sonar.application.process.JavaProcessLauncher in project sonarqube by SonarSource.

the class App method start.

public void start(String[] cliArguments) throws IOException {
    AppSettingsLoader settingsLoader = new AppSettingsLoaderImpl(cliArguments);
    AppSettings settings = settingsLoader.load();
    // order is important - logging must be configured before any other components (AppFileSystem, ...)
    AppLogging logging = new AppLogging(settings);
    logging.configure();
    AppFileSystem fileSystem = new AppFileSystem(settings);
    try (AppState appState = new AppStateFactory(settings).create()) {
        appState.registerSonarQubeVersion(getSonarqubeVersion());
        AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging);
        JavaCommandFactory javaCommandFactory = new JavaCommandFactoryImpl(settings);
        fileSystem.reset();
        try (JavaProcessLauncher javaProcessLauncher = new JavaProcessLauncherImpl(fileSystem.getTempDir())) {
            Scheduler scheduler = new SchedulerImpl(settings, appReloader, javaCommandFactory, javaProcessLauncher, appState);
            // intercepts CTRL-C
            Runtime.getRuntime().addShutdownHook(new ShutdownHook(scheduler));
            scheduler.schedule();
            stopRequestWatcher = StopRequestWatcherImpl.create(settings, scheduler, fileSystem);
            stopRequestWatcher.startWatching();
            scheduler.awaitTermination();
            stopRequestWatcher.stopWatching();
        }
        systemExit.exit(0);
    }
}
Also used : JavaCommandFactoryImpl(org.sonar.application.process.JavaCommandFactoryImpl) AppSettings(org.sonar.application.config.AppSettings) AppSettingsLoader(org.sonar.application.config.AppSettingsLoader) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) AppSettingsLoaderImpl(org.sonar.application.config.AppSettingsLoaderImpl) JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommandFactory(org.sonar.application.process.JavaCommandFactory)

Aggregations

JavaProcessLauncher (org.sonar.application.process.JavaProcessLauncher)4 JavaProcessLauncherImpl (org.sonar.application.process.JavaProcessLauncherImpl)4 File (java.io.File)3 Test (org.junit.Test)3 JavaCommand (org.sonar.application.process.JavaCommand)3 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 AppSettings (org.sonar.application.config.AppSettings)1 AppSettingsLoader (org.sonar.application.config.AppSettingsLoader)1 AppSettingsLoaderImpl (org.sonar.application.config.AppSettingsLoaderImpl)1 JavaCommandFactory (org.sonar.application.process.JavaCommandFactory)1 JavaCommandFactoryImpl (org.sonar.application.process.JavaCommandFactoryImpl)1 ProcessMonitor (org.sonar.application.process.ProcessMonitor)1