org.sonar.api.batch.rule.internal.DefaultActiveRules Java Examples
The following examples show how to use
org.sonar.api.batch.rule.internal.DefaultActiveRules.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckstyleProfileExporterTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void activeRulesThrowsException() { try { new CheckstyleProfileExporter(settings).exportProfile( new DefaultActiveRules(Collections.emptyList()), new IoExceptionWriter()); Assert.fail("IOException while writing should not be ignored"); } catch (IllegalStateException ex) { Assertions.assertThat(ex.getMessage()).isEqualTo("Fail to export active rules."); } }
Example #2
Source File: CheckstyleConfigurationTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void writeConfigurationToWorkingDir() throws IOException { final CheckstyleProfileExporter exporter = new FakeExporter(); final CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter, new DefaultActiveRules(Collections.emptyList()), fileSystem); final File xmlFile = configuration.getXmlDefinitionFile(); assertThat(xmlFile.exists()).isTrue(); assertThat(FileUtils.readFileToString(xmlFile, StandardCharsets.UTF_8)) .isEqualTo("<conf/>"); FileUtils.forceDelete(xmlFile); }
Example #3
Source File: CheckstyleConfigurationTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void getCheckstyleConfiguration() throws Exception { fileSystem.setEncoding(StandardCharsets.UTF_8); final MapSettings mapSettings = new MapSettings(new PropertyDefinitions( new CheckstylePlugin().getExtensions())); mapSettings.setProperty(CheckstyleConstants.CHECKER_FILTERS_KEY, CheckstyleConstants.CHECKER_FILTERS_DEFAULT_VALUE); final org.sonar.api.config.Configuration settings = new ConfigurationBridge(mapSettings); final RulesProfile profile = RulesProfile.create("sonar way", "java"); final Rule rule = Rule.create("checkstyle", "CheckStyleRule1", "checkstyle rule one"); rule.setConfigKey("checkstyle/rule1"); profile.activateRule(rule, null); final CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings, new CheckstyleProfileExporter(settings), new DefaultActiveRules(Collections.emptyList()), fileSystem); final Configuration checkstyleConfiguration = configuration.getCheckstyleConfiguration(); assertThat(checkstyleConfiguration).isNotNull(); assertThat(checkstyleConfiguration.getAttribute("charset")).isEqualTo("UTF-8"); final File xmlFile = new File("checkstyle.xml"); assertThat(xmlFile.exists()).isTrue(); FileUtils.forceDelete(xmlFile); }
Example #4
Source File: HtlSensorTest.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private CheckFactory getCheckFactory(Repository htlRepository) { List<NewActiveRule> ar = new ArrayList<>(); for (RulesDefinition.Rule rule : htlRepository.rules()) { ar.add(new NewActiveRule.Builder().setRuleKey(RuleKey.of(HtlCheckClasses.REPOSITORY_KEY, rule.key())).build()); } return new CheckFactory(new DefaultActiveRules(ar)); }
Example #5
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { NewActiveRule ar = new ActiveRulesBuilder().create(RuleKey.of("lua", "S1125")).setSeverity("BLOCKER"); ActiveRules activeRules = new DefaultActiveRules(Collections.singletonList(ar)); CheckFactory checkFactory = new CheckFactory(activeRules); FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); when(fileLinesContextFactory.createFor(Mockito.any(InputFile.class))).thenReturn(mock(FileLinesContext.class)); sensor = new LuaSquidSensor(checkFactory, fileLinesContextFactory); tester = SensorContextTester.create(TEST_DIR); }