From 57c4dde906aa448933d6fbbaa8435d1751901957 Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Fri, 3 May 2024 11:43:09 +0200 Subject: [PATCH] NO-JIRA remove redundant quality gate UUID creation --- .../java/org/sonar/db/qualitygate/QualityGateDaoIT.java | 4 +--- .../sonar/server/qualitygate/QualityGateUpdaterIT.java | 3 +-- .../org/sonar/server/qualitygate/ws/CopyActionIT.java | 3 +-- .../org/sonar/server/qualitygate/ws/CreateActionIT.java | 5 +---- .../org/sonar/server/qualitygate/QualityGateUpdater.java | 8 ++------ 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java index 174a1e17a0a..7d588c0d1e8 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.sonar.api.measures.Metric; import org.sonar.api.utils.System2; -import org.sonar.core.util.Uuids; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.component.BranchDto; @@ -53,7 +52,6 @@ class QualityGateDaoIT { @Test void insert() { QualityGateDto newQgate = new QualityGateDto() - .setUuid(Uuids.createFast()) .setName("My Quality Gate") .setBuiltIn(false) .setUpdatedAt(new Date()); @@ -71,7 +69,7 @@ class QualityGateDaoIT { @Test void insert_built_in() { - underTest.insert(db.getSession(), new QualityGateDto().setName("test").setBuiltIn(true).setUuid(Uuids.createFast())); + underTest.insert(db.getSession(), new QualityGateDto().setName("test").setBuiltIn(true)); QualityGateDto reloaded = underTest.selectByName(db.getSession(), "test"); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/QualityGateUpdaterIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/QualityGateUpdaterIT.java index edac704a9fa..c3ef0fe02b1 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/QualityGateUpdaterIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/QualityGateUpdaterIT.java @@ -21,7 +21,6 @@ package org.sonar.server.qualitygate; import org.junit.Rule; import org.junit.Test; -import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -39,7 +38,7 @@ public class QualityGateUpdaterIT { private final DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); - private final QualityGateUpdater underTest = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance()); + private final QualityGateUpdater underTest = new QualityGateUpdater(dbClient); @Test public void create_quality_gate() { diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java index 99e86f49b6c..f13c6647947 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CopyActionIT.java @@ -27,7 +27,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.api.server.ws.WebService; -import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -63,7 +62,7 @@ public class CopyActionIT { private final DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); - private final QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient, UuidFactoryFast.getInstance()); + private final QualityGateUpdater qualityGateUpdater = new QualityGateUpdater(dbClient); private final QualityGatesWsSupport wsSupport = new QualityGatesWsSupport(dbClient, userSession, TestComponentFinder.from(db)); private final CopyAction underTest = new CopyAction(dbClient, userSession, qualityGateUpdater, wsSupport); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java index 6c13b0673ef..7f3e80da5ee 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/CreateActionIT.java @@ -29,10 +29,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; import org.sonar.api.server.ws.WebService; -import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; @@ -65,8 +63,7 @@ public class CreateActionIT { private final DbClient dbClient = db.getDbClient(); private final DbSession dbSession = db.getSession(); - private final CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient, - UuidFactoryFast.getInstance()), + private final CreateAction underTest = new CreateAction(dbClient, userSession, new QualityGateUpdater(dbClient), new QualityGateConditionsUpdater(dbClient)); private final WsActionTester ws = new WsActionTester(underTest); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java index e26266d1fd1..868182d1cc7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualitygate; -import org.sonar.core.util.UuidFactory; import org.sonar.core.util.Uuids; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -32,19 +31,16 @@ import static org.sonar.server.util.Validation.IS_ALREADY_USED_MESSAGE; public class QualityGateUpdater { private final DbClient dbClient; - private final UuidFactory uuidFactory; - public QualityGateUpdater(DbClient dbClient, UuidFactory uuidFactory) { + public QualityGateUpdater(DbClient dbClient) { this.dbClient = dbClient; - this.uuidFactory = uuidFactory; } public QualityGateDto create(DbSession dbSession, String name) { validateQualityGate(dbSession, name); QualityGateDto newQualityGate = new QualityGateDto() .setName(name) - .setBuiltIn(false) - .setUuid(uuidFactory.create()); + .setBuiltIn(false); dbClient.qualityGateDao().insert(dbSession, newQualityGate); return newQualityGate; } -- 2.39.5