aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java18
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentTreeQuery.java7
2 files changed, 15 insertions, 10 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 bdde220e428..cffa000bc2f 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
@@ -361,15 +361,15 @@ public class TreeActionTest {
for (JsonElement componentAsJsonElement : components) {
JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject();
componentDb.insertComponentAndSnapshot(new ComponentDto()
- .setUuid(getJsonField(componentAsJsonObject, "id"))
- .setKey(getJsonField(componentAsJsonObject, "key"))
- .setName(getJsonField(componentAsJsonObject, "name"))
- .setPath(getJsonField(componentAsJsonObject, "path"))
- .setProjectUuid(project.projectUuid())
- .setQualifier(getJsonField(componentAsJsonObject, "qualifier"))
- .setDescription(getJsonField(componentAsJsonObject, "description"))
- .setEnabled(true)
- .setCreatedAt(now),
+ .setUuid(getJsonField(componentAsJsonObject, "id"))
+ .setKey(getJsonField(componentAsJsonObject, "key"))
+ .setName(getJsonField(componentAsJsonObject, "name"))
+ .setPath(getJsonField(componentAsJsonObject, "path"))
+ .setProjectUuid(project.projectUuid())
+ .setQualifier(getJsonField(componentAsJsonObject, "qualifier"))
+ .setDescription(getJsonField(componentAsJsonObject, "description"))
+ .setEnabled(true)
+ .setCreatedAt(now),
projectSnapshot);
}
db.commit();
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 749c21e3aff..7fe84cd77c1 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
@@ -54,7 +54,7 @@ public class ComponentTreeQuery {
this.page = builder.page;
this.pageSize = builder.pageSize;
this.baseSnapshot = builder.baseSnapshot;
- this.baseSnapshotPath = buildLikeValue(baseSnapshot.getPath() + baseSnapshot.getId() + ".", WildcardPosition.AFTER);
+ this.baseSnapshotPath = buildBaseSnapshotPath(baseSnapshot);
this.direction = builder.asc ? "ASC" : "DESC";
this.sqlSort = sortFieldsToSqlSort(builder.sortFields, direction);
}
@@ -112,6 +112,11 @@ public class ComponentTreeQuery {
return Joiner.on(", ").join(sqlSortFields);
}
+ private String buildBaseSnapshotPath(SnapshotDto baseSnapshot) {
+ String existingSnapshotPath = baseSnapshot.getPath() == null ? "" : baseSnapshot.getPath();
+ return buildLikeValue(existingSnapshotPath + baseSnapshot.getId() + ".", WildcardPosition.AFTER);
+ }
+
public static class Builder {
@CheckForNull
private String nameOrKeyQuery;