diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-22 12:06:38 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-04-22 12:06:38 +0200 |
commit | 617bd05a326531e8d64faa8ba0bf54fbe0bce421 (patch) | |
tree | d8856eaf58d3db52f6610f451506d29a76d7d672 /sonar-core | |
parent | cc5bd59de2151261944161f5324e0adc329a8cd2 (diff) | |
download | sonarqube-617bd05a326531e8d64faa8ba0bf54fbe0bce421.tar.gz sonarqube-617bd05a326531e8d64faa8ba0bf54fbe0bce421.zip |
ONAR-5132 Issues search WS should allow to search by language
Diffstat (limited to 'sonar-core')
4 files changed, 127 insertions, 5 deletions
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index bd85afc9313..785410c1ae2 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -236,9 +236,16 @@ <foreach item="component" index="index" collection="query.components()" open="(" separator=" or " close=")">project_component.kee=#{component} </foreach> </if> - <if test="query.rules().size()>0"> - inner join rules r on r.id=i.rule_id and (<foreach item="rule" index="index" collection="query.rules()" open="(" separator=" or " close=")"> - r.plugin_name=#{rule.repository} and r.plugin_rule_key=#{rule.rule}</foreach>) + <if test="query.rules().size()>0 or query.languages().size()>0"> + inner join rules r on r.id=i.rule_id + <if test="query.rules().size()>0"> + and (<foreach item="rule" index="index" collection="query.rules()" open="(" separator=" or " close=")"> + r.plugin_name=#{rule.repository} and r.plugin_rule_key=#{rule.rule}</foreach>) + </if> + <if test="query.languages().size()>0"> + and (<foreach item="language" index="index" collection="query.languages()" open="(" separator=" or " close=")"> + r.language=#{language}</foreach>) + </if> </if> <where> <if test="query.issueKeys().size()>0"> diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index 45790762a26..196b10204e0 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -260,6 +260,20 @@ public class IssueDaoTest extends AbstractDaoTestCase { } @Test + public void select_by_languages() { + setupData("shared", "select_by_languages"); + + IssueQuery query = IssueQuery.builder().languages(newArrayList("java")).requiredRole("user").build(); + assertThat(dao.selectIssueIds(query)).hasSize(2); + + query = IssueQuery.builder().languages(newArrayList("java", "xoo")).requiredRole("user").build(); + assertThat(dao.selectIssueIds(query)).hasSize(3); + + query = IssueQuery.builder().languages(newArrayList("Other")).requiredRole("user").build(); + assertThat(dao.selectIssueIds(query)).isEmpty(); + } + + @Test public void should_select_issues_for_authorized_projects() { setupData("should_select_issues_for_authorized_projects"); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/select_by_languages.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/select_by_languages.xml new file mode 100644 index 00000000000..3162d272b36 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/select_by_languages.xml @@ -0,0 +1,101 @@ +<!-- + ~ SonarQube, open source software quality management tool. + ~ Copyright (C) 2008-2014 SonarSource + ~ mailto:contact AT sonarsource DOT com + ~ + ~ SonarQube 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. + ~ + ~ SonarQube 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. + --> + +<dataset> + + <!-- language Java --> + <issues + id="100" + kee="ABCDE-1" + component_id="401" + root_component_id="399" + rule_id="500" + severity="BLOCKER" + manual_severity="[false]" + message="[null]" + line="200" + effort_to_fix="4.2" + status="OPEN" + resolution="FIXED" + checksum="XXX" + reporter="arthur" + assignee="perceval" + author_login="[null]" + issue_attributes="JIRA=FOO-1234" + issue_creation_date="2013-04-16" + issue_update_date="2013-04-16" + issue_close_date="2013-04-16" + created_at="2013-04-16" + updated_at="2013-04-16" + /> + + <issues + id="101" + kee="ABCDE-2" + component_id="401" + root_component_id="399" + rule_id="500" + severity="BLOCKER" + manual_severity="[false]" + message="[null]" + line="200" + effort_to_fix="4.2" + status="OPEN" + resolution="FIXED" + checksum="XXX" + reporter="arthur" + assignee="perceval" + author_login="[null]" + issue_attributes="JIRA=FOO-1234" + issue_creation_date="2013-04-16" + issue_update_date="2013-04-16" + issue_close_date="2013-04-16" + created_at="2013-04-16" + updated_at="2013-04-16" + /> + + + <!-- language Xoo --> + <issues + id="102" + kee="ABCDE-3" + component_id="401" + root_component_id="399" + rule_id="501" + severity="BLOCKER" + manual_severity="[false]" + message="[null]" + line="200" + effort_to_fix="4.2" + status="OPEN" + resolution="FIXED" + checksum="XXX" + reporter="arthur" + assignee="perceval" + author_login="[null]" + issue_attributes="JIRA=FOO-1234" + issue_creation_date="2013-04-16" + issue_update_date="2013-04-16" + issue_close_date="2013-04-16" + created_at="2013-04-16" + updated_at="2013-04-16" + /> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/shared.xml index 49364f57eb6..89d4696e367 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/shared.xml @@ -12,7 +12,7 @@ <snapshots id="102" project_id="401" root_snapshot_id="100" parent_snapshot_id="101" root_project_id="399" path="100.101." islast="[true]" /> <snapshots id="103" project_id="402" root_snapshot_id="100" parent_snapshot_id="101" root_project_id="399" path="100.101." islast="[true]" /> - <rules id="500" plugin_rule_key="AvoidCycle" plugin_name="squid" /> - <rules id="501" plugin_rule_key="NullRef" plugin_name="squid" /> + <rules id="500" plugin_rule_key="AvoidCycle" plugin_name="squid" language="java" /> + <rules id="501" plugin_rule_key="NullRef" plugin_name="squid" language="xoo" /> </dataset> |