]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5988 When a quality profile is selected, filter rules using its language
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 22 Jan 2015 14:57:25 +0000 (15:57 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 22 Jan 2015 14:57:30 +0000 (15:57 +0100)
server/sonar-server/src/main/java/org/sonar/server/rule/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWebServiceMediumTest.java

index 384503263f48993388f2a90340c6bf2c29858e86..d2c00afe29b0ae4bc2b01ddd45d6ff80be694320 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.rule.Severity;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
 import org.sonar.server.qualityprofile.ActiveRule;
 import org.sonar.server.rule.Rule;
 import org.sonar.server.rule.RuleService;
@@ -273,7 +274,17 @@ public class SearchAction extends SearchRequestHandler<RuleQuery, Rule> implemen
 
   @Override
   protected RuleQuery doQuery(Request request) {
-    return createRuleQuery(ruleService.newRuleQuery(), request);
+    RuleQuery plainQuery = createRuleQuery(ruleService.newRuleQuery(), request);
+
+    String qProfileKey = request.param(PARAM_QPROFILE);
+    if (qProfileKey != null) {
+      QualityProfileDto qProfile = activeRuleCompleter.loadProfile(qProfileKey);
+      if (qProfile != null) {
+        plainQuery.setLanguages(ImmutableList.of(qProfile.getLanguage()));
+      }
+    }
+
+    return plainQuery;
   }
 
   @Override
index 3df679acc8c169560b264eb2478b06fc2ed44e2f..698499022d9106dc60b18b9d1aecfde13f30c643 100644 (file)
@@ -392,6 +392,13 @@ public class RulesWebServiceMediumTest {
     request.setParam(SearchOptions.PARAM_FIELDS, "actives");
     WsTester.Result result = request.execute();
     result.assertJson(this.getClass(), "search_profile_active_rules.json", false);
+
+    tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
+      .setParam(SearchAction.PARAM_ACTIVATION, "true")
+      .setParam(SearchAction.PARAM_QPROFILE, "unknown_profile")
+      .setParam(SearchOptions.PARAM_FIELDS, "actives")
+      .execute()
+      .assertJson(this.getClass(), "search_no_rules.json", false);
   }
 
   @Test