changes for jdk 1.4 support (weaved classes now behave exactly the same way as

regular classes, i.e. same number of failures):

testDtd() needs the full path for the SYSTEM ruleset.dtd even if that's not
the one used by the validator.

isJdk14 boolean set in setUp() method and used in testXmlSchema() to ignore
test as Xerces is not present.


git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5599 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch
2007-10-28 18:21:41 +00:00
parent e2f9edae98
commit 5adbdcb4dc

View File

@ -34,6 +34,7 @@ import net.sourceforge.pmd.RuleSetNotFoundException;
import net.sourceforge.pmd.rules.UnusedLocalVariableRule; import net.sourceforge.pmd.rules.UnusedLocalVariableRule;
import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.ResourceLoader;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -60,6 +61,17 @@ import javax.xml.parsers.SAXParserFactory;
import junit.framework.JUnit4TestAdapter; import junit.framework.JUnit4TestAdapter;
public class RuleSetFactoryTest { public class RuleSetFactoryTest {
private boolean isJdk14;
@Before
public void setUp() {
try {
Class.forName("java.lang.Appendable");
} catch (Throwable t) {
isJdk14 = true;
}
}
@Test @Test
public void testRefs() throws Throwable { public void testRefs() throws Throwable {
InputStream in = ResourceLoader.loadResourceAsStream("rulesets/favorites.xml", this.getClass().getClassLoader()); InputStream in = ResourceLoader.loadResourceAsStream("rulesets/favorites.xml", this.getClass().getClassLoader());
@ -193,6 +205,11 @@ public class RuleSetFactoryTest {
@Test @Test
public void testXmlSchema() throws IOException, RuleSetNotFoundException, ParserConfigurationException, SAXException { public void testXmlSchema() throws IOException, RuleSetNotFoundException, ParserConfigurationException, SAXException {
if (isJdk14) {
// ignore failure with jdk 1.4
return;
}
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setValidating(true); saxParserFactory.setValidating(true);
saxParserFactory.setNamespaceAware(true); saxParserFactory.setNamespaceAware(true);
@ -247,7 +264,10 @@ public class RuleSetFactoryTest {
file = file.replaceAll("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", ""); file = file.replaceAll("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "");
file = file.replaceAll("xsi:schemaLocation=\"http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd\"", ""); file = file.replaceAll("xsi:schemaLocation=\"http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd\"", "");
file = file.replaceAll("xsi:noNamespaceSchemaLocation=\"http://pmd.sf.net/ruleset_xml_schema.xsd\"", ""); file = file.replaceAll("xsi:noNamespaceSchemaLocation=\"http://pmd.sf.net/ruleset_xml_schema.xsd\"", "");
file = "<?xml version=\"1.0\"?>" + PMD.EOL + "<!DOCTYPE ruleset SYSTEM \"ruleset.dtd\">" + PMD.EOL + file;
file = "<?xml version=\"1.0\"?>" + PMD.EOL + "<!DOCTYPE ruleset SYSTEM \"file://" +
System.getProperty("user.dir") + "/etc/ruleset.dtd\">" + PMD.EOL + file;
inputStream = new ByteArrayInputStream(file.getBytes()); inputStream = new ByteArrayInputStream(file.getBytes());
SAXParser saxParser = saxParserFactory.newSAXParser(); SAXParser saxParser = saxParserFactory.newSAXParser();