Search in sources :

Example 16 with ProgressMonitor

use of org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor in project sonarlint-core by SonarSource.

the class SensorsExecutorTests method testThrowingSensorShouldBeLogged.

@Test
void testThrowingSensorShouldBeLogged() {
    var sensorOptimizer = mock(SensorOptimizer.class);
    when(sensorOptimizer.shouldExecute(any())).thenReturn(true);
    var executor = new SensorsExecutor(null, sensorOptimizer, new ProgressMonitor(null), new Sensor[] { new ThrowingSensor() });
    executor.execute();
    assertThat(logTester.logs(ClientLogOutput.Level.ERROR)).contains("Error executing sensor: 'Throwing sensor'");
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) Test(org.junit.jupiter.api.Test)

Example 17 with ProgressMonitor

use of org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(ConnectedAnalysisConfiguration configuration, IssueListener issueListener, @Nullable ClientLogOutput logOutput, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(configuration);
    requireNonNull(issueListener);
    setLogging(logOutput);
    checkStatus(configuration.projectKey());
    var analysisConfigBuilder = AnalysisConfiguration.builder().addInputFiles(configuration.inputFiles());
    var projectKey = configuration.projectKey();
    if (projectKey != null) {
        analysisConfigBuilder.putAllExtraProperties(projectStorage.getAnalyzerConfiguration(projectKey).getSettings().getAll());
        analysisConfigBuilder.putAllExtraProperties(globalConfig.extraProperties());
    }
    var activeRulesContext = buildActiveRulesContext(configuration);
    analysisConfigBuilder.putAllExtraProperties(configuration.extraProperties()).addActiveRules(activeRulesContext.activeRules).setBaseDir(configuration.baseDir()).build();
    var analysisConfiguration = analysisConfigBuilder.build();
    try {
        var analysisResults = getAnalysisEngine().post(new AnalyzeCommand(configuration.moduleKey(), analysisConfiguration, issue -> streamIssue(issueListener, issue, activeRulesContext), logOutput), new ProgressMonitor(monitor)).get();
        return analysisResults == null ? new AnalysisResults() : analysisResults;
    } catch (Exception e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) DownloadException(org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)

Example 18 with ProgressMonitor

use of org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method sync.

@Override
public void sync(EndpointParams endpoint, HttpClient client, Set<String> projectKeys, @Nullable ClientProgressMonitor monitor) {
    var serverApi = new ServerApi(new ServerApiHelper(endpoint, client));
    var result = storageSynchronizer.synchronize(serverApi, projectKeys, new ProgressMonitor(monitor));
    if (result.hasAnalyzerBeenUpdated()) {
        restartAnalysisEngine();
    }
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)

Example 19 with ProgressMonitor

use of org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method update.

@Override
public UpdateResult update(EndpointParams endpoint, HttpClient client, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(endpoint);
    setLogging(null);
    globalStorageUpdateExecutor.update(new ServerApiHelper(endpoint, client), new ProgressMonitor(monitor));
    return new UpdateResult(globalStatusReader.read());
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)

Example 20 with ProgressMonitor

use of org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor in project sonarlint-core by SonarSource.

the class IssueApiTest method should_download_all_vulnerabilities.

@Test
void should_download_all_vulnerabilities() {
    mockServer.addProtobufResponse("/api/issues/search.protobuf?statuses=OPEN,CONFIRMED,REOPENED&types=VULNERABILITY&componentKeys=keyyy&rules=ruleKey&ps=500&p=1", Issues.SearchWsResponse.newBuilder().addIssues(Issues.Issue.newBuilder().setKey("issueKey").build()).build());
    mockServer.addProtobufResponse("/api/issues/search.protobuf?statuses=OPEN,CONFIRMED,REOPENED&types=VULNERABILITY&componentKeys=keyyy&rules=ruleKey&ps=500&p=2", Issues.SearchWsResponse.newBuilder().addComponents(Issues.Component.newBuilder().setKey("componentKey").setPath("componentPath").build()).build());
    var result = underTest.downloadVulnerabilitiesForRules("keyyy", Set.of("ruleKey"), null, new ProgressMonitor(null));
    assertThat(result.getIssues()).extracting("key").containsOnly("issueKey");
    assertThat(result.getComponentPathsByKey()).containsOnly(entry("componentKey", "componentPath"));
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) Test(org.junit.jupiter.api.Test)

Aggregations

ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)20 Test (org.junit.jupiter.api.Test)14 ServerApi (org.sonarsource.sonarlint.core.serverapi.ServerApi)12 ClientProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor)5 ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)4 AnalysisResults (org.sonarsource.sonarlint.core.analysis.api.AnalysisResults)2 AnalyzeCommand (org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)2 SonarLintWrappedException (org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException)2 StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)2 ServerProjectsStore (org.sonarsource.sonarlint.core.container.storage.ServerProjectsStore)2 StorageFolder (org.sonarsource.sonarlint.core.container.storage.StorageFolder)2 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DefaultClientIssue (org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue)1 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)1 DownloadException (org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException)1 AuthenticationChecker (org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker)1 ServerOrganization (org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization)1 DefaultValidationResult (org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult)1 ServerVersionAndStatusChecker (org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker)1