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);
}
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());
}
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);
}
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();
}
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);
}
Aggregations