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) {
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\">");
}
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;
TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml"),
- writer.toString());
+ sanitizeForTests(writer.toString()));
}
@Test
public void noCheckstyleRulesToExport() throws IOException, SAXException {
TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml"),
- writer.toString());
+ sanitizeForTests(writer.toString()));
}
@Test
TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml"),
- writer.toString());
+ sanitizeForTests(writer.toString()));
}
@Test
TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml"),
- writer.toString());
+ sanitizeForTests(writer.toString()));
}
@Test
TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml"),
- writer.toString());
+ sanitizeForTests(writer.toString()));
}
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);
}
}