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;
}
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));
}
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;
}
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());
}
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);
}
Aggregations