Search in sources :

Example 1 with Settings

use of org.sonar.api.config.Settings in project sonarqube by SonarSource.

the class DefaultDatabaseTest method shouldGuessDefaultDriver.

@Test
public void shouldGuessDefaultDriver() {
    Settings settings = new MapSettings();
    settings.setProperty("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
    DefaultDatabase database = new DefaultDatabase(logbackHelper, settings);
    database.initSettings();
    assertThat(database.getProperties().getProperty("sonar.jdbc.driverClassName")).isEqualTo("org.postgresql.Driver");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 2 with Settings

use of org.sonar.api.config.Settings in project sonarqube by SonarSource.

the class DefaultDatabaseTest method shouldCompleteProperties.

@Test
public void shouldCompleteProperties() {
    Settings settings = new MapSettings();
    DefaultDatabase db = new DefaultDatabase(logbackHelper, settings) {

        @Override
        protected void doCompleteProperties(Properties properties) {
            properties.setProperty("sonar.jdbc.maxActive", "2");
        }
    };
    db.initSettings();
    Properties props = db.getProperties();
    assertThat(props.getProperty("sonar.jdbc.maxActive")).isEqualTo("2");
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Properties(java.util.Properties) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 3 with Settings

use of org.sonar.api.config.Settings in project sonarqube by SonarSource.

the class LoadPeriodsStep method buildPeriod.

@CheckForNull
private Period buildPeriod(Component projectOrView, DbSession session) {
    Optional<ComponentDto> projectDto = dbClient.componentDao().selectByKey(session, projectOrView.getKey());
    // No project on first analysis, no period
    if (!projectDto.isPresent()) {
        return null;
    }
    boolean isReportType = projectOrView.getType().isReportType();
    PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectDto.get().uuid(), analysisMetadataHolder.getAnalysisDate(), isReportType ? projectOrView.getReportAttributes().getVersion() : null);
    Settings settings = settingsRepository.getSettings(projectOrView);
    Period period = periodResolver.resolve(settings);
    // SONAR-4700 Add a past snapshot only if it exists
    if (period != null) {
        return period;
    }
    return null;
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) Period(org.sonar.server.computation.task.projectanalysis.period.Period) Settings(org.sonar.api.config.Settings) CheckForNull(javax.annotation.CheckForNull)

Example 4 with Settings

use of org.sonar.api.config.Settings in project sonarqube by SonarSource.

the class LoadQualityGateStep method executeForProject.

private void executeForProject(Component project) {
    String projectKey = project.getKey();
    Settings settings = settingsRepository.getSettings(project);
    String qualityGateSetting = settings.getString(PROPERTY_QUALITY_GATE);
    if (qualityGateSetting == null || StringUtils.isBlank(qualityGateSetting)) {
        LOGGER.debug("No quality gate is configured for project " + projectKey);
        qualityGateHolder.setNoQualityGate();
        return;
    }
    try {
        long qualityGateId = Long.parseLong(qualityGateSetting);
        Optional<QualityGate> qualityGate = qualityGateService.findById(qualityGateId);
        if (qualityGate.isPresent()) {
            qualityGateHolder.setQualityGate(qualityGate.get());
        } else {
            qualityGateHolder.setNoQualityGate();
        }
    } catch (NumberFormatException e) {
        throw new IllegalStateException(String.format("Unsupported value (%s) in property %s", qualityGateSetting, PROPERTY_QUALITY_GATE), e);
    }
}
Also used : Settings(org.sonar.api.config.Settings) QualityGate(org.sonar.server.computation.task.projectanalysis.qualitygate.QualityGate)

Example 5 with Settings

use of org.sonar.api.config.Settings in project sonarqube by SonarSource.

the class EsClientProvider method provide.

public EsClient provide(Settings settings) {
    if (cache == null) {
        TransportClient nativeClient;
        org.elasticsearch.common.settings.Settings.Builder esSettings = org.elasticsearch.common.settings.Settings.builder();
        // mandatory property defined by bootstrap process
        esSettings.put("cluster.name", settings.getString(ProcessProperties.CLUSTER_NAME));
        boolean clusterEnabled = settings.getBoolean(ProcessProperties.CLUSTER_ENABLED);
        if (clusterEnabled && settings.getBoolean(ProcessProperties.CLUSTER_SEARCH_DISABLED)) {
            esSettings.put("client.transport.sniff", true);
            nativeClient = TransportClient.builder().settings(esSettings).build();
            Arrays.stream(settings.getStringArray(ProcessProperties.CLUSTER_SEARCH_HOSTS)).map(Host::parse).forEach(h -> h.addTo(nativeClient));
            LOGGER.info("Connected to remote Elasticsearch: [{}]", displayedAddresses(nativeClient));
        } else {
            nativeClient = TransportClient.builder().settings(esSettings).build();
            Host host = new Host(settings.getString(ProcessProperties.SEARCH_HOST), settings.getInt(ProcessProperties.SEARCH_PORT));
            host.addTo(nativeClient);
            LOGGER.info("Connected to local Elasticsearch: [{}]", displayedAddresses(nativeClient));
        }
        cache = new EsClient(nativeClient);
    }
    return cache;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) Settings(org.sonar.api.config.Settings)

Aggregations

Settings (org.sonar.api.config.Settings)50 MapSettings (org.sonar.api.config.MapSettings)43 Test (org.junit.Test)39 Before (org.junit.Before)5 Languages (org.sonar.api.resources.Languages)5 FileExclusions (org.sonar.api.scan.filesystem.FileExclusions)5 DefaultLanguagesRepository (org.sonar.scanner.repository.language.DefaultLanguagesRepository)5 LanguagesRepository (org.sonar.scanner.repository.language.LanguagesRepository)5 IndexedFile (org.sonar.api.batch.fs.IndexedFile)4 DefaultIndexedFile (org.sonar.api.batch.fs.internal.DefaultIndexedFile)4 File (java.io.File)3 String.format (java.lang.String.format)3 TransportClient (org.elasticsearch.client.transport.TransportClient)3 PropertyDto (org.sonar.db.property.PropertyDto)3 InetAddress (java.net.InetAddress)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Condition (org.assertj.core.api.Condition)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 Rule (org.junit.Rule)2 ExpectedException (org.junit.rules.ExpectedException)2