Search in sources :

Example 1 with PluginCache

use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache in project sonarlint-core by SonarSource.

the class ConnectedIssueMediumTest 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(ConnectedIssueMediumTest.class.getResource("/sample-storage").toURI());
    Path tmpStorage = slHome.resolve("storage");
    FileUtils.copyDirectory(storage.toFile(), tmpStorage.toFile());
    Files.move(tmpStorage.resolve("local"), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)));
    PluginCache cache = PluginCache.create(pluginCache);
    PluginReferences.Builder builder = PluginReferences.newBuilder();
    builder.addReference(PluginReference.newBuilder().setFilename(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH).setKey("javascript").build());
    cache.get(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR, PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH, new Copier() {

        @Override
        public void copy(String filename, Path toFile) throws IOException {
            FileUtils.copyURLToFile(PluginLocator.getJavaScriptPluginUrl(), toFile.toFile());
        }
    });
    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, new Copier() {

        @Override
        public void copy(String filename, Path toFile) throws IOException {
            FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), toFile.toFile());
        }
    });
    ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve(StoragePaths.encodeForFs(SERVER_ID)).resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
    // update versions in test storage and create an empty stale module storage
    writeModuleStatus(tmpStorage, "test-project", StoragePaths.STORAGE_VERSION);
    writeModuleStatus(tmpStorage, JAVA_MODULE_KEY, StoragePaths.STORAGE_VERSION);
    writeModuleStatus(tmpStorage, "stale_module", "0");
    writeStatus(tmpStorage, VersionUtils.getLibraryVersion());
    ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : Path(java.nio.file.Path) PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) Copier(org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) PluginCache(org.sonarsource.sonarlint.core.plugin.cache.PluginCache) IOException(java.io.IOException) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) BeforeClass(org.junit.BeforeClass)

Example 2 with PluginCache

use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache in project sonarlint-core by SonarSource.

the class DefaultPluginJarExploderTest method setUp.

@Before
public void setUp() throws IOException {
    userHome = temp.newFolder();
    PluginCache fileCache = new PluginCacheProvider().provide(StandaloneGlobalConfiguration.builder().setSonarLintUserHome(userHome.toPath()).build());
    underTest = new DefaultPluginJarExploder(fileCache);
}
Also used : PluginCacheProvider(org.sonarsource.sonarlint.core.plugin.cache.PluginCacheProvider) PluginCache(org.sonarsource.sonarlint.core.plugin.cache.PluginCache) Before(org.junit.Before)

Example 3 with PluginCache

use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache in project sonarlint-core by SonarSource.

the class BrokenStorageMissingPluginMediumTest 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" with references to java and javascript plugins but javascript is not in cache
     */
    Path storage = Paths.get(BrokenStorageMissingPluginMediumTest.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_JAVASCRIPT_PLUGIN_JAR).setHash(PluginLocator.SONAR_JAVASCRIPT_PLUGIN_JAR_HASH).setKey("javascript").build());
    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, new Copier() {

        @Override
        public void copy(String filename, Path toFile) throws IOException {
            FileUtils.copyURLToFile(PluginLocator.getJavaPluginUrl(), toFile.toFile());
        }
    });
    ProtobufUtil.writeToFile(builder.build(), tmpStorage.resolve("local").resolve("global").resolve(StoragePaths.PLUGIN_REFERENCES_PB));
    ConnectedGlobalConfiguration config = ConnectedGlobalConfiguration.builder().setServerId("local").setSonarLintUserHome(slHome).setStorageRoot(tmpStorage).setLogOutput(createNoOpLogOutput()).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    baseDir = temp.newFolder();
}
Also used : Path(java.nio.file.Path) PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) Copier(org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) PluginCache(org.sonarsource.sonarlint.core.plugin.cache.PluginCache) IOException(java.io.IOException) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) BeforeClass(org.junit.BeforeClass)

Example 4 with PluginCache

use of org.sonarsource.sonarlint.core.plugin.cache.PluginCache 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();
}
Also used : Path(java.nio.file.Path) PluginReferences(org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences) StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) PluginCache(org.sonarsource.sonarlint.core.plugin.cache.PluginCache) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) StoragePaths(org.sonarsource.sonarlint.core.container.storage.StoragePaths) BeforeClass(org.junit.BeforeClass)

Aggregations

PluginCache (org.sonarsource.sonarlint.core.plugin.cache.PluginCache)4 Path (java.nio.file.Path)3 BeforeClass (org.junit.BeforeClass)3 ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)3 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)3 PluginReferences (org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences)3 IOException (java.io.IOException)2 Copier (org.sonarsource.sonarlint.core.plugin.cache.PluginCache.Copier)2 Before (org.junit.Before)1 StoragePaths (org.sonarsource.sonarlint.core.container.storage.StoragePaths)1 StorageReader (org.sonarsource.sonarlint.core.container.storage.StorageReader)1 PluginCacheProvider (org.sonarsource.sonarlint.core.plugin.cache.PluginCacheProvider)1