Search in sources :

Example 21 with ActiveRulesBuilder

use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.

the class ModuleSensorOptimizerTest method should_optimize_on_repository.

@Test
public void should_optimize_on_repository() {
    DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().createIssuesForRuleRepositories("squid");
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    ActiveRules activeRules = new ActiveRulesBuilder().addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("repo1", "foo")).build()).build();
    optimizer = new ModuleSensorOptimizer(fs, activeRules, settings.asConfig());
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    activeRules = new ActiveRulesBuilder().addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("repo1", "foo")).build()).addRule(new NewActiveRule.Builder().setRuleKey(RuleKey.of("squid", "rule")).build()).build();
    optimizer = new ModuleSensorOptimizer(fs, activeRules, settings.asConfig());
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ActiveRules(org.sonar.api.batch.rule.ActiveRules) Test(org.junit.Test)

Example 22 with ActiveRulesBuilder

use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.

the class ModuleSensorContextTest method prepare.

@Before
public void prepare() throws Exception {
    activeRules = new ActiveRulesBuilder().build();
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    settings = new MapSettings();
    sensorStorage = mock(SensorStorage.class);
    branchConfiguration = mock(BranchConfiguration.class);
    runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MapSettings(org.sonar.api.config.internal.MapSettings) MetricFinder(org.sonar.api.batch.measure.MetricFinder) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Aggregations

ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)22 Test (org.junit.Test)11 ActiveRules (org.sonar.api.batch.rule.ActiveRules)9 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)9 Before (org.junit.Before)6 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)5 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)4 RulesProfile (org.sonar.api.profiles.RulesProfile)4 Map (java.util.Map)3 InputFile (org.sonar.api.batch.fs.InputFile)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 MapSettings (org.sonar.api.config.internal.MapSettings)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 MetricFinder (org.sonar.api.batch.measure.MetricFinder)2 CheckFactory (org.sonar.api.batch.rule.CheckFactory)2 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)2 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)2 File (java.io.File)1