--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import java.util.List;
+
+/**
+ * @since 2.5
+ */
+public class Rule extends Model {
+
+ private String title = null;
+ private String key = null;
+ private String plugin = null;
+ private String description = null;
+ private String severity = null;
+ private List<RuleParam> params;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public Rule setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Rule setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getPlugin() {
+ return plugin;
+ }
+
+ public Rule setPlugin(String plugin) {
+ this.plugin = plugin;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Rule setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public Rule setSeverity(String severity) {
+ this.severity = severity;
+ return this;
+ }
+
+ public List<RuleParam> getParams() {
+ return params;
+ }
+
+ public void setParams(List<RuleParam> params) {
+ this.params = params;
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.5
+ */
+public class RuleParam {
+
+ private String name;
+
+ private String description;
+
+ private String value;
+
+ public String getName() {
+ return name;
+ }
+
+ public RuleParam setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public RuleParam setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public RuleParam setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.5
+ */
+public class RuleQuery extends Query<Rule> {
+ public static final String BASE_URL = "/api/rules";
+
+ private String language;
+ private String[] plugins;
+ private String searchText;
+ private String profile;
+ private String[] severities;
+
+ public RuleQuery(String language) {
+ this.language = language;
+ }
+
+ public RuleQuery setLanguage(String language) {
+ this.language = language;
+ return this;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public RuleQuery setPlugin(String... plugins) {
+ this.plugins = plugins;
+ return this;
+ }
+
+ public String[] getPlugins() {
+ return plugins;
+ }
+
+ public RuleQuery setSearchText(String searchText) {
+ this.searchText = searchText;
+ return this;
+ }
+
+ public String getSearchText() {
+ return searchText;
+ }
+
+ public RuleQuery setProfile(String profile) {
+ this.profile = profile;
+ return this;
+ }
+
+ public String getProfile() {
+ return profile;
+ }
+
+ public RuleQuery setSeverities(String... severities) {
+ this.severities = severities;
+ return this;
+ }
+
+ public String[] getSeverities() {
+ return severities;
+ }
+
+ @Override
+ public String getUrl() {
+ StringBuilder url = new StringBuilder(BASE_URL);
+ url.append('?');
+ appendUrlParameter(url, "language", language);
+ appendUrlParameter(url, "plugins", plugins);
+ appendUrlParameter(url, "searchtext", searchText);
+ appendUrlParameter(url, "profile", profile);
+ appendUrlParameter(url, "priorities", severities);
+ return url.toString();
+ }
+
+ @Override
+ public Class<Rule> getModelClass() {
+ return Rule.class;
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Rule;
+import org.sonar.wsclient.services.RuleParam;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @since 2.5
+ */
+public class RuleUnmarshaller extends AbstractUnmarshaller<Rule> {
+
+ @Override
+ protected Rule parse(JSONObject json) {
+ Rule rule = new Rule();
+ parseRuleFields(json, rule);
+ parseParams(json, rule);
+ return rule;
+ }
+
+ private void parseRuleFields(JSONObject json, Rule rule) {
+ rule.setTitle(JsonUtils.getString(json, "title"))
+ .setKey(JsonUtils.getString(json, "key"))
+ .setPlugin(JsonUtils.getString(json, "plugin"))
+ .setDescription(JsonUtils.getString(json, "description"))
+ .setSeverity(JsonUtils.getString(json, "priority"));
+ }
+
+ private void parseParams(JSONObject json, Rule rule) {
+ JSONArray paramsJson = (JSONArray) json.get("params");
+ if (paramsJson != null) {
+ rule.setParams(parseParams(paramsJson));
+ }
+ }
+
+ private List<RuleParam> parseParams(JSONArray paramsJson) {
+ List<RuleParam> ruleParams = new ArrayList<RuleParam>();
+ int len = paramsJson.size();
+ for (int i = 0; i < len; i++) {
+ JSONObject paramJson = (JSONObject) paramsJson.get(i);
+ if (paramJson != null) {
+ RuleParam param = parseParam(paramJson);
+ ruleParams.add(param);
+ }
+ }
+ return ruleParams;
+ }
+
+ private RuleParam parseParam(JSONObject json) {
+ RuleParam param = new RuleParam();
+ param.setName(JsonUtils.getString(json, "name"))
+ .setDescription(JsonUtils.getString(json, "description"))
+ .setValue(JsonUtils.getString(json, "value"));
+ return param;
+ }
+
+}
unmarshallers.put(Event.class, new EventUnmarshaller());
unmarshallers.put(Favourite.class, new FavouriteUnmarshaller());
unmarshallers.put(Plugin.class, new PluginUnmarshaller());
+ unmarshallers.put(Rule.class, new RuleUnmarshaller());
}
public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class RuleQueryTest {
+
+ @Test
+ public void languageRules() {
+ RuleQuery query = new RuleQuery("java");
+ assertThat(query.getUrl(), is("/api/rules?language=java&"));
+ assertThat(query.getModelClass().getName(), is(Rule.class.getName()));
+ }
+
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient.unmarshallers;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.wsclient.services.Rule;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class RuleUnmarshallerTest {
+
+ @Test
+ public void toModels() throws IOException {
+ Rule rule = new RuleUnmarshaller().toModel("[]");
+ assertThat(rule, nullValue());
+
+ List<Rule> rules = new RuleUnmarshaller().toModels("[]");
+ assertThat(rules.size(), is(0));
+
+ rules = new RuleUnmarshaller().toModels(loadFile("/rules/rules.json"));
+ assertThat(rules.size(), is(6));
+
+ rule = rules.get(0);
+ assertThat(rule.getTitle(), is("Indentation"));
+ assertThat(rule.getKey(), is("checkstyle:com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck"));
+ assertThat(rule.getPlugin(), is("checkstyle"));
+ assertThat(rule.getDescription(), is("Checks correct indentation of Java Code."));
+ assertThat(rule.getSeverity(), is("MINOR"));
+ assertThat(rule.getParams().size(), is(3));
+ assertThat(rule.getParams().get(0).getName(), is("basicOffset"));
+ assertThat(rule.getParams().get(0).getDescription(), is("how many spaces to use for new indentation level. Default is 4."));
+ }
+
+ private static String loadFile(String path) throws IOException {
+ return IOUtils.toString(MetricUnmarshallerTest.class.getResourceAsStream(path));
+ }
+
+}
--- /dev/null
+[
+ {"title":"Indentation","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck","category":"Usability","plugin":"checkstyle","description":"Checks correct indentation of Java Code.","priority":"MINOR","params":[{"name":"basicOffset","description":"how many spaces to use for new indentation level. Default is 4."},{"name":"braceAdjustment","description":"how far brace should be indented when on next line. Default is 0."},{"name":"caseIndent","description":"how much to indent a case label. Default is 4."}]},
+ {"title":"Javadoc Method","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck","category":"Usability","plugin":"checkstyle","description":"Checks the Javadoc of a method or constructor. By default, does not check for unused throws. \n To allow documented java.lang.RuntimeExceptions that are not declared, set property allowUndeclaredRTE to true. \n The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. \n To verify another scope, set property scope to a different scope.\n \n <br><br>Error messages about parameters and type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags. \n Error messages about exceptions which are declared to be thrown, but for which no throws tag is present can be suppressed by defining property allowMissingThrowsTags. \n Error messages about methods which return non-void but for which no return tag is present can be suppressed by defining property allowMissingReturnTag.\n\n <br><br>Javadoc is not required on a method that is tagged with the @Override annotation. \n However under Java 5 it is not possible to mark a method required for an interface (this was corrected under Java 6). \n Hence Checkstyle supports using the convention of using a single {@inheritDoc} tag instead of all the other tags.\n \n <br><br>Note that only inheritable items will allow the {@inheritDoc} tag to be used in place of comments. \n Static methods at all visibilities, private non-static methods and constructors are not inheritable.","priority":"MAJOR","params":[{"name":"scope","description":"visibility scope where Javadoc comments are checked"},{"name":"excludeScope","description":"visibility scope where Javadoc comments are not checked"},{"name":"allowUndeclaredRTE","description":"whether to allow documented exceptions that are not declared if they are a subclass of java.lang.RuntimeException. Default is false."},{"name":"allowThrowsTagsForSubclasses","description":"whether to allow documented exceptions that are subclass of one of declared exception. Default is false."},{"name":"allowMissingParamTags","description":"whether to ignore errors when a method has parameters but does not have matching param tags in the javadoc. Default is false."},{"name":"allowMissingThrowsTags","description":"whether to ignore errors when a method declares that it throws exceptions but does have matching throws tags in the javadoc. Default is false."},{"name":"allowMissingReturnTag","description":"whether to ignore errors when a method returns non-void type does have a return tag in the javadoc. Default is false."},{"name":"allowMissingJavadoc","description":"whether to ignore errors when a method javadoc is missed. Default is false."},{"name":"allowMissingPropertyJavadoc","description":"Whether to allow missing Javadoc on accessor methods for properties (setters and getters). The setter and getter methods must match exactly the structures below. <code> public void setNumber(final int number) { mNumber = number; } public int getNumber() { return mNumber; } public boolean isSomething() { return false; } </code>. Default is false."},{"name":"tokens","description":"definitions to check"}]},
+ {"title":"Javadoc Package","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck","category":"Maintainability","plugin":"checkstyle","description":"<p>Checks that each Java package has a Javadoc file used for commenting. By default it only allows a package-info.java file, but can be configured to allow a package.html file. An error will be reported if both files exist as this is not allowed by the Javadoc tool.</p>","priority":"MINOR","params":[{"name":"allowLegacy","description":"If set then allow the use of a package.html file."}]},
+ {"title":"Javadoc Style","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck","category":"Usability","plugin":"checkstyle","description":"Validates Javadoc comments to help ensure they are well formed. The following checks are performed:\n <ul>\n <li>Ensures the first sentence ends with proper punctuation (That is a period, question mark, or exclamation mark, by default). \n Javadoc automatically places the first sentence in the method summary table and index. With out proper punctuation the Javadoc may be malformed. \n All items eligible for the {@inheritDoc} tag are exempt from this requirement.</li>\n <li>Check text for Javadoc statements that do not have any description. \n This includes both completely empty Javadoc, and Javadoc with only tags such as @param and @return.</li>\n <li>Check text for incomplete HTML tags. Verifies that HTML tags have corresponding end tags and issues an \"Unclosed HTML tag found:\" error if not. \n An \"Extra HTML tag found:\" error is issued if an end tag is found without a previous open tag.</li>\n <li>Check that a package Javadoc comment is well-formed (as described above) and NOT missing from any package-info.java files.</li>\n <li>Check for allowed HTML tags. The list of allowed HTML tags is \"a\", \"abbr\", \"acronym\", \"address\", \"area\", \"b\", \n \"bdo\", \"big\", \"blockquote\", \"br\", \"caption\", \"cite\", \"code\", \"colgroup\", \"del\", \"div\", \"dfn\", \"dl\", \"em\", \"fieldset\", \n \"h1\" to \"h6\", \"hr\", \"i\", \"img\", \"ins\", \"kbd\", \"li\", \"ol\", \"p\", \"pre\", \"q\", \"samp\", \"small\", \"span\", \"strong\", \n \"sub\", \"sup\", \"table\", \"tbody\", \"td\", \"tfoot\", \"th\", \"thread\", \"tr\", \"tt\", \"ul\"</li>\n </ul>","priority":"MAJOR","params":[{"name":"scope","description":"visibility scope where Javadoc comments are checked"},{"name":"excludeScope","description":"visibility scope where Javadoc comments are not checked"},{"name":"checkFirstSentence","description":"Whether to check the first sentence for proper end of sentence. Default is true."},{"name":"checkEmptyJavadoc","description":"Whether to check if the Javadoc is missing a describing text. Default is false."},{"name":"checkHtml","description":"Whether to check for incomplete html tags. Default is true."},{"name":"tokens","description":"definitions to check"}]},
+ {"title":"Javadoc Type","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck","category":"Usability","plugin":"checkstyle","description":"Checks Javadoc comments for class and interface definitions. By default, does not check for author or version tags. \n The scope to verify is specified using the Scope class and defaults to Scope.PRIVATE. To verify another scope, set property scope to one of the Scope constants. \n To define the format for an author tag or a version tag, set property authorFormat or versionFormat respectively to a regular expression.\n <br><br>Error messages about type parameters for which no param tags are present can be suppressed by defining property allowMissingParamTags.","priority":"MAJOR","params":[{"name":"scope","description":"visibility scope where Javadoc comments are checked"},{"name":"excludeScope","description":"visibility scope where Javadoc comments are not checked"},{"name":"authorFormat","description":"pattern for @author tag"},{"name":"versionFormat","description":"pattern for @version tag"},{"name":"allowMissingParamTags","description":"whether to ignore errors when a class has type parameters but does not have matching param tags in the javadoc. Default is false."},{"name":"tokens","description":"definitions to check"}]},
+ {"title":"Javadoc Variable","key":"checkstyle:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck","category":"Usability","plugin":"checkstyle","description":"Checks that a variable has Javadoc comment.","priority":"MAJOR","params":[{"name":"scope","description":"visibility scope where Javadoc comments are checked"},{"name":"excludeScope","description":"visibility scope where Javadoc comments are not checked"}]}
+]