Search in sources :

Example 1 with ModuleQProfiles

use of org.sonar.scanner.rule.ModuleQProfiles in project sonarqube by SonarSource.

the class QualityProfileProviderTest method testProvide.

@Test
public void testProvide() {
    when(loader.load(eq("project"), isNull(String.class))).thenReturn(response);
    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
    assertResponse(qps);
    verify(loader).load(eq("project"), isNull(String.class));
    verifyNoMoreInteractions(loader);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Test(org.junit.Test)

Example 2 with ModuleQProfiles

use of org.sonar.scanner.rule.ModuleQProfiles in project sonarqube by SonarSource.

the class QualityProfileProviderTest method testProfilePropDefault.

@Test
public void testProfilePropDefault() {
    when(projectRepo.exists()).thenReturn(false);
    when(loader.loadDefault(eq("custom"))).thenReturn(response);
    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
    when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
    assertResponse(qps);
    verify(loader).loadDefault(eq("custom"));
    verifyNoMoreInteractions(loader);
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
}
Also used : ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Test(org.junit.Test)

Example 3 with ModuleQProfiles

use of org.sonar.scanner.rule.ModuleQProfiles in project sonarqube by SonarSource.

the class ActiveRulesProviderTest method testCombinationOfRules.

@Test
public void testCombinationOfRules() {
    LoadedActiveRule r1 = mockRule("rule1");
    LoadedActiveRule r2 = mockRule("rule2");
    LoadedActiveRule r3 = mockRule("rule3");
    List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2);
    List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
    List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
    when(loader.load(eq("qp1"))).thenReturn(qp1Rules);
    when(loader.load(eq("qp2"))).thenReturn(qp2Rules);
    when(loader.load(eq("qp3"))).thenReturn(qp3Rules);
    ModuleQProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
    ActiveRules activeRules = provider.provide(loader, profiles);
    assertThat(activeRules.findAll()).hasSize(3);
    assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
    verify(loader).load(eq("qp1"));
    verify(loader).load(eq("qp2"));
    verify(loader).load(eq("qp3"));
    verifyNoMoreInteractions(loader);
}
Also used : ActiveRules(org.sonar.api.batch.rule.ActiveRules) LoadedActiveRule(org.sonar.scanner.rule.LoadedActiveRule) ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Test(org.junit.Test)

Example 4 with ModuleQProfiles

use of org.sonar.scanner.rule.ModuleQProfiles 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 5 with ModuleQProfiles

use of org.sonar.scanner.rule.ModuleQProfiles in project sonarqube by SonarSource.

the class QualityProfileProviderTest method testProfileProp.

@Test
public void testProfileProp() {
    when(loader.load(eq("project"), eq("custom"))).thenReturn(response);
    when(props.property(ModuleQProfiles.SONAR_PROFILE_PROP)).thenReturn("custom");
    when(props.properties()).thenReturn(ImmutableMap.of(ModuleQProfiles.SONAR_PROFILE_PROP, "custom"));
    ModuleQProfiles qps = qualityProfileProvider.provide(key, loader, projectRepo, props);
    assertResponse(qps);
    verify(loader).load(eq("project"), eq("custom"));
    verifyNoMoreInteractions(loader);
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
}
Also used : ModuleQProfiles(org.sonar.scanner.rule.ModuleQProfiles) Test(org.junit.Test)

Aggregations

ModuleQProfiles (org.sonar.scanner.rule.ModuleQProfiles)7 Test (org.junit.Test)5 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)2 LinkedList (java.util.LinkedList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 Profiler (org.sonar.api.utils.log.Profiler)1 LoadedActiveRule (org.sonar.scanner.rule.LoadedActiveRule)1