Search in sources :

Example 1 with ModuleConfiguration

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration in project sonarlint-core by SonarSource.

the class ModuleStorageUpdateChecker method checkForUpdates.

public StorageUpdateCheckResult checkForUpdates(String moduleKey, ProgressWrapper progress) {
    DefaultStorageUpdateCheckResult result = new DefaultStorageUpdateCheckResult();
    String serverVersion = storageReader.readServerInfos().getVersion();
    GlobalProperties globalProps = settingsDownloader.fetchGlobalSettings(serverVersion);
    ModuleConfiguration serverModuleConfiguration = moduleConfigurationDownloader.fetchModuleConfiguration(serverVersion, moduleKey, globalProps, progress);
    ModuleConfiguration storageModuleConfiguration = storageReader.readModuleConfig(moduleKey);
    checkForSettingsUpdates(result, serverModuleConfiguration, storageModuleConfiguration);
    checkForQualityProfilesUpdates(result, serverModuleConfiguration, storageModuleConfiguration);
    return result;
}
Also used : ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) GlobalProperties(org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)

Example 2 with ModuleConfiguration

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration in project sonarlint-core by SonarSource.

the class ModuleStorageUpdateExecutor method updateModuleConfiguration.

private void updateModuleConfiguration(String moduleKey, GlobalProperties globalProps, Path temp, ProgressWrapper progress) {
    ModuleConfiguration moduleConfiguration = moduleConfigurationDownloader.fetchModuleConfiguration(storageReader.readServerInfos().getVersion(), moduleKey, globalProps, progress);
    final Set<String> qProfileKeys = storageReader.readQProfiles().getQprofilesByKeyMap().keySet();
    for (String qpKey : moduleConfiguration.getQprofilePerLanguageMap().values()) {
        if (!qProfileKeys.contains(qpKey)) {
            throw new IllegalStateException("Module '" + moduleKey + "' is associated to quality profile '" + qpKey + "' that is not in the storage. " + "The SonarQube server binding is probably outdated,  please update it.");
        }
    }
    ProtobufUtil.writeToFile(moduleConfiguration, temp.resolve(StoragePaths.MODULE_CONFIGURATION_PB));
}
Also used : ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration)

Example 3 with ModuleConfiguration

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration in project sonarlint-core by SonarSource.

the class IssueStoreReader method getFileKey.

public String getFileKey(String moduleKey, String filePath) {
    ModuleConfiguration moduleConfig = storageReader.readModuleConfig(moduleKey);
    if (moduleConfig == null) {
        // unknown module
        throw new IllegalStateException("module not in storage: " + moduleKey);
    }
    Map<String, String> modulePaths = moduleConfig.getModulePathByKeyMap();
    // find longest prefix match
    String subModuleKey = moduleKey;
    int prefixLen = 0;
    for (Map.Entry<String, String> entry : modulePaths.entrySet()) {
        String entryModuleKey = entry.getKey();
        String entryPath = entry.getValue();
        if (!entryPath.isEmpty() && filePath.startsWith(entryPath) && prefixLen <= entryPath.length()) {
            subModuleKey = entryModuleKey;
            prefixLen = entryPath.length() + 1;
        }
    }
    String relativeFilePath = filePath.substring(prefixLen);
    return subModuleKey + ":" + relativeFilePath;
}
Also used : ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) Map(java.util.Map)

Example 4 with ModuleConfiguration

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration 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 5 with ModuleConfiguration

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration in project sonarlint-core by SonarSource.

the class ConnectedFileExclusionsMediumTest method fileInclusionsExclusions.

@Test
public void fileInclusionsExclusions() throws Exception {
    ClientInputFile mainFile1 = prepareInputFile("foo.xoo", "function xoo() {}", false);
    ClientInputFile mainFile2 = prepareInputFile("src/foo2.xoo", "function xoo() {}", false);
    ClientInputFile testFile1 = prepareInputFile("fooTest.xoo", "function xoo() {}", true);
    ClientInputFile testFile2 = prepareInputFile("test/foo2Test.xoo", "function xoo() {}", true);
    StoragePaths storagePaths = sonarlint.getGlobalContainer().getComponentByType(StoragePaths.class);
    StorageReader storageReader = sonarlint.getGlobalContainer().getComponentByType(StorageReader.class);
    ModuleConfiguration originalModuleConfig = storageReader.readModuleConfig(MODULE_KEY);
    int result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(4);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "file:**/src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.exclusions", "src/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.test.inclusions", "test/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.test.exclusions", "test/**"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(3);
    updateModuleConfig(storagePaths, originalModuleConfig, ImmutableMap.of("sonar.inclusions", "file:**/src/**", "sonar.test.exclusions", "**/*Test.*"));
    result = count(mainFile1, mainFile2, testFile1, testFile2);
    assertThat(result).isEqualTo(1);
}
Also used : StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) ModuleConfiguration(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) StoragePaths(org.sonarsource.sonarlint.core.container.storage.StoragePaths) Test(org.junit.Test)

Aggregations

ModuleConfiguration (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration)6 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)3 Map (java.util.Map)2 Test (org.junit.Test)2 StoragePaths (org.sonarsource.sonarlint.core.container.storage.StoragePaths)2 StorageReader (org.sonarsource.sonarlint.core.container.storage.StorageReader)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 Before (org.junit.Before)1