diff options
author | Godin <mandrikov@gmail.com> | 2010-12-09 10:35:08 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-09 10:35:08 +0000 |
commit | 1df1fa8bd7539b8a0358e52d10cbdf7a580e90d9 (patch) | |
tree | 3e5cf59f82b538803e53a328a201da8dec9328eb /sonar-plugin-api | |
parent | 43338cdc403db95555e7f46672729f4c72abb903 (diff) | |
download | sonarqube-1df1fa8bd7539b8a0358e52d10cbdf7a580e90d9.tar.gz sonarqube-1df1fa8bd7539b8a0358e52d10cbdf7a580e90d9.zip |
Backward compatibility for XMLProfileParser
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java | 22 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java | 16 |
2 files changed, 36 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java index 84cc6c0ea79..819ee316b15 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java @@ -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(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java index 6a6ca1af8da..765c58ae667 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java @@ -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() { |