Search in sources :

Example 1 with SonarAnalyzer

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

the class ConnectedSonarLintEngineImpl method update.

@Override
public UpdateResult update(ServerConfiguration serverConfig, @Nullable ProgressMonitor monitor) {
    checkNotNull(serverConfig);
    setLogging(null);
    return withRwLock(() -> {
        stop(false);
        changeState(State.UPDATING);
        List<SonarAnalyzer> analyzers;
        try {
            analyzers = runInConnectedContainer(serverConfig, container -> container.update(new ProgressWrapper(monitor)));
        } finally {
            start();
        }
        return new UpdateResult(getHandler().getGlobalStorageStatus(), analyzers);
    });
}
Also used : LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) LoggerFactory(org.slf4j.LoggerFactory) ModuleStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ModuleStorageStatus) GlobalUpdateRequiredException(org.sonarsource.sonarlint.core.client.api.exceptions.GlobalUpdateRequiredException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) RemoteModule(org.sonarsource.sonarlint.core.client.api.connected.RemoteModule) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) Map(java.util.Map) StorageContainerHandler(org.sonarsource.sonarlint.core.container.storage.StorageContainerHandler) LoadedAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.LoadedAnalyzer) SonarLintLogging(org.sonarsource.sonarlint.core.log.SonarLintLogging) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Nullable(javax.annotation.Nullable) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) StorageUpdateCheckResult(org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult) StorageContainer(org.sonarsource.sonarlint.core.container.storage.StorageContainer) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Logger(org.slf4j.Logger) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) StateListener(org.sonarsource.sonarlint.core.client.api.connected.StateListener) List(java.util.List) ConnectedContainer(org.sonarsource.sonarlint.core.container.connected.ConnectedContainer) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)

Example 2 with SonarAnalyzer

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

the class GlobalStorageUpdateChecker method checkForUpdate.

public StorageUpdateCheckResult checkForUpdate(ProgressWrapper progress) {
    DefaultStorageUpdateCheckResult result = new DefaultStorageUpdateCheckResult();
    progress.setProgressAndCheckCancel("Checking server version and status", 0.1f);
    ServerInfos serverStatus = statusChecker.checkVersionAndStatus();
    // Currently with don't check server version change since it is unlikely to have impact on SL
    progress.setProgressAndCheckCancel("Checking global properties", 0.3f);
    globalSettingsUpdateChecker.checkForUpdates(serverStatus.getVersion(), result);
    progress.setProgressAndCheckCancel("Checking plugins", 0.5f);
    List<SonarAnalyzer> pluginList = pluginListDownloader.downloadPluginList(serverStatus.getVersion());
    pluginsUpdateChecker.checkForUpdates(result, pluginList);
    progress.setProgressAndCheckCancel("Checking quality profiles", 0.7f);
    qualityProfilesUpdateChecker.checkForUpdates(result);
    progress.setProgressAndCheckCancel("Done", 1.0f);
    return result;
}
Also used : SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Example 3 with SonarAnalyzer

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

the class GlobalStorageUpdateExecutor method update.

public List<SonarAnalyzer> update(ProgressWrapper progress) {
    Path temp = tempFolder.newDir().toPath();
    try {
        progress.setProgressAndCheckCancel("Checking server version and status", 0.1f);
        ServerInfos serverStatus = statusChecker.checkVersionAndStatus();
        progress.setProgressAndCheckCancel("Fetching list of analyzers", 0.12f);
        List<SonarAnalyzer> analyzers = pluginListDownloader.downloadPluginList(serverStatus.getVersion());
        ProtobufUtil.writeToFile(serverStatus, temp.resolve(StoragePaths.SERVER_INFO_PB));
        progress.setProgressAndCheckCancel("Fetching global properties", 0.15f);
        globalSettingsDownloader.fetchGlobalSettingsTo(serverStatus.getVersion(), temp);
        progress.setProgressAndCheckCancel("Fetching analyzers", 0.25f);
        pluginReferenceDownloader.fetchPluginsTo(temp, analyzers);
        progress.setProgressAndCheckCancel("Fetching rules", 0.4f);
        rulesDownloader.fetchRulesTo(temp, progress.subProgress(0.4f, 0.6f, "Fetching rules"));
        progress.setProgressAndCheckCancel("Fetching quality profiles", 0.6f);
        qualityProfilesDownloader.fetchQualityProfilesTo(temp);
        progress.setProgressAndCheckCancel("Fetching list of modules", 0.8f);
        moduleListDownloader.fetchModulesListTo(temp, serverStatus.getVersion(), progress.subProgress(0.8f, 1.0f, "Fetching list of modules"));
        progress.startNonCancelableSection();
        progress.setProgressAndCheckCancel("Finalizing...", 1.0f);
        StorageStatus storageStatus = StorageStatus.newBuilder().setStorageVersion(StoragePaths.STORAGE_VERSION).setClientUserAgent(wsClient.getUserAgent()).setSonarlintCoreVersion(VersionUtils.getLibraryVersion()).setUpdateTimestamp(new Date().getTime()).build();
        ProtobufUtil.writeToFile(storageStatus, temp.resolve(StoragePaths.STORAGE_STATUS_PB));
        Path dest = storageManager.getGlobalStorageRoot();
        FileUtils.deleteRecursively(dest);
        FileUtils.mkdirs(dest.getParent());
        FileUtils.moveDir(temp, dest);
        return analyzers;
    } catch (RuntimeException e) {
        try {
            FileUtils.deleteRecursively(temp);
        } catch (RuntimeException ignore) {
        // ignore because we want to throw original exception
        }
        throw e;
    }
}
Also used : Path(java.nio.file.Path) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) StorageStatus(org.sonarsource.sonarlint.core.proto.Sonarlint.StorageStatus) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos) Date(java.util.Date)

