]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21821 Add monorepo related project 'CreationMethod's
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Wed, 27 Mar 2024 13:54:08 +0000 (14:54 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 28 Mar 2024 20:02:50 +0000 (20:02 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/project/CreationMethod.java
server/sonar-db-dao/src/test/java/org/sonar/db/project/CreationMethodTest.java
server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java
server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java

index 668e7ee2a37d6ffbd1e4bd4c498c3e51591d91e2..481c400743df14292f7148ee33a22158506bd5cc 100644 (file)
@@ -27,6 +27,8 @@ public enum CreationMethod {
   LOCAL_BROWSER(Category.LOCAL, true, true),
   ALM_IMPORT_API(Category.ALM_IMPORT, false, false),
   ALM_IMPORT_BROWSER(Category.ALM_IMPORT, true, false),
+  ALM_IMPORT_MONOREPO_API(Category.ALM_IMPORT_MONOREPO, false, false),
+  ALM_IMPORT_MONOREPO_BROWSER(Category.ALM_IMPORT_MONOREPO, true, false),
   SCANNER_API(Category.SCANNER, false, true),
   SCANNER_API_DEVOPS_AUTO_CONFIG(Category.SCANNER, false, false);
 
@@ -60,5 +62,7 @@ public enum CreationMethod {
     return isLocal;
   }
 
-  public enum Category {UNKNOWN, LOCAL, ALM_IMPORT, SCANNER}
+  public enum Category {
+    UNKNOWN, LOCAL, ALM_IMPORT, ALM_IMPORT_MONOREPO, SCANNER
+  }
 }
index fdab1c56e73fea32cc1455178149a6a295d781d9..a73f7585134fcffb5d362c9c600b4c9bd39759f8 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.ArgumentsProvider;
 import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.sonar.db.project.CreationMethod.Category;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -33,20 +34,22 @@ class CreationMethodTest {
   static class CreationMethodProvider implements ArgumentsProvider {
     @Override
     public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
-      return Stream.of(Arguments.of(CreationMethod.Category.UNKNOWN, true, CreationMethod.UNKNOWN),
-        Arguments.of(CreationMethod.Category.UNKNOWN, false, CreationMethod.UNKNOWN),
-        Arguments.of(CreationMethod.Category.LOCAL, true, CreationMethod.LOCAL_BROWSER),
-        Arguments.of(CreationMethod.Category.LOCAL, false, CreationMethod.LOCAL_API),
-        Arguments.of(CreationMethod.Category.ALM_IMPORT, true, CreationMethod.ALM_IMPORT_BROWSER),
-        Arguments.of(CreationMethod.Category.ALM_IMPORT, false, CreationMethod.ALM_IMPORT_API),
-        Arguments.of(CreationMethod.Category.SCANNER, true, CreationMethod.UNKNOWN),
-        Arguments.of(CreationMethod.Category.SCANNER, false, CreationMethod.SCANNER_API));
+      return Stream.of(Arguments.of(Category.UNKNOWN, true, CreationMethod.UNKNOWN),
+        Arguments.of(Category.UNKNOWN, false, CreationMethod.UNKNOWN),
+        Arguments.of(Category.LOCAL, true, CreationMethod.LOCAL_BROWSER),
+        Arguments.of(Category.LOCAL, false, CreationMethod.LOCAL_API),
+        Arguments.of(Category.ALM_IMPORT, true, CreationMethod.ALM_IMPORT_BROWSER),
+        Arguments.of(Category.ALM_IMPORT, false, CreationMethod.ALM_IMPORT_API),
+        Arguments.of(Category.ALM_IMPORT_MONOREPO, true, CreationMethod.ALM_IMPORT_MONOREPO_BROWSER),
+        Arguments.of(Category.ALM_IMPORT_MONOREPO, false, CreationMethod.ALM_IMPORT_MONOREPO_API),
+        Arguments.of(Category.SCANNER, true, CreationMethod.UNKNOWN),
+        Arguments.of(Category.SCANNER, false, CreationMethod.SCANNER_API));
     }
   }
 
   @ParameterizedTest()
   @ArgumentsSource(CreationMethodProvider.class)
-  void getCreationMethod_returnsCorrectCreationMethod(CreationMethod.Category category, boolean isCreatedViaBrowser,
+  void getCreationMethod_returnsCorrectCreationMethod(Category category, boolean isCreatedViaBrowser,
     CreationMethod expectedCreationMethod) {
     CreationMethod creationMethod = CreationMethod.getCreationMethod(category, isCreatedViaBrowser);
     assertThat(creationMethod).isEqualTo(expectedCreationMethod);
index e2b8f841f1290f3a12b21194a2dab015369a628e..ef714ed876fb3b60e0bd8685924aabeac793e4f0 100644 (file)
@@ -37,8 +37,8 @@ import org.sonar.server.component.ComponentCreationData;
 import org.sonar.server.user.UserSession;
 
 import static java.lang.String.format;
-import static org.sonar.db.project.CreationMethod.getCreationMethod;
 import static org.sonar.db.project.CreationMethod.Category.ALM_IMPORT;
+import static org.sonar.db.project.CreationMethod.Category.ALM_IMPORT_MONOREPO;
 import static org.sonar.server.common.newcodeperiod.NewCodeDefinitionResolver.checkNewCodeDefinitionParam;
 
 @ServerSide
@@ -68,7 +68,7 @@ public class ImportProjectService {
       DevOpsProjectCreator projectCreator = devOpsProjectCreatorFactory.getDevOpsProjectCreator(almSetting, projectDescriptor)
         .orElseThrow(() -> new IllegalArgumentException(format("Platform %s not supported", almSetting.getAlm().name())));
 
-      CreationMethod creationMethod = getCreationMethod(ALM_IMPORT, userSession.isAuthenticatedBrowserSession());
+      CreationMethod creationMethod = getCreationMethod(request.monorepo());
       ComponentCreationData componentCreationData = projectCreator.createProjectAndBindToDevOpsPlatform(
         dbSession,
         creationMethod,
@@ -91,4 +91,12 @@ public class ImportProjectService {
     }
   }
 
+  private CreationMethod getCreationMethod(boolean monorepo) {
+    if (monorepo) {
+      return CreationMethod.getCreationMethod(ALM_IMPORT_MONOREPO, userSession.isAuthenticatedBrowserSession());
+    } else {
+      return CreationMethod.getCreationMethod(ALM_IMPORT, userSession.isAuthenticatedBrowserSession());
+    }
+  }
+
 }
index 4bf728aee16a4972206529067114f20d9526a563..7ef4c197df90d8122689e6dbe1283597942e9dfb 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.db.alm.setting.ALM;
 import org.sonar.db.alm.setting.AlmSettingDto;
 import org.sonar.db.alm.setting.ProjectAlmSettingDto;
 import org.sonar.db.component.BranchDto;
+import org.sonar.db.project.CreationMethod;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.server.common.almsettings.DevOpsProjectCreator;
 import org.sonar.server.common.almsettings.DevOpsProjectCreatorFactory;
@@ -47,6 +48,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
+import static org.sonar.db.project.CreationMethod.ALM_IMPORT_API;
+import static org.sonar.db.project.CreationMethod.ALM_IMPORT_MONOREPO_API;
 
 class ImportProjectServiceTest {
 
@@ -111,7 +114,7 @@ class ImportProjectServiceTest {
 
     DevOpsProjectCreator devOpsProjectCreator = mockDevOpsProjectCreator(almSetting);
 
-    ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, dbSession);
+    ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, ALM_IMPORT_MONOREPO_API, true, dbSession);
 
     ProjectDto projectDto = mockProjectDto(componentCreationData);
     when(componentCreationData.mainBranchDto()).thenReturn(mock(BranchDto.class));
@@ -136,14 +139,14 @@ class ImportProjectServiceTest {
 
     DevOpsProjectCreator devOpsProjectCreator = mockDevOpsProjectCreator(almSetting);
 
-    ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, dbSession);
+    ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, ALM_IMPORT_API, false, dbSession);
 
     ProjectDto projectDto = mockProjectDto(componentCreationData);
     mockBranchDto(componentCreationData);
 
     ProjectAlmSettingDto projectAlmSettingDto = mockProjectAlmSetting(dbSession, projectDto);
 
-    ImportProjectRequest request = new ImportProjectRequest(PROJECT_KEY, PROJECT_NAME, ALM_SETTING_ID, DOP_REPOSITORY_ID, DOP_PROJECT_ID, "NUMBER_OF_DAYS", "10", true);
+    ImportProjectRequest request = new ImportProjectRequest(PROJECT_KEY, PROJECT_NAME, ALM_SETTING_ID, DOP_REPOSITORY_ID, DOP_PROJECT_ID, "NUMBER_OF_DAYS", "10", false);
 
     ImportedProject importedProject = importProjectService.importProject(request);
 
@@ -182,9 +185,9 @@ class ImportProjectServiceTest {
     return devOpsProjectCreator;
   }
 
-  private static ComponentCreationData mockProjectCreation(DevOpsProjectCreator devOpsProjectCreator, DbSession dbSession) {
+  private static ComponentCreationData mockProjectCreation(DevOpsProjectCreator devOpsProjectCreator, CreationMethod creationMethod, boolean monorepo, DbSession dbSession) {
     ComponentCreationData componentCreationData = mock(ComponentCreationData.class);
-    when(devOpsProjectCreator.createProjectAndBindToDevOpsPlatform(eq(dbSession), any(), eq(true), eq(PROJECT_KEY), eq(PROJECT_NAME)))
+    when(devOpsProjectCreator.createProjectAndBindToDevOpsPlatform(dbSession, creationMethod, monorepo, PROJECT_KEY, PROJECT_NAME))
       .thenReturn(componentCreationData);
     return componentCreationData;
   }