Search in sources :

Example 1 with ServiceLoaderWrapper

use of org.sonar.core.extension.ServiceLoaderWrapper in project sonarqube by SonarSource.

the class CommandFactoryImplTest method newFactory.

private CommandFactoryImpl newFactory(Properties userProps, System2 system2) {
    Properties p = new Properties();
    p.setProperty("sonar.path.home", homeDir.getAbsolutePath());
    p.setProperty("sonar.path.temp", tempDir.getAbsolutePath());
    p.setProperty("sonar.path.logs", logsDir.getAbsolutePath());
    p.putAll(userProps);
    Props props = new Props(p);
    ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
    when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    return new CommandFactoryImpl(props, tempDir, system2);
}
Also used : ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) Props(org.sonar.process.Props) ProcessProperties(org.sonar.process.ProcessProperties)

Example 2 with ServiceLoaderWrapper

use of org.sonar.core.extension.ServiceLoaderWrapper in project sonarqube by SonarSource.

the class EsSettingsTest method minProps.

private Props minProps(boolean cluster, @Nullable String host, @Nullable String port) throws IOException {
    File homeDir = temp.newFolder();
    Props props = new Props(new Properties());
    ServiceLoaderWrapper serviceLoaderWrapper = mock(ServiceLoaderWrapper.class);
    when(serviceLoaderWrapper.load()).thenReturn(ImmutableSet.of());
    new ProcessProperties(serviceLoaderWrapper).completeDefaults(props);
    props.set(PATH_HOME.getKey(), homeDir.getAbsolutePath());
    props.set(Property.CLUSTER_ENABLED.getKey(), Boolean.toString(cluster));
    if (cluster) {
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_ES_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_ES_PORT.getKey(), p));
        ofNullable(host).ifPresent(h -> props.set(CLUSTER_NODE_SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(CLUSTER_NODE_SEARCH_PORT.getKey(), p));
        ofNullable(port).ifPresent(h -> props.set(CLUSTER_ES_HOSTS.getKey(), h));
    } else {
        ofNullable(host).ifPresent(h -> props.set(SEARCH_HOST.getKey(), h));
        ofNullable(port).ifPresent(p -> props.set(SEARCH_PORT.getKey(), p));
    }
    return props;
}
Also used : ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper) Props(org.sonar.process.Props) Properties(java.util.Properties) ProcessProperties(org.sonar.process.ProcessProperties) File(java.io.File) ProcessProperties(org.sonar.process.ProcessProperties)

Example 3 with ServiceLoaderWrapper

use of org.sonar.core.extension.ServiceLoaderWrapper in project sonarqube by SonarSource.

the class App method start.

public void start(String[] cliArguments) {
    AppSettingsLoader settingsLoader = new AppSettingsLoaderImpl(System2.INSTANCE, cliArguments, new ServiceLoaderWrapper());
    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());
        appState.registerClusterName(settings.getProps().nonNullValue(CLUSTER_NAME.getKey()));
        AppReloader appReloader = new AppReloaderImpl(settingsLoader, fileSystem, appState, logging);
        fileSystem.reset();
        CommandFactory commandFactory = new CommandFactoryImpl(settings.getProps(), fileSystem.getTempDir(), System2.INSTANCE);
        try (ProcessLauncher processLauncher = new ProcessLauncherImpl(fileSystem.getTempDir())) {
            Scheduler scheduler = new SchedulerImpl(settings, appReloader, commandFactory, processLauncher, appState);
            scheduler.schedule();
            stopRequestWatcher = StopRequestWatcherImpl.create(settings, scheduler, fileSystem);
            hardStopRequestWatcher = HardStopRequestWatcherImpl.create(scheduler, fileSystem);
            // intercepts CTRL-C
            Runtime.getRuntime().addShutdownHook(new ShutdownHook(scheduler));
            stopRequestWatcher.startWatching();
            hardStopRequestWatcher.startWatching();
            scheduler.awaitTermination();
            hardStopRequestWatcher.stopWatching();
        }
    } catch (Exception e) {
        Loggers.get(App.class).error("Startup failure", e);
    }
    systemExit.exit(0);
}
Also used : CommandFactoryImpl(org.sonar.application.command.CommandFactoryImpl) AppSettings(org.sonar.application.config.AppSettings) AppSettingsLoader(org.sonar.application.config.AppSettingsLoader) AppSettingsLoaderImpl(org.sonar.application.config.AppSettingsLoaderImpl) CommandFactory(org.sonar.application.command.CommandFactory) ServiceLoaderWrapper(org.sonar.core.extension.ServiceLoaderWrapper)

Aggregations

ServiceLoaderWrapper (org.sonar.core.extension.ServiceLoaderWrapper)3 Properties (java.util.Properties)2 ProcessProperties (org.sonar.process.ProcessProperties)2 Props (org.sonar.process.Props)2 File (java.io.File)1 CommandFactory (org.sonar.application.command.CommandFactory)1 CommandFactoryImpl (org.sonar.application.command.CommandFactoryImpl)1 AppSettings (org.sonar.application.config.AppSettings)1 AppSettingsLoader (org.sonar.application.config.AppSettingsLoader)1 AppSettingsLoaderImpl (org.sonar.application.config.AppSettingsLoaderImpl)1