]> source.dussan.org Git - sonarqube.git/commitdiff
Backward compatibility for XMLProfileParser
authorGodin <mandrikov@gmail.com>
Thu, 9 Dec 2010 10:35:08 +0000 (10:35 +0000)
committerGodin <mandrikov@gmail.com>
Thu, 9 Dec 2010 10:35:08 +0000 (10:35 +0000)
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java

index 84cc6c0ea796d4b6928f8502fe78f9a7cfcc586f..819ee316b15affe7fd6cc5e4b300345232c97add 100644 (file)
@@ -45,6 +45,8 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 
 /**
+ * TODO should be an interface
+ * 
  * @since 2.3
  */
 public final class XMLProfileParser implements ServerComponent {
@@ -52,6 +54,22 @@ public final class XMLProfileParser implements ServerComponent {
   private RuleFinder ruleFinder;
   private MetricFinder metricFinder;
 
+  /**
+   * For backward compatibility.
+   * 
+   * @deprecated since 2.5. Plugins shouldn't directly instantiate this class,
+   *             because it should be retrieved as an IoC dependency.
+   */
+  @Deprecated
+  public XMLProfileParser(RuleFinder ruleFinder) {
+    this.ruleFinder = ruleFinder;
+  }
+
+  /**
+   * @deprecated since 2.5. Plugins shouldn't directly instantiate this class,
+   *             because it should be retrieved as an IoC dependency.
+   */
+  @Deprecated
   public XMLProfileParser(RuleFinder ruleFinder, MetricFinder metricFinder) {
     this.ruleFinder = ruleFinder;
     this.metricFinder = metricFinder;
@@ -183,6 +201,10 @@ public final class XMLProfileParser implements ServerComponent {
   }
 
   private void processAlerts(SMInputCursor alertsCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException {
+    if (metricFinder == null) {
+      // TODO remove when constructor without MetricFinder would be removed
+      return;
+    }
     while (alertsCursor.getNext() != null) {
       SMInputCursor alertCursor = alertsCursor.childElementCursor();
 
index 6a6ca1af8da88c8fb37b06e72c1d3f246c1f2eba..765c58ae667eca2f4ff2db7222f27e914443a3de 100644 (file)
@@ -62,7 +62,6 @@ public class XMLProfileParserTest {
 
     assertThat(validation.getErrors().size(), is(2));
     assertThat(validation.getErrors().get(0), containsString(""));
-
   }
 
   @Test
@@ -100,9 +99,22 @@ public class XMLProfileParserTest {
     assertThat(alert.getValueError(), is("12"));
   }
 
+  @Test
+  public void shouldNotFailWhenNoMetricFinder() {
+    ValidationMessages validation = ValidationMessages.create();
+    RulesProfile profile = new XMLProfileParser(newRuleFinder(), null)
+        .parseResource(getClass().getClassLoader(), getResourcePath("importProfileWithAlerts.xml"), validation);
+
+    assertThat(profile.getAlerts().size(), is(0));
+  }
+
   private RulesProfile parse(String resource, ValidationMessages validation) {
     return new XMLProfileParser(newRuleFinder(), newMetricFinder())
-        .parseResource(getClass().getClassLoader(), "org/sonar/api/profiles/XMLProfileParserTest/" + resource, validation);
+        .parseResource(getClass().getClassLoader(), getResourcePath(resource), validation);
+  }
+
+  private String getResourcePath(String resource) {
+    return "org/sonar/api/profiles/XMLProfileParserTest/" + resource;
   }
 
   private MetricFinder newMetricFinder() {