Search in sources :

Example 36 with ProgressWrapper

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

the class ConnectedSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(ConnectedAnalysisConfiguration configuration, IssueListener issueListener, @Nullable LogOutput logOutput, @Nullable ProgressMonitor monitor) {
    checkNotNull(configuration);
    checkNotNull(issueListener);
    setLogging(logOutput);
    LoggedErrorHandler errorHandler = new LoggedErrorHandler(configuration.inputFiles());
    SonarLintLogging.setErrorHandler(errorHandler);
    return withReadLock(() -> {
        try {
            AnalysisResults results = getHandler().analyze(storageContainer.getGlobalExtensionContainer(), configuration, issueListener, new ProgressWrapper(monitor));
            errorHandler.getErrorFiles().forEach(results.failedAnalysisFiles()::add);
            return results;
        } catch (RuntimeException e) {
            throw SonarLintWrappedException.wrap(e);
        }
    });
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)

Example 37 with ProgressWrapper

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

the class StandaloneSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(StandaloneAnalysisConfiguration configuration, IssueListener issueListener, @Nullable LogOutput logOutput, @Nullable ProgressMonitor monitor) {
    checkNotNull(configuration);
    checkNotNull(issueListener);
    setLogging(logOutput);
    LoggedErrorHandler errorHandler = new LoggedErrorHandler(configuration.inputFiles());
    SonarLintLogging.setErrorHandler(errorHandler);
    rwl.readLock().lock();
    try {
        AnalysisResults results = globalContainer.analyze(configuration, issueListener, new ProgressWrapper(monitor));
        errorHandler.getErrorFiles().forEach(results.failedAnalysisFiles()::add);
        return results;
    } catch (RuntimeException e) {
        throw SonarLintWrappedException.wrap(e);
    } finally {
        rwl.readLock().unlock();
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)

Example 38 with ProgressWrapper

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

the class WsHelperImpl method validateConnection.

static ValidationResult validateConnection(SonarLintWsClient client, @Nullable String organizationKey) {
    ServerVersionAndStatusChecker serverChecker = new ServerVersionAndStatusChecker(client);
    AuthenticationChecker authChecker = new AuthenticationChecker(client);
    try {
        ServerInfos serverStatus = serverChecker.checkVersionAndStatus();
        ValidationResult validateCredentials = authChecker.validateCredentials();
        if (validateCredentials.success() && organizationKey != null) {
            Version serverVersion = Version.create(serverStatus.getVersion());
            if (serverVersion.compareToIgnoreQualifier(Version.create(MIN_VERSION_FOR_ORGANIZATIONS)) < 0) {
                return new DefaultValidationResult(false, "No organization support for this server version: " + serverStatus.getVersion());
            }
            if (fetchOrganizations(client, organizationKey, new ProgressWrapper(null)).isEmpty()) {
                return new DefaultValidationResult(false, "No organizations found for key: " + organizationKey);
            }
        }
        return validateCredentials;
    } catch (UnsupportedServerException e) {
        return new DefaultValidationResult(false, e.getMessage());
    } catch (RuntimeException e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ServerVersionAndStatusChecker(org.sonarsource.sonarlint.core.container.connected.validate.ServerVersionAndStatusChecker) Version(org.sonarsource.sonarlint.core.plugin.Version) AuthenticationChecker(org.sonarsource.sonarlint.core.container.connected.validate.AuthenticationChecker) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) DefaultValidationResult(org.sonarsource.sonarlint.core.container.connected.validate.DefaultValidationResult) UnsupportedServerException(org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)

Aggregations

ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)38 Test (org.junit.Test)31 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)14 File (java.io.File)11 StorageUpdateCheckResult (org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult)9 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)8 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)6 Path (java.nio.file.Path)5 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.entry (org.assertj.core.api.Assertions.entry)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 ExpectedException (org.junit.rules.ExpectedException)4