aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-01-23 15:29:16 -0600
committersonartech <sonartech@sonarsource.com>2023-02-02 20:03:39 +0000
commit2a867fa579517222177bd14eb6e2d8d0b5cf287e (patch)
treec6d91cd3a653a8aae5a98682d8100598c189cdb9
parentbbf23d6ad4ee140edbc02825d699a849ab47305a (diff)
downloadsonarqube-2a867fa579517222177bd14eb6e2d8d0b5cf287e.tar.gz
sonarqube-2a867fa579517222177bd14eb6e2d8d0b5cf287e.zip
SONAR-17706 Drop support for projects still using modules in SonarQube server
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java140
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java40
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplTest.java87
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java241
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java15
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml19
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java88
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java6
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java8
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java13
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/DefaultResourceTypes.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java10
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/DefaultResourceTypesTest.java2
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java1
20 files changed, 125 insertions, 581 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java
deleted file mode 100644
index 78301ff62c5..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigration.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.ce.task.projectanalysis.component;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.BranchType;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentWithModuleUuidDto;
-import org.sonar.db.component.KeyWithUuidDto;
-
-public class ComponentUuidFactoryWithMigration implements ComponentUuidFactory {
- private final Map<String, String> uuidsByDbKey = new HashMap<>();
- private final Map<String, String> uuidsByMigratedKey = new HashMap<>();
-
- public ComponentUuidFactoryWithMigration(DbClient dbClient, DbSession dbSession, String rootKey, Branch branch,
- Function<String, String> pathToKey, Map<String, String> reportModulesPath) {
- Map<String, String> modulePathsByUuid;
- List<KeyWithUuidDto> keys;
- if (branch.isMain()) {
- keys = dbClient.componentDao().selectUuidsByKeyFromProjectKey(dbSession, rootKey);
- } else if (branch.getType() == BranchType.PULL_REQUEST) {
- keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndPullRequest(dbSession, rootKey, branch.getPullRequestKey());
- } else {
- keys = dbClient.componentDao().selectUuidsByKeyFromProjectKeyAndBranch(dbSession, rootKey, branch.getName());
- }
-
- keys.forEach(dto -> uuidsByDbKey.put(dto.key(), dto.uuid()));
-
- if (!reportModulesPath.isEmpty()) {
- modulePathsByUuid = loadModulePathsByUuid(dbClient, dbSession, rootKey, branch, reportModulesPath);
-
- if (!modulePathsByUuid.isEmpty()) {
- doMigration(dbClient, dbSession, rootKey, pathToKey, modulePathsByUuid);
- }
- }
- }
-
- private void doMigration(DbClient dbClient, DbSession dbSession, String rootKey, Function<String, String> pathToKey, Map<String, String> modulePathsByUuid) {
- List<ComponentWithModuleUuidDto> dtos = loadComponentsWithModuleUuid(dbClient, dbSession, rootKey);
- for (ComponentWithModuleUuidDto dto : dtos) {
- if ("/".equals(dto.path())) {
- // skip root folders
- continue;
- }
-
- if (Scopes.PROJECT.equals(dto.scope())) {
- String modulePathFromRootProject = modulePathsByUuid.get(dto.uuid());
- if (modulePathFromRootProject != null || StringUtils.isEmpty(dto.moduleUuid())) {
- // means that it's a root or a module with a valid path (to avoid overwriting key of root)
- pathToKey.apply(modulePathFromRootProject);
- uuidsByMigratedKey.put(pathToKey.apply(modulePathFromRootProject), dto.uuid());
- }
- } else {
- String modulePathFromRootProject = modulePathsByUuid.get(dto.moduleUuid());
- String componentPath = createComponentPath(dto, modulePathFromRootProject);
- uuidsByMigratedKey.put(pathToKey.apply(componentPath), dto.uuid());
- }
- }
- }
-
- @CheckForNull
- private static String createComponentPath(ComponentWithModuleUuidDto dto, @Nullable String modulePathFromRootProject) {
- if (StringUtils.isEmpty(modulePathFromRootProject)) {
- return dto.path();
- }
-
- if (StringUtils.isEmpty(dto.path())) {
- // will be the case for modules
- return modulePathFromRootProject;
- }
-
- return modulePathFromRootProject + "/" + dto.path();
- }
-
- private static List<ComponentWithModuleUuidDto> loadComponentsWithModuleUuid(DbClient dbClient, DbSession dbSession, String rootKey) {
- return dbClient.componentDao().selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, rootKey);
- }
-
- private static Map<String, String> loadModulePathsByUuid(DbClient dbClient, DbSession dbSession, String rootKey,
- Branch branch, Map<String, String> pathByModuleKey) {
- String branchKey = branch.getType() == BranchType.BRANCH ? branch.getName() : null;
- String prKey = branch.getType() == BranchType.PULL_REQUEST ? branch.getPullRequestKey() : null;
-
- List<ComponentDto> moduleDtos = dbClient.componentDao()
- .selectProjectAndModulesFromProjectKey(dbSession, rootKey, true, branchKey, prKey).stream()
- .filter(c -> Qualifiers.MODULE.equals(c.qualifier()))
- .toList();
-
- if (moduleDtos.isEmpty()) {
- return Collections.emptyMap();
- }
-
- Map<String, String> modulePathByUuid = new HashMap<>();
- for (ComponentDto dto : moduleDtos) {
- String relativePath = pathByModuleKey.get(dto.getKey());
- if (relativePath != null) {
- modulePathByUuid.put(dto.uuid(), relativePath);
- }
- }
- return modulePathByUuid;
- }
-
- /**
- * Get UUID from component having the same key in database if it exists, otherwise look for migrated keys, and finally generate a new one.
- */
- @Override
- public String getOrCreateForKey(String key) {
- return uuidsByDbKey.computeIfAbsent(key, k1 -> uuidsByMigratedKey.computeIfAbsent(k1, k2 -> Uuids.create()));
- }
-}
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
index 5a8f164d620..07946acb212 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
@@ -20,7 +20,6 @@
package org.sonar.ce.task.projectanalysis.step;
import java.util.Optional;
-import java.util.function.Function;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.analysis.Analysis;
import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
@@ -28,7 +27,8 @@ import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.ComponentKeyGenerator;
import org.sonar.ce.task.projectanalysis.component.ComponentTreeBuilder;
-import org.sonar.ce.task.projectanalysis.component.ComponentUuidFactoryWithMigration;
+import org.sonar.ce.task.projectanalysis.component.ComponentUuidFactory;
+import org.sonar.ce.task.projectanalysis.component.ComponentUuidFactoryImpl;
import org.sonar.ce.task.projectanalysis.component.MutableTreeRootHolder;
import org.sonar.ce.task.projectanalysis.component.ProjectAttributes;
import org.sonar.ce.task.projectanalysis.component.ReportModulesPath;
@@ -77,16 +77,14 @@ public class BuildComponentTreeStep implements ComputationStep {
// root key of branch, not necessarily of project
String rootKey = keyGenerator.generateKey(reportProject.getKey(), null);
- Function<String, String> pathToKey = path -> keyGenerator.generateKey(reportProject.getKey(), path);
// loads the UUIDs from database. If they don't exist, then generate new ones
- ComponentUuidFactoryWithMigration componentUuidFactoryWithMigration =
- new ComponentUuidFactoryWithMigration(dbClient, dbSession, rootKey, analysisMetadataHolder.getBranch(), pathToKey, reportModulesPath.get());
+ ComponentUuidFactory componentUuidFactory = new ComponentUuidFactoryImpl(dbClient, dbSession, rootKey, analysisMetadataHolder.getBranch());
- String rootUuid = componentUuidFactoryWithMigration.getOrCreateForKey(rootKey);
+ String rootUuid = componentUuidFactory.getOrCreateForKey(rootKey);
Optional<SnapshotDto> baseAnalysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, rootUuid);
ComponentTreeBuilder builder = new ComponentTreeBuilder(keyGenerator,
- componentUuidFactoryWithMigration::getOrCreateForKey,
+ componentUuidFactory::getOrCreateForKey,
reportReader::readComponent,
analysisMetadataHolder.getProject(),
analysisMetadataHolder.getBranch(),
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
index 52320e49b28..df21088be7d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
@@ -23,9 +23,7 @@ import com.google.common.base.Joiner;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -64,14 +62,10 @@ public class ValidateProjectStep implements ComputationStep {
@Override
public void execute(ComputationStep.Context context) {
try (DbSession dbSession = dbClient.openSession(false)) {
- validateTargetBranch(dbSession);
Component root = treeRootHolder.getRoot();
- // FIXME if module have really be dropped, no more need to load them
String branchKey = analysisMetadataHolder.isBranch() ? analysisMetadataHolder.getBranch().getName() : null;
String prKey = analysisMetadataHolder.isPullRequest() ? analysisMetadataHolder.getBranch().getPullRequestKey() : null;
- List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey(), branchKey, prKey);
- Map<String, ComponentDto> baseModulesByKey = baseModules.stream().collect(Collectors.toMap(ComponentDto::getKey, x -> x));
- ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
+ ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao());
new DepthTraversalTypeAwareCrawler(visitor).visit(root);
if (!visitor.validationMessages.isEmpty()) {
@@ -80,20 +74,6 @@ public class ValidateProjectStep implements ComputationStep {
}
}
- private void validateTargetBranch(DbSession session) {
- if (!analysisMetadataHolder.isPullRequest()) {
- return;
- }
- String referenceBranchUuid = analysisMetadataHolder.getBranch().getReferenceBranchUuid();
- int moduleCount = dbClient.componentDao().countEnabledModulesByBranchUuid(session, referenceBranchUuid);
- if (moduleCount > 0) {
- Optional<BranchDto> opt = dbClient.branchDao().selectByUuid(session, referenceBranchUuid);
- checkState(opt.isPresent(), "Reference branch '%s' does not exist", referenceBranchUuid);
- throw MessageException.of(String.format(
- "Due to an upgrade, you need first to re-analyze the target branch '%s' before analyzing this pull request.", opt.get().getKey()));
- }
- }
-
@Override
public String getDescription() {
return "Validate project";
@@ -102,14 +82,12 @@ public class ValidateProjectStep implements ComputationStep {
private class ValidateProjectsVisitor extends TypeAwareVisitorAdapter {
private final DbSession session;
private final ComponentDao componentDao;
- private final Map<String, ComponentDto> baseModulesByKey;
private final List<String> validationMessages = new ArrayList<>();
- public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, Map<String, ComponentDto> baseModulesByKey) {
+ public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao) {
super(CrawlerDepthLimit.PROJECT, ComponentVisitor.Order.PRE_ORDER);
this.session = session;
this.componentDao = componentDao;
- this.baseModulesByKey = baseModulesByKey;
}
@Override
@@ -142,16 +120,12 @@ public class ValidateProjectStep implements ComputationStep {
}
private Optional<ComponentDto> loadBaseComponent(String rawComponentKey) {
- ComponentDto baseComponent = baseModulesByKey.get(rawComponentKey);
- if (baseComponent == null) {
- // Load component from key to be able to detect issue (try to analyze a module, etc.)
- if (analysisMetadataHolder.isBranch()) {
- return componentDao.selectByKeyAndBranch(session, rawComponentKey, analysisMetadataHolder.getBranch().getName());
- } else {
- return componentDao.selectByKeyAndPullRequest(session, rawComponentKey, analysisMetadataHolder.getBranch().getPullRequestKey());
- }
+ // Load component from key to be able to detect issue (try to analyze a module, etc.)
+ if (analysisMetadataHolder.isBranch()) {
+ return componentDao.selectByKeyAndBranch(session, rawComponentKey, analysisMetadataHolder.getBranch().getName());
+ } else {
+ return componentDao.selectByKeyAndPullRequest(session, rawComponentKey, analysisMetadataHolder.getBranch().getPullRequestKey());
}
- return Optional.of(baseComponent);
}
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplTest.java
new file mode 100644
index 00000000000..a7e9ef3ab74
--- /dev/null
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryImplTest.java
@@ -0,0 +1,87 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.ce.task.projectanalysis.component;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchType;
+import org.sonar.db.component.ComponentDto;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
+
+public class ComponentUuidFactoryImplTest {
+ private final Branch mainBranch = new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME);
+ private final Branch mockedBranch = mock(Branch.class);
+
+ @Rule
+ public DbTester db = DbTester.create(System2.INSTANCE);
+
+ @Test
+ public void getOrCreateForKey_when_existingComponentsInDbForMainBranch_should_load() {
+ ComponentDto project = db.components().insertPrivateProject();
+
+ ComponentUuidFactory underTest = new ComponentUuidFactoryImpl(db.getDbClient(), db.getSession(), project.getKey(), mainBranch);
+
+ assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
+ }
+
+ @Test
+ public void getOrCreateForKey_when_existingComponentsInDbForNonMainBranch_should_load() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("b1"));
+ when(mockedBranch.getType()).thenReturn(BranchType.BRANCH);
+ when(mockedBranch.isMain()).thenReturn(false);
+ when(mockedBranch.getName()).thenReturn("b1");
+
+ ComponentUuidFactory underTest = new ComponentUuidFactoryImpl(db.getDbClient(), db.getSession(), project.getKey(), mockedBranch);
+
+ assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(branch.uuid());
+ }
+
+ @Test
+ public void getOrCreateForKey_when_existingComponentsInDbForPr_should_load() {
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr1"));
+ when(mockedBranch.getType()).thenReturn(BranchType.PULL_REQUEST);
+ when(mockedBranch.isMain()).thenReturn(false);
+ when(mockedBranch.getPullRequestKey()).thenReturn("pr1");
+
+ ComponentUuidFactory underTest = new ComponentUuidFactoryImpl(db.getDbClient(), db.getSession(), project.getKey(), mockedBranch);
+
+ assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(pr.uuid());
+ }
+
+ @Test
+ public void getOrCreateForKey_when_componentsNotInDb_should_generate() {
+ ComponentUuidFactory underTest = new ComponentUuidFactoryImpl(db.getDbClient(), db.getSession(), "theProjectKey", mainBranch);
+
+ String generatedKey = underTest.getOrCreateForKey("foo");
+ assertThat(generatedKey).isNotEmpty();
+
+ // uuid is kept in memory for further calls with same key
+ assertThat(underTest.getOrCreateForKey("foo")).isEqualTo(generatedKey);
+ }
+}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
deleted file mode 100644
index ecc5747b8e6..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.ce.task.projectanalysis.component;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Function;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.System2;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ComponentTesting;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
-
-public class ComponentUuidFactoryWithMigrationTest {
- private final Branch mainBranch = new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME);
- @Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
- private Function<String, String> pathToKey = path -> path != null ? "project:" + path : "project";
-
- @Test
- public void load_uuids_from_existing_components_in_db() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
- Map<String, String> reportModulesPath = Collections.singletonMap(module.getKey(), "module1_path");
- pathToKey = path -> path != null ? project.getKey() + ":" + path : project.getKey();
-
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, reportModulesPath);
-
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- assertThat(underTest.getOrCreateForKey(module.getKey())).isEqualTo(module.uuid());
- }
-
- @Test
- public void migrate_project_with_modules() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1)
- .setKey("project:module1:module2"));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file1")
- .setPath("file1_path"));
- ComponentDto file2 = db.components().insertComponent(ComponentTesting.newFileDto(module2)
- .setKey("project:module1:module2:file2")
- .setPath("file2_path"));
-
- assertThat(file2.moduleUuidPath()).isEqualTo("." + project.uuid() + "." + module1.uuid() + "." + module2.uuid() + ".");
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project:module1", "module1_path");
- modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // migrated files
- assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid());
- assertThat(underTest.getOrCreateForKey("project:module1_path/module2_path/file2_path")).isEqualTo(file2.uuid());
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- }
-
- @Test
- public void migrate_project_with_disabled_components_no_path() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file1")
- .setPath("file1"));
- ComponentDto disabledFileNoPath = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file2")
- .setPath(null)
- .setEnabled(false));
-
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // migrated files
- assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- }
-
- @Test
- public void migrate_project_with_disabled_components_same_path() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file1")
- .setPath("file1"));
- ComponentDto disabledFileSamePath = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file2")
- .setPath("file1")
- .setEnabled(false));
-
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // migrated files
- assertThat(underTest.getOrCreateForKey("project:file1")).isEqualTo(file1.uuid());
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- }
-
- @Test
- public void prefers_component_having_same_key() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(module1)
- .setKey("project:module1:file1")
- .setPath("file1"));
- ComponentDto disabledFileSameKey = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:module1/file1")
- .setPath("module1_path/file1")
- .setEnabled(false));
-
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // in theory we should migrate file1. But since disabledFileSameKey already have the expected migrated key, let's reuse it.
- assertThat(underTest.getOrCreateForKey("project:module1/file1")).isEqualTo(disabledFileSameKey.uuid());
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- }
-
- @Test
- public void migrate_branch_with_modules() {
- pathToKey = path -> path != null ? "project:" + path : "project";
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1)
- .setKey("project:module1:module2"));
- ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project)
- .setKey("project:file1")
- .setPath("file1_path"));
- ComponentDto file2 = db.components().insertComponent(ComponentTesting.newFileDto(module2)
- .setKey("project:module1:module2:file2")
- .setPath("file2_path"));
-
- assertThat(file2.moduleUuidPath()).isEqualTo("." + project.uuid() + "." + module1.uuid() + "." + module2.uuid() + ".");
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project:module1", "module1_path");
- modulesRelativePaths.put("project:module1:module2", "module1_path/module2_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // migrated files
- assertThat(underTest.getOrCreateForKey("project:file1_path")).isEqualTo(file1.uuid());
- assertThat(underTest.getOrCreateForKey("project:module1_path/module2_path/file2_path")).isEqualTo(file2.uuid());
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
- }
-
- @Test
- public void migrate_project_with_root_folders() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1"));
- ComponentDto dir1 = db.components().insertComponent(ComponentTesting.newDirectory(module1, "/")
- .setKey("project:module1:/"));
-
- Map<String, String> modulesRelativePaths = Collections.singletonMap("project:module1", "module1_path");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // project remains the same
- assertThat(underTest.getOrCreateForKey(project.getKey())).isEqualTo(project.uuid());
-
- // module migrated to folder
- assertThat(underTest.getOrCreateForKey("project:module1_path")).isEqualTo(module1.uuid());
- }
-
- @Test
- public void dont_override_root_uuid_if_module_path_is_not_sent() {
- ComponentDto project = db.components().insertPrivateProject(dto -> dto.setKey("project"));
- ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module1")
- .setEnabled(false));
- ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project)
- .setKey("project:module2")
- .setEnabled(false));
- Map<String, String> modulesRelativePaths = new HashMap<>();
- modulesRelativePaths.put("project", "");
- modulesRelativePaths.put("project:module2", "module2");
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), project.getKey(), mainBranch, pathToKey, modulesRelativePaths);
-
- // check root project.
- assertThat(underTest.getOrCreateForKey("project")).isEqualTo(project.uuid());
- }
-
- @Test
- public void generate_uuid_if_it_does_not_exist_in_db() {
- ComponentUuidFactoryWithMigration underTest =
- new ComponentUuidFactoryWithMigration(db.getDbClient(), db.getSession(), "theProjectKey", mainBranch, pathToKey, Collections.emptyMap());
-
- String generatedKey = underTest.getOrCreateForKey("foo");
- assertThat(generatedKey).isNotEmpty();
-
- // uuid is kept in memory for further calls with same key
- assertThat(underTest.getOrCreateForKey("foo")).isEqualTo(generatedKey);
- }
-
-}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index dc6070aa9e7..4823fa8cfab 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -52,7 +52,6 @@ import org.sonar.db.component.BranchMapper;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentKeyUpdaterMapper;
import org.sonar.db.component.ComponentMapper;
-import org.sonar.db.component.ComponentWithModuleUuidDto;
import org.sonar.db.component.FilePathWithHashDto;
import org.sonar.db.component.KeyWithUuidDto;
import org.sonar.db.component.PrBranchAnalyzedLanguageCountByProjectDto;
@@ -192,7 +191,6 @@ public class MyBatis {
confBuilder.loadAlias("ApplicationProject", ApplicationProjectDto.class);
confBuilder.loadAlias("CeTaskCharacteristic", CeTaskCharacteristicDto.class);
confBuilder.loadAlias("Component", ComponentDto.class);
- confBuilder.loadAlias("ComponentWithModuleUuid", ComponentWithModuleUuidDto.class);
confBuilder.loadAlias("DuplicationUnit", DuplicationUnitDto.class);
confBuilder.loadAlias("Event", EventDto.class);
confBuilder.loadAlias("FilePathWithHash", FilePathWithHashDto.class);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
index aea15fb93a6..a73c55936ca 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
@@ -105,10 +105,6 @@ public class ComponentDao implements Dao {
return mapper(dbSession).selectByBranchUuid(branchUuid);
}
- public int countEnabledModulesByBranchUuid(DbSession session, String branchUuid) {
- return mapper(session).countEnabledModulesByBranchUuid(branchUuid);
- }
-
/*
SELECT BY QUERY
*/
@@ -175,13 +171,6 @@ public class ComponentDao implements Dao {
return mapper(session).selectComponentsFromProjectKeyAndScope(projectKey, Scopes.PROJECT, excludeDisabled, branch, pullRequest);
}
- /**
- * If no branch or pull request is provided, returns components in the main branch
- */
- public List<ComponentDto> selectEnabledModulesFromProjectKey(DbSession session, String projectKey, @Nullable String branch, @Nullable String pullRequest) {
- return selectProjectAndModulesFromProjectKey(session, projectKey, true, branch, pullRequest);
- }
-
public List<ComponentDto> selectByKeys(DbSession session, Collection<String> keys) {
return selectByKeys(session, keys, null, null);
}
@@ -301,10 +290,6 @@ public class ComponentDao implements Dao {
return new HashSet<>(mapper(dbSession).selectComponentsByQualifiers(qualifiers));
}
- public List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(DbSession dbSession, String projectKey) {
- return mapper(dbSession).selectEnabledComponentsWithModuleUuidFromProjectKey(projectKey);
- }
-
/**
* Returns components with open issues from P/Rs that use a certain branch as reference (reference branch).
* Excludes components from the current branch.
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
index d16cad7608a..48d934d15c1 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentMapper.java
@@ -54,8 +54,6 @@ public interface ComponentMapper {
List<ComponentDto> selectComponentsByQualifiers(@Param("qualifiers") Collection<String> qualifiers);
- int countEnabledModulesByBranchUuid(@Param("branchUuid") String branchUuid);
-
List<ComponentDto> selectByQuery(@Param("query") ComponentQuery query, RowBounds rowBounds);
int countByQuery(@Param("query") ComponentQuery query);
@@ -139,7 +137,5 @@ public interface ComponentMapper {
List<ProjectNclocDistributionDto> selectPrivateProjectsWithNcloc();
- List<ComponentWithModuleUuidDto> selectEnabledComponentsWithModuleUuidFromProjectKey(String projectKey);
-
short checkIfAnyOfComponentsWithQualifiers(@Param("componentKeys") Collection<String> componentKeys, @Param("qualifiers") Set<String> qualifiers);
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 5605626e4b8..a10a3051773 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -257,16 +257,6 @@
</foreach>
</select>
- <select id="countEnabledModulesByBranchUuid" resultType="int">
- select
- count(1)
- from components p
- where
- p.enabled=${_true}
- and p.branch_uuid = #{branchUuid,jdbcType=VARCHAR}
- and p.qualifier = 'BRC'
- </select>
-
<select id="selectByQuery" resultType="Component">
select
<include refid="componentColumns"/>
@@ -541,15 +531,6 @@
p.branch_uuid = #{branchUuid,jdbcType=VARCHAR}
</select>
- <select id="selectEnabledComponentsWithModuleUuidFromProjectKey" resultType="ComponentWithModuleUuid">
- SELECT
- p.uuid as uuid, p.module_uuid as moduleUuid, p.path as path, p.scope as scope
- FROM
- components p
- INNER JOIN
- components root ON root.uuid=p.branch_uuid AND p.enabled = ${_true} AND root.kee=#{projectKey,jdbcType=VARCHAR}
- </select>
-
<select id="selectUuidsByKeyFromProjectKeyAndBranchOrPr" parameterType="string" resultType="KeyWithUuid">
SELECT
p.kee, p.uuid
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 79a16f640d7..5d48d654a7e 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -408,20 +408,6 @@ public class ComponentDaoTest {
}
@Test
- public void count_enabled_modules_by_project_uuid() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- db.components().insertComponent(newModuleDto(module));
- ComponentDto subModule2 = newModuleDto(module);
- subModule2.setEnabled(false);
- db.components().insertComponent(subModule2);
-
- int result = underTest.countEnabledModulesByBranchUuid(dbSession, project.uuid());
-
- assertThat(result).isEqualTo(2);
- }
-
- @Test
public void find_sub_projects_by_component_keys() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
@@ -505,29 +491,6 @@ public class ComponentDaoTest {
}
@Test
- public void select_enabled_components_with_module_dto() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
-
- // From root project
- assertThat(underTest.selectEnabledComponentsWithModuleUuidFromProjectKey(dbSession, project.getKey()))
- .extracting(ComponentWithModuleUuidDto::uuid)
- .containsExactlyInAnyOrder(
- project.uuid(),
- module.uuid(),
- subModule.uuid(),
- directory.uuid(),
- file.uuid());
- }
-
- @Test
public void select_all_modules_tree() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
@@ -719,57 +682,6 @@ public class ComponentDaoTest {
}
@Test
- public void select_enabled_modules_from_project() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
- ComponentDto module = db.components().insertComponent(newModuleDto(project));
- ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto removedSubModule = db.components().insertComponent(newModuleDto(module).setEnabled(false));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto removedDirectory = db.components().insertComponent(newDirectory(subModule, "src2").setEnabled(false));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
- ComponentDto removedFile = db.components().insertComponent(newFileDto(subModule, directory).setEnabled(false));
-
- // Removed modules are not included
- assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, project.getKey(), null, null))
- .extracting(ComponentDto::getKey)
- .containsExactlyInAnyOrder(project.getKey(), module.getKey(), subModule.getKey());
-
- assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, "UNKNOWN", null, null)).isEmpty();
- }
-
- @Test
- public void select_enabled_modules_from_branch() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1"));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
-
- // Removed modules are not included
- assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, project.getKey(), "branch1", null))
- .extracting(ComponentDto::getKey)
- .containsExactlyInAnyOrder(project.getKey(), module.getKey(), subModule.getKey());
- }
-
- @Test
- public void select_enabled_modules_from_pr() {
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey("pr1"));
- ComponentDto module = db.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
- ComponentDto directory = db.components().insertComponent(newDirectory(subModule, "src"));
- ComponentDto file = db.components().insertComponent(newFileDto(subModule, directory));
-
- // Removed modules are not included
- assertThat(underTest.selectEnabledModulesFromProjectKey(dbSession, project.getKey(), null, "pr1"))
- .extracting(ComponentDto::getKey)
- .containsExactlyInAnyOrder(project.getKey(), module.getKey(), subModule.getKey());
- }
-
- @Test
public void select_views_and_sub_views_and_applications() {
db.components().insertPublicPortfolio("ABCD", p -> {
});
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java
index e19adead7d6..a9243048871 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexScoreTest.java
@@ -26,8 +26,8 @@ import org.sonar.db.component.ComponentTesting;
import org.sonar.server.es.textsearch.ComponentTextSearchFeatureRepertoire;
import static java.util.Arrays.asList;
+import static org.sonar.api.resources.Qualifiers.DIRECTORY;
import static org.sonar.api.resources.Qualifiers.FILE;
-import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
public class ComponentIndexScoreTest extends ComponentIndexTest {
@@ -121,14 +121,14 @@ public class ComponentIndexScoreTest extends ComponentIndexTest {
assertSearch(SuggestionQuery.builder()
.setQuery("File")
- .setQualifiers(asList(PROJECT, MODULE, FILE))
+ .setQualifiers(asList(PROJECT, DIRECTORY, FILE))
.setRecentlyBrowsedKeys(ImmutableSet.of(file1.getKey()))
.setFavoriteKeys(ImmutableSet.of(file2.getKey()))
.build()).containsExactly(uuids(file2, file1));
assertSearch(SuggestionQuery.builder()
.setQuery("File")
- .setQualifiers(asList(PROJECT, MODULE, FILE))
+ .setQualifiers(asList(PROJECT, DIRECTORY, FILE))
.setRecentlyBrowsedKeys(ImmutableSet.of(file2.getKey()))
.setFavoriteKeys(ImmutableSet.of(file1.getKey()))
.build()).containsExactly(uuids(file1, file2));
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
index 84368c780c3..3751a7dea19 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java
@@ -37,7 +37,6 @@ import org.sonar.server.tester.UserSessionRule;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.api.resources.Qualifiers.FILE;
-import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
public abstract class ComponentIndexTest {
@@ -85,7 +84,7 @@ public abstract class ComponentIndexTest {
}
protected ListAssert<String> assertSearch(String query) {
- return assertSearch(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build());
+ return assertSearch(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, FILE)).build());
}
protected ListAssert<String> assertSearch(SuggestionQuery query) {
@@ -95,7 +94,7 @@ public abstract class ComponentIndexTest {
}
protected void assertSearchResults(String query, ComponentDto... expectedComponents) {
- assertSearchResults(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, MODULE, FILE)).build(), expectedComponents);
+ assertSearchResults(SuggestionQuery.builder().setQuery(query).setQualifiers(asList(PROJECT, FILE)).build(), expectedComponents);
}
protected void assertSearchResults(SuggestionQuery query, ComponentDto... expectedComponents) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
index 35f06d7f035..009c5c4269a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchAction.java
@@ -130,11 +130,7 @@ public class SearchAction implements ComponentsWsAction {
Set<String> projectUuidsToSearch = components.stream()
.map(ComponentDto::branchUuid)
.collect(toHashSet());
- List<ComponentDto> projects = dbClient.componentDao()
- .selectByUuids(dbSession, projectUuidsToSearch)
- .stream()
- .filter(c -> !c.qualifier().equals(Qualifiers.MODULE))
- .toList();
+ List<ComponentDto> projects = dbClient.componentDao().selectByUuids(dbSession, projectUuidsToSearch);
return projects.stream().collect(toMap(ComponentDto::uuid, ComponentDto::getKey));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java
index 082b73bf7d1..3cf51c4c2cf 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingValidations.java
@@ -61,7 +61,7 @@ public class SettingValidations {
"sonar.security.config.pythonsecurity",
"sonar.security.config.roslyn.sonaranalyzer.security.cs"
);
- private static final Set<String> SUPPORTED_QUALIFIERS = Set.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP, Qualifiers.MODULE, Qualifiers.SUBVIEW);
+ private static final Set<String> SUPPORTED_QUALIFIERS = Set.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.APP, Qualifiers.SUBVIEW);
private final PropertyDefinitions definitions;
private final DbClient dbClient;
@@ -180,16 +180,16 @@ public class SettingValidations {
validateJsonSchema(jsonContent.get(), definition);
} catch (ValidationException e) {
throw new IllegalArgumentException(String.format("Provided JSON is invalid [%s]", e.getMessage()));
- } catch (IOException e){
+ } catch (IOException e) {
throw new IllegalArgumentException("Provided JSON is invalid");
}
}
}
private void validateJsonSchema(String json, PropertyDefinition definition) {
- if(SECURITY_JSON_PROPERTIES.contains(definition.key())){
+ if (SECURITY_JSON_PROPERTIES.contains(definition.key())) {
InputStream jsonSchemaInputStream = this.getClass().getClassLoader().getResourceAsStream("json-schemas/security.json");
- if(jsonSchemaInputStream != null){
+ if (jsonSchemaInputStream != null) {
JSONObject jsonSchema = new JSONObject(new JSONTokener(jsonSchemaInputStream));
JSONObject jsonSubject = new JSONObject(new JSONTokener(json));
SchemaLoader.load(jsonSchema).validate(jsonSubject);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java
index 40029ac15c1..54d458221da 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java
@@ -50,7 +50,6 @@ import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;
-import static org.sonar.api.resources.Qualifiers.MODULE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.web.UserRole.ADMIN;
import static org.sonar.api.web.UserRole.CODEVIEWER;
@@ -193,9 +192,9 @@ public class ListDefinitionsActionTest {
public void return_JSON_property() {
logIn();
propertyDefinitions.addComponent(PropertyDefinition
- .builder("foo")
- .type(PropertyType.JSON)
- .build());
+ .builder("foo")
+ .type(PropertyType.JSON)
+ .build());
ListDefinitionsWsResponse result = executeRequest();
@@ -293,8 +292,7 @@ public class ListDefinitionsActionTest {
propertyDefinitions.addComponents(asList(
PropertyDefinition.builder("global").build(),
PropertyDefinition.builder("global-and-project").onQualifiers(PROJECT).build(),
- PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build(),
- PropertyDefinition.builder("only-on-module").onlyOnQualifiers(MODULE).build()));
+ PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build()));
ListDefinitionsWsResponse result = executeRequest();
@@ -307,8 +305,7 @@ public class ListDefinitionsActionTest {
propertyDefinitions.addComponents(asList(
PropertyDefinition.builder("global").build(),
PropertyDefinition.builder("global-and-project").onQualifiers(PROJECT).build(),
- PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build(),
- PropertyDefinition.builder("only-on-module").onlyOnQualifiers(MODULE).build()));
+ PropertyDefinition.builder("only-on-project").onlyOnQualifiers(PROJECT).build()));
ListDefinitionsWsResponse result = executeRequest(project.getKey());
diff --git a/sonar-core/src/main/java/org/sonar/core/component/DefaultResourceTypes.java b/sonar-core/src/main/java/org/sonar/core/component/DefaultResourceTypes.java
index b5fbcd596ef..22ddb56748c 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/DefaultResourceTypes.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/DefaultResourceTypes.java
@@ -19,11 +19,11 @@
*/
package org.sonar.core.component;
-import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypeTree;
+import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.server.ServerSide;
@ScannerSide
@@ -61,8 +61,7 @@ public final class DefaultResourceTypes {
.hasSourceCode()
.build())
- .addRelations(Qualifiers.PROJECT, Qualifiers.MODULE)
- .addRelations(Qualifiers.MODULE, Qualifiers.DIRECTORY)
+ .addRelations(Qualifiers.PROJECT, Qualifiers.DIRECTORY)
.addRelations(Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE)
.build();
diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
index 90e0b4c2a98..b53d41fa78a 100644
--- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
+++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
@@ -31,7 +31,10 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.core.extension.PluginRiskConsent;
import static java.util.Arrays.asList;
-import static org.sonar.api.PropertyType.*;
+import static org.sonar.api.PropertyType.BOOLEAN;
+import static org.sonar.api.PropertyType.SINGLE_SELECT_LIST;
+import static org.sonar.api.PropertyType.STRING;
+import static org.sonar.api.PropertyType.TEXT;
import static org.sonar.core.extension.PluginRiskConsent.NOT_ACCEPTED;
public class CorePropertyDefinitions {
@@ -73,7 +76,8 @@ public class CorePropertyDefinitions {
.build(),
PropertyDefinition.builder(CoreProperties.SERVER_BASE_URL)
.name("Server base URL")
- .description("HTTP(S) URL of this SonarQube server, such as <i>https://yourhost.yourdomain/sonar</i>. This value is used outside SonarQube itself, e.g. for PR decoration, emails, etc.")
+ .description(
+ "HTTP(S) URL of this SonarQube server, such as <i>https://yourhost.yourdomain/sonar</i>. This value is used outside SonarQube itself, e.g. for PR decoration, emails, etc.")
.category(CoreProperties.CATEGORY_GENERAL)
.build(),
PropertyDefinition.builder(SONAR_PROJECTCREATION_MAINBRANCHNAME)
@@ -196,7 +200,7 @@ public class CorePropertyDefinitions {
.name("Duplication Exclusions")
.description("Patterns used to exclude some source files from the duplication detection mechanism. " +
"See below to know how to use wildcards to specify this property.")
- .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
+ .onQualifiers(Qualifiers.PROJECT)
.category(CoreProperties.CATEGORY_EXCLUSIONS)
.subCategory(CoreProperties.SUBCATEGORY_DUPLICATIONS_EXCLUSIONS)
.multiValues(true)
diff --git a/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java b/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java
index b948a8cfbed..efe7d03ca38 100644
--- a/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java
+++ b/sonar-core/src/main/java/org/sonar/core/config/ExclusionProperties.java
@@ -41,7 +41,7 @@ public class ExclusionProperties {
.subCategory(CoreProperties.SUBCATEGORY_COVERAGE_EXCLUSIONS)
.type(PropertyType.STRING)
.multiValues(true)
- .onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
+ .onQualifiers(Qualifiers.PROJECT)
.build(),
// FILES
diff --git a/sonar-core/src/test/java/org/sonar/core/component/DefaultResourceTypesTest.java b/sonar-core/src/test/java/org/sonar/core/component/DefaultResourceTypesTest.java
index a1280ca20fc..6658a35c768 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/DefaultResourceTypesTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/DefaultResourceTypesTest.java
@@ -31,6 +31,6 @@ public class DefaultResourceTypesTest {
ResourceTypeTree tree = DefaultResourceTypes.get();
assertThat(tree.getTypes()).hasSize(5);
- assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.MODULE);
+ assertThat(tree.getChildren(Qualifiers.PROJECT)).containsExactly(Qualifiers.DIRECTORY);
}
}
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java
index 7002827e5cb..88570cad9c3 100644
--- a/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/issues/SearchRequest.java
@@ -266,7 +266,6 @@ public class SearchRequest {
* Possible values:
* <ul>
* <li>"projects"</li>
- * <li>"moduleUuids"</li>
* <li>"fileUuids"</li>
* <li>"assigned_to_me"</li>
* <li>"severities"</li>