Search in sources :

Example 6 with ConnectedAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration 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 ConnectedAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration in project sonarlint-intellij by SonarSource.

the class ConnectedSonarLintFacade method analyze.

@Override
protected AnalysisResults analyze(Path baseDir, Path workDir, Collection<ClientInputFile> inputFiles, Map<String, String> props, IssueListener issueListener, ProgressMonitor progressMonitor) {
    ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(moduleKey, baseDir, workDir, inputFiles, props);
    console.debug("Starting analysis with configuration:\n" + config.toString());
    return sonarlint.analyze(config, issueListener, new ProjectLogOutput(console, projectSettings), progressMonitor);
}
Also used : ProjectLogOutput(org.sonarlint.intellij.util.ProjectLogOutput) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)

Example 8 with ConnectedAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration in project sonarlint-core by SonarSource.

the class ConnectedSonarLintImpl method analyze.

@Override
public void analyze(ConnectedAnalysisReq requestConfig, StreamObserver<org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Issue> response) {
    try {
        List<ClientInputFile> files = new LinkedList<>();
        List<InputFile> requestFiles = requestConfig.getFileList();
        Path baseDir = Paths.get(requestConfig.getBaseDir());
        for (InputFile f : requestFiles) {
            files.add(new DefaultClientInputFile(baseDir, Paths.get(f.getPath()), f.getIsTest(), Charset.forName(f.getCharset()), f.getUserObject(), trimToNull(f.getLanguage())));
        }
        ConnectedAnalysisConfiguration config = new ConnectedAnalysisConfiguration(requestConfig.getModuleKey(), baseDir, Paths.get(requestConfig.getWorkDir()), files, requestConfig.getPropertiesMap());
        engine.analyze(config, new ProxyIssueListener(response), logOutput, null);
        response.onCompleted();
    } catch (Exception e) {
        LOGGER.error("Error analyzing", e);
        response.onError(e);
    }
}
Also used : Path(java.nio.file.Path) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ProxyIssueListener(org.sonarlint.daemon.model.ProxyIssueListener) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) LinkedList(java.util.LinkedList) DefaultClientInputFile(org.sonarlint.daemon.model.DefaultClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) InputFile(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)

Example 9 with ConnectedAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration in project sonarlint-core by SonarSource.

the class BrokenStorageMissingPluginMediumTest method require_update.

@Test
public void require_update() throws Exception {
    assertThat(sonarlint.getState()).isEqualTo(ConnectedSonarLintEngine.State.NEED_UPDATE);
    ClientInputFile inputFile = prepareJavaInputFile();
    final List<Issue> issues = new ArrayList<>();
    try {
        sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).isExactlyInstanceOf(GlobalUpdateRequiredException.class);
    }
}
Also used : GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with ConnectedAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration in project sonarlint-core by SonarSource.

the class ConnectedEmptyStorageMediumTest method test_no_storage.

@Test
public void test_no_storage() throws Exception {
    assertThat(sonarlint.getState()).isEqualTo(State.NEVER_UPDATED);
    assertThat(sonarlint.getGlobalStorageStatus()).isNull();
    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) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) Test(org.junit.Test)

Aggregations

ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)13 Test (org.junit.Test)9 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)9 ArrayList (java.util.ArrayList)7 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)7 IOException (java.io.IOException)3 GlobalUpdateRequiredException (org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException)3 Path (java.nio.file.Path)2 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 DefaultClientInputFile (org.sonarlint.daemon.model.DefaultClientInputFile)1 ProxyIssueListener (org.sonarlint.daemon.model.ProxyIssueListener)1 ProjectLogOutput (org.sonarlint.intellij.util.ProjectLogOutput)1 ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)1 RuleDetails (org.sonarsource.sonarlint.core.client.api.common.RuleDetails)1 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)1 StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)1 InputFile (org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.InputFile)1