@@ -20,7 +20,6 @@ | |||
package org.sonar.ce.task.projectanalysis.step; | |||
import java.util.ArrayList; | |||
import java.util.HashSet; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
@@ -42,8 +41,6 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.measure.LiveMeasureDto; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.unmodifiableSet; | |||
import static org.sonar.api.measures.CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY; | |||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; |
@@ -190,11 +190,6 @@ public class MeasureRepositoryImplTest { | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
@Test | |||
public void update_throws_NPE_if_Component_argument_is_null() { | |||
} | |||
@Test | |||
public void update_throws_NPE_if_Component_metric_is_null() { | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, null, SOME_MEASURE)) |
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2021 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.platform.db.migration.version.v93; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -24,10 +24,13 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.function.Function; | |||
import org.apache.commons.lang.builder.ReflectionToStringBuilder; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.search.SearchHit; | |||
import org.elasticsearch.search.SearchHits; | |||
import static java.util.Optional.ofNullable; | |||
public class SearchIdResult<ID> { | |||
private final List<ID> uuids; | |||
@@ -36,10 +39,14 @@ public class SearchIdResult<ID> { | |||
public SearchIdResult(SearchResponse response, Function<String, ID> converter, ZoneId timeZone) { | |||
this.facets = new Facets(response, timeZone); | |||
this.total = response.getHits().getTotalHits().value; | |||
this.total = getTotalHits(response).value; | |||
this.uuids = convertToIds(response.getHits(), converter); | |||
} | |||
private static TotalHits getTotalHits(SearchResponse response) { | |||
return ofNullable(response.getHits().getTotalHits()).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
public List<ID> getUuids() { | |||
return uuids; | |||
} |
@@ -24,8 +24,11 @@ import java.util.List; | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
import org.apache.commons.lang.builder.ReflectionToStringBuilder; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import static java.util.Optional.ofNullable; | |||
public class SearchResult<DOC extends BaseDoc> { | |||
private final List<DOC> docs; | |||
@@ -34,10 +37,14 @@ public class SearchResult<DOC extends BaseDoc> { | |||
public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter, ZoneId timeZone) { | |||
this.facets = new Facets(response, timeZone); | |||
this.total = response.getHits().getTotalHits().value; | |||
this.total = getTotalHits(response).value; | |||
this.docs = EsUtils.convertToDocs(response.getHits(), converter); | |||
} | |||
private static TotalHits getTotalHits(SearchResponse response) { | |||
return ofNullable(response.getHits().getTotalHits()).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
public List<DOC> getDocs() { | |||
return docs; | |||
} |
@@ -26,6 +26,7 @@ import java.util.List; | |||
import java.util.function.Consumer; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.elasticsearch.action.search.SearchRequest; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.index.query.BoolQueryBuilder; | |||
@@ -53,6 +54,7 @@ import org.sonar.server.es.textsearch.ComponentTextSearchQueryFactory; | |||
import org.sonar.server.es.textsearch.ComponentTextSearchQueryFactory.ComponentTextSearchQuery; | |||
import org.sonar.server.permission.index.WebAuthorizationTypeSupport; | |||
import static java.util.Optional.ofNullable; | |||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; | |||
import static org.elasticsearch.index.query.QueryBuilders.termQuery; | |||
import static org.elasticsearch.index.query.QueryBuilders.termsQuery; | |||
@@ -194,7 +196,11 @@ public class ComponentIndex { | |||
SearchHits hitList = docs.getHits(); | |||
SearchHit[] hits = hitList.getHits(); | |||
return new ComponentHitsPerQualifier(bucket.getKey(), ComponentHit.fromSearchHits(hits), hitList.getTotalHits().value); | |||
return new ComponentHitsPerQualifier(bucket.getKey(), ComponentHit.fromSearchHits(hits), getTotalHits(hitList.getTotalHits()).value); | |||
} | |||
private static TotalHits getTotalHits(@Nullable TotalHits totalHits) { | |||
return ofNullable(totalHits).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
private static <T> void setNullable(@Nullable T parameter, Consumer<T> consumer) { |
@@ -32,6 +32,7 @@ import java.util.function.Function; | |||
import java.util.stream.IntStream; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.apache.lucene.search.join.ScoreMode; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.index.query.BoolQueryBuilder; | |||
@@ -74,6 +75,7 @@ import org.sonar.server.permission.index.WebAuthorizationTypeSupport; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.util.Collections.emptyList; | |||
import static java.util.Optional.ofNullable; | |||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery; | |||
import static org.elasticsearch.index.query.QueryBuilders.nestedQuery; | |||
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; | |||
@@ -270,7 +272,7 @@ public class ProjectMeasuresIndex { | |||
SearchResponse response = client.search(EsClient.prepareSearch(TYPE_PROJECT_MEASURES.getMainType()) | |||
.source(searchSourceBuilder)); | |||
statistics.setProjectCount(response.getHits().getTotalHits().value); | |||
statistics.setProjectCount(getTotalHits(response.getHits().getTotalHits()).value); | |||
statistics.setProjectCountByLanguage(termsToMap(response.getAggregations().get(FIELD_LANGUAGES))); | |||
Function<Terms.Bucket, Long> bucketToNcloc = bucket -> Math.round(((Sum) bucket.getAggregations().get(FIELD_NCLOC_DISTRIBUTION_NCLOC)).getValue()); | |||
Map<String, Long> nclocByLanguage = Stream.of((Nested) response.getAggregations().get(FIELD_NCLOC_DISTRIBUTION)) | |||
@@ -282,6 +284,10 @@ public class ProjectMeasuresIndex { | |||
return statistics.build(); | |||
} | |||
private static TotalHits getTotalHits(@Nullable TotalHits totalHits) { | |||
return ofNullable(totalHits).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
private static void addSort(ProjectMeasuresQuery query, SearchSourceBuilder requestBuilder) { | |||
String sort = query.getSort(); | |||
if (SORT_BY_NAME.equals(sort)) { |
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2021 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.monitoring.ce; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2021 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.monitoring.devops; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2021 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.monitoring; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -19,21 +19,17 @@ | |||
*/ | |||
package org.sonar.server.almsettings.ws; | |||
import org.sonar.alm.client.azure.AzureDevOpsHttpClient; | |||
import org.sonar.alm.client.azure.AzureDevOpsValidator; | |||
import org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient; | |||
import org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator; | |||
import org.sonar.api.config.internal.Encryption; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator; | |||
import org.sonar.alm.client.github.GithubGlobalSettingsValidator; | |||
import org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator; | |||
import org.sonar.api.server.ws.Request; | |||
import org.sonar.api.server.ws.Response; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.alm.setting.AlmSettingDto; | |||
import org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator; | |||
import org.sonar.alm.client.github.GithubGlobalSettingsValidator; | |||
import org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator; | |||
import org.sonar.server.user.UserSession; | |||
public class ValidateAction implements AlmSettingsWsAction { | |||
@@ -41,10 +37,8 @@ public class ValidateAction implements AlmSettingsWsAction { | |||
private static final String PARAM_KEY = "key"; | |||
private final DbClient dbClient; | |||
private final Encryption encryption; | |||
private final UserSession userSession; | |||
private final AlmSettingsSupport almSettingsSupport; | |||
private final AzureDevOpsHttpClient azureDevOpsHttpClient; | |||
private final GitlabGlobalSettingsValidator gitlabSettingsValidator; | |||
private final GithubGlobalSettingsValidator githubGlobalSettingsValidator; | |||
private final BitbucketServerSettingsValidator bitbucketServerSettingsValidator; | |||
@@ -52,20 +46,16 @@ public class ValidateAction implements AlmSettingsWsAction { | |||
private final AzureDevOpsValidator azureDevOpsValidator; | |||
public ValidateAction(DbClient dbClient, | |||
Settings settings, | |||
UserSession userSession, | |||
AlmSettingsSupport almSettingsSupport, | |||
AzureDevOpsHttpClient azureDevOpsHttpClient, | |||
GithubGlobalSettingsValidator githubGlobalSettingsValidator, | |||
GitlabGlobalSettingsValidator gitlabSettingsValidator, | |||
BitbucketServerSettingsValidator bitbucketServerSettingsValidator, | |||
BitbucketCloudValidator bitbucketCloudValidator, | |||
AzureDevOpsValidator azureDevOpsValidator) { | |||
this.dbClient = dbClient; | |||
this.encryption = settings.getEncryption(); | |||
this.userSession = userSession; | |||
this.almSettingsSupport = almSettingsSupport; | |||
this.azureDevOpsHttpClient = azureDevOpsHttpClient; | |||
this.githubGlobalSettingsValidator = githubGlobalSettingsValidator; | |||
this.gitlabSettingsValidator = gitlabSettingsValidator; | |||
this.bitbucketServerSettingsValidator = bitbucketServerSettingsValidator; |
@@ -34,6 +34,7 @@ import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.search.SearchHit; | |||
import org.sonar.api.resources.Qualifiers; | |||
@@ -311,10 +312,14 @@ public class SearchAction implements HotspotsWsAction { | |||
List<IssueDto> hotspots = toIssueDtos(dbSession, issueKeys); | |||
Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) result.getHits().getTotalHits().value); | |||
Paging paging = forPageIndex(wsRequest.getPage()).withPageSize(wsRequest.getIndex()).andTotal((int) getTotalHits(result).value); | |||
return new SearchResponseData(paging, hotspots); | |||
} | |||
private static TotalHits getTotalHits(SearchResponse response) { | |||
return ofNullable(response.getHits().getTotalHits()).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
private List<IssueDto> toIssueDtos(DbSession dbSession, List<String> issueKeys) { | |||
List<IssueDto> unorderedHotspots = dbClient.issueDao().selectByKeys(dbSession, issueKeys); | |||
Map<String, IssueDto> hotspotsByKey = unorderedHotspots |
@@ -29,6 +29,7 @@ import java.util.Optional; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Nullable; | |||
import org.apache.lucene.search.TotalHits; | |||
import org.elasticsearch.action.search.SearchResponse; | |||
import org.elasticsearch.search.SearchHit; | |||
import org.sonar.api.rule.Severity; | |||
@@ -407,10 +408,14 @@ public class SearchAction implements IssuesWsAction { | |||
SearchResponseData data = searchResponseLoader.load(preloadedData, collector, additionalFields, facets); | |||
// FIXME allow long in Paging | |||
Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) result.getHits().getTotalHits().value); | |||
Paging paging = forPageIndex(options.getPage()).withPageSize(options.getLimit()).andTotal((int) getTotalHits(result).value); | |||
return searchResponseFormat.formatSearch(additionalFields, data, paging, facets); | |||
} | |||
private static TotalHits getTotalHits(SearchResponse response) { | |||
return ofNullable(response.getHits().getTotalHits()).orElseThrow(() -> new IllegalStateException("Could not get total hits of search results")); | |||
} | |||
private static SearchOptions createSearchOptionsFromRequest(SearchRequest request) { | |||
SearchOptions options = new SearchOptions(); | |||
options.setPage(request.getPage(), request.getPageSize()); |
@@ -75,7 +75,7 @@ public class ValidateActionTest { | |||
private final BitbucketCloudValidator bitbucketCloudValidator = new BitbucketCloudValidator(bitbucketCloudRestClient, settings); | |||
private final AzureDevOpsValidator azureDevOpsValidator = new AzureDevOpsValidator(azureDevOpsHttpClient, settings); | |||
private final WsActionTester ws = new WsActionTester( | |||
new ValidateAction(db.getDbClient(), settings, userSession, almSettingsSupport, azureDevOpsHttpClient, githubGlobalSettingsValidator, | |||
new ValidateAction(db.getDbClient(), userSession, almSettingsSupport, githubGlobalSettingsValidator, | |||
gitlabSettingsValidator, bitbucketServerSettingsValidator, bitbucketCloudValidator, azureDevOpsValidator)); | |||
@BeforeClass |
@@ -19,8 +19,6 @@ | |||
*/ | |||
package org.sonar.scanner.bootstrap; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.annotation.concurrent.Immutable; | |||
@@ -19,8 +19,6 @@ | |||
*/ | |||
package org.sonar.scanner.issue.ignore; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.LinkedHashSet; | |||
import java.util.List; | |||
import java.util.Set; |
@@ -19,8 +19,6 @@ | |||
*/ | |||
package org.sonar.scanner.repository; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.concurrent.Immutable; |
@@ -20,7 +20,6 @@ | |||
package org.sonar.scanner.repository; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.concurrent.Immutable; |
@@ -19,8 +19,6 @@ | |||
*/ | |||
package org.sonar.scanner.scan; | |||
import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import javax.annotation.concurrent.Immutable; | |||