aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-12-21 15:21:13 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-12-21 15:21:38 +0100
commit612eca3d6a8df519a502b31b7cbe8f735f34decb (patch)
tree627e9b38f9fe830398a8d1d953d0c2f32ff64226 /sonar-db
parentd1e303f8412f61f426a6c746cc2ac10b584940bd (diff)
downloadsonarqube-612eca3d6a8df519a502b31b7cbe8f735f34decb.tar.gz
sonarqube-612eca3d6a8df519a502b31b7cbe8f735f34decb.zip
SONAR-7127 Add language parameter to WS api/components/search
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java9
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml3
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java19
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java2
4 files changed, 28 insertions, 5 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java
index 57d4536f968..142d98ce781 100644
--- a/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java
+++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentQuery.java
@@ -30,8 +30,10 @@ import static org.sonar.db.WildcardPosition.AFTER;
public class ComponentQuery {
private final String nameOrKeyQuery;
private final String[] qualifiers;
+ private final String language;
- public ComponentQuery(@Nullable String nameOrKeyQuery, String... qualifiers) {
+ public ComponentQuery(@Nullable String nameOrKeyQuery, String language, String... qualifiers) {
+ this.language = language;
checkArgument(qualifiers.length > 0, "At least one qualifier must be provided");
this.nameOrKeyQuery = nameOrKeyQuery;
@@ -56,4 +58,9 @@ public class ComponentQuery {
public String getNameOrKeyQueryToSqlForProjectKey() {
return buildLikeValue(nameOrKeyQuery, AFTER);
}
+
+ @CheckForNull
+ public String getLanguage() {
+ return language;
+ }
}
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 f88928f83ca..0618022f2f8 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
@@ -283,6 +283,9 @@
<foreach collection="query.qualifiers" item="qualifier" open="(" close=")" separator=",">
#{qualifier}
</foreach>
+ <if test="query.language!=null">
+ AND p.language = #{query.language}
+ </if>
<if test="query.nameOrKeyQuery!=null">
AND (exists (
select 1
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 5cf3d42c5f7..3c3491ca31e 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
@@ -683,7 +683,7 @@ public class ComponentDaoTest {
db.commit();
componentDb.indexProjects();
- ComponentQuery query = new ComponentQuery("oJect", Qualifiers.PROJECT);
+ ComponentQuery query = new ComponentQuery("oJect", null, Qualifiers.PROJECT);
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 1, 3);
assertThat(result).hasSize(3);
@@ -697,7 +697,7 @@ public class ComponentDaoTest {
db.commit();
componentDb.indexProjects();
- ComponentQuery query = new ComponentQuery("-\\_%/-", Qualifiers.PROJECT);
+ ComponentQuery query = new ComponentQuery("-\\_%/-", null, Qualifiers.PROJECT);
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
assertThat(result).hasSize(1);
@@ -711,7 +711,7 @@ public class ComponentDaoTest {
db.commit();
componentDb.indexProjects();
- ComponentQuery query = new ComponentQuery("project-_%-", Qualifiers.PROJECT);
+ ComponentQuery query = new ComponentQuery("project-_%-", null, Qualifiers.PROJECT);
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
assertThat(result).hasSize(1);
@@ -719,6 +719,19 @@ public class ComponentDaoTest {
}
@Test
+ public void select_by_query_filter_on_language() {
+ componentDb.insertComponent(newProjectDto().setKey("java-project-key").setLanguage("java"));
+ componentDb.insertComponent(newProjectDto().setKey("cpp-project-key").setLanguage("cpp"));
+ db.commit();
+
+ ComponentQuery query = new ComponentQuery(null, "java", Qualifiers.PROJECT);
+ List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
+
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0).key()).isEqualTo("java-project-key");
+ }
+
+ @Test
public void select_direct_children_of_a_project() {
ComponentDto project = newProjectDto().setKey("project-key").setUuid("project-uuid");
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project);
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java
index 7ba69c6f7b9..94dbecd7e22 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentQueryTest.java
@@ -35,6 +35,6 @@ public class ComponentQueryTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("At least one qualifier must be provided");
- underTest = new ComponentQuery(null);
+ underTest = new ComponentQuery(null, "java");
}
}