use of org.sonar.application.process.JavaProcessLauncherImpl 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()));
}
}
use of org.sonar.application.process.JavaProcessLauncherImpl 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());
}
use of org.sonar.application.process.JavaProcessLauncherImpl 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));
}
use of org.sonar.application.process.JavaProcessLauncherImpl 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);
}
}
Aggregations