01: package liquibase.test;
02:
03: import liquibase.FileOpener;
04:
05: import java.io.File;
06: import java.io.IOException;
07: import java.io.InputStream;
08: import java.net.URI;
09: import java.net.URL;
10: import java.net.URLClassLoader;
11: import java.util.Enumeration;
12:
13: public class JUnitFileOpener implements FileOpener {
14: private URLClassLoader classLoader;
15:
16: public JUnitFileOpener() throws Exception {
17: File this ClassFile = new File(new URI(this .getClass()
18: .getClassLoader().getResource(
19: "liquibase/test/JUnitFileOpener.class")
20: .toExternalForm()));
21: File srcDir = new File(this ClassFile.getParentFile()
22: .getParentFile().getParentFile().getParent(), "src");
23: classLoader = new URLClassLoader(new URL[] {
24: new File(srcDir, "samples").toURL(),
25: new File(srcDir, "java-test").toURL(),
26: new File(System.getProperty("java.io.tmpdir")).toURL(),
27:
28: });
29:
30: }
31:
32: public InputStream getResourceAsStream(String file)
33: throws IOException {
34: return classLoader.getResourceAsStream(file);
35: }
36:
37: public Enumeration<URL> getResources(String packageName)
38: throws IOException {
39: return classLoader.getResources(packageName);
40: }
41:
42: public ClassLoader toClassLoader() {
43: return classLoader;
44: }
45: }
|