From: simonbrandhof Date: Tue, 28 Sep 2010 12:52:26 +0000 (+0000) Subject: checkstyle unit tests must not request http://www.puppycrawl.com when parsing XML... X-Git-Tag: 2.6~929 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90dee8b40e12fc044f854cbe49a35f7d7dff5af3;p=sonarqube.git checkstyle unit tests must not request http://www.puppycrawl.com when parsing XML. It avoids building sonar in offline mode. --- diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java index ab91ee2f647..96b8acfe714 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java +++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java @@ -39,6 +39,7 @@ import java.util.List; public class CheckstyleProfileExporter extends ProfileExporter { + static final String DOCTYPE_DECLARATION = ""; private Configuration conf; public CheckstyleProfileExporter(Configuration conf) { @@ -76,7 +77,7 @@ public class CheckstyleProfileExporter extends ProfileExporter { private void appendXmlHeader(Writer writer) throws IOException { writer.append("" - + "" + + DOCTYPE_DECLARATION + "" + ""); } diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java index a7c4ff76e72..88010b7a919 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java @@ -21,6 +21,7 @@ package org.sonar.plugins.checkstyle; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.configuration.Configuration; +import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.Rule; @@ -42,7 +43,7 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); } @Test public void noCheckstyleRulesToExport() throws IOException, SAXException { @@ -56,7 +57,7 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); } @Test @@ -77,7 +78,7 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); } @Test @@ -94,7 +95,7 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); } @Test @@ -114,7 +115,7 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); } @@ -137,6 +138,12 @@ public class CheckstyleProfileExporterTest { TestUtils.assertSimilarXml( TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addCustomFilters.xml"), - writer.toString()); + sanitizeForTests(writer.toString())); + } + + + private static String sanitizeForTests(String xml) { + // remove the doctype declaration, else the unit test fails when executed offline + return StringUtils.remove(xml, CheckstyleProfileExporter.DOCTYPE_DECLARATION); } }