From 26c6766b813955ba662f91a9a7b720b8eb6dd8f4 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 29 Nov 2012 14:34:30 +0100 Subject: SONAR-1352 alert property "period" should not be mandatory in the different xml exports --- .../org/sonar/api/profiles/XMLProfileSerializer.java | 17 +++++++++++------ .../sonar/api/profiles/XMLProfileSerializerTest.java | 8 ++++++-- .../XMLProfileParserTest/importProfileWithAlerts.xml | 1 + .../profiles/XMLProfileSerializerTest/exportAlerts.xml | 8 +++++++- 4 files changed, 25 insertions(+), 9 deletions(-) (limited to 'sonar-plugin-api') 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(""); StringEscapeUtils.escapeXml(writer, alert.getMetric().getKey()); - writer.append(""); - StringEscapeUtils.escapeXml(writer, ObjectUtils.toString(alert.getPeriod())); - writer.append(""); + writer.append(""); + if (alert.getPeriod() !=null) { + writer.append(""); + StringEscapeUtils.escapeXml(writer, Integer.toString(alert.getPeriod())); + writer.append(""); + } + writer.append(""); StringEscapeUtils.escapeXml(writer, alert.getOperator()); - writer.append(""); + writer.append(""); + writer.append(""); StringEscapeUtils.escapeXml(writer, alert.getValueWarning()); - writer.append(""); + writer.append(""); + writer.append(""); StringEscapeUtils.escapeXml(writer, alert.getValueError()); writer.append(""); } 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 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 @@ complexity + 1 > 12 10 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 @@ coverage - 1 < 60 80 + + complexity + 1 + > + 12 + 10 + \ No newline at end of file -- cgit v1.2.3