import javax.xml.stream.XMLStreamException;
/**
+ * TODO should be an interface
+ *
* @since 2.3
*/
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;
}
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();
assertThat(validation.getErrors().size(), is(2));
assertThat(validation.getErrors().get(0), containsString(""));
-
}
@Test
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() {