use of org.sonarsource.sonarlint.core.container.storage.StorageReader 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);
}
use of org.sonarsource.sonarlint.core.container.storage.StorageReader in project sonarlint-core by SonarSource.
the class ConnectedIssueExclusionsMediumTest method prepare.
@BeforeClass
public static void prepare() throws Exception {
Path slHome = temp.newFolder().toPath();
Path pluginCache = slHome.resolve("plugins");
/*
* This storage contains one server id "local" and two modules: "test-project" (with an empty QP) and "test-project-2" (with default QP)
*/
Path storage = Paths.get(ConnectedIssueExclusionsMediumTest.class.getResource("/sample-storage").toURI());
Path tmpStorage = slHome.resolve("storage");
FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
PluginCache cache = PluginCache.create(pluginCache);
PluginReferences.Builder builder = PluginReferences.newBuilder();
builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVA_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH).setKey("java").build());
cache.get(PluginLocator.SONAR_JAVA_PLUGIN_JAR, PluginLocator.SONAR_JAVA_PLUGIN_JAR_HASH, (filename, target) -> FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), target.toFile()));
ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve("local").resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
// update versions in test storage and create an empty stale module storage
writeModuleStatus(tmpStorage, "test-project", VersionUtils.getLibraryVersion());
writeModuleStatus(tmpStorage, JAVA_MODULE_KEY, VersionUtils.getLibraryVersion());
writeStatus(tmpStorage, VersionUtils.getLibraryVersion());
ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId("local").setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
sonarlint = new ConnectedSonarLintEngineImpl(config);
storagePaths = sonarlint.getGlobalContainer().getComponentByType(StoragePaths.class);
storageReader = sonarlint.getGlobalContainer().getComponentByType(StorageReader.class);
originalModuleConfig = storageReader.readModuleConfig(JAVA_MODULE_KEY);
baseDir = temp.newFolder();
}
use of org.sonarsource.sonarlint.core.container.storage.StorageReader in project sonarlint-core by SonarSource.
the class ModuleStorageUpdateExecutorTest method module_update.
@Test
public void module_update() throws Exception {
File destDir = temp.newFolder();
QProfiles.Builder builder = QProfiles.newBuilder();
builder.putQprofilesByKey("cs-sonar-way-58886", QProfiles.QProfile.newBuilder().build());
builder.putQprofilesByKey("java-empty-74333", QProfiles.QProfile.newBuilder().build());
builder.putQprofilesByKey("js-sonar-way-60746", QProfiles.QProfile.newBuilder().build());
builder.putQprofilesByKey("xoo2-basic-34035", QProfiles.QProfile.newBuilder().build());
when(storageReader.readQProfiles()).thenReturn(builder.build());
when(storagePaths.getModuleStorageRoot(MODULE_KEY_WITH_BRANCH)).thenReturn(destDir.toPath());
moduleUpdate = new ModuleStorageUpdateExecutor(storageReader, storagePaths, wsClient, (key) -> Collections.emptyList(), issueStoreFactory, tempFolder, moduleConfigurationDownloader);
moduleUpdate.update(MODULE_KEY_WITH_BRANCH, new ProgressWrapper(null));
ModuleConfiguration moduleConfiguration = ProtobufUtil.readFile(destDir.toPath().resolve(StoragePaths.MODULE_CONFIGURATION_PB), ModuleConfiguration.parser());
assertThat(moduleConfiguration.getQprofilePerLanguage()).containsOnly(entry("cs", "cs-sonar-way-58886"), entry("java", "java-empty-74333"), entry("js", "js-sonar-way-60746"));
assertThat(moduleConfiguration.getModulePathByKey()).containsOnly(entry(MODULE_KEY_WITH_BRANCH, ""), entry(MODULE_KEY_WITH_BRANCH + "child1", "child 1"));
}
Aggregations