Search in sources :

Example 6 with ProgressMonitor

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

the class PluginsSynchronizerTests method should_synchronize_a_plugin_when_hash_is_different.

@Test
void should_synchronize_a_plugin_when_hash_is_different(@TempDir Path tmp) throws Exception {
    var dest = tmp.resolve("destDir");
    Files.createDirectory(dest);
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"sonar-java-plugin-5.13.1.18282.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java");
    underTest = new PluginsSynchronizer(Set.of(Language.JAVA), new PluginsStorage(dest), emptySet());
    underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"79dba9cab72d8d31767f47c03d169598\", \"filename\": \"sonar-java-plugin-5.14.0.18485.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java2");
    var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    var references = ProtobufUtil.readFile(dest.resolve("plugin_references.pb"), PluginReferences.parser());
    assertThat(references.getPluginsByKeyMap().values()).extracting("key", "hash", "filename").containsOnly(tuple("java", "79dba9cab72d8d31767f47c03d169598", "sonar-java-plugin-5.14.0.18485.jar"));
    assertThat(dest.resolve("sonar-java-plugin-5.14.0.18485.jar")).hasContent("content-java2");
    assertThat(anyPluginUpdated).isTrue();
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.jupiter.api.Test)

Example 7 with ProgressMonitor

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

the class ConnectedSonarLintEngineImpl method updateProject.

@Override
public void updateProject(EndpointParams endpoint, HttpClient client, String projectKey, boolean fetchTaintVulnerabilities, @Nullable String branchName, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(endpoint);
    requireNonNull(projectKey);
    setLogging(null);
    var globalStorageStatus = globalStatusReader.read();
    if (globalStorageStatus == null || globalStorageStatus.isStale()) {
        throw new StorageException("Missing or outdated storage for connection '" + globalConfig.getConnectionId() + "'");
    }
    projectStorageUpdateExecutor.update(new ServerApiHelper(endpoint, client), projectKey, fetchTaintVulnerabilities, branchName, new ProgressMonitor(monitor));
}
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) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)

Example 8 with ProgressMonitor

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

the class StandaloneSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(StandaloneAnalysisConfiguration configuration, IssueListener issueListener, @Nullable ClientLogOutput logOutput, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(configuration);
    requireNonNull(issueListener);
    setLogging(logOutput);
    var analysisConfig = AnalysisConfiguration.builder().addInputFiles(configuration.inputFiles()).putAllExtraProperties(configuration.extraProperties()).addActiveRules(identifyActiveRules(configuration)).setBaseDir(configuration.baseDir()).build();
    try {
        var analysisResults = analysisEngine.post(new AnalyzeCommand(configuration.moduleKey(), analysisConfig, i -> issueListener.handle(new DefaultClientIssue(i, allRulesDefinitionsByKey.get(i.getRuleKey()))), 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) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) DefaultClientIssue(org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue)

Example 9 with ProgressMonitor

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

the class ConnectionValidator method validateConnection.

public CompletableFuture<ValidationResult> validateConnection() {
    var serverChecker = new ServerVersionAndStatusChecker(helper);
    var authChecker = new AuthenticationChecker(helper);
    return serverChecker.checkVersionAndStatusAsync().thenApply(check -> {
        var validateCredentials = authChecker.validateCredentials();
        var organizationKey = helper.getOrganizationKey();
        if (validateCredentials.success() && organizationKey.isPresent()) {
            var organization = new ServerApi(helper).organization().fetchOrganization(organizationKey.get(), new ProgressMonitor(null));
            if (organization.isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey.get());
            }
        }
        return validateCredentials;
    }).exceptionally(e -> new DefaultValidationResult(false, e.getCause().getMessage()));
}
Also used : AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) ServerOrganization(org.sonarsource.sonarlint.core.serverapi.organization.ServerOrganization) ValidationResult(org.sonarsource.sonarlint.core.serverapi.system.ValidationResult) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.serverapi.system.ServerVersionAndStatusChecker) AuthenticationChecker(org.sonarsource.sonarlint.core.serverapi.authentication.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.serverapi.system.DefaultValidationResult) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi)

Example 10 with ProgressMonitor

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

the class PluginsSynchronizerTests method should_synchronize_plugins.

@Test
void should_synchronize_plugins(@TempDir Path tmp) throws Exception {
    var dest = tmp.resolve("destDir");
    Files.createDirectory(dest);
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"sonar-java-plugin-5.13.1.18282.jar\", \"sonarLintSupported\": true}," + "{\"key\": \"javascript\", \"hash\": \"79dba9cab72d8d31767f47c03d169598\", \"filename\": \"sonar-javascript-plugin-5.2.1.7778.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java");
    mockServer.addStringResponse("/api/plugins/download?plugin=javascript", "content-js");
    underTest = new PluginsSynchronizer(Set.of(Language.JAVA, Language.JS), new PluginsStorage(dest), emptySet());
    var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    var references = ProtobufUtil.readFile(dest.resolve("plugin_references.pb"), PluginReferences.parser());
    assertThat(references.getPluginsByKeyMap().values()).extracting("key", "hash", "filename").containsOnly(tuple("java", "de5308f43260d357acc97712ce4c5475", "sonar-java-plugin-5.13.1.18282.jar"), tuple("javascript", "79dba9cab72d8d31767f47c03d169598", "sonar-javascript-plugin-5.2.1.7778.jar"));
    assertThat(dest.resolve("sonar-java-plugin-5.13.1.18282.jar")).hasContent("content-java");
    assertThat(dest.resolve("sonar-javascript-plugin-5.2.1.7778.jar")).hasContent("content-js");
    assertThat(anyPluginUpdated).isTrue();
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) 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