Search in sources :

Example 11 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonarlint-core by SonarSource.

the class StorageFileExclusions method getExcludedFiles.

public Set<String> getExcludedFiles(String moduleKey, Collection<String> filePaths, Predicate<String> testFilePredicate) {
    GlobalProperties globalProps = storageReader.readGlobalProperties();
    ModuleConfiguration moduleConfig = storageReader.readModuleConfig(moduleKey);
    MapSettings settings = new MapSettings();
    settings.addProperties(globalProps.getProperties());
    settings.addProperties(moduleConfig.getProperties());
    ExclusionFilters exclusionFilters = new ExclusionFilters(new ConfigurationBridge(settings));
    exclusionFilters.prepare();
    return filePaths.stream().filter(filePath -> !exclusionFilters.accept(filePath, testFilePredicate.test(filePath) ? Type.TEST : Type.MAIN)).collect(Collectors.toSet());
}
Also used : GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Type(org.sonar.api.batch.fs.InputFile.Type) ConfigurationBridge(org.sonar.api.config.internal.ConfigurationBridge) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) MapSettings(org.sonar.api.config.internal.MapSettings) Collectors(java.util.stream.Collectors) ExclusionFilters(org.sonarsource.sonarlint.core.container.analysis.ExclusionFilters) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties) MapSettings(org.sonar.api.config.internal.MapSettings) ExclusionFilters(org.sonarsource.sonarlint.core.container.analysis.ExclusionFilters) ConfigurationBridge(org.sonar.api.config.internal.ConfigurationBridge)

Example 12 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonarlint-core by SonarSource.

the class DefaultServerTest method shouldLoadServerProperties.

@Test
public void shouldLoadServerProperties() {
    SonarRuntime runtime = mock(SonarRuntime.class);
    when(runtime.getApiVersion()).thenReturn(Version.create(2, 2));
    Settings settings = new MapSettings();
    settings.setProperty(CoreProperties.SERVER_ID, "123");
    settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000");
    settings.setProperty(CoreProperties.PERMANENT_SERVER_ID, "abcde");
    DefaultServer metadata = new DefaultServer(settings, runtime);
    assertThat(metadata.getId()).isEqualTo("123");
    assertThat(metadata.getVersion()).isEqualTo("2.2");
    assertThat(metadata.getStartedAt()).isNotNull();
    assertThat(metadata.getURL()).isNull();
    assertThat(metadata.getPermanentServerId()).isEqualTo("abcde");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) SonarRuntime(org.sonar.api.SonarRuntime) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 13 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaTestClasspathTest method setUp.

@Before
public void setUp() throws Exception {
    fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
    TestInputFileBuilder inputFile = new TestInputFileBuilder("", "foo.java");
    inputFile.setLanguage("java");
    inputFile.setType(InputFile.Type.TEST);
    fs.add(inputFile.build());
    settings = new MapSettings();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 14 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaClasspathTest method setUp.

@Before
public void setUp() throws Exception {
    fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
    TestInputFileBuilder inputFile = new TestInputFileBuilder("", "foo.java");
    inputFile.setLanguage("java");
    inputFile.setType(InputFile.Type.MAIN);
    fs.add(inputFile.build());
    settings = new MapSettings();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 15 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaRulesDefinitionTest method debug_rules.

@Test
public void debug_rules() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.java.debug", true);
    JavaRulesDefinition definition = new JavaRulesDefinition(settings.asConfig());
    RulesDefinition.Context context = new RulesDefinition.Context();
    definition.define(context);
    RulesDefinition.Repository repository = context.repository("squid");
    assertThat(repository.name()).isEqualTo("SonarAnalyzer");
    assertThat(repository.language()).isEqualTo("java");
    assertThat(repository.rules()).hasSize(CheckList.getChecks().size() + CheckList.getDebugChecks().size());
}
Also used : RulesDefinition(org.sonar.api.server.rule.RulesDefinition) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Aggregations

MapSettings (org.sonar.api.config.internal.MapSettings)24 Test (org.junit.Test)11 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)11 File (java.io.File)9 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)5 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 SonarComponents (org.sonar.java.SonarComponents)4 JavaClasspath (org.sonar.java.JavaClasspath)3 Path (java.nio.file.Path)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SonarRuntime (org.sonar.api.SonarRuntime)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)2