01: package liquibase.ant;
02:
03: import liquibase.FileOpener;
04: import org.apache.tools.ant.AntClassLoader;
05: import org.apache.tools.ant.Project;
06: import org.apache.tools.ant.types.Path;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10: import java.net.URL;
11: import java.security.AccessController;
12: import java.security.PrivilegedAction;
13: import java.util.Enumeration;
14:
15: /**
16: * An implementation of FileOpener that is specific to how Ant works.
17: */
18: public class AntFileOpener implements FileOpener {
19: private AntClassLoader loader;
20:
21: public AntFileOpener(final Project project, final Path classpath) {
22: loader = AccessController
23: .doPrivileged(new PrivilegedAction<AntClassLoader>() {
24: public AntClassLoader run() {
25: return new AntClassLoader(project, classpath);
26: }
27: });
28: }
29:
30: public InputStream getResourceAsStream(String file)
31: throws IOException {
32: URL resource = loader.getResource(file);
33: if (resource == null) {
34: return null;
35: }
36: return resource.openStream();
37: }
38:
39: public Enumeration<URL> getResources(String packageName)
40: throws IOException {
41: return loader.getResources(packageName);
42: }
43:
44: public ClassLoader toClassLoader() {
45: return loader;
46: }
47: }
|