diff options
Diffstat (limited to 'server')
10 files changed, 110 insertions, 20 deletions
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java index 4ca698cd35d..43ef628cfdd 100644 --- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java +++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/gitlab/GitlabApplicationClientTest.java @@ -484,7 +484,8 @@ public class GitlabApplicationClientTest { .hasMessage("Could not validate GitLab read permission. Got an unexpected answer."); assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects") + "] " + - "failed with error message : [Failed to connect to " + server.getHostName()); + "failed with error message : [Failed to connect to ") + .contains(server.getHostName()); } @Test @@ -496,7 +497,8 @@ public class GitlabApplicationClientTest { .hasMessage("Could not validate GitLab token. Got an unexpected answer."); assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("user") + "] " + - "failed with error message : [Failed to connect to " + server.getHostName()); + "failed with error message : [Failed to connect to ") + .contains(server.getHostName()); } @Test @@ -508,7 +510,8 @@ public class GitlabApplicationClientTest { .hasMessage("Could not validate GitLab write permission. Got an unexpected answer."); assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/markdown") + "] " + - "failed with error message : [Failed to connect to " + server.getHostName()); + "failed with error message : [Failed to connect to ") + .contains(server.getHostName()); } @Test @@ -520,7 +523,8 @@ public class GitlabApplicationClientTest { .hasMessageContaining("Failed to connect to"); assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects/0") + "] " + - "failed with error message : [Failed to connect to " + server.getHostName()); + "failed with error message : [Failed to connect to ") + .contains( server.getHostName()); } @Test @@ -529,7 +533,8 @@ public class GitlabApplicationClientTest { assertThatThrownBy(() -> underTest.getBranches(gitlabUrl, "token", 0L)) .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("Failed to connect to " + server.getHostName()); + .hasMessageContaining("Failed to connect to ") + .hasMessageContaining(server.getHostName()); assertThat(logTester.logs(Level.INFO).get(0)) .contains("Gitlab API call to [" + server.url("/projects/0/repository/branches") + "] " + "failed with error message : [Failed to connect to " + server.getHostName()); @@ -546,7 +551,8 @@ public class GitlabApplicationClientTest { .contains( "Gitlab API call to [" + server.url("/projects?archived=false&simple=true&membership=true&order_by=name&sort=asc&search=&page=1&per_page=1") + "] " + - "failed with error message : [Failed to connect to " + server.getHostName()); + "failed with error message : [Failed to connect to ") + .contains( server.getHostName()); } @Test diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/report/RegulatoryReportDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/report/RegulatoryReportDaoIT.java index 3b3d9ca49cc..88440d187a1 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/report/RegulatoryReportDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/report/RegulatoryReportDaoIT.java @@ -90,7 +90,7 @@ class RegulatoryReportDaoIT { List<IssueFindingDto> issues = new ArrayList<>(); underTest.scrollIssues(db.getSession(), PROJECT_UUID, result -> issues.add(result.getResultObject())); - assertThat(issues).extracting(IssueFindingDto::getKey).containsOnly(issue1.getKey(), issue2.getKey(), issue3.getKey()); + assertThat(issues).extracting(IssueFindingDto::getKey).containsOnly(issue1.getKey(), issue2.getKey(), issue3.getKey(), issueCodeSmell.getKey()); // check fields IssueFindingDto issue = issues.stream().filter(i -> i.getKey().equals(issue1.getKey())).findFirst().get(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java index ebefc919835..17e310f3887 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateFindingDto.java @@ -27,6 +27,7 @@ public class QualityGateFindingDto { private String operator = null; private String valueType = null; private String errorThreshold = null; + private String qualityGateName = null; public String getDescription() { return description; @@ -52,6 +53,10 @@ public class QualityGateFindingDto { return errorThreshold; } + public String getQualityGateName() { + return qualityGateName; + } + private String getOperator() { return operator; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml index d4dd06bf35d..16df5308d01 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml @@ -7,6 +7,12 @@ </sql> <sql id="qualityGateFindingColumns"> + <!-- + If a row's columns are all `null`, MyBatis, by default, will return `null` + instead of an instantiated object with all its properties set to `null`. + This case expression, for the QG name, is designed to preserve that behavior. + --> + CASE WHEN qgc.operator IS NULL THEN NULL ELSE qg.name END AS qualityGateName, m.short_name as description, qgc.operator as operator, m.val_type as valueType, diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml index 7506b52f060..6281acad179 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml @@ -69,8 +69,8 @@ left outer join issues_impacts ii on i.kee = ii.issue_key where i.project_uuid=#{branchUuid,jdbcType=VARCHAR} and i.status !='CLOSED' - <!--BUG, VULNERABILITY, SECURITY_HOTSPOT --> - and i.issue_type in (2, 3, 4) + <!--CODE_SMELL, BUG, VULNERABILITY, SECURITY_HOTSPOT --> + and i.issue_type in (1, 2, 3, 4) order by i.kee, ic.issue_change_creation_date </select> </mapper> diff --git a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java index 46f57e2c65c..dcc39aa99a5 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java +++ b/server/sonar-main/src/main/java/org/sonar/application/es/EsSettings.java @@ -252,5 +252,9 @@ public class EsSettings { if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-D" + ALLOW_MMAP + "=" + Boolean.FALSE)) { builder.put(ALLOW_MMAP, Boolean.FALSE.toString()); } + + if (props.value(JAVA_ADDITIONAL_OPS_PROPERTY, "").contains("-Dcluster.routing.allocation.disk.threshold_enabled=" + Boolean.FALSE)) { + builder.put("cluster.routing.allocation.disk.threshold_enabled", Boolean.FALSE.toString()); + } } } diff --git a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java index 012445ff83c..974ffd79dcb 100644 --- a/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java +++ b/server/sonar-main/src/test/java/org/sonar/application/es/EsSettingsTest.java @@ -367,6 +367,25 @@ public class EsSettingsTest { } @Test + @UseDataProvider("clusterEnabledOrNot") + public void disable_disk_threshold_if_configured_in_search_additional_props(boolean clusterEnabled) throws Exception { + Props props = minProps(clusterEnabled); + props.set("sonar.search.javaAdditionalOpts", "-Dcluster.routing.allocation.disk.threshold_enabled=false"); + Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build(); + + assertThat(settings).containsEntry("cluster.routing.allocation.disk.threshold_enabled", "false"); + } + + @Test + @UseDataProvider("clusterEnabledOrNot") + public void disk_threshold_not_set_by_default(boolean clusterEnabled) throws Exception { + Props props = minProps(clusterEnabled); + Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build(); + + assertThat(settings.get("cluster.routing.allocation.disk.threshold_enabled")).isNull(); + } + + @Test public void configureSecurity_givenClusterSearchPasswordNotProvided_dontAddXpackParameters() throws Exception { Props props = minProps(true); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/metric/StandardToMQRMetrics.java b/server/sonar-server-common/src/main/java/org/sonar/server/metric/StandardToMQRMetrics.java index 53d39f62652..6ebf315f6ca 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/metric/StandardToMQRMetrics.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/metric/StandardToMQRMetrics.java @@ -22,6 +22,7 @@ package org.sonar.server.metric; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import java.util.Optional; +import java.util.Set; import org.sonar.api.measures.CoreMetrics; import org.sonar.core.metric.SoftwareQualitiesMetrics; @@ -120,6 +121,14 @@ public class StandardToMQRMetrics { return MQR_TO_STANDARD_MODE_METRICS.containsKey(metricKey); } + public static Set<String> getMQRMetrics() { + return STANDARD_TO_MQR_MODE_METRICS.keySet(); + } + + public static Set<String> getStandardMetrics() { + return MQR_TO_STANDARD_MODE_METRICS.keySet(); + } + /** * Retrieves equivalent metric in the other mode. Return empty if metric has no equivalence */ diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 9235bc57b1a..6b2c826f2c9 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -871,7 +871,7 @@ public class IssueIndex { if (newCodeOnReference != null) { filters.addFilter( FIELD_ISSUE_NEW_CODE_REFERENCE, new SimpleFieldFilterScope(FIELD_ISSUE_NEW_CODE_REFERENCE), - termQuery(FIELD_ISSUE_NEW_CODE_REFERENCE, true)); + termQuery(FIELD_ISSUE_NEW_CODE_REFERENCE, newCodeOnReference)); } } diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index a8c4216b14f..f1d99c660b3 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -45,6 +46,7 @@ import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.db.component.ComponentQualifiers; import org.sonar.api.rule.RuleKey; import org.sonar.core.rule.RuleType; @@ -69,6 +71,8 @@ import static java.lang.String.format; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; import static org.sonar.api.issue.Issue.STATUSES; +import static org.sonar.api.issue.Issue.STATUS_CONFIRMED; +import static org.sonar.api.issue.Issue.STATUS_OPEN; import static org.sonar.api.issue.Issue.STATUS_REVIEWED; import static org.sonar.api.issue.Issue.STATUS_TO_REVIEW; import static org.sonar.api.measures.CoreMetrics.ANALYSIS_FROM_SONARQUBE_9_4_KEY; @@ -181,6 +185,39 @@ public class IssueQueryFactory { } } + public IssueQuery openIssueCountBySeverity( + String projectUuid, + String branchUuid, + String componentUuid, + boolean isMainBranch, + boolean newCode, + SoftwareQuality softwareQuality + ) { + var timeZone = clock.getZone(); + + var types = EnumSet.complementOf(EnumSet.of(RuleType.SECURITY_HOTSPOT)) + .stream() + .map(RuleType::name) + .toList(); + + var query = IssueQuery.builder() + .branchUuid(branchUuid) + .mainBranch(isMainBranch) + .issueStatuses(List.of(STATUS_OPEN, STATUS_CONFIRMED)) + .impactSoftwareQualities(List.of(softwareQuality.name())) + .projectUuids(List.of(projectUuid)) + .timeZone(timeZone) + .types(types); + + if (newCode) { + try (DbSession dbSession = dbClient.openSession(false)) { + setInNewCodePeriod(dbSession, query, componentUuid); + } + } + + return query.build(); + } + private Collection<String> collectIssueKeys(DbSession dbSession, SearchRequest request) { Collection<String> issueKeys = null; if (request.getFixedInPullRequest() != null) { @@ -269,18 +306,22 @@ public class IssueQueryFactory { ComponentDto component = componentUuids.iterator().next(); if (!QUALIFIERS_WITHOUT_LEAK_PERIOD.contains(component.qualifier()) && request.getPullRequest() == null) { - Optional<SnapshotDto> snapshot = getLastAnalysis(dbSession, component); - if (!snapshot.isEmpty() && isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, snapshot.get())) { - builder.newCodeOnReference(true); - return; - } - // if last analysis has no period date, then no issue should be considered new. - Date createdAfterFromSnapshot = findCreatedAfterFromComponentUuid(snapshot); - setCreatedAfterFromDates(builder, createdAfterFromSnapshot, null, false); + setInNewCodePeriod(dbSession, builder, component.uuid()); } } } + private void setInNewCodePeriod(DbSession dbSession, IssueQuery.Builder builder, String componentUuid) { + Optional<SnapshotDto> snapshot = getLastAnalysis(dbSession, componentUuid); + if (!snapshot.isEmpty() && isLastAnalysisFromReAnalyzedReferenceBranch(dbSession, snapshot.get())) { + builder.newCodeOnReference(true); + return; + } + // if last analysis has no period date, then no issue should be considered new. + Date createdAfterFromSnapshot = findCreatedAfterFromComponentUuid(snapshot); + setCreatedAfterFromDates(builder, createdAfterFromSnapshot, null, false); + } + private static boolean notInNewCodePeriod(SearchRequest request) { Boolean inNewCodePeriod = request.getInNewCodePeriod(); inNewCodePeriod = Boolean.TRUE.equals(inNewCodePeriod); @@ -301,8 +342,8 @@ public class IssueQueryFactory { .isPresent(); } - private Optional<SnapshotDto> getLastAnalysis(DbSession dbSession, ComponentDto component) { - return dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.uuid()); + private Optional<SnapshotDto> getLastAnalysis(DbSession dbSession, String componentUuid) { + return dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, componentUuid); } private List<SnapshotDto> getLastAnalysis(DbSession dbSession, Set<String> projectUuids) { |