Search in sources :

Example 6 with ConnectedSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class ConnectedStaleStorageMediumTest method test_stale_global.

@Test
public void test_stale_global() throws Exception {
    writeUpdateStatus(storage, "0");
    ConnectedSonarLintEngine sonarlint = new ConnectedSonarLintEngineImpl(config);
    assertThat(sonarlint.getState()).isEqualTo(State.NEED_UPDATE);
    assertThat(sonarlint.getGlobalStorageStatus()).isNotNull();
    assertThat(sonarlint.getModuleStorageStatus("foo")).isNull();
    try {
        sonarlint.allModulesByKey();
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.getRuleDetails("rule");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
    try {
        sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Collections.<ClientInputFile>emptyList(), ImmutableMap.<String, String>of()), mock(IssueListener.class), null, null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(GlobalUpdateRequiredException.class).hasMessage("Please update server 'localhost'");
    }
}
Also used : IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with ConnectedSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class ConnectedSonarLintImpl method start.

@Override
public void start(ConnectedConfiguration requestConfig, StreamObserver<Void> response) {
    if (engine != null) {
        engine.stop(false);
        engine = null;
    }
    try {
        Builder builder = ConnectedGlobalConfiguration.builder();
        if (requestConfig.getHomePath() != null) {
            builder.setSonarLintUserHome(Paths.get(requestConfig.getHomePath()));
        }
        builder.setLogOutput(logOutput).setServerId(requestConfig.getStorageId());
        engine = new ConnectedSonarLintEngineImpl(builder.build());
        response.onNext(Void.newBuilder().build());
        response.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Error registering", e);
        response.onError(e);
    }
}
Also used : Builder(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration.Builder) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)

Example 8 with ConnectedSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl 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 9 with ConnectedSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl 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)

Example 10 with ConnectedSonarLintEngineImpl

use of org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl in project sonarlint-core by SonarSource.

the class LicenseTest method start.

@Before
public void start() {
    FileUtils.deleteQuietly(sonarUserHome.toFile());
    engine = new ConnectedSonarLintEngineImpl(ConnectedGlobalConfiguration.builder().setServerId("orchestrator").setSonarLintUserHome(sonarUserHome).setLogOutput((msg, level) -> System.out.println(msg)).build());
    licenses = new Licenses();
}
Also used : BeforeClass(org.junit.BeforeClass) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) OrchestratorBuilder(com.sonar.orchestrator.OrchestratorBuilder) PropertyDeleteQuery(org.sonar.wsclient.services.PropertyDeleteQuery) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) WsClient(org.sonarqube.ws.client.WsClient) After(org.junit.After) Assume(org.junit.Assume) PropertyUpdateQuery(org.sonar.wsclient.services.PropertyUpdateQuery) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Before(org.junit.Before) PropertyCreateQuery(org.sonar.wsclient.services.PropertyCreateQuery) Licenses(com.sonar.orchestrator.config.Licenses) AfterClass(org.junit.AfterClass) RemoveGroupWsRequest(org.sonarqube.ws.client.permission.RemoveGroupWsRequest) MavenLocation(com.sonar.orchestrator.locator.MavenLocation) UserParameters(org.sonar.wsclient.user.UserParameters) URLLocation(com.sonar.orchestrator.locator.URLLocation) Version(com.sonar.orchestrator.version.Version) FileLocation(com.sonar.orchestrator.locator.FileLocation) SetRequest(org.sonarqube.ws.client.setting.SetRequest) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) Rule(org.junit.Rule) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) Assertions.fail(org.assertj.core.api.Assertions.fail) StringUtils(org.sonarsource.sonarlint.core.util.StringUtils) ResetRequest(org.sonarqube.ws.client.setting.ResetRequest) Orchestrator(com.sonar.orchestrator.Orchestrator) TemporaryFolder(org.junit.rules.TemporaryFolder) Licenses(com.sonar.orchestrator.config.Licenses) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Before(org.junit.Before)

Aggregations

ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)11 Path (java.nio.file.Path)8 BeforeClass (org.junit.BeforeClass)8 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)8 Test (org.junit.Test)5 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)5 IOException (java.io.IOException)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Before (org.junit.Before)4 ClassRule (org.junit.ClassRule)4 TemporaryFolder (org.junit.rules.TemporaryFolder)4 PluginReferences (org.sonarsource.sonarlint.core.proto.Sonarlint.PluginReferences)4 Orchestrator (com.sonar.orchestrator.Orchestrator)3 FileUtils (org.apache.commons.io.FileUtils)3 After (org.junit.After)3 Rule (org.junit.Rule)3 ExpectedException (org.junit.rules.ExpectedException)3 UserParameters (org.sonar.wsclient.user.UserParameters)3 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)3 PluginCache (org.sonarsource.sonarlint.core.plugin.cache.PluginCache)3