org.sonar.api.config.PropertyDefinitions Java Examples

The following examples show how to use org.sonar.api.config.PropertyDefinitions. 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 vote down vote up
@SuppressWarnings("unchecked")
private void initSettings(@Nullable String key, @Nullable String property) {
    final MapSettings mapSettings = new MapSettings(
            new PropertyDefinitions(new CheckstylePlugin().getExtensions()));
    if (Objects.nonNull(key)) {
        mapSettings.setProperty(key, property);
    }
    settings = new ConfigurationBridge(mapSettings);
}
 
Example #2
Source File: CheckstyleConfigurationTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
}