diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2012-11-29 14:34:30 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2012-11-29 14:46:01 +0100 |
commit | 26c6766b813955ba662f91a9a7b720b8eb6dd8f4 (patch) | |
tree | d1e036514fe6a0bc07c09b5e51978bbb479464da /sonar-plugin-api | |
parent | 4457d168a71ca24ba9d33dbbca1f7822ed7a5443 (diff) | |
download | sonarqube-26c6766b813955ba662f91a9a7b720b8eb6dd8f4.tar.gz sonarqube-26c6766b813955ba662f91a9a7b720b8eb6dd8f4.zip |
SONAR-1352 alert property "period" should not be mandatory in the different xml exports
Diffstat (limited to 'sonar-plugin-api')
4 files changed, 25 insertions, 9 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java index 5e93ca45c0d..e8e59e513b1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileSerializer.java @@ -19,7 +19,6 @@ */ package org.sonar.api.profiles; -import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; @@ -116,13 +115,19 @@ public final class XMLProfileSerializer implements ServerComponent { private void appendAlert(Alert alert, Writer writer) throws IOException { writer.append("<alert><metric>"); StringEscapeUtils.escapeXml(writer, alert.getMetric().getKey()); - writer.append("</metric><period>"); - StringEscapeUtils.escapeXml(writer, ObjectUtils.toString(alert.getPeriod())); - writer.append("</period><operator>"); + writer.append("</metric>"); + if (alert.getPeriod() !=null) { + writer.append("<period>"); + StringEscapeUtils.escapeXml(writer, Integer.toString(alert.getPeriod())); + writer.append("</period>"); + } + writer.append("<operator>"); StringEscapeUtils.escapeXml(writer, alert.getOperator()); - writer.append("</operator><warning>"); + writer.append("</operator>"); + writer.append("<warning>"); StringEscapeUtils.escapeXml(writer, alert.getValueWarning()); - writer.append("</warning><error>"); + writer.append("</warning>"); + writer.append("<error>"); StringEscapeUtils.escapeXml(writer, alert.getValueError()); writer.append("</error></alert>"); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java index f54bde9a043..92c5f9c8659 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileSerializerTest.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.io.Writer; +import java.util.List; import static org.junit.Assert.assertTrue; @@ -80,8 +81,11 @@ public class XMLProfileSerializerTest { public void exportAlerts() throws Exception { Writer writer = new StringWriter(); RulesProfile profile = RulesProfile.create("sonar way", "java"); - Alert alert = new Alert(profile, new Metric("coverage"), Alert.OPERATOR_SMALLER, "60", "80", 1); - profile.getAlerts().add(alert); + List<Alert> alerts = profile.getAlerts(); + Alert alert1 = new Alert(profile, new Metric("coverage"), Alert.OPERATOR_SMALLER, "60", "80"); + alerts.add(alert1); + Alert alert2 = new Alert(profile, new Metric("complexity"), Alert.OPERATOR_GREATER, "12", "10", 1); + alerts.add(alert2); new XMLProfileSerializer().write(profile, writer); assertSimilarXml("exportAlerts.xml", writer.toString()); diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml index 3a34a304562..5b5f42632cb 100644 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileParserTest/importProfileWithAlerts.xml @@ -13,6 +13,7 @@ <alerts> <alert> <metric>complexity</metric> + <period>1</period> <operator>></operator> <error>12</error> <warning>10</warning> diff --git a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml index 1ae4e6eda4a..bdf2f1b904c 100644 --- a/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml +++ b/sonar-plugin-api/src/test/resources/org/sonar/api/profiles/XMLProfileSerializerTest/exportAlerts.xml @@ -6,10 +6,16 @@ <alerts> <alert> <metric>coverage</metric> - <period>1</period> <operator><</operator> <error>60</error> <warning>80</warning> </alert> + <alert> + <metric>complexity</metric> + <period>1</period> + <operator>></operator> + <error>12</error> + <warning>10</warning> + </alert> </alerts> </profile>
\ No newline at end of file |