Search in sources :

Example 11 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 12 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)

Example 13 with Settings

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

the class WebhookPostTask method finished.

@Override
public void finished(ProjectAnalysis analysis) {
    Settings settings = settingsRepository.getSettings(rootHolder.getRoot());
    Iterable<String> webhookProps = Iterables.concat(getWebhookProperties(settings, WebhookProperties.GLOBAL_KEY), getWebhookProperties(settings, WebhookProperties.PROJECT_KEY));
    if (!Iterables.isEmpty(webhookProps)) {
        process(settings, analysis, webhookProps);
        deliveryStorage.purge(analysis.getProject().getUuid());
    }
}
Also used : Settings(org.sonar.api.config.Settings)

Example 14 with Settings

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

the class UserUpdater method addDefaultGroup.

private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
    String defaultGroupName = settings.getString(CoreProperties.CORE_DEFAULT_GROUP);
    if (defaultGroupName == null) {
        return;
    }
    String defOrgUuid = defaultOrganizationProvider.get().getUuid();
    List<GroupDto> userGroups = dbClient.groupDao().selectByUserLogin(dbSession, userDto.getLogin());
    if (!userGroups.stream().anyMatch(g -> defOrgUuid.equals(g.getOrganizationUuid()) && g.getName().equals(defaultGroupName))) {
        Optional<GroupDto> groupDto = dbClient.groupDao().selectByName(dbSession, defOrgUuid, defaultGroupName);
        if (!groupDto.isPresent()) {
            throw new ServerException(HttpURLConnection.HTTP_INTERNAL_ERROR, format("The default group '%s' for new users does not exist. Please update the general security settings to fix this issue.", defaultGroupName));
        }
        dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(groupDto.get().getId()));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) UserGroupDto(org.sonar.db.user.UserGroupDto) UserDto(org.sonar.db.user.UserDto) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Random(java.util.Random) ServerException(org.sonar.server.exceptions.ServerException) DbSession(org.sonar.db.DbSession) SecureRandom(java.security.SecureRandom) Strings(com.google.common.base.Strings) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OrganizationCreation(org.sonar.server.organization.OrganizationCreation) WsUtils.checkFound(org.sonar.server.ws.WsUtils.checkFound) WsUtils.checkRequest(org.sonar.server.ws.WsUtils.checkRequest) Validation(org.sonar.server.util.Validation) NewUserHandler(org.sonar.api.platform.NewUserHandler) Nullable(javax.annotation.Nullable) GroupDto(org.sonar.db.user.GroupDto) DefaultOrganizationProvider(org.sonar.server.organization.DefaultOrganizationProvider) System2(org.sonar.api.utils.System2) CoreProperties(org.sonar.api.CoreProperties) Collectors(org.sonar.core.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) UserIndexer(org.sonar.server.user.index.UserIndexer) DbClient(org.sonar.db.DbClient) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) UserDto.encryptPassword(org.sonar.db.user.UserDto.encryptPassword) Settings(org.sonar.api.config.Settings) ServerSide(org.sonar.api.server.ServerSide) Optional(java.util.Optional) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ServerException(org.sonar.server.exceptions.ServerException) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto)

Example 15 with Settings

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

the class CeHttpClientTest method setUp.

@Before
public void setUp() throws Exception {
    ipcSharedDir = temp.newFolder();
    Settings settings = new MapSettings();
    settings.setProperty(ProcessEntryPoint.PROPERTY_SHARED_PATH, ipcSharedDir.getAbsolutePath());
    underTest = new CeHttpClient(settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Before(org.junit.Before)

Aggregations

Settings (org.sonar.api.config.Settings)52 MapSettings (org.sonar.api.config.MapSettings)43 Test (org.junit.Test)41 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