From d8d85378928cc6ef3a86826ccf7b315c90cc2af2 Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Wed, 18 Dec 2024 11:01:28 +0100 Subject: SONAR-24000 Remove creation of SonarWay(legacy) --- .../server/qualitygate/RegisterQualityGatesIT.java | 71 ---------------------- .../server/qualitygate/RegisterQualityGates.java | 50 --------------- 2 files changed, 121 deletions(-) diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/RegisterQualityGatesIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/RegisterQualityGatesIT.java index 4feda68dd67..a915580aa1d 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/RegisterQualityGatesIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/RegisterQualityGatesIT.java @@ -21,7 +21,6 @@ package org.sonar.server.qualitygate; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -239,53 +238,6 @@ public class RegisterQualityGatesIT { logTester.logs(Level.INFO)).contains("Quality Gate's conditions of [Sonar way] has been updated"); } - @Test - public void register_sonar_way_legacy_qg_if_not_exists_and_existing_instance() { - insertMetrics(); - QualityGateDto builtin = new QualityGateDto().setName(SonarWayQualityGate.NAME).setBuiltIn(true).setUuid(Uuids.createFast()); - qualityGateDao.insert(dbSession, builtin); - createBuiltInConditions(builtin); - dbSession.commit(); - - underTest.start(); - - var qualityGateDto = qualityGateDao.selectByName(dbSession, RegisterQualityGates.SONAR_WAY_LEGACY_NAME); - assertThat(qualityGateDto).isNotNull(); - - verifyCorrectSonarWayLegacyQualityGate(); - assertThat( - logTester.logs(Level.INFO)).contains("Sonar way (legacy) Quality Gate has been created"); - - } - - @Test - @UseDataProvider("data") - public void do_not_register_sonar_way_legacy_qg(boolean isNewInstance, boolean hasSonarWayLegacyQG) { - insertMetrics(); - QualityGateDto builtin = new QualityGateDto().setName(SonarWayQualityGate.NAME).setBuiltIn(true).setUuid(Uuids.createFast()); - qualityGateDao.insert(dbSession, builtin); - if (!isNewInstance) { - createBuiltInConditions(builtin); - } - if (hasSonarWayLegacyQG) { - QualityGateDto sonarWayLegacy = new QualityGateDto().setName(RegisterQualityGates.SONAR_WAY_LEGACY_NAME).setBuiltIn(false).setUuid(Uuids.createFast()); - qualityGateDao.insert(dbSession, sonarWayLegacy); - } - dbSession.commit(); - - underTest.start(); - - var qualityGateDto = qualityGateDao.selectByName(dbSession, RegisterQualityGates.SONAR_WAY_LEGACY_NAME); - if (hasSonarWayLegacyQG) { - assertThat(qualityGateDto).isNotNull(); - } else { - assertThat(qualityGateDto).isNull(); - } - - assertThat( - logTester.logs(Level.INFO)).doesNotContain("Sonar way (legacy) quality gate has been created"); - } - @DataProvider public static Object[][] data() { return new Object[][] { @@ -333,29 +285,6 @@ public class RegisterQualityGatesIT { tuple(newSecurityHotspots.getUuid(), OPERATOR_LESS_THAN, "100")); } - private void verifyCorrectSonarWayLegacyQualityGate() { - MetricDto newReliability = metricDao.selectByKey(dbSession, NEW_RELIABILITY_RATING_KEY); - MetricDto newSecurity = metricDao.selectByKey(dbSession, NEW_SECURITY_RATING_KEY); - MetricDto newMaintainability = metricDao.selectByKey(dbSession, NEW_MAINTAINABILITY_RATING_KEY); - MetricDto newCoverage = metricDao.selectByKey(dbSession, NEW_COVERAGE_KEY); - MetricDto newDuplication = metricDao.selectByKey(dbSession, NEW_DUPLICATED_LINES_DENSITY_KEY); - MetricDto newSecurityHotspots = metricDao.selectByKey(dbSession, NEW_SECURITY_HOTSPOTS_REVIEWED_KEY); - QualityGateDto qualityGateDto = qualityGateDao.selectByName(dbSession, RegisterQualityGates.SONAR_WAY_LEGACY_NAME); - assertThat(qualityGateDto).isNotNull(); - assertThat(qualityGateDto.getCreatedAt()).isNotNull(); - assertThat(qualityGateDto.isBuiltIn()).isFalse(); - assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getUuid())) - .extracting(QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, - QualityGateConditionDto::getErrorThreshold) - .containsExactlyInAnyOrder( - tuple(newReliability.getUuid(), OPERATOR_GREATER_THAN, "1"), - tuple(newSecurity.getUuid(), OPERATOR_GREATER_THAN, "1"), - tuple(newMaintainability.getUuid(), OPERATOR_GREATER_THAN, "1"), - tuple(newCoverage.getUuid(), OPERATOR_LESS_THAN, "80"), - tuple(newDuplication.getUuid(), OPERATOR_GREATER_THAN, "3"), - tuple(newSecurityHotspots.getUuid(), OPERATOR_LESS_THAN, "100")); - } - private List createBuiltInConditions(QualityGateDto qg) { List conditions = new ArrayList<>(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java index fb019348f22..693b32b0c26 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -49,25 +48,12 @@ import org.sonar.db.qualitygate.QualityGateConditionDao; import org.sonar.db.qualitygate.QualityGateConditionDto; import org.sonar.db.qualitygate.QualityGateDao; import org.sonar.db.qualitygate.QualityGateDto; -import org.sonar.server.measure.Rating; import org.sonar.server.qualitygate.builtin.BuiltInQualityGate; -import org.sonar.server.qualitygate.builtin.SonarWayQualityGate; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.toMap; -import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; -import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY; -import static org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY; -import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY; -import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_HOTSPOTS_REVIEWED_KEY; -import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY; -import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_GREATER_THAN; -import static org.sonar.db.qualitygate.QualityGateConditionDto.OPERATOR_LESS_THAN; public class RegisterQualityGates implements Startable { - static final String SONAR_WAY_LEGACY_NAME = "Sonar way (legacy)"; - private static final Logger LOGGER = LoggerFactory.getLogger(RegisterQualityGates.class); private final DbClient dbClient; @@ -97,8 +83,6 @@ public class RegisterQualityGates implements Startable { List newBuiltinQualityGates = createBuiltInQualityGates(dbSession, builtinQualityGates); builtinQualityGates.addAll(newBuiltinQualityGates); - - createLegacyQualityGate(dbSession, builtinQualityGates); updateQualityGates(dbSession, builtinQualityGates); cleanupQualityGates(dbSession); @@ -122,40 +106,6 @@ public class RegisterQualityGates implements Startable { .toList(); } - private void createLegacyQualityGate(DbSession dbSession, List builtinQualityGates) { - Optional existingSonarWay = builtinQualityGates.stream().filter(qg -> SonarWayQualityGate.NAME.equals(qg.getName())).findFirst(); - - if (existingSonarWay.isEmpty()) { - return; - } - - // Create sonar way (legacy) only if it is not a new instance (a new instance has a Sonar way QG and no conditions) and if it is - // not already present - // FIXME:: The logic explained above doesn't make any sense as after upgrade - legacy Quality Gate will created, - // FIXME:: There is open bug ticket to address this issue: SONAR-23753 - boolean shouldCreateLegacy = qualityGateConditionDao.countByQualityGateUuid(dbSession, existingSonarWay.get().getUuid()) > 0; - - if (!shouldCreateLegacy) { - return; - } - - QualityGateDto sonarWayLegacyQualityGate = qualityGateDao.selectByName(dbSession, SONAR_WAY_LEGACY_NAME); - - if (sonarWayLegacyQualityGate == null) { - sonarWayLegacyQualityGate = createQualityGate(dbSession, SONAR_WAY_LEGACY_NAME, false, false); - addConditionsToQualityGate(dbSession, sonarWayLegacyQualityGate, asList( - new QualityGateCondition().setMetricKey(NEW_SECURITY_RATING_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold(Integer.toString(Rating.A.getIndex())), - new QualityGateCondition().setMetricKey(NEW_RELIABILITY_RATING_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold(Integer.toString(Rating.A.getIndex())), - new QualityGateCondition().setMetricKey(NEW_MAINTAINABILITY_RATING_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold(Integer.toString(Rating.A.getIndex())), - new QualityGateCondition().setMetricKey(NEW_COVERAGE_KEY).setOperator(OPERATOR_LESS_THAN).setErrorThreshold("80"), - new QualityGateCondition().setMetricKey(NEW_DUPLICATED_LINES_DENSITY_KEY).setOperator(OPERATOR_GREATER_THAN).setErrorThreshold("3"), - new QualityGateCondition().setMetricKey(NEW_SECURITY_HOTSPOTS_REVIEWED_KEY).setOperator(OPERATOR_LESS_THAN).setErrorThreshold("100"))); - LOGGER.info("Sonar way (legacy) Quality Gate has been created"); - } else { - LOGGER.info("Sonar way legacy Gate uuid: {} ", sonarWayLegacyQualityGate.getUuid()); - } - } - private void updateQualityGates(DbSession dbSession, List builtinQualityGates) { Map uuidToKeyMetric = dbClient.metricDao().selectAll(dbSession).stream() .collect(toMap(MetricDto::getUuid, MetricDto::getKey)); -- cgit v1.2.3