Java Code Examples for org.sonar.api.config.internal.MapSettings#setProperty()

The following examples show how to use org.sonar.api.config.internal.MapSettings#setProperty() . 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: CheckstyleConfigurationTest.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void getTargetXmlReport() {
    final org.sonar.api.config.Configuration settings =
            new ConfigurationBridge(new MapSettings());
    final CheckstyleConfiguration configuration = new CheckstyleConfiguration(settings,
            null, null, fileSystem);
    assertThat(configuration.getTargetXmlReport()).isNull();

    final MapSettings mapSettings = new MapSettings();
    mapSettings.setProperty(CheckstyleConfiguration.PROPERTY_GENERATE_XML, "true");
    final org.sonar.api.config.Configuration settings2 = new ConfigurationBridge(mapSettings);
    final CheckstyleConfiguration configuration2 = new CheckstyleConfiguration(settings2,
            null, null, fileSystem);
    assertThat(configuration2.getTargetXmlReport()).isEqualTo(
            new File(fileSystem.workDir(), "checkstyle-result.xml"));
}
 
Example 2
Source File: TraceSensorTest.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws FileNotFoundException {
	settings = new MapSettings();
	settings.setProperty("sonar.esql.trace.reportPaths", "TraceSensorTest/trace.txt");
	context = SensorContextTester.create(moduleBaseDir);
	context.setSettings(settings);

	InputFile inputFile1 = inputFile("file1.esql", Type.MAIN);
	InputFile inputFile2 = inputFile("file2.esql", Type.MAIN);
	InputFile inputFile3 = inputFile("file3.esql", Type.MAIN);
	// inputFile("tests/file1.esql", Type.TEST);

	linesOfCode = new HashMap<>();
	linesOfCode.put(inputFile1, ImmutableSet.of(1, 2, 3, 4));
	linesOfCode.put(inputFile2, null);
	linesOfCode.put(inputFile3, ImmutableSet.of(1, 2, 3, 4));

	sensor = new TraceSensor();

}
 
Example 3
Source File: CloverSensorTest.java    From sonar-clover with Apache License 2.0 6 votes vote down vote up
@Test
public void should_process_file() throws Exception {
  final String cloverFilePath = "org/sonar/plugins/clover/CloverXmlReportParserTest/clover_2_6_0.xml";
  final File cloverFile = TestUtils.getResource(cloverFilePath);
  final MapSettings settings = new MapSettings();
  settings.setProperty(CloverSensor.REPORT_PATH_PROPERTY, cloverFile.getAbsolutePath());

  final DefaultFileSystem fs = context.fileSystem();
  fs.add(new TestInputFileBuilder("", cloverFile.getAbsolutePath()).build());

  final Configuration configuration = new ConfigurationBridge(settings);
  final CloverSensor sensor = new CloverSensor(configuration, fs, new PathResolver());

  sensor.execute(context);

  assertThat(logTester.logs(LoggerLevel.INFO)).contains("Parsing " + cloverFile.getCanonicalPath());
  assertThat(logTester.logs(LoggerLevel.WARN).stream().anyMatch(s -> s.contains("14 files in Clover report did not match any file in SonarQube Index"))).isEqualTo(true);
}
 
Example 4
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 5
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);
}
 
Example 6
Source File: EsqlLanguageTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultSuffixes() {
 MapSettings mapSettings = new MapSettings();
 mapSettings.setProperty(EsqlLanguage.FILE_SUFFIXES_KEY, EsqlLanguage.FILE_SUFFIXES_DEFVALUE);
 EsqlLanguage esqlLanguage = new EsqlLanguage(mapSettings.asConfig());
 assertThat(esqlLanguage.getFileSuffixes()).containsOnly(".esql");

}
 
Example 7
Source File: EsqlLanguageTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void customSuffixes() {

 MapSettings mapSettings = new MapSettings();
 mapSettings.setProperty(EsqlLanguage.FILE_SUFFIXES_KEY, "esql");
 EsqlLanguage esqlLanguage = new EsqlLanguage(mapSettings.asConfig());
 assertThat(esqlLanguage.getFileSuffixes()).containsOnly("esql");

}
 
Example 8
Source File: EsqlExclusionsFileFilterTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_exclude_using_custom_path_regex() throws Exception {
    MapSettings settings = new MapSettings();
    settings.setProperty(
            EsqlPlugin.ESQL_EXCLUSIONS_KEY, EsqlPlugin.ESQL_EXCLUSIONS_DEFAULT_VALUE + "," + "**/libs/**");

    EsqlExclusionsFileFilter filter = new EsqlExclusionsFileFilter(settings.asConfig());

    assertThat(filter.accept(inputFile("some_app.esql"))).isTrue();
    assertThat(filter.accept(inputFile("libs/some_lib.esql"))).isFalse();
}
 
Example 9
Source File: EsqlExclusionsFileFilterTest.java    From sonar-esql-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_ignore_empty_path_regex() throws Exception {
    MapSettings settings = new MapSettings();
    settings.setProperty(EsqlPlugin.ESQL_EXCLUSIONS_KEY, "," + EsqlPlugin.ESQL_EXCLUSIONS_DEFAULT_VALUE + ",");

    EsqlExclusionsFileFilter filter = new EsqlExclusionsFileFilter(settings.asConfig());

    assertThat(filter.accept(inputFile("some_app.esql"))).isTrue();
}
 
Example 10
Source File: CloverSensorTest.java    From sonar-clover with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_interact_if_no_report_path() {
  final MapSettings settings = new MapSettings();
  settings.setProperty(CloverSensor.REPORT_PATH_PROPERTY, "");

  final Configuration configuration = new ConfigurationBridge(settings);
  final CloverSensor sensor = new CloverSensor(configuration, context.fileSystem(), new PathResolver());

  sensor.execute(context);

  assertThat(logTester.logs(LoggerLevel.WARN)).contains(
          CloverSensor.MISSING_FILE_MESSAGE);
}
 
Example 11
Source File: CrowdConfigurationTest.java    From sonar-crowd with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void usesFallbackForUnsetApplicationName() {
  MapSettings settings = new MapSettings();
  settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
  settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_PASSWORD, "secret");
  CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings.asConfig());
  assertThat(crowdConfiguration.getCrowdApplicationName(), is(CrowdConfiguration.FALLBACK_NAME));
}
 
Example 12
Source File: CrowdConfigurationTest.java    From sonar-crowd with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void createsClientProperties() {
  MapSettings settings = new MapSettings();
  settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
  settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_NAME, "SonarQube");
  settings.setProperty(CrowdConfiguration.KEY_CROWD_APP_PASSWORD, "secret");
  CrowdConfiguration crowdConfiguration = new CrowdConfiguration(settings.asConfig());

  assertThat(crowdConfiguration.getCrowdUrl(), is("http://localhost:8095"));
  assertThat(crowdConfiguration.getCrowdApplicationName(), is("SonarQube"));
  assertThat(crowdConfiguration.getCrowdApplicationPassword(), is("secret"));
}
 
Example 13
Source File: CrowdConfigurationTest.java    From sonar-crowd with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void applicationPasswordMissing() {
  MapSettings settings = new MapSettings();
  settings.setProperty(CrowdConfiguration.KEY_CROWD_URL, "http://localhost:8095");
  new CrowdConfiguration(settings.asConfig()).getCrowdApplicationPassword();
}