use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ConnectedModeTest method canFetchHotspot.
@Test
public void canFetchHotspot() throws InvalidProtocolBufferException {
assumeTrue("SonarQube should support opening security hotspots", ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(8, 6));
analyzeMavenProject(PROJECT_KEY_JAVA_HOTSPOT);
var securityHotspotsService = new ServerApi(endpointParams(ORCHESTRATOR), sqHttpClient()).hotspot();
var remoteHotspot = securityHotspotsService.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT));
assertThat(remoteHotspot).isNotEmpty();
var actualHotspot = remoteHotspot.get();
assertThat(actualHotspot.message).isEqualTo("Make sure using this hardcoded IP address is safe here.");
assertThat(actualHotspot.filePath).isEqualTo("src/main/java/foo/Foo.java");
assertThat(actualHotspot.textRange).isEqualToComparingFieldByField(new TextRange(5, 14, 5, 29));
assertThat(actualHotspot.author).isEmpty();
assertThat(actualHotspot.status).isEqualTo(ServerHotspot.Status.TO_REVIEW);
assertThat(actualHotspot.resolution).isNull();
assertThat(actualHotspot.rule.key).isEqualTo("java:S1313");
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class IssueDownloader method download.
/**
* Fetch all issues of the component with specified key.
* If the component doesn't exist or it exists but has no issues, an empty iterator is returned.
*
* @param key project key, or file key.
* @param branchName name of the branch. If null - issues will be downloaded only for the main branch.
* @return Iterator of issues. It can be empty but never null.
*/
public List<Sonarlint.ServerIssue> download(ServerApiHelper serverApiHelper, String key, ProjectConfiguration projectConfiguration, boolean fetchTaintVulnerabilities, @Nullable String branchName, ProgressMonitor progress) {
var issueApi = new ServerApi(serverApiHelper).issue();
var issueBuilder = Sonarlint.ServerIssue.newBuilder();
var locationBuilder = Location.newBuilder();
var textRangeBuilder = Sonarlint.ServerIssue.TextRange.newBuilder();
var flowBuilder = Sonarlint.ServerIssue.Flow.newBuilder();
List<Sonarlint.ServerIssue> result = new ArrayList<>();
var batchIssues = issueApi.downloadAllFromBatchIssues(key, branchName);
Set<String> taintRuleKeys = new HashSet<>();
for (ScannerInput.ServerIssue batchIssue : batchIssues) {
if (IssueApi.TAINT_REPOS.contains(batchIssue.getRuleRepository())) {
if (NON_CLOSED_STATUSES.contains(batchIssue.getStatus())) {
taintRuleKeys.add(new org.sonarsource.sonarlint.core.client.api.common.RuleKey(batchIssue.getRuleRepository(), batchIssue.getRuleKey()).toString());
}
} else {
result.add(toStorageIssue(batchIssue, projectConfiguration, issueBuilder, locationBuilder, textRangeBuilder));
}
}
if (fetchTaintVulnerabilities && !taintRuleKeys.isEmpty()) {
Map<String, String> sourceCodeByKey = new HashMap<>();
try {
var downloadVulnerabilitiesForRules = issueApi.downloadVulnerabilitiesForRules(key, taintRuleKeys, branchName, progress);
downloadVulnerabilitiesForRules.getIssues().forEach(i -> result.add(convertTaintIssue(new ServerApi(serverApiHelper).source(), projectConfiguration, issueBuilder, locationBuilder, textRangeBuilder, flowBuilder, i, downloadVulnerabilitiesForRules.getComponentPathsByKey(), sourceCodeByKey)));
} catch (Exception e) {
LOG.warn("Unable to fetch taint vulnerabilities", e);
}
}
return result;
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ModuleHierarchyDownloader method fetchModuleHierarchy.
/**
* Downloads the module hierarchy information starting from a given module key.
* It returns the relative paths to the given root module for all its sub projects.
*
* @param projectKey project for which the hierarchy will be returned.
* @return Mapping of moduleKey -> relativePath from given module
*/
public Map<String, String> fetchModuleHierarchy(ServerApiHelper serverApiHelper, String projectKey, ProgressMonitor progress) {
var componentApi = new ServerApi(serverApiHelper).component();
var modules = componentApi.getSubProjects(projectKey, progress);
// doesn't include root
Map<String, ComponentPath> modulesByKey = modules.stream().collect(Collectors.toMap(ComponentPath::getKey, Function.identity()));
// component -> ancestorComponent. Doesn't include root
Map<ComponentPath, ComponentPath> ancestors = new HashMap<>();
for (ComponentPath c : modules) {
ancestors.put(c, modulesByKey.get(componentApi.fetchFirstAncestorKey(c.getKey()).orElse(null)));
}
// module key -> path from root project base directory
Map<String, String> modulesWithPath = new HashMap<>();
modulesWithPath.put(projectKey, "");
modules.forEach(c -> modulesWithPath.put(c.getKey(), findPathFromRoot(c, ancestors)));
return modulesWithPath;
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class SonarCloudTest method downloadUserOrganizations.
@Test
public void downloadUserOrganizations() {
var helper = new ServerApi(sonarcloudEndpointITOrg(), new SonarLintHttpClientOkHttpImpl(SC_CLIENT)).organization();
assertThat(helper.listUserOrganizations(progress)).hasSize(1);
}
use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.
the class ConnectedSonarLintEngineImpl method sync.
@Override
public void sync(EndpointParams endpoint, HttpClient client, Set<String> projectKeys, @Nullable ClientProgressMonitor monitor) {
var serverApi = new ServerApi(new ServerApiHelper(endpoint, client));
var result = storageSynchronizer.synchronize(serverApi, projectKeys, new ProgressMonitor(monitor));
if (result.hasAnalyzerBeenUpdated()) {
restartAnalysisEngine();
}
}
Aggregations