Java源码示例:org.sonar.api.batch.rule.internal.DefaultActiveRules
示例1
@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.");
}
}
示例2
@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);
}
示例3
@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);
}
示例4
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));
}
示例5
@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);
}