Example 4 with SonarAnalyzer

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

the class ServerUpdateTask method run.

public void run(@NotNull ProgressIndicator indicator) {
    indicator.setText("Fetching data...");
    try {
        TaskProgressMonitor monitor = new TaskProgressMonitor(indicator);
        ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
        if (!onlyModules) {
            UpdateResult updateResult = engine.update(serverConfiguration, monitor);
            Collection<SonarAnalyzer> tooOld = updateResult.analyzers().stream().filter(SonarAnalyzer::sonarlintCompatible).filter(ServerUpdateTask::tooOld).collect(Collectors.toList());
            if (!tooOld.isEmpty()) {
                ApplicationManager.getApplication().invokeAndWait(() -> Messages.showWarningDialog(buildMinimumVersionFailMessage(tooOld), "Analyzers Not Loaded"), ModalityState.any());
            }
            log.log("Server binding '" + server.getName() + "' updated", LogOutput.Level.INFO);
        }
        updateModules(serverConfiguration, monitor);
    } catch (CanceledException e) {
        LOGGER.info("Update of server '" + server.getName() + "' was cancelled");
        log.log("Update of server '" + server.getName() + "' was cancelled", LogOutput.Level.INFO);
    } catch (Exception e) {
        LOGGER.info("Error updating from server '" + server.getName() + "'", e);
        final String msg = (e.getMessage() != null) ? e.getMessage() : ("Failed to update binding for server configuration '" + server.getName() + "'");
        ApplicationManager.getApplication().invokeAndWait(new RunnableAdapter() {

            @Override
            public void doRun() {
                Messages.showErrorDialog((Project) null, msg, "Update Failed");
            }
        }, ModalityState.any());
    }
}
Also used : CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) RunnableAdapter(com.intellij.history.utils.RunnableAdapter) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException)

Example 5 with SonarAnalyzer

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

the class PluginListDownloader method downloadPluginListBefore66.

public List<SonarAnalyzer> downloadPluginListBefore66(Version serverVersion) {
    List<SonarAnalyzer> analyzers = new LinkedList<>();
    boolean compatibleFlagPresent = serverVersion.compareToIgnoreQualifier(Version.create("6.0")) >= 0;
    String responseStr;
    try (WsResponse response = wsClient.get(WS_PATH_LTS)) {
        responseStr = response.content();
    }
    Scanner scanner = new Scanner(responseStr);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        String[] fields = StringUtils.split(line, ",");
        String[] nameAndHash = StringUtils.split(fields[fields.length - 1], "|");
        String key = fields[0];
        String filename = nameAndHash[0];
        String hash = nameAndHash[1];
        String version = VersionUtils.getJarVersion(filename);
        String minVersion = pluginVersionChecker.getMinimumVersion(key);
        boolean sonarlintCompatible = PluginCacheLoader.isWhitelisted(key) || !compatibleFlagPresent || "true".equals(fields[1]);
        DefaultSonarAnalyzer analyzer = new DefaultSonarAnalyzer(key, filename, hash, version, sonarlintCompatible, minVersion);
        analyzers.add(analyzer);
    }
    scanner.close();
    return analyzers;
}
Also used : Scanner(java.util.Scanner) DefaultSonarAnalyzer(org.sonarsource.sonarlint.core.container.model.DefaultSonarAnalyzer) SonarAnalyzer(org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer) DefaultSonarAnalyzer(org.sonarsource.sonarlint.core.container.model.DefaultSonarAnalyzer) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) LinkedList(java.util.LinkedList)

Aggregations

SonarAnalyzer (org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer)5 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)2 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)2 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 RunnableAdapter (com.intellij.history.utils.RunnableAdapter)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Scanner (java.util.Scanner)1 Set (java.util.Set)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1