Skip to content
This repository
Browse code

Issue #75 - change Resource paths to be absolute.

change the android tests to use simpler process (no longer needs to use android Assets), instead us this.getClass().getResource(...). The same mechanism now works in Java an Android.
  • Loading branch information...
commit c2c34d6b3d5935306d4c743e9044b1cc3c094024 1 parent a5a1a75
Rolf rolfl authored
15 build.xml
@@ -354,21 +354,12 @@ For instructions on how to build JDOM, please view the README.txt file.
354 354 <java classname="org.jdom2.contrib.android.TranslateTests"
355 355 classpathref="at.class.path" >
356 356 <arg value="${package}/${jarbase}-junit.jar" />
357   - <arg value="${android}/${android.project}/assets" />
358 357 <arg value="${android}/${android.project}Test/src" />
359 358 </java>
360   -
361   - <mkdir dir="${android}/${android.project}Test/src/org/jdom2/test/util" />
362   - <copy todir="${android}/${android.project}Test/src/org/jdom2/test/util"
363   - file="test/android/AndroidFetch.java" />
364   -
365   - <!-- Create a Jar file with just the JUnit4 tests, not the resources. -->
366   - <jar jarfile="${android.libs}/${jarbase}-android-junit4.jar" >
367   - <fileset dir="${junit.build}" includes="**/*.class" />
368   - </jar>
369   -
  359 +
370 360 <copy todir="${android.libs}">
371   - <fileset dir="${package}" includes="${jarbase}.jar, ${jarbase}-contrib.jar" />
  361 + <fileset dir="${package}"
  362 + includes="${jarbase}.jar, ${jarbase}-contrib.jar ${jarbase}-junit.jar" />
