public void write(RulesProfile profile, Writer writer) { try { appendHeader(profile, writer); appendRules(profile, writer); appendFooter(writer); } catch (IOException e) { throw new SonarException("Fail to export the profile " + profile, e); } }
private static void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }
private static void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException { if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) { writer.append("<parameters>"); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { appendRuleParameter(writer, activeRuleParam); } writer.append("</parameters>"); } }
@Test public void exportEmptyProfile() throws IOException, SAXException { Writer writer = new StringWriter(); RulesProfile profile = RulesProfile.create("sonar way", "java"); new XMLProfileSerializer().write(profile, writer); assertSimilarXml("exportEmptyProfile.xml", writer.toString()); }
private static void appendRule(ActiveRule activeRule, Writer writer) throws IOException { writer.append("<rule><repositoryKey>"); writer.append(activeRule.getRepositoryKey()); writer.append("</repositoryKey><key>"); StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey()); writer.append("</key>"); if (activeRule.getSeverity() != null) { writer.append("<priority>"); writer.append(activeRule.getSeverity().name()); writer.append("</priority>"); } appendRuleParameters(activeRule, writer); writer.append("</rule>"); }
private void appendRule(ActiveRule activeRule, Writer writer) throws IOException { writer.append("<rule><repositoryKey>"); writer.append(activeRule.getRepositoryKey()); writer.append("</repositoryKey><key>"); StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey()); writer.append("</key>"); if (activeRule.getSeverity() != null) { writer.append("<priority>"); writer.append(activeRule.getSeverity().name()); writer.append("</priority>"); } appendRuleParameters(activeRule, writer); writer.append("</rule>"); }
@Test public void exportProfile() throws IOException, SAXException { Writer writer = new StringWriter(); RulesProfile profile = RulesProfile.create("sonar way", "java"); profile.activateRule(Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"), RulePriority.BLOCKER); new XMLProfileSerializer().write(profile, writer); assertSimilarXml("exportProfile.xml", writer.toString()); }
public void write(RulesProfile profile, Writer writer) { try { appendHeader(profile, writer); appendRules(profile, writer); appendFooter(writer); } catch (IOException e) { throw new SonarException("Fail to export the profile " + profile, e); } }
private void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException { if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) { writer.append("<parameters>"); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { appendRuleParameter(writer, activeRuleParam); } writer.append("</parameters>"); } }
private void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }
private static void appendRule(ActiveRule activeRule, Writer writer) throws IOException { writer.append("<rule><repositoryKey>"); writer.append(activeRule.getRepositoryKey()); writer.append("</repositoryKey><key>"); StringEscapeUtils.escapeXml(writer, activeRule.getRuleKey()); writer.append("</key>"); if (activeRule.getSeverity() != null) { writer.append("<priority>"); writer.append(activeRule.getSeverity().name()); writer.append("</priority>"); } appendRuleParameters(activeRule, writer); writer.append("</rule>"); }
@Test public void exportRuleParameters() throws IOException, SAXException { Writer writer = new StringWriter(); RulesProfile profile = RulesProfile.create("sonar way", "java"); Rule rule = Rule.create("checkstyle", "IllegalRegexp", "illegal regexp"); rule.createParameter("format"); rule.createParameter("message"); rule.createParameter("tokens"); ActiveRule activeRule = profile.activateRule(rule, RulePriority.BLOCKER); activeRule.setParameter("format", "foo"); activeRule.setParameter("message", "with special characters < > &"); // the tokens parameter is not set new XMLProfileSerializer().write(profile, writer); assertSimilarXml("exportRuleParameters.xml", writer.toString()); }
public void write(RulesProfile profile, Writer writer) { try { appendHeader(profile, writer); appendRules(profile, writer); appendFooter(writer); } catch (IOException e) { throw new SonarException("Fail to export the profile " + profile, e); } }
private static void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException { if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) { writer.append("<parameters>"); for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) { appendRuleParameter(writer, activeRuleParam); } writer.append("</parameters>"); } }
private static void appendRules(RulesProfile profile, Writer writer) throws IOException { if (!profile.getActiveRules().isEmpty()) { writer.append("<rules>"); for (ActiveRule activeRule : profile.getActiveRules()) { appendRule(activeRule, writer); } writer.append("</rules>"); } }