Search in sources :

Example 6 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 7 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 8 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)

Example 9 with Settings

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

the class SettingsRepositoryTest method get_project_settings_from_db.

@Test
public void get_project_settings_from_db() {
    ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey());
    dbClient.componentDao().insert(session, project);
    dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value"));
    session.commit();
    Settings settings = underTest.getSettings(ROOT);
    assertThat(settings.getString("key")).isEqualTo("value");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) PropertyDto(org.sonar.db.property.PropertyDto) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) Test(org.junit.Test)

Example 10 with Settings

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

the class NotificationDaemonTest method setUpMocks.

private void setUpMocks() {
    when(emailChannel.getKey()).thenReturn("email");
    when(gtalkChannel.getKey()).thenReturn("gtalk");
    when(commentOnIssueAssignedToMe.getKey()).thenReturn("CommentOnIssueAssignedToMe");
    when(commentOnIssueAssignedToMe.getType()).thenReturn("issue-changes");
    when(commentOnIssueCreatedByMe.getKey()).thenReturn("CommentOnIssueCreatedByMe");
    when(commentOnIssueCreatedByMe.getType()).thenReturn("issue-changes");
    when(qualityGateChange.getKey()).thenReturn("QGateChange");
    when(qualityGateChange.getType()).thenReturn("qgate-changes");
    when(manager.getFromQueue()).thenReturn(notification).thenReturn(null);
    Settings settings = new MapSettings().setProperty("sonar.notifications.delay", 1L);
    underTest = new NotificationDaemon(settings, manager, service);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings)

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