aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-28 12:52:26 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-28 12:52:26 +0000
commit90dee8b40e12fc044f854cbe49a35f7d7dff5af3 (patch)
treeb623eed8f4a90333c71525280e10538d447c60b7 /plugins
parent48e72253d7cbbb5ee4936375a540e8c725880d09 (diff)
downloadsonarqube-90dee8b40e12fc044f854cbe49a35f7d7dff5af3.tar.gz
sonarqube-90dee8b40e12fc044f854cbe49a35f7d7dff5af3.zip
checkstyle unit tests must not request http://www.puppycrawl.com when parsing XML. It avoids building sonar in offline mode.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java3
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java19
2 files changed, 15 insertions, 7 deletions
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 = "<!DOCTYPE module PUBLIC \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\" \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">";
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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<!DOCTYPE module PUBLIC \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\" \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">"
+ + DOCTYPE_DECLARATION
+ "<!-- Generated by Sonar -->"
+ "<module name=\"Checker\">");
}
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);
}
}