summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java2
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java24
4 files changed, 27 insertions, 6 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
index aaa504649ff..59c7c542482 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
@@ -243,10 +243,10 @@ public class TreeActionTest {
public void direct_children_of_a_view() throws IOException {
ComponentDto view = newView("view-uuid");
SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view);
- ComponentDto project = newProjectDto("project-uuid-1");
+ ComponentDto project = newProjectDto("project-uuid-1").setName("project-name");
componentDb.insertProjectAndSnapshot(project);
componentDb.insertComponentAndSnapshot(newProjectCopy("project-uuid-1-copy", project, view), viewSnapshot);
- componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key"), viewSnapshot);
+ componentDb.insertComponentAndSnapshot(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"), viewSnapshot);
db.commit();
componentDb.indexProjects();
@@ -254,6 +254,7 @@ public class TreeActionTest {
.setMediaType(MediaTypes.PROTOBUF)
.setParam(PARAM_STRATEGY, "children")
.setParam(PARAM_BASE_COMPONENT_ID, "view-uuid")
+ .setParam(Param.TEXT_QUERY, "name")
.execute().getInputStream();
WsComponents.TreeWsResponse response = WsComponents.TreeWsResponse.parseFrom(responseStream);
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
index 96ac077613a..42a76c6f65a 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java
@@ -112,7 +112,7 @@ public class ComponentTreeQuery {
return Joiner.on(", ").join(sqlSortFields);
}
- private String buildBaseSnapshotPath(SnapshotDto baseSnapshot) {
+ private static String buildBaseSnapshotPath(SnapshotDto baseSnapshot) {
String existingSnapshotPath = baseSnapshot.getPath() == null ? "" : baseSnapshot.getPath();
return buildLikeValue(existingSnapshotPath + baseSnapshot.getId() + ".", WildcardPosition.AFTER);
}
diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 28c94bb38f5..6d92ed2c932 100644
--- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -355,7 +355,7 @@
select 1
from resource_index ri
where
- ri.resource_id=p.id
+ (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id)
AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/')
OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/')
</if>
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 0eaf33e3482..65dd56ee237 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -43,7 +43,9 @@ import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newDeveloper;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
+import static org.sonar.db.component.ComponentTesting.newSubView;
import static org.sonar.db.component.ComponentTesting.newView;
@Category(DbTests.class)
@@ -869,6 +871,25 @@ public class ComponentDaoTest {
}
@Test
+ public void select_direct_children_of_a_view() {
+ ComponentDto view = newView("view-uuid");
+ SnapshotDto viewSnapshot = componentDb.insertViewAndSnapshot(view);
+ // one subview
+ ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview-name");
+ componentDb.insertComponentAndSnapshot(subView, viewSnapshot);
+ // one project and its copy linked to the view
+ ComponentDto project = newProjectDto("project-uuid").setName("project-name");
+ componentDb.insertProjectAndSnapshot(project);
+ componentDb.insertComponentAndSnapshot(newProjectCopy("project-copy-uuid", project, view), viewSnapshot);
+ componentDb.indexProjects();
+ ComponentTreeQuery dbQuery = newTreeQuery(viewSnapshot).setNameOrKeyQuery("name").build();
+
+ List<ComponentDtoWithSnapshotId> components = underTest.selectDirectChildren(dbSession, dbQuery);
+
+ assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid");
+ }
+
+ @Test
public void select_all_files_of_a_project_paginated_and_ordered() {
ComponentDto project = newProjectDto().setKey("project-key").setUuid("project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
@@ -903,7 +924,6 @@ public class ComponentDaoTest {
.setPageSize(500)
.setBaseSnapshot(baseSnapshot)
.setSortFields(singletonList("name"))
- .setAsc(true)
- .setQualifiers(newArrayList(Qualifiers.FILE, Qualifiers.MODULE, Qualifiers.DIRECTORY, Qualifiers.PROJECT));
+ .setAsc(true);
}
}