]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19558 Fix Settings using components instead of project
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Thu, 22 Jun 2023 09:21:12 +0000 (11:21 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 26 Jun 2023 20:03:55 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/ExportSettingsStep.java
server/sonar-ce-task-projectanalysis/src/main/protobuf/project_dump.proto
server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectExportMapper.xml

index 43e407dbbac80e0a1defd188975ddae6b2f99838..e41a08af8d2c0c782c7271c135de286261f2dd45 100644 (file)
@@ -34,6 +34,9 @@ import org.sonar.ce.task.projectexport.component.MutableComponentRepository;
 import org.sonar.ce.task.step.TestComputationStepContext;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.project.ProjectExportMapper;
 import org.sonar.db.property.PropertyDto;
 
@@ -43,7 +46,6 @@ import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 
 public class ExportSettingsStepIT {
 
-  private static final ComponentDto GLOBAL = null;
   private static final ComponentDto PROJECT = new ComponentDto()
     .setUuid("project_uuid")
     .setUuidPath(UUID_PATH_OF_ROOT)
@@ -59,19 +61,19 @@ public class ExportSettingsStepIT {
   public LogTester logTester = new LogTester();
   @Rule
   public DbTester dbTester = DbTester.createWithExtensionMappers(System2.INSTANCE, true, ProjectExportMapper.class);
-  private final MutableComponentRepository componentRepository = new ComponentRepositoryImpl();
   private final MutableProjectHolder projectHolder = new MutableProjectHolderImpl();
   private final FakeDumpWriter dumpWriter = new FakeDumpWriter();
-  private final ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, componentRepository, dumpWriter);
+  private final ExportSettingsStep underTest = new ExportSettingsStep(dbTester.getDbClient(), projectHolder, dumpWriter);
+  private ProjectDto project;
+  private ProjectDto anotherProject;
 
   @Before
   public void setUp() {
     logTester.setLevel(Level.DEBUG);
-    dbTester.components().insertPublicProject(PROJECT);
-    dbTester.components().insertPublicProject(ANOTHER_PROJECT);
+    project = dbTester.components().insertPublicProject(PROJECT).getProjectDto();
+    anotherProject = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getProjectDto();
     dbTester.commit();
-    projectHolder.setProjectDto(dbTester.components().getProjectDtoByMainBranch(PROJECT));
-    componentRepository.register(1, PROJECT.uuid(), false);
+    projectHolder.setProjectDto(project);
   }
 
   @Test
@@ -84,13 +86,13 @@ public class ExportSettingsStepIT {
 
   @Test
   public void export_only_project_settings() {
-    PropertyDto projectProperty1 = newDto("p1", "v1", PROJECT);
-    PropertyDto projectProperty2 = newDto("p2", "v2", PROJECT);
+    PropertyDto projectProperty1 = newDto("p1", "v1", project);
+    PropertyDto projectProperty2 = newDto("p2", "v2", project);
     // the following properties are not exported
-    PropertyDto propOnOtherProject = newDto("p3", "v3", ANOTHER_PROJECT);
-    PropertyDto globalProperty = newDto("p4", "v4", GLOBAL);
-    insertProperties(PROJECT.getKey(), PROJECT.name(), projectProperty1, projectProperty2);
-    insertProperties(ANOTHER_PROJECT.getKey(), ANOTHER_PROJECT.name(), propOnOtherProject);
+    PropertyDto propOnOtherProject = newDto("p3", "v3", anotherProject);
+    PropertyDto globalProperty = newDto("p4", "v4", null);
+    insertProperties(project.getKey(), project.getName(), projectProperty1, projectProperty2);
+    insertProperties(anotherProject.getKey(), anotherProject.getName(), propOnOtherProject);
     insertProperties(null, null, globalProperty);
 
     underTest.execute(new TestComputationStepContext());
@@ -103,7 +105,7 @@ public class ExportSettingsStepIT {
 
   @Test
   public void exclude_properties_specific_to_environment() {
-    insertProperties(PROJECT.getKey(), PROJECT.name(), newDto("sonar.issues.defaultAssigneeLogin", null, PROJECT));
+    insertProperties(project.getKey(), project.getName(), newDto("sonar.issues.defaultAssigneeLogin", null, project));
 
     underTest.execute(new TestComputationStepContext());
 
@@ -113,8 +115,8 @@ public class ExportSettingsStepIT {
 
   @Test
   public void test_exported_fields() {
-    PropertyDto dto = newDto("p1", "v1", PROJECT);
-    insertProperties(PROJECT.getKey(), PROJECT.name(), dto);
+    PropertyDto dto = newDto("p1", "v1", project);
+    insertProperties(project.getKey(), project.getName(), dto);
 
     underTest.execute(new TestComputationStepContext());
 
@@ -125,7 +127,7 @@ public class ExportSettingsStepIT {
 
   @Test
   public void property_can_have_empty_value() {
-    insertProperties(PROJECT.getKey(), PROJECT.name(), newDto("p1", null, PROJECT));
+    insertProperties(project.getKey(), project.getName(), newDto("p1", null, project));
 
     underTest.execute(new TestComputationStepContext());
 
@@ -137,8 +139,8 @@ public class ExportSettingsStepIT {
   @Test
   public void throws_ISE_if_error() {
     dumpWriter.failIfMoreThan(1, DumpElement.SETTINGS);
-    insertProperties(PROJECT.getKey(), PROJECT.name(), newDto("p1", null, PROJECT),
-      newDto("p2", null, PROJECT));
+    insertProperties(project.getKey(), project.getName(), newDto("p1", null, project),
+      newDto("p2", null, project));
 
     assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
       .isInstanceOf(IllegalStateException.class)
@@ -150,17 +152,17 @@ public class ExportSettingsStepIT {
     assertThat(underTest.getDescription()).isEqualTo("Export settings");
   }
 
-  private static PropertyDto newDto(String key, @Nullable String value, @Nullable ComponentDto project) {
+  private static PropertyDto newDto(String key, @Nullable String value, @Nullable EntityDto project) {
     PropertyDto dto = new PropertyDto().setKey(key).setValue(value);
     if (project != null) {
-      dto.setEntityUuid(project.uuid());
+      dto.setEntityUuid(project.getUuid());
     }
     return dto;
   }
 
-  private void insertProperties(@Nullable String componentKey, @Nullable String componentName, PropertyDto... dtos) {
+  private void insertProperties(@Nullable String entityKey, @Nullable String entityName, PropertyDto... dtos) {
     for (PropertyDto dto : dtos) {
-      dbTester.getDbClient().propertiesDao().saveProperty(dbTester.getSession(), dto, null, componentKey, componentName, Qualifiers.VIEW);
+      dbTester.getDbClient().propertiesDao().saveProperty(dbTester.getSession(), dto, null, entityKey, entityName, Qualifiers.VIEW);
     }
     dbTester.commit();
   }
index 092b7b35e65fa13ae6deae7031ce8d9a611c00c0..c2fd4569e8c295fdeca9cc496c1c5022ea9de86a 100644 (file)
@@ -43,13 +43,11 @@ public class ExportSettingsStep implements ComputationStep {
 
   private final DbClient dbClient;
   private final ProjectHolder projectHolder;
-  private final ComponentRepository componentRepository;
   private final DumpWriter dumpWriter;
 
-  public ExportSettingsStep(DbClient dbClient, ProjectHolder projectHolder, ComponentRepository componentRepository, DumpWriter dumpWriter) {
+  public ExportSettingsStep(DbClient dbClient, ProjectHolder projectHolder,DumpWriter dumpWriter) {
     this.dbClient = dbClient;
     this.projectHolder = projectHolder;
-    this.componentRepository = componentRepository;
     this.dumpWriter = dumpWriter;
   }
 
@@ -70,10 +68,6 @@ public class ExportSettingsStep implements ComputationStep {
         builder.clear()
           .setKey(property.getKey())
           .setValue(defaultString(property.getValue()));
-
-        if (property.getEntityUuid() != null) {
-          builder.setComponentRef(componentRepository.getRef(property.getEntityUuid()));
-        }
         output.write(builder.build());
         ++count;
       }
index d889f946871cac24580ace6528debde631093a02..7e4e29da8fcdc7595e04836f6bb3401521251c3e 100644 (file)
@@ -175,7 +175,7 @@ message AdHocRule {
 message Setting {
   string key = 1;
   string value = 2;
-  int64 component_ref = 3;
+  reserved 3; // component_ref
 }
 
 // links specified on the project, and only on the project (not on modules
index c63777e80f2d7cdc5c3f645dcaba1031c2cfb569..64ced52a1b9f39b0b6bace40163928bd4c61a546 100644 (file)
@@ -23,9 +23,7 @@
         p.entity_uuid as entityUuid,
         p.user_uuid as userUuid
         from properties p
-        join components pr on p.entity_uuid=pr.uuid
-        join project_branches pb on pb.uuid = pr.uuid
-        where p.user_uuid is null and pb.project_uuid=#{projectUuid,jdbcType=VARCHAR} and pb.branch_type='BRANCH' and pb.exclude_from_purge = ${_true}
+        where p.entity_uuid=#{projectUuid,jdbcType=VARCHAR} and p.user_uuid is null
     </select>
 
     <select id="selectLinksForExport" parameterType="string" resultType="org.sonar.db.component.ProjectLinkDto">