372 363 </copy>
373 364
374 365 <copy todir="${android.libs}" file="${jaxen.jar}"/>
39 contrib/src/java/org/jdom2/contrib/android/TranslateTests.java
... ... @@ -1,10 +1,8 @@
1 1 package org.jdom2.contrib.android;
2 2
3 3 import java.io.File;
4   -import java.io.FileOutputStream;
5 4 import java.io.FileWriter;
6 5 import java.io.IOException;
7   -import java.io.InputStream;
8 6 import java.lang.reflect.Method;
9 7 import java.util.ArrayList;
10 8 import java.util.Enumeration;
@@ -68,20 +66,12 @@ private static String potentialTest(String zename) {
68 66 * @throws IOException
69 67 */
70 68 public static void main(String[] args) throws IOException {
71   - if (args.length != 3) {
72   - throw new IllegalArgumentException("Usage: Jar AssetOutDir SrcOutDir");
  69 + if (args.length != 2) {
  70 + throw new IllegalArgumentException("Usage: Jar SrcOutDir");
73 71 }
74 72 final String jarname = args[0];
75 73
76   - File assoutdir = new File(args[1]);
77   - if (!assoutdir.exists()) {
78   - assoutdir.mkdirs();
79   - }
80   - if (!assoutdir.isDirectory()) {
81   - throw new IllegalArgumentException("Could not create/use AssetOutput directory: " + assoutdir);
82   - }
83   -
84   - final File srcoutdir = new File(args[2]);
  74 + final File srcoutdir = new File(args[1]);
85 75 if (!srcoutdir.exists()) {
86 76 srcoutdir.mkdirs();
87 77 }
@@ -92,7 +82,6 @@ public static void main(String[] args) throws IOException {
92 82 final ArrayList<String> classes = new ArrayList<String>();
93 83
94 84 final ZipFile zfile = new ZipFile(jarname);
95   - StringBuilder assetnames = new StringBuilder();
96 85 try {
97 86 final Enumeration<? extends ZipEntry> e = zfile.entries();
98 87 while (e.hasMoreElements()) {
@@ -107,28 +96,8 @@ public static void main(String[] args) throws IOException {
107 96 TranslateTests tt = new TranslateTests(srcoutdir, classname);
108 97 classes.add(tt.translate());
109 98 }
110   - } else if (zename.indexOf("META-INF") < 0){
111   - // copy resources in to output folder with full path.
112   - System.out.println("Asset: " + zename);
113   - assetnames.append(zename).append("\n");
114   - final InputStream zis = zfile.getInputStream(ze);
115   - final File outfile = new File(assoutdir, zename);
116   - outfile.getParentFile().mkdirs();
117   - final FileOutputStream fos = new FileOutputStream(outfile);
118   - final byte[] buffer = new byte[4096];
119   - int len = 0;
120   - while ((len = zis.read(buffer)) >= 0) {
121   - fos.write(buffer, 0, len);
122   - }
123   - fos.flush();
124   - fos.close();
125   - zis.close();
126 99 }
127 100 }
128   - final FileWriter fw = new FileWriter(new File(assoutdir, "assetlist.txt"));
129   - fw.write(assetnames.toString());
130   - fw.flush();
131   - fw.close();
132 101 } finally {
133 102 zfile.close();
134 103 }
@@ -210,7 +179,6 @@ private String translate() throws IOException {
210 179 sb.append(" // tests run when class starts...\n");
211 180 sb.append(" System.setProperty(\"javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema\",\n");
212 181 sb.append(" \"org.apache.xerces.jaxp.validation.XMLSchemaFactory\");\n");
213   - sb.append(" org.jdom2.test.util.AndroidFetch.check(this.getContext());\n");
214 182 for (Method m : methods) {
215 183 if (m.getAnnotation(BeforeClass.class) != null) {
216 184 sb.append(" test.").append(m.getName()).append("();\n");
@@ -235,7 +203,6 @@ private String translate() throws IOException {
235 203 final String tname = getTestName(m);
236 204 sb.append("\n");
237 205 sb.append(" public void ").append(tname).append("()").append(buildThrows(excepts, m)).append("{\n");
238   - sb.append(" org.jdom2.test.util.AndroidFetch.check(this.getContext());\n");
239 206 for (Method pre : pretest) {
240 207 sb.append(" // pre test\n");
241 208 sb.append(" test.").append(pre.getName()).append("();\n");
129 test/android/AndroidFetch.java
... ... @@ -1,129 +0,0 @@
1   -package org.jdom2.test.util;
2   -
3   -import java.io.BufferedReader;
4   -import java.io.ByteArrayInputStream;
5   -import java.io.ByteArrayOutputStream;
6   -import java.io.File;
7   -import java.io.FileInputStream;
8   -import java.io.FileOutputStream;
9   -import java.io.IOException;
10   -import java.io.InputStream;
11   -import java.io.InputStreamReader;
12   -import java.net.URL;
13   -import java.util.ArrayList;
14   -import java.util.concurrent.atomic.AtomicReference;
15   -
16   -import android.content.Context;
17   -import android.content.res.AssetManager;
18   -import android.util.Log;
19   -
20   -/**
21   - * This class is a hack class that adapts the JDOM Unit test environment to work on android.
22   - * See the wiki page: https://github.com/hunterhacker/jdom/wiki/JDOM2-and-Android
23   - *
24   - * @author Rolf Lear
25   - *
26   - */
27   -public class AndroidFetch extends FidoFetch{
28   -
29   - private final AtomicReference<File> folder = new AtomicReference<File>();
30   -
31   - private void writeCache(File cf, byte[] data) throws IOException {
32   - final File d = cf.getParentFile();
33   - if (!d.exists()) {
34   - d.mkdirs();
35   - }
36   - final FileOutputStream fos = new FileOutputStream(cf);
37   - fos.write(data);
38   - fos.flush();
39   - fos.close();
40   - }
41   -
42   - private byte[] readAsset(AssetManager am, String name) throws IOException {
43   - final ByteArrayOutputStream baos = new ByteArrayOutputStream();
44   - final InputStream is = am.open(name);
45   - final byte[] buffer = new byte[2048];
46   - int len = 0;
47   - while ((len = is.read(buffer)) >= 0) {
48   - baos.write(buffer, 0, len);
49   - }
50   - is.close();
51   - return baos.toByteArray();
52   - }
53   -
54   - private String[] parseAssets(byte[] data) throws IOException {
55   - final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data)));
56   - final ArrayList<String> al = new ArrayList<String>();
57   - String line = null;
58   - while ((line = br.readLine()) != null) {
59   - if (line.trim().length() > 0) {
60   - al.add(line.trim());
61   - }
62   - }
63   - return al.toArray(new String[al.size()]);
64   - }
65   -
66   -
67   - /**
68   - * @param o This should be a context object
69   - */
70   - public static final void check(Context o) {
71   - final FidoFetch ff = getFido();
72   - final AndroidFetch af = (AndroidFetch)ff;
73   - af.checkFolder(o);
74   -
75   - }
76   -
77   - private void checkFolder(Context ctx) {
78   - if (folder.get() == null) {
79   - // first time in....
80   -
81   - // OK, now set the cache folder.
82   - final File dir = new File(ctx.getCacheDir(), "jdomassets");
83   - if (!dir.exists()) {
84   - dir.mkdirs();
85   - }
86   -
87   - // Then, get the Asset Manager.
88   - final AssetManager am = ctx.getAssets();
89   -
90   - try {
91   -
92   - // we want the special asset 'assetlist.txt' which is created by the
93   - // JDOM 'android' build target, listing all the required assets.
94   - final String[] assets = parseAssets(readAsset(am, "assetlist.txt"));
95   - for (String asset : assets) {
96   - final byte[] data = readAsset(am, asset);
97   - final File f = new File(dir, asset);
98   - writeCache(f, data);
99   - Log.i("JDOM", "Transfer asset " + asset + " to cache.");
100   - }
101   - } catch (Exception e) {
102   - throw new IllegalStateException("Unable to transfer assets to " + dir, e);
103   - }
104   -
105   - folder.set(dir.getAbsoluteFile());
106   - }
107   - }
108   -
109   - @Override
110   - public URL getURL(String name) {
111   - try {
112   - final File f = new File(folder.get(), name);
113   - return f.toURI().toURL();
114   - } catch (Exception e) {
115   - throw new IllegalStateException("Unable to get resource " + name, e);
116   - }
117   - }
118   -
119   - @Override
120   - public InputStream getStream(String name) {
121   - try {
122   - final File f = new File(folder.get(), name);
123   - return new FileInputStream(f);
124   - } catch (Exception e) {
125   - throw new IllegalStateException("Unable to get resource " + name, e);
126   - }
127   - }
128   -
129   -}
12 test/src/java/org/jdom2/test/cases/input/TestDOMBuilder.java
@@ -43,32 +43,32 @@ public void testFactory() {
43 43
44 44 @Test
45 45 public void testSimpleDocument() {
46   - checkDOM("DOMBuilder/simple.xml", false);
  46 + checkDOM("/DOMBuilder/simple.xml", false);
47 47 }
48 48
49 49 @Test
50 50 public void testAttributesDocument() {
51   - checkDOM("DOMBuilder/attributes.xml", false);
  51 + checkDOM("/DOMBuilder/attributes.xml", false);
52 52 }
53 53
54 54 @Test
55 55 public void testNamespaceDocument() {
56   - checkDOM("DOMBuilder/namespaces.xml", false);
  56 + checkDOM("/DOMBuilder/namespaces.xml", false);
57 57 }
58 58
59 59 @Test
60 60 public void testDocTypeDocument() {
61   - checkDOM("DOMBuilder/doctype.xml", false);
  61 + checkDOM("/DOMBuilder/doctype.xml", false);
62 62 }
63 63
64 64 @Test
65 65 public void testComplexDocument() {
66   - checkDOM("DOMBuilder/complex.xml", false);
  66 + checkDOM("/DOMBuilder/complex.xml", false);
67 67 }
68 68
69 69 @Test
70 70 public void testXSDDocument() {
71   - checkDOM("xsdcomplex/input.xml", true);
  71 + checkDOM("/xsdcomplex/input.xml", true);
72 72 }
73 73
74 74 private void checkDOM(String resname, boolean xsdvalidate) {
10 test/src/java/org/jdom2/test/cases/input/TestSAXBuilder.java
@@ -675,7 +675,7 @@ public void testSetPropertyTwo() {
675 675 public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOException {
676 676 //test entity exansion on internal entity
677 677
678   - URL src = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
  678 + URL src = FidoFetch.getFido().getURL("/SAXBuilderTestEntity.xml");
679 679
680 680 SAXBuilder builder = new SAXBuilder();
681 681
@@ -701,7 +701,7 @@ public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOE
701 701 content.get(2) instanceof EntityRef);
702 702
703 703 //test entity expansion on external entity
704   - URL src2 = FidoFetch.getFido().getURL("SAXBuilderTestEntity2.xml");
  704 + URL src2 = FidoFetch.getFido().getURL("/SAXBuilderTestEntity2.xml");
705 705
706 706 builder.setExpandEntities(true);
707 707 assertTrue(builder.getExpandEntities());
@@ -738,7 +738,7 @@ public void test_TCU__DTDComments() throws JDOMException, IOException {
738 738
739 739 SAXBuilder builder = new SAXBuilder();
740 740 //test entity expansion on external entity
741   - URL file = FidoFetch.getFido().getURL("SAXBuilderTestDecl.xml");
  741 + URL file = FidoFetch.getFido().getURL("/SAXBuilderTestDecl.xml");
742 742
743 743 //test that entity declaration appears in doctype
744 744 //and EntityRef is created in content with external entity
@@ -764,7 +764,7 @@ public void test_TCU__InternalAndExternalEntities() throws JDOMException, IOExce
764 764
765 765 SAXBuilder builder = new SAXBuilder();
766 766 //test entity expansion on internal and external entity
767   - URL file = FidoFetch.getFido().getURL("SAXBuilderTestIntExtEntity.xml");
  767 + URL file = FidoFetch.getFido().getURL("/SAXBuilderTestIntExtEntity.xml");
768 768
769 769 builder.setExpandEntities(true);
770 770 Document doc = builder.build(file);
@@ -801,7 +801,7 @@ public void test_TCU__InternalSubset() throws JDOMException, IOException {
801 801
802 802 SAXBuilder builder = new SAXBuilder();
803 803 //test entity expansion on internal subset
804   - URL file = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
  804 + URL file = FidoFetch.getFido().getURL("/SAXBuilderTestEntity.xml");
805 805
806 806 builder.setExpandEntities(true);
807 807 Document doc = builder.build(file);
4 test/src/java/org/jdom2/test/cases/input/TestSAXComplexSchema.java
@@ -46,7 +46,7 @@ public void testBuildFileOldWay() throws IOException {
46 46 builder.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
47 47 builder.setFeature("http://apache.org/xml/features/validation/schema", true);
48 48
49   - URL rurl = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
  49 + URL rurl = FidoFetch.getFido().getURL("/xsdcomplex/input.xml");
50 50
51 51
52 52 try {
@@ -86,7 +86,7 @@ public void testBuildFileOldWay() throws IOException {
86 86 public void testBuildFileNewSAX() throws IOException {
87 87 SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
88 88
89   - URL rurl = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
  89 + URL rurl = FidoFetch.getFido().getURL("/xsdcomplex/input.xml");
90 90
91 91
92 92 try {
28 test/src/java/org/jdom2/test/cases/input/TestStAXEventBuilder.java
@@ -48,74 +48,74 @@ public void testFactory() {
48 48
49 49 @Test
50 50 public void testSimpleDocumentExpand() {
51   - checkStAX("DOMBuilder/simple.xml", true);
  51 + checkStAX("/DOMBuilder/simple.xml", true);
52 52 }
53 53
54 54 @Test
55 55 public void testAttributesDocumentExpand() {
56   - checkStAX("DOMBuilder/attributes.xml", true);
  56 + checkStAX("/DOMBuilder/attributes.xml", true);
57 57 }
58 58
59 59 @Test
60 60 public void testNamespaceDocumentExpand() {
61   - checkStAX("DOMBuilder/namespaces.xml", true);
  61 + checkStAX("/DOMBuilder/namespaces.xml", true);
62 62 }
63 63
64 64 @Test
65 65 @Ignore
66 66 // TODO
67 67 public void testDocTypeDocumentExpand() {
68   - checkStAX("DOMBuilder/doctype.xml", true);
  68 + checkStAX("/DOMBuilder/doctype.xml", true);
69 69 }
70 70
71 71 @Test
72 72 public void testDocTypeDocumentSimpleExpand() {
73   - checkStAX("DOMBuilder/doctypesimple.xml", true);
  73 + checkStAX("/DOMBuilder/doctypesimple.xml", true);
74 74 }
75 75
76 76 @Test
77 77 public void testComplexDocumentExpand() {
78   - checkStAX("DOMBuilder/complex.xml", true);
  78 + checkStAX("/DOMBuilder/complex.xml", true);
79 79 }
80 80
81 81 @Test
82 82 public void testXSDDocumentExpand() {
83   - checkStAX("xsdcomplex/input.xml", true);
  83 + checkStAX("/xsdcomplex/input.xml", true);
84 84 }
85 85
86 86 @Test
87 87 public void testSimpleDocument() {
88   - checkStAX("DOMBuilder/simple.xml", false);
  88 + checkStAX("/DOMBuilder/simple.xml", false);
89 89 }
90 90
91 91 @Test
92 92 public void testAttributesDocument() {
93   - checkStAX("DOMBuilder/attributes.xml", false);
  93 + checkStAX("/DOMBuilder/attributes.xml", false);
94 94 }
95 95
96 96 @Test
97 97 public void testNamespaceDocument() {
98   - checkStAX("DOMBuilder/namespaces.xml", false);
  98 + checkStAX("/DOMBuilder/namespaces.xml", false);
99 99 }
100 100
101 101 @Test
102 102 public void testDocTypeDocument() {
103   - checkStAX("DOMBuilder/doctype.xml", false);
  103 + checkStAX("/DOMBuilder/doctype.xml", false);
104 104 }
105 105
106 106 @Test
107 107 public void testDocTypeSimpleDocument() {
108   - checkStAX("DOMBuilder/doctypesimple.xml", false);
  108 + checkStAX("/DOMBuilder/doctypesimple.xml", false);
109 109 }
110 110
111 111 @Test
112 112 public void testComplexDocument() {
113   - checkStAX("DOMBuilder/complex.xml", false);
  113 + checkStAX("/DOMBuilder/complex.xml", false);
114 114 }
115 115
116 116 @Test
117 117 public void testXSDDocument() {
118   - checkStAX("xsdcomplex/input.xml", false);
  118 + checkStAX("/xsdcomplex/input.xml", false);
119 119 }
120 120
121 121 private void checkStAX(String resourcename, boolean expand) {
28 test/src/java/org/jdom2/test/cases/input/TestStAXStreamBuilder.java
@@ -49,74 +49,74 @@ public void testFactory() {
49 49
50 50 @Test
51 51 public void testSimpleDocumentExpand() {
52   - checkStAX("DOMBuilder/simple.xml", true);
  52 + checkStAX("/DOMBuilder/simple.xml", true);
53 53 }
54 54
55 55 @Test
56 56 public void testAttributesDocumentExpand() {
57   - checkStAX("DOMBuilder/attributes.xml", true);
  57 + checkStAX("/DOMBuilder/attributes.xml", true);
58 58 }
59 59
60 60 @Test
61 61 public void testNamespaceDocumentExpand() {
62   - checkStAX("DOMBuilder/namespaces.xml", true);
  62 + checkStAX("/DOMBuilder/namespaces.xml", true);
63 63 }
64 64
65 65 @Test
66 66 @Ignore
67 67 public void testDocTypeDocumentExpand() {
68   - checkStAX("DOMBuilder/doctype.xml", true);
  68 + checkStAX("/DOMBuilder/doctype.xml", true);
69 69 }
70 70
71 71 @Test
72 72 @Ignore
73 73 public void testDocTypeDocumentSimpleExpand() {
74   - checkStAX("DOMBuilder/doctypesimple.xml", true);
  74 + checkStAX("/DOMBuilder/doctypesimple.xml", true);
75 75 }
76 76
77 77 @Test
78 78 public void testComplexDocumentExpand() {
79   - checkStAX("DOMBuilder/complex.xml", true);
  79 + checkStAX("/DOMBuilder/complex.xml", true);
80 80 }
81 81
82 82 @Test
83 83 public void testXSDDocumentExpand() {
84   - checkStAX("xsdcomplex/input.xml", true);
  84 + checkStAX("/xsdcomplex/input.xml", true);
85 85 }
86 86
87 87 @Test
88 88 public void testSimpleDocument() {
89   - checkStAX("DOMBuilder/simple.xml", false);
  89 + checkStAX("/DOMBuilder/simple.xml", false);
90 90 }
91 91
92 92 @Test
93 93 public void testAttributesDocument() {
94   - checkStAX("DOMBuilder/attributes.xml", false);
  94 + checkStAX("/DOMBuilder/attributes.xml", false);
95 95 }
96 96
97 97 @Test
98 98 public void testNamespaceDocument() {
99   - checkStAX("DOMBuilder/namespaces.xml", false);
  99 + checkStAX("/DOMBuilder/namespaces.xml", false);
100 100 }
101 101
102 102 @Test
103 103 public void testDocTypeDocument() {
104   - checkStAX("DOMBuilder/doctype.xml", false);
  104 + checkStAX("/DOMBuilder/doctype.xml", false);
105 105 }
106 106
107 107 @Test
108 108 public void testDocTypeSimpleDocument() {
109   - checkStAX("DOMBuilder/doctypesimple.xml", false);
  109 + checkStAX("/DOMBuilder/doctypesimple.xml", false);
110 110 }
111 111
112 112 @Test
113 113 public void testComplexDocument() {
114   - checkStAX("DOMBuilder/complex.xml", false);
  114 + checkStAX("/DOMBuilder/complex.xml", false);
115 115 }
116 116
117 117 @Test
118 118 public void testXSDDocument() {
119   - checkStAX("xsdcomplex/input.xml", false);
  119 + checkStAX("/xsdcomplex/input.xml", false);
120 120 }
121 121
122 122 private void checkStAX(String resname, boolean expand) {
6 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSAX2Factory.java
@@ -77,7 +77,7 @@ public void testParseValidateWorks() throws JDOMException, IOException {
77 77 XMLReaderSAX2Factory fac = new XMLReaderSAX2Factory(true);
78 78 assertTrue(fac.isValidating());
79 79 SAXBuilder builder = new SAXBuilder(fac);
80   - Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
  80 + Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/doctype.xml"));
81 81 assertEquals("root", doc.getRootElement().getName());
82 82 }
83 83
@@ -87,7 +87,7 @@ public void testParseValidateFails() {
87 87 assertTrue(fac.isValidating());
88 88 SAXBuilder builder = new SAXBuilder(fac);
89 89 try {
90   - builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
  90 + builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
91 91 UnitTestUtil.failNoException(JDOMException.class);
92 92 } catch (Exception e) {
93 93 UnitTestUtil.checkException(JDOMException.class, e);
@@ -99,7 +99,7 @@ public void testParseNonValidateWorks() throws JDOMException, IOException {
99 99 XMLReaderSAX2Factory fac = new XMLReaderSAX2Factory(false);
100 100 assertFalse(fac.isValidating());
101 101 SAXBuilder builder = new SAXBuilder(fac);
102   - Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
  102 + Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
103 103 assertEquals("root", doc.getRootElement().getName());
104 104 }
105 105
6 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSchemaFactory.java
@@ -29,7 +29,7 @@
29 29 public void testSchemaXMLReaderFactory() throws SAXException, JDOMException {
30 30 SchemaFactory schemafac =
31 31 SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
32   - Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("xsdcomplex/SAXTestComplexMain.xsd"));
  32 + Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("/xsdcomplex/SAXTestComplexMain.xsd"));
33 33 XMLReaderSchemaFactory readerfac = new XMLReaderSchemaFactory(schema);
34 34 assertTrue(readerfac.isValidating());
35 35 assertNotNull(readerfac.createXMLReader());
@@ -49,11 +49,11 @@ public void testSchemaXMLReaderFactoryNull() {
49 49 public void testParseValidateWorks() throws JDOMException, IOException, SAXException {
50 50 SchemaFactory schemafac =
51 51 SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
52   - Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("xsdcomplex/SAXTestComplexMain.xsd"));
  52 + Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("/xsdcomplex/SAXTestComplexMain.xsd"));
53 53 XMLReaderSchemaFactory readerfac = new XMLReaderSchemaFactory(schema);
54 54 assertTrue(readerfac.isValidating());
55 55 SAXBuilder builder = new SAXBuilder(readerfac);
56   - Document doc = builder.build(FidoFetch.getFido().getURL("xsdcomplex/input.xml"));
  56 + Document doc = builder.build(FidoFetch.getFido().getURL("/xsdcomplex/input.xml"));
57 57 assertEquals("test", doc.getRootElement().getName());
58 58 // the whole point of this particular XML input is that it should apply
59 59 // default attribute values.... lets make sure they make it.
10 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSingletons.java
@@ -24,7 +24,7 @@
24 24 public void testNonValidatingReader() throws JDOMException, IOException {
25 25 SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
26 26 assertFalse(builder.isValidating());
27   - Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
  27 + Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
28 28 assertEquals("root", doc.getRootElement().getName());
29 29 }
30 30
@@ -32,7 +32,7 @@ public void testNonValidatingReader() throws JDOMException, IOException {
32 32 public void testDTDValidatingReader() throws JDOMException, IOException {
33 33 SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
34 34 assertTrue(builder.isValidating());
35   - Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
  35 + Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/doctype.xml"));
36 36 assertEquals("root", doc.getRootElement().getName());
37 37 }
38 38
@@ -41,7 +41,7 @@ public void testDTDValidatingReaderFails() {
41 41 SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
42 42 assertTrue(builder.isValidating());
43 43 try {
44   - builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
  44 + builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
45 45 UnitTestUtil.failNoException(JDOMException.class);
46 46 } catch (Exception e) {
47 47 UnitTestUtil.checkException(JDOMException.class, e);
@@ -52,7 +52,7 @@ public void testDTDValidatingReaderFails() {
52 52 public void testXSDValidatingReader() throws JDOMException, IOException {
53 53 SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
54 54 assertTrue(builder.isValidating());
55   - Document doc = builder.build(FidoFetch.getFido().getURL("xsdcomplex/input.xml"));
  55 + Document doc = builder.build(FidoFetch.getFido().getURL("/xsdcomplex/input.xml"));
56 56 assertEquals("test", doc.getRootElement().getName());
57 57 // the whole point of this particular XML input is that it should apply
58 58 // default attribute values.... lets make sure they make it.
@@ -69,7 +69,7 @@ public void testXSDValidatingReaderFails() {
69 69 SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
70 70 assertTrue(builder.isValidating());
71 71 try {
72   - builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
  72 + builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
73 73 UnitTestUtil.failNoException(JDOMException.class);
74 74 } catch (Exception e) {
75 75 UnitTestUtil.checkException(JDOMException.class, e);
8 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderXSDFactory.java
@@ -27,17 +27,17 @@
27 27 //"./test/resources/xscomplex/multi_one.xsd",
28 28
29 29 private final URL filemain() {
30   - return FidoFetch.getFido().getURL("xsdcomplex/multi_main.xsd");
  30 + return FidoFetch.getFido().getURL("/xsdcomplex/multi_main.xsd");
31 31 }
32 32 private final URL fileone() {
33   - return FidoFetch.getFido().getURL("xsdcomplex/multi_one.xsd");
  33 + return FidoFetch.getFido().getURL("/xsdcomplex/multi_one.xsd");
34 34 }
35 35
36 36 private final URL filetwo() {
37   - return FidoFetch.getFido().getURL("xsdcomplex/multi_two.xsd");
  37 + return FidoFetch.getFido().getURL("/xsdcomplex/multi_two.xsd");
38 38 }
39 39 private final URL source() {
40   - return FidoFetch.getFido().getURL("xsdcomplex/multi.xml");
  40 + return FidoFetch.getFido().getURL("/xsdcomplex/multi.xml");
41 41 }
42 42
43 43 private void checkXML(XMLReaderJDOMFactory fac) {
2  test/src/java/org/jdom2/test/cases/located/TestLocatedJDOMFactory.java
@@ -52,7 +52,7 @@ public void testLocation() throws JDOMException, IOException {
52 52 SAXBuilder sb = new SAXBuilder();
53 53 sb.setJDOMFactory(new LocatedJDOMFactory());
54 54 sb.setExpandEntities(false);
55   - Document doc = sb.build(FidoFetch.getFido().getURL("complex.xml"));
  55 + Document doc = sb.build(FidoFetch.getFido().getURL("/complex.xml"));
56 56 // it appears the location of the DocType is the start of the internal subset.
57 57 checkLocation(doc.getDocType(), 2, 16);
58 58 final Element root = doc.getRootElement();
2  test/src/java/org/jdom2/test/cases/special/TestIssue008ExpandEntity.java
@@ -18,7 +18,7 @@
18 18 public class TestIssue008ExpandEntity {
19 19
20 20 private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) {
21   - String docloc = this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
  21 + String docloc = "/" + this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
22 22 URL docurl = FidoFetch.getFido().getURL(docloc);
23 23
24 24 if (docurl == null) {
2  test/src/java/org/jdom2/test/cases/xpath/TestXPathHepler.java
@@ -123,7 +123,7 @@ private static final void checkRelative(final NamespaceAware nsa, final Namespac
123 123 public void testComplex() throws JDOMException, IOException {
124 124 SAXBuilder sb = new SAXBuilder();
125 125 sb.setExpandEntities(false);
126   - Document doc = sb.build(FidoFetch.getFido().getURL("complex.xml"));
  126 + Document doc = sb.build(FidoFetch.getFido().getURL("/complex.xml"));
127 127 final Iterator<Content> des = doc.getDescendants();
128 128 final ArrayList<NamespaceAware> allc = new ArrayList<NamespaceAware>();
129 129 while (des.hasNext()) {
14 test/src/java/org/jdom2/test/util/FidoFetch.java
@@ -4,8 +4,6 @@
4 4 import java.net.URL;
5 5 import java.util.concurrent.atomic.AtomicReference;
6 6
7   -import org.jdom2.internal.ReflectionConstructor;
8   -
9 7 /**
10 8 * Android does not have a reliable ClassLoader.getResource() set of methods.
11 9 * We do a poor-man's hack that works on Android too.
@@ -22,7 +20,7 @@
22 20 * @return The URL to the name.
23 21 */
24 22 public URL getURL(String name) {
25   - return ClassLoader.getSystemResource(name);
  23 + return this.getClass().getResource(name);
26 24 }
27 25
28 26 /**
@@ -30,7 +28,7 @@ public URL getURL(String name) {
30 28 * @return The Resource as a stream
31 29 */
32 30 public InputStream getStream(String name) {
33   - return ClassLoader.getSystemResourceAsStream(name);
  31 + return this.getClass().getResourceAsStream(name);
34 32 }
35 33
36 34 private static final AtomicReference<FidoFetch> fetch = new AtomicReference<FidoFetch>();
@@ -42,11 +40,11 @@ public InputStream getStream(String name) {
42 40 public static final FidoFetch getFido() {
43 41 FidoFetch ret = fetch.get();
44 42 if (ret == null) {
45   - if ("Dalvik".equalsIgnoreCase(System.getProperty("java.vm.name", "junk"))) {
46   - ret = ReflectionConstructor.construct("org.jdom2.test.util.AndroidFetch", FidoFetch.class);
47   - } else {
  43 +// if ("Dalvik".equalsIgnoreCase(System.getProperty("java.vm.name", "junk"))) {
  44 +// ret = ReflectionConstructor.construct("org.jdom2.test.util.AndroidFetch", FidoFetch.class);
  45 +// } else {
48 46 ret = new FidoFetch();
49   - }
  47 +// }
50 48 fetch.set(ret);
51 49 }
52 50 return ret;

0 comments on commit c2c34d6

Please sign in to comment.
Something went wrong with that request. Please try again.