Search in sources :

Example 1 with StorageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.StorageException 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 2 with StorageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.StorageException in project sonarlint-core by SonarSource.

the class StandalonePluginIndexTest method testCacheStorageError.

@Test
public void testCacheStorageError() {
    when(cache.get(eq("filename"), eq("b45cffe084dd3d20d928bee85e7b0f21"), any(PluginCache.Copier.class))).thenThrow(new StorageException("msg", true));
    exception.expect(StorageException.class);
    exception.expectMessage("msg");
    index.references();
}
Also used : StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) Test(org.junit.Test)

Example 3 with StorageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.StorageException in project sonarlint-core by SonarSource.

the class StandalonePluginIndex method getFromCacheOrCopy.

private PluginReference getFromCacheOrCopy(final URL pluginUrl) {
    try (InputStream is = pluginUrl.openStream()) {
        String hash = org.sonarsource.sonarlint.core.util.StringUtils.md5(is);
        String filename = StringUtils.substringAfterLast(pluginUrl.getFile(), "/");
        fileCache.get(filename, hash, new FileCopier(pluginUrl));
        return new PluginReference(hash, filename);
    } catch (StorageException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException("Fail to copy plugin from URL: " + pluginUrl, e);
    }
}
Also used : InputStream(java.io.InputStream) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) IOException(java.io.IOException)

Example 4 with StorageException

use of org.sonarsource.sonarlint.core.client.api.exceptions.StorageException in project sonarlint-core by SonarSource.

the class PluginsStorage method store.

public void store(ServerPlugin plugin, InputStream pluginBinary) {
    try {
        FileUtils.copyInputStreamToFile(pluginBinary, rootPath.resolve(plugin.getFilename()).toFile());
        var reference = adapt(plugin);
        rwLock.write(() -> {
            var pluginsFilePath = getPluginsFilePath();
            var references = Files.exists(pluginsFilePath) ? ProtobufUtil.readFile(pluginsFilePath, Sonarlint.PluginReferences.parser()) : Sonarlint.PluginReferences.newBuilder().build();
            var currentReferences = Sonarlint.PluginReferences.newBuilder(references);
            currentReferences.putPluginsByKey(plugin.getKey(), reference);
            ProtobufUtil.writeToFile(currentReferences.build(), pluginsFilePath);
        });
    } catch (IOException e) {
        // XXX should we stop the whole sync ? just continue and log ?
        throw new StorageException("Cannot save plugin " + plugin.getFilename() + " in " + rootPath, e);
    }
}
Also used : IOException(java.io.IOException) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)

Aggregations

StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 ClientProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor)1 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)1 ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)1