1 | |
package liquibase.integration.ant; |
2 | |
|
3 | |
import liquibase.resource.ResourceAccessor; |
4 | |
import org.apache.tools.ant.AntClassLoader; |
5 | |
import org.apache.tools.ant.Project; |
6 | |
import org.apache.tools.ant.types.Path; |
7 | |
|
8 | |
import java.io.IOException; |
9 | |
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 | |
|
17 | |
|
18 | |
public class AntResourceAccessor implements ResourceAccessor { |
19 | |
private AntClassLoader loader; |
20 | |
|
21 | 3 | public AntResourceAccessor(final Project project, final Path classpath) { |
22 | 3 | loader = AccessController.doPrivileged(new PrivilegedAction<AntClassLoader>() { |
23 | |
public AntClassLoader run() { |
24 | 3 | return new AntClassLoader(project, classpath); |
25 | |
} |
26 | |
}); |
27 | 3 | } |
28 | |
|
29 | |
public InputStream getResourceAsStream(String file) throws IOException { |
30 | 2 | URL resource = loader.getResource(file); |
31 | 2 | if (resource == null) { |
32 | 1 | return null; |
33 | |
} |
34 | 1 | return resource.openStream(); |
35 | |
} |
36 | |
|
37 | |
public Enumeration<URL> getResources(String packageName) throws IOException { |
38 | 1 | return loader.getResources(packageName); |
39 | |
} |
40 | |
|
41 | |
public ClassLoader toClassLoader() { |
42 | 0 | return loader; |
43 | |
} |
44 | |
|
45 | |
@Override |
46 | |
public String toString() { |
47 | 0 | return getClass().getName() + "(" + loader.getClasspath() + ")"; |
48 | |
} |
49 | |
} |