From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:54:08 +0000 (+0100) Subject: SONAR-21821 Add monorepo related project 'CreationMethod's X-Git-Tag: 10.5.0.89998~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0720dee972bcc286fad8f8b73000dfe07aaca5b3;p=sonarqube.git SONAR-21821 Add monorepo related project 'CreationMethod's --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/CreationMethod.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/CreationMethod.java index 668e7ee2a37..481c400743d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/CreationMethod.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/CreationMethod.java @@ -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 + } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/CreationMethodTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/CreationMethodTest.java index fdab1c56e73..a73f7585134 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/CreationMethodTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/CreationMethodTest.java @@ -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 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); diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java index e2b8f841f12..ef714ed876f 100644 --- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java +++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java @@ -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()); + } + } + } diff --git a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java index 4bf728aee16..7ef4c197df9 100644 --- a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java +++ b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java @@ -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; }