]> source.dussan.org Git - sonarqube.git/commitdiff
rename org.sonar.api.rules.StandardRuleXmlFormat to XMLRuleParser
authorsimonbrandhof <simon.brandhof@gmail.com>
Thu, 30 Sep 2010 09:00:18 +0000 (09:00 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Thu, 30 Sep 2010 09:00:18 +0000 (09:00 +0000)
13 files changed:
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdRuleRepository.java
sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardRuleXmlFormat.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml [deleted file]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/rules.xml [new file with mode: 0644]
sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/utf8.xml [new file with mode: 0644]

index 5d7073f266e9f97c4760a1d22b702bb64ce47f19..ee533a1cffa993ac2d27b768743ba99d224fe479 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.resources.Java;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.rules.StandardRuleXmlFormat;
+import org.sonar.api.rules.XMLRuleParser;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -43,9 +43,9 @@ public final class CheckstyleRuleRepository extends RuleRepository {
   @Override
   public List<Rule> createRules() {
     List<Rule> rules = new ArrayList<Rule>();
-    rules.addAll(StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml")));
+    rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml")));
     for (File userExtensionXml : fileSystem.getExtensions(CheckstyleConstants.REPOSITORY_KEY, "xml")) {
-      rules.addAll(StandardRuleXmlFormat.parseXml(userExtensionXml));
+      rules.addAll(XMLRuleParser.parseXML(userExtensionXml));
     }
     return rules;
   }
index f690c82619b0e534f68d73b83c108440e53228a8..bf4b11febb6206401002d7b6f797a0478b85ae22 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.resources.Java;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.rules.StandardRuleXmlFormat;
+import org.sonar.api.rules.XMLRuleParser;
 
 public final class FindbugsRuleRepository extends RuleRepository {
 
@@ -38,7 +38,7 @@ public final class FindbugsRuleRepository extends RuleRepository {
   @Override
   public List<Rule> createRules() {
     List<Rule> rules = new ArrayList<Rule>();
-    rules.addAll(StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml")));
+    rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml")));
     return rules;
   }
 }
index 308a93b90fea03d4b43744e193f6e2466439aacd..19214409b08ba4e72967ed798ce0659942e9ec87 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.resources.Java;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.rules.StandardRuleXmlFormat;
+import org.sonar.api.rules.XMLRuleParser;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -43,9 +43,9 @@ public final class PmdRuleRepository extends RuleRepository {
   @Override
   public List<Rule> createRules() {
     List<Rule> rules = new ArrayList<Rule>();
-    rules.addAll(StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml")));
+    rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/pmd/rules.xml")));
     for (File userExtensionXml : fileSystem.getExtensions(PmdConstants.REPOSITORY_KEY, "xml")) {
-      rules.addAll(StandardRuleXmlFormat.parseXml(userExtensionXml));
+      rules.addAll(XMLRuleParser.parseXML(userExtensionXml));
     }
     return rules;
   }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardRuleXmlFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardRuleXmlFormat.java
deleted file mode 100644 (file)
index 9e56a4e..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.api.rules;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
-import org.apache.commons.lang.StringUtils;
-import org.codehaus.stax2.XMLInputFactory2;
-import org.codehaus.staxmate.SMInputFactory;
-import org.codehaus.staxmate.in.SMHierarchicCursor;
-import org.codehaus.staxmate.in.SMInputCursor;
-import org.sonar.api.utils.SonarException;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @since 2.3
- */
-public final class StandardRuleXmlFormat {
-
-  private StandardRuleXmlFormat() {
-    // only static methods
-  }
-
-  public static List<Rule> parseXml(File file) {
-    Reader reader = null;
-    try {
-      reader = new InputStreamReader(FileUtils.openInputStream(file), CharEncoding.UTF_8);
-      return parseXml(reader);
-
-    } catch (IOException e) {
-      throw new SonarException("Fail to load the file: " + file, e);
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  /**
-   * Warning : the input stream is closed in this method
-   */
-  public static List<Rule> parseXml(InputStream input) {
-    Reader reader = null;
-    try {
-      reader = new InputStreamReader(input, CharEncoding.UTF_8);
-      return parseXml(reader);
-
-    } catch (IOException e) {
-      throw new SonarException("Fail to load the xml stream", e);
-
-    } finally {
-      IOUtils.closeQuietly(reader);
-    }
-  }
-
-  public static List<Rule> parseXml(Reader reader) {
-    XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
-    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
-    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
-    // just so it won't try to load DTD in if there's DOCTYPE
-    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
-    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
-    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
-    try {
-      SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
-      rootC.advance(); // <rules>
-      List<Rule> rules = new ArrayList<Rule>();
-
-      SMInputCursor rulesC = rootC.childElementCursor("rule");
-      while (rulesC.getNext() != null) {
-        // <rule>
-        Rule rule = Rule.create();
-        rules.add(rule);
-
-        processRule(rule, rulesC);
-      }
-      return rules;
-
-    } catch (XMLStreamException e) {
-      throw new SonarException("XML is not valid", e);
-    }
-  }
-
-  private static void processRule(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
-    /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
-    String keyAttribute = ruleC.getAttrValue("key");
-    if (StringUtils.isNotBlank(keyAttribute)) {
-      rule.setKey(StringUtils.trim(keyAttribute));
-    }
-
-    /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
-    String priorityAttribute = ruleC.getAttrValue("priority");
-    if (StringUtils.isNotBlank(priorityAttribute)) {
-      rule.setPriority(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
-    }
-
-    SMInputCursor cursor = ruleC.childElementCursor();
-
-    while (cursor.getNext() != null) {
-      String nodeName = cursor.getLocalName();
-
-      if (StringUtils.equalsIgnoreCase("name", nodeName)) {
-        rule.setName(StringUtils.trim(cursor.collectDescendantText(false)));
-
-      } else if (StringUtils.equalsIgnoreCase("description", nodeName)) {
-        rule.setDescription(StringUtils.trim(cursor.collectDescendantText(false)));
-
-      } else if (StringUtils.equalsIgnoreCase("key", nodeName)) {
-        rule.setKey(StringUtils.trim(cursor.collectDescendantText(false)));
-
-      } else if (StringUtils.equalsIgnoreCase("configKey", nodeName)) {
-        rule.setConfigKey(StringUtils.trim(cursor.collectDescendantText(false)));
-
-      } else if (StringUtils.equalsIgnoreCase("priority", nodeName)) {
-        rule.setPriority(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
-
-      } else if (StringUtils.equalsIgnoreCase("category", nodeName)) {
-        /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT : attribute "name" */
-        String category = StringUtils.trim(StringUtils.defaultString(cursor.getAttrValue("name"), cursor.collectDescendantText(false)));
-        rule.setRulesCategory(new RulesCategory(category));
-
-      } else if (StringUtils.equalsIgnoreCase("cardinality", nodeName)) {
-        rule.setCardinality(Rule.Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
-
-      } else if (StringUtils.equalsIgnoreCase("param", nodeName)) {
-        processParameter(rule, cursor);
-      }
-    }
-    if (StringUtils.isEmpty(rule.getKey())) {
-      throw new SonarException("Node <key> is missing in <rule>");
-    }
-    if (StringUtils.isEmpty(rule.getName())) {
-      throw new SonarException("Node <name> is missing in <rule>");
-    }
-  }
-
-  private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
-    RuleParam param = rule.createParameter();
-
-    String keyAttribute = ruleC.getAttrValue("key");
-    if (StringUtils.isNotBlank(keyAttribute)) {
-      /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
-      param.setKey(StringUtils.trim(keyAttribute));
-    }
-
-    String typeAttribute = ruleC.getAttrValue("type");
-    if (StringUtils.isNotBlank(typeAttribute)) {
-      /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
-      param.setType(StringUtils.trim(typeAttribute));
-    }
-
-    SMInputCursor paramC = ruleC.childElementCursor();
-    while (paramC.getNext() != null) {
-      String propNodeName = paramC.getLocalName();
-      String propText = StringUtils.trim(paramC.collectDescendantText(false));
-      if (StringUtils.equalsIgnoreCase("key", propNodeName)) {
-        param.setKey(propText);
-
-      } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) {
-        param.setDescription(propText);
-
-      } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) {
-        param.setType(propText);
-
-      } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) {
-        param.setDefaultValue(propText);
-      }
-    }
-    if (StringUtils.isEmpty(param.getKey())) {
-      throw new SonarException("Node <key> is missing in <param>");
-    }
-  }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
new file mode 100644 (file)
index 0000000..4537da5
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * 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.api.rules;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.CharEncoding;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.stax2.XMLInputFactory2;
+import org.codehaus.staxmate.SMInputFactory;
+import org.codehaus.staxmate.in.SMHierarchicCursor;
+import org.codehaus.staxmate.in.SMInputCursor;
+import org.sonar.api.utils.SonarException;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @since 2.3
+ */
+public final class XMLRuleParser {
+
+  private XMLRuleParser() {
+    // only static methods
+  }
+
+  public static List<Rule> parseXML(File file) {
+    Reader reader = null;
+    try {
+      reader = new InputStreamReader(FileUtils.openInputStream(file), CharEncoding.UTF_8);
+      return parseXML(reader);
+
+    } catch (IOException e) {
+      throw new SonarException("Fail to load the file: " + file, e);
+
+    } finally {
+      IOUtils.closeQuietly(reader);
+    }
+  }
+
+  /**
+   * Warning : the input stream is closed in this method
+   */
+  public static List<Rule> parseXML(InputStream input) {
+    Reader reader = null;
+    try {
+      reader = new InputStreamReader(input, CharEncoding.UTF_8);
+      return parseXML(reader);
+
+    } catch (IOException e) {
+      throw new SonarException("Fail to load the xml stream", e);
+
+    } finally {
+      IOUtils.closeQuietly(reader);
+    }
+  }
+
+  public static List<Rule> parseXML(Reader reader) {
+    XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
+    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
+    // just so it won't try to load DTD in if there's DOCTYPE
+    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
+    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
+    try {
+      SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
+      rootC.advance(); // <rules>
+      List<Rule> rules = new ArrayList<Rule>();
+
+      SMInputCursor rulesC = rootC.childElementCursor("rule");
+      while (rulesC.getNext() != null) {
+        // <rule>
+        Rule rule = Rule.create();
+        rules.add(rule);
+
+        processRule(rule, rulesC);
+      }
+      return rules;
+
+    } catch (XMLStreamException e) {
+      throw new SonarException("XML is not valid", e);
+    }
+  }
+
+  private static void processRule(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
+    /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
+    String keyAttribute = ruleC.getAttrValue("key");
+    if (StringUtils.isNotBlank(keyAttribute)) {
+      rule.setKey(StringUtils.trim(keyAttribute));
+    }
+
+    /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
+    String priorityAttribute = ruleC.getAttrValue("priority");
+    if (StringUtils.isNotBlank(priorityAttribute)) {
+      rule.setPriority(RulePriority.valueOf(StringUtils.trim(priorityAttribute)));
+    }
+
+    SMInputCursor cursor = ruleC.childElementCursor();
+
+    while (cursor.getNext() != null) {
+      String nodeName = cursor.getLocalName();
+
+      if (StringUtils.equalsIgnoreCase("name", nodeName)) {
+        rule.setName(StringUtils.trim(cursor.collectDescendantText(false)));
+
+      } else if (StringUtils.equalsIgnoreCase("description", nodeName)) {
+        rule.setDescription(StringUtils.trim(cursor.collectDescendantText(false)));
+
+      } else if (StringUtils.equalsIgnoreCase("key", nodeName)) {
+        rule.setKey(StringUtils.trim(cursor.collectDescendantText(false)));
+
+      } else if (StringUtils.equalsIgnoreCase("configKey", nodeName)) {
+        rule.setConfigKey(StringUtils.trim(cursor.collectDescendantText(false)));
+
+      } else if (StringUtils.equalsIgnoreCase("priority", nodeName)) {
+        rule.setPriority(RulePriority.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
+
+      } else if (StringUtils.equalsIgnoreCase("category", nodeName)) {
+        /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT : attribute "name" */
+        String category = StringUtils.trim(StringUtils.defaultString(cursor.getAttrValue("name"), cursor.collectDescendantText(false)));
+        rule.setRulesCategory(new RulesCategory(category));
+
+      } else if (StringUtils.equalsIgnoreCase("cardinality", nodeName)) {
+        rule.setCardinality(Rule.Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
+
+      } else if (StringUtils.equalsIgnoreCase("param", nodeName)) {
+        processParameter(rule, cursor);
+      }
+    }
+    if (StringUtils.isEmpty(rule.getKey())) {
+      throw new SonarException("Node <key> is missing in <rule>");
+    }
+    if (StringUtils.isEmpty(rule.getName())) {
+      throw new SonarException("Node <name> is missing in <rule>");
+    }
+  }
+
+  private static void processParameter(Rule rule, SMInputCursor ruleC) throws XMLStreamException {
+    RuleParam param = rule.createParameter();
+
+    String keyAttribute = ruleC.getAttrValue("key");
+    if (StringUtils.isNotBlank(keyAttribute)) {
+      /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
+      param.setKey(StringUtils.trim(keyAttribute));
+    }
+
+    String typeAttribute = ruleC.getAttrValue("type");
+    if (StringUtils.isNotBlank(typeAttribute)) {
+      /* BACKWARD COMPATIBILITY WITH DEPRECATED FORMAT */
+      param.setType(StringUtils.trim(typeAttribute));
+    }
+
+    SMInputCursor paramC = ruleC.childElementCursor();
+    while (paramC.getNext() != null) {
+      String propNodeName = paramC.getLocalName();
+      String propText = StringUtils.trim(paramC.collectDescendantText(false));
+      if (StringUtils.equalsIgnoreCase("key", propNodeName)) {
+        param.setKey(propText);
+
+      } else if (StringUtils.equalsIgnoreCase("description", propNodeName)) {
+        param.setDescription(propText);
+
+      } else if (StringUtils.equalsIgnoreCase("type", propNodeName)) {
+        param.setType(propText);
+
+      } else if (StringUtils.equalsIgnoreCase("defaultValue", propNodeName)) {
+        param.setDefaultValue(propText);
+      }
+    }
+    if (StringUtils.isEmpty(param.getKey())) {
+      throw new SonarException("Node <key> is missing in <param>");
+    }
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java
deleted file mode 100644 (file)
index cfcc626..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.api.rules;
-
-import org.hamcrest.core.Is;
-import org.junit.Test;
-import org.sonar.api.utils.SonarException;
-
-import java.io.StringReader;
-import java.util.List;
-
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
-public class StandardRuleXmlFormatTest {
-
-  @Test
-  public void parseXml() {
-    List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml"));
-    assertThat(rules.size(), is(2));
-
-    Rule rule = rules.get(0);
-    assertThat(rule.getName(), is("Local Variable Name"));
-    assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property."));
-    assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
-    assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.MULTIPLE));
-    assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));
-
-    assertThat(rule.getParams().size(), is(2));
-    RuleParam prop = rule.getParam("ignore");
-    assertThat(prop.getKey(), is("ignore"));
-    assertThat(prop.getDescription(), is("Ignore ?"));
-    assertThat(prop.getDefaultValue(), is("false"));
-
-    Rule minimalRule = rules.get(1);
-    assertThat(minimalRule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"));
-    assertThat(minimalRule.getParams().size(), is(0));
-
-  }
-
-  @Test(expected = SonarException.class)
-  public void failIfMissingRuleKey() {
-    StandardRuleXmlFormat.parseXml(new StringReader("<rules><rule><name>Foo</name></rule></rules>"));
-  }
-
-  @Test(expected = SonarException.class)
-  public void failIfMissingPropertyKey() {
-    StandardRuleXmlFormat.parseXml(new StringReader("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"));
-  }
-
-  @Test
-  public void utf8Encoding() {
-    List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml"));
-    assertThat(rules.size(), is(1));
-    Rule rule = rules.get(0);
-    assertThat(rule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck"));
-    assertThat(rule.getName(), is("M & M"));
-    assertThat(rule.getDescription().charAt(0), is('\u00E9'));
-    assertThat(rule.getDescription().charAt(1), is('\u00E0'));
-    assertThat(rule.getDescription().charAt(2), is('\u0026'));
-  }
-
-  @Test
-  public void supportDeprecatedFormat() {
-    // the deprecated format uses some attributes instead of nodes
-    List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml"));
-    assertThat(rules.size(), is(1));
-    Rule rule = rules.get(0);
-    assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL));
-    assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
-    assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
-  }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
new file mode 100644 (file)
index 0000000..73f41a4
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * 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.api.rules;
+
+import org.hamcrest.core.Is;
+import org.junit.Test;
+import org.sonar.api.utils.SonarException;
+
+import java.io.StringReader;
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class XMLRuleParserTest {
+
+  @Test
+  public void parseXml() {
+    List<Rule> rules = XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/rules.xml"));
+    assertThat(rules.size(), is(2));
+
+    Rule rule = rules.get(0);
+    assertThat(rule.getName(), is("Local Variable Name"));
+    assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property."));
+    assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
+    assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.MULTIPLE));
+    assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));
+
+    assertThat(rule.getParams().size(), is(2));
+    RuleParam prop = rule.getParam("ignore");
+    assertThat(prop.getKey(), is("ignore"));
+    assertThat(prop.getDescription(), is("Ignore ?"));
+    assertThat(prop.getDefaultValue(), is("false"));
+
+    Rule minimalRule = rules.get(1);
+    assertThat(minimalRule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"));
+    assertThat(minimalRule.getParams().size(), is(0));
+
+  }
+
+  @Test(expected = SonarException.class)
+  public void failIfMissingRuleKey() {
+    XMLRuleParser.parseXML(new StringReader("<rules><rule><name>Foo</name></rule></rules>"));
+  }
+
+  @Test(expected = SonarException.class)
+  public void failIfMissingPropertyKey() {
+    XMLRuleParser.parseXML(new StringReader("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"));
+  }
+
+  @Test
+  public void utf8Encoding() {
+    List<Rule> rules = XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/utf8.xml"));
+    assertThat(rules.size(), is(1));
+    Rule rule = rules.get(0);
+    assertThat(rule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck"));
+    assertThat(rule.getName(), is("M & M"));
+    assertThat(rule.getDescription().charAt(0), is('\u00E9'));
+    assertThat(rule.getDescription().charAt(1), is('\u00E0'));
+    assertThat(rule.getDescription().charAt(2), is('\u0026'));
+  }
+
+  @Test
+  public void supportDeprecatedFormat() {
+    // the deprecated format uses some attributes instead of nodes
+    List<Rule> rules = XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml"));
+    assertThat(rules.size(), is(1));
+    Rule rule = rules.get(0);
+    assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL));
+    assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
+    assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
+  }
+}
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml
deleted file mode 100644 (file)
index 44cf56d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<rules>
-  <rule key="org.sonar.it.checkstyle.MethodsCountCheck" priority="CRITICAL">
-    <name>Methods Count Check</name>
-    <configKey>Checker/TreeWalker/org.sonar.it.checkstyle.MethodsCountCheck</configKey>
-    <category name="Usability"/>
-    <description>Count methods.</description>
-    <param key="minMethodsCount" type="i">
-      <description>Le nombre minimum de méthodes. 10 par défaut.</description>
-    </param>
-  </rule>
-</rules>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml
deleted file mode 100644 (file)
index 4d80740..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<rules>
-  <rule>
-    <!-- with exhaustive fields -->
-    <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
-    <name>Local Variable Name</name>
-    <description>
-      <![CDATA[Checks that local, non-final variable names conform to a format specified by the format property.]]>
-    </description>
-    <isoCategory>Efficiency</isoCategory>
-    <configKey>Checker/TreeWalker/LocalVariableName</configKey>
-    <priority>BLOCKER</priority>
-    <cardinality>MULTIPLE</cardinality>
-    <param>
-      <key>tokens</key>
-      <description>
-        <![CDATA[
-          Controls whether the check applies to variable declarations or catch clause parameters
-          ]]>
-      </description>
-    </param>
-    <param>
-      <key>ignore</key>
-      <description>
-        Ignore ?
-      </description>
-      <defaultValue>false</defaultValue>
-    </param>
-  </rule>
-
-
-  <rule>
-    <!-- with only required fields -->
-    <key>com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck</key>
-    <name>Magic Number</name>
-    <description>
-      <![CDATA[Checks for magic numbers.]]>
-    </description>
-    <isoCategory>Maintainability</isoCategory>
-  </rule>
-</rules>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml
deleted file mode 100644 (file)
index 6197e03..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<rules>
-  <rule>
-    <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
-    <priority>BLOCKER</priority>
-    <configKey>Checker/TreeWalker/LocalVariableName</configKey>
-    <name>M &amp; M</name>
-    <description>
-      <![CDATA[éà&]]>
-    </description>
-  </rule>
-</rules>
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml
new file mode 100644 (file)
index 0000000..44cf56d
--- /dev/null
@@ -0,0 +1,11 @@
+<rules>
+  <rule key="org.sonar.it.checkstyle.MethodsCountCheck" priority="CRITICAL">
+    <name>Methods Count Check</name>
+    <configKey>Checker/TreeWalker/org.sonar.it.checkstyle.MethodsCountCheck</configKey>
+    <category name="Usability"/>
+    <description>Count methods.</description>
+    <param key="minMethodsCount" type="i">
+      <description>Le nombre minimum de méthodes. 10 par défaut.</description>
+    </param>
+  </rule>
+</rules>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/rules.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/rules.xml
new file mode 100644 (file)
index 0000000..4d80740
--- /dev/null
@@ -0,0 +1,40 @@
+<rules>
+  <rule>
+    <!-- with exhaustive fields -->
+    <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
+    <name>Local Variable Name</name>
+    <description>
+      <![CDATA[Checks that local, non-final variable names conform to a format specified by the format property.]]>
+    </description>
+    <isoCategory>Efficiency</isoCategory>
+    <configKey>Checker/TreeWalker/LocalVariableName</configKey>
+    <priority>BLOCKER</priority>
+    <cardinality>MULTIPLE</cardinality>
+    <param>
+      <key>tokens</key>
+      <description>
+        <![CDATA[
+          Controls whether the check applies to variable declarations or catch clause parameters
+          ]]>
+      </description>
+    </param>
+    <param>
+      <key>ignore</key>
+      <description>
+        Ignore ?
+      </description>
+      <defaultValue>false</defaultValue>
+    </param>
+  </rule>
+
+
+  <rule>
+    <!-- with only required fields -->
+    <key>com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck</key>
+    <name>Magic Number</name>
+    <description>
+      <![CDATA[Checks for magic numbers.]]>
+    </description>
+    <isoCategory>Maintainability</isoCategory>
+  </rule>
+</rules>
\ No newline at end of file
diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/utf8.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/rules/XMLRuleParserTest/utf8.xml
new file mode 100644 (file)
index 0000000..6197e03
--- /dev/null
@@ -0,0 +1,11 @@
+<rules>
+  <rule>
+    <key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
+    <priority>BLOCKER</priority>
+    <configKey>Checker/TreeWalker/LocalVariableName</configKey>
+    <name>M &amp; M</name>
+    <description>
+      <![CDATA[éà&]]>
+    </description>
+  </rule>
+</rules>