Search in sources :

Example 11 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class QualityProfileProvider method provide.

public ModuleQProfiles provide(ProjectKey projectKey, QualityProfileLoader loader, ProjectRepositories projectRepositories, AnalysisProperties props) {
    if (this.profiles == null) {
        List<QualityProfile> profileList;
        Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
        if (!projectRepositories.exists()) {
            profileList = loader.loadDefault(getSonarProfile(props));
        } else {
            profileList = loader.load(projectKey.get(), getSonarProfile(props));
        }
        profiler.stopInfo();
        profiles = new ModuleQProfiles(profileList);
    }
    return profiles;
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles)

Example 12 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarlint-core by SonarSource.

the class QualityProfilesDownloader method fetchQualityProfiles.

public QProfiles fetchQualityProfiles() {
    QProfiles.Builder qProfileBuilder = QProfiles.newBuilder();
    String searchUrl = DEFAULT_QP_SEARCH_URL;
    if (wsClient.getOrganizationKey() != null) {
        searchUrl += "?organization=" + StringUtils.urlEncode(wsClient.getOrganizationKey());
    }
    try (InputStream contentStream = wsClient.get(searchUrl).contentStream()) {
        SearchWsResponse qpResponse = QualityProfiles.SearchWsResponse.parseFrom(contentStream);
        for (QualityProfile qp : qpResponse.getProfilesList()) {
            QProfile.Builder qpBuilder = QProfile.newBuilder();
            qpBuilder.setKey(qp.getKey());
            qpBuilder.setName(qp.getName());
            qpBuilder.setLanguage(qp.getLanguage());
            qpBuilder.setLanguageName(qp.getLanguageName());
            qpBuilder.setActiveRuleCount(qp.getActiveRuleCount());
            qpBuilder.setRulesUpdatedAt(qp.getRulesUpdatedAt());
            qpBuilder.setUserUpdatedAt(qp.getUserUpdatedAt());
            qProfileBuilder.putQprofilesByKey(qp.getKey(), qpBuilder.build());
            if (qp.getIsDefault()) {
                qProfileBuilder.putDefaultQProfilesByLanguage(qp.getLanguage(), qp.getKey());
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Failed to load default quality profiles", e);
    }
    return qProfileBuilder.build();
}
Also used : InputStream(java.io.InputStream) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) IOException(java.io.IOException) QProfile(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)

Example 13 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class DefaultQualityProfileLoaderTest method createStreamOfProfiles.

private static InputStream createStreamOfProfiles(String... names) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Qualityprofiles.SearchWsResponse.Builder responseBuilder = Qualityprofiles.SearchWsResponse.newBuilder();
    for (String n : names) {
        QualityProfile qp = QualityProfile.newBuilder().setKey(n).setName(n).setLanguage("lang").build();
        responseBuilder.addProfiles(qp);
    }
    responseBuilder.build().writeTo(os);
    return new ByteArrayInputStream(os.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class ActiveRulesProviderTest method mockProfiles.

private static QualityProfiles mockProfiles(String... keys) {
    List<QualityProfile> profiles = new LinkedList<>();
    for (String k : keys) {
        QualityProfile p = QualityProfile.newBuilder().setKey(k).setLanguage(k).setRulesUpdatedAt(DateUtils.formatDateTime(new Date())).build();
        profiles.add(p);
    }
    return new QualityProfiles(profiles);
}
Also used : QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 15 with QualityProfile

use of org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile in project sonarqube by SonarSource.

the class SearchActionTest method actions_when_user_can_edit_profile.

@Test
public void actions_when_user_can_edit_profile() {
    QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
    QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
    QProfileDto profile3 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
    QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()).setIsBuiltIn(true));
    UserDto user = db.users().insertUser();
    GroupDto group = db.users().insertGroup();
    db.qualityProfiles().addUserPermission(profile1, user);
    db.qualityProfiles().addGroupPermission(profile3, group);
    userSession.logIn(user).setGroups(group);
    SearchWsResponse result = call(ws.newRequest());
    assertThat(result.getProfilesList()).extracting(QualityProfile::getKey, qp -> qp.getActions().getEdit(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getDelete(), qp -> qp.getActions().getAssociateProjects()).containsExactlyInAnyOrder(tuple(profile1.getKee(), true, false, false, true, true), tuple(profile2.getKee(), false, false, false, false, false), tuple(profile3.getKee(), true, false, false, true, true), tuple(builtInProfile.getKee(), false, false, false, false, false));
    assertThat(result.getActions().getCreate()).isFalse();
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) IntStream.range(java.util.stream.IntStream.range) GlobalPermission(org.sonar.db.permission.GlobalPermission) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Languages(org.sonar.api.resources.Languages) QualityProfileDbTester(org.sonar.db.qualityprofile.QualityProfileDbTester) PARAM_PROJECT(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_LANGUAGE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE) PARAM_DEFAULTS(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_DEFAULTS) MediaTypes(org.sonarqube.ws.MediaTypes) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Language(org.sonar.api.resources.Language) PARAM_QUALITY_PROFILE(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_QUALITY_PROFILE) PARAM_PROJECT_KEY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROJECT_KEY) GroupDto(org.sonar.db.user.GroupDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) QualityProfile(org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) DEPRECATED(org.sonar.api.rule.RuleStatus.DEPRECATED) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) Rule(org.junit.Rule) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ProjectDto(org.sonar.db.project.ProjectDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Change(org.sonar.api.server.ws.Change) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) SearchWsResponse(org.sonarqube.ws.Qualityprofiles.SearchWsResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 QualityProfile (org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile)16 SearchWsResponse (org.sonarqube.ws.Qualityprofiles.SearchWsResponse)13 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)12 ProjectDto (org.sonar.db.project.ProjectDto)7 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)7 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 InputStream (java.io.InputStream)4 List (java.util.List)4 IntStream.range (java.util.stream.IntStream.range)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Rule (org.junit.Rule)4 Language (org.sonar.api.resources.Language)4 Languages (org.sonar.api.resources.Languages)4 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)4 Change (org.sonar.api.server.ws.Change)4 WebService (org.sonar.api.server.ws.WebService)4 DateUtils (org.sonar.api.utils.DateUtils)4