Search in sources :

Example 1 with ActiveRulesBuilder

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

the class SensorOptimizerTest method prepare.

@Before
public void prepare() throws Exception {
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    settings = new MapSettings();
    optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) MapSettings(org.sonar.api.config.MapSettings) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 2 with ActiveRulesBuilder

use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarlint-core by SonarSource.

the class SensorOptimizerTest method prepare.

@Before
public void prepare() throws Exception {
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    settings = new MapSettings();
    optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 3 with ActiveRulesBuilder

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

the class WebSensorTest method setUp.

@Before
public void setUp() throws Exception {
    WebRulesDefinition rulesDefinition = new WebRulesDefinition();
    RulesDefinition.Context context = new RulesDefinition.Context();
    rulesDefinition.define(context);
    RulesDefinition.Repository repository = context.repository(WebRulesDefinition.REPOSITORY_KEY);
    List<NewActiveRule> ar = new ArrayList<>();
    for (RulesDefinition.Rule rule : repository.rules()) {
        ar.add(new ActiveRulesBuilder().create(RuleKey.of(WebRulesDefinition.REPOSITORY_KEY, rule.key())));
    }
    ActiveRules activeRules = new DefaultActiveRules(ar);
    CheckFactory checkFactory = new CheckFactory(activeRules);
    FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
    when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class));
    sensor = new WebSensor(new NoSonarFilter(), fileLinesContextFactory, checkFactory);
    tester = SensorContextTester.create(TEST_DIR);
}
Also used : FileLinesContext(org.sonar.api.measures.FileLinesContext) ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) FileLinesContextFactory(org.sonar.api.measures.FileLinesContextFactory) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) RulesDefinition(org.sonar.api.server.rule.RulesDefinition) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) CheckFactory(org.sonar.api.batch.rule.CheckFactory) WebRulesDefinition(org.sonar.plugins.web.rules.WebRulesDefinition) FileLinesContext(org.sonar.api.measures.FileLinesContext) Before(org.junit.Before)

Example 4 with ActiveRulesBuilder

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

the class SonarComponentsTest method ucfg_activation_should_rely_on_active_rules.

@Test
public void ucfg_activation_should_rely_on_active_rules() {
    File file = new File("src/test/files/ParseError.java");
    SensorContextTester sensorContext = SensorContextTester.create(file.getParentFile().getAbsoluteFile());
    SonarComponents sonarComponents = new SonarComponents(null, null, null, null, null);
    sonarComponents.setRuleRepositoryKey("squid");
    sonarComponents.setSensorContext(sensorContext);
    // no security rules available
    JavaRules.ruleKeys = new HashSet<>();
    assertThat(sonarComponents.shouldGenerateUCFG()).isFalse();
    ActiveRules activeRules = new ActiveRulesBuilder().create(RuleKey.of("squid", "S3649")).activate().build();
    // one security rule available
    JavaRules.ruleKeys = new HashSet<>(Arrays.asList("S3649"));
    sensorContext.setActiveRules(activeRules);
    assertThat(sonarComponents.shouldGenerateUCFG()).isTrue();
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) ActiveRules(org.sonar.api.batch.rule.ActiveRules) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 5 with ActiveRulesBuilder

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

the class SensorContextTesterTest method testActiveRules.

@Test
public void testActiveRules() {
    NewActiveRule activeRule = new NewActiveRule.Builder().setRuleKey(RuleKey.of("foo", "bar")).build();
    ActiveRules activeRules = new ActiveRulesBuilder().addRule(activeRule).build();
    tester.setActiveRules(activeRules);
    assertThat(tester.activeRules().findAll()).hasSize(1);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) 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)

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