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();
}
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));
}
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);
}
}
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()));
}
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();
}
Aggregations