Search in sources :

Example 1 with RuleRepositoryDto

use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.

the class RepositoriesAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String query = request.param(Param.TEXT_QUERY);
    String languageKey = request.param(LANGUAGE);
    JsonWriter json = response.newJsonWriter().beginObject().name("repositories").beginArray();
    for (RuleRepositoryDto repo : listMatchingRepositories(query, languageKey)) {
        json.beginObject().prop("key", repo.getKey()).prop("name", repo.getName()).prop(LANGUAGE, repo.getLanguage()).endObject();
    }
    json.endArray().endObject().close();
}
Also used : RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 2 with RuleRepositoryDto

use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.

the class RepositoriesActionTest method setUp.

@Before
public void setUp() {
    DbSession dbSession = dbTester.getSession();
    RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
    RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
    RuleRepositoryDto repo3 = new RuleRepositoryDto("common-ws", "ws", "SonarQube Common");
    dbTester.getDbClient().ruleRepositoryDao().insert(dbSession, asList(repo1, repo2, repo3));
    dbSession.commit();
    wsTester = new WsTester(new RulesWs(new RepositoriesAction(dbTester.getDbClient())));
}
Also used : DbSession(org.sonar.db.DbSession) WsTester(org.sonar.server.ws.WsTester) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) Before(org.junit.Before)

Example 3 with RuleRepositoryDto

use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.

the class AppActionTest method should_generate_app_init_info.

@Test
public void should_generate_app_init_info() throws Exception {
    AppAction app = new AppAction(languages, db.getDbClient(), i18n, userSessionRule, defaultOrganizationProvider);
    WsTester tester = new WsTester(new RulesWs(app));
    userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
    QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
    db.commit();
    Language xoo = mock(Language.class);
    when(xoo.getKey()).thenReturn("xoo");
    when(xoo.getName()).thenReturn("Xoo");
    Language whitespace = mock(Language.class);
    when(whitespace.getKey()).thenReturn("ws");
    when(whitespace.getName()).thenReturn("Whitespace");
    when(languages.get("xoo")).thenReturn(xoo);
    when(languages.all()).thenReturn(new Language[] { xoo, whitespace });
    RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
    RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
    db.getDbClient().ruleRepositoryDao().insert(db.getSession(), asList(repo1, repo2));
    db.getSession().commit();
    when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(invocation -> invocation.getArguments()[1]);
    tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}
Also used : Locale(java.util.Locale) WsTester(org.sonar.server.ws.WsTester) Language(org.sonar.api.resources.Language) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 4 with RuleRepositoryDto

use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.

the class RegisterRulesTest method delete_repositories_that_have_been_uninstalled.

@Test
public void delete_repositories_that_have_been_uninstalled() {
    RuleRepositoryDto repository = new RuleRepositoryDto("findbugs", "java", "Findbugs");
    DbSession dbSession = dbTester.getSession();
    dbTester.getDbClient().ruleRepositoryDao().insert(dbSession, asList(repository));
    dbSession.commit();
    execute(new FakeRepositoryV1());
    assertThat(dbTester.getDbClient().ruleRepositoryDao().selectAll(dbSession)).extracting(RuleRepositoryDto::getKey).containsOnly("fake");
}
Also used : DbSession(org.sonar.db.DbSession) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) Test(org.junit.Test)

Example 5 with RuleRepositoryDto

use of org.sonar.db.rule.RuleRepositoryDto in project sonarqube by SonarSource.

the class CompareAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String leftKey = request.mandatoryParam(PARAM_LEFT_KEY);
    String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);
    QProfileComparisonResult result = comparator.compare(leftKey, rightKey);
    try (DbSession dbSession = dbClient.openSession(false)) {
        List<RuleDto> referencedRules = dbClient.ruleDao().selectByKeys(dbSession, new ArrayList<>(result.collectRuleKeys()));
        Map<RuleKey, RuleDto> rulesByKey = Maps.uniqueIndex(referencedRules, RuleDtoToRuleKey.INSTANCE);
        Map<String, RuleRepositoryDto> repositoriesByKey = Maps.uniqueIndex(dbClient.ruleRepositoryDao().selectAll(dbSession), RuleRepositoryDto::getKey);
        writeResult(response.newJsonWriter(), result, rulesByKey, repositoriesByKey);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) RuleKey(org.sonar.api.rule.RuleKey) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QProfileComparisonResult(org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult)

Aggregations

RuleRepositoryDto (org.sonar.db.rule.RuleRepositoryDto)6 DbSession (org.sonar.db.DbSession)3 Test (org.junit.Test)2 WsTester (org.sonar.server.ws.WsTester)2 Locale (java.util.Locale)1 Before (org.junit.Before)1 Language (org.sonar.api.resources.Language)1 RuleKey (org.sonar.api.rule.RuleKey)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)1 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 QProfileComparisonResult (org.sonar.server.qualityprofile.QProfileComparison.QProfileComparisonResult)1