use of org.sonar.api.server.rule.RulesDefinition 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.server.rule.RulesDefinition in project sonarqube by SonarSource.
the class RuleDefinitionsLoader method load.
public RulesDefinition.Context load() {
RulesDefinition.Context context = new RulesDefinitionContext();
for (RulesDefinition pluginDefinition : pluginDefs) {
context.setCurrentPluginKey(serverPluginRepository.getPluginKey(pluginDefinition));
pluginDefinition.define(context);
}
context.setCurrentPluginKey(null);
coreCommonDefs.define(context);
return context;
}
use of org.sonar.api.server.rule.RulesDefinition in project sonarqube by SonarSource.
the class RegisterRulesTest method execute.
private void execute(RulesDefinition... defs) {
ServerPluginRepository pluginRepository = mock(ServerPluginRepository.class);
when(pluginRepository.getPluginKey(any(RulesDefinition.class))).thenReturn(FAKE_PLUGIN_KEY);
RuleDefinitionsLoader loader = new RuleDefinitionsLoader(mock(CommonRuleDefinitionsImpl.class), pluginRepository, defs);
Languages languages = mock(Languages.class);
when(languages.get(any())).thenReturn(mock(Language.class));
reset(webServerRuleFinder);
RegisterRules task = new RegisterRules(loader, qProfileRules, dbClient, ruleIndexer, activeRuleIndexer, languages, system, webServerRuleFinder, uuidFactory, metadataIndex);
task.start();
// Execute a commit to refresh session state as the task is using its own session
db.getSession().commit();
verify(webServerRuleFinder).startCaching();
}
use of org.sonar.api.server.rule.RulesDefinition in project sonarqube by SonarSource.
the class ScannerMediumTester method addRules.
public ScannerMediumTester addRules(RulesDefinition rulesDefinition) {
RulesDefinition.Context context = new RulesDefinitionContext();
rulesDefinition.define(context);
List<Repository> repositories = context.repositories();
for (Repository repo : repositories) {
for (RulesDefinition.Rule rule : repo.rules()) {
this.addRule(rule.key(), rule.repository().key(), rule.internalKey(), rule.name());
}
}
return this;
}
use of org.sonar.api.server.rule.RulesDefinition in project sonar-web by SonarSource.
the class HtmlSensorTest method setUp.
@Before
public void setUp() {
HtmlRulesDefinition rulesDefinition = new HtmlRulesDefinition();
RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
RulesDefinition.Repository repository = context.repository(HtmlRulesDefinition.REPOSITORY_KEY);
List<NewActiveRule> ar = new ArrayList<>();
for (RulesDefinition.Rule rule : repository.rules()) {
ar.add(new NewActiveRule.Builder().setRuleKey(RuleKey.of(HtmlRulesDefinition.REPOSITORY_KEY, rule.key())).build());
}
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));
final SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(8, 9), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
sensor = new HtmlSensor(sonarRuntime, new NoSonarFilter(), fileLinesContextFactory, checkFactory);
tester = SensorContextTester.create(TEST_DIR).setRuntime(sonarRuntime);
}
Aggregations