aboutsummaryrefslogtreecommitdiff
path: root/java/com/google/turbine/binder/ClassPathBinder.java
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2019-07-27 15:27:51 -0700
committerLiam Miller-Cushon <cushon@google.com>2019-07-31 18:55:40 -0400
commit314e9abfc556d3b85206639ddf73738e4396fe0b (patch)
tree82e33ef3eb8d4dda91fd4e3f883b31bccbf36058 /java/com/google/turbine/binder/ClassPathBinder.java
parent2f5526b2079192717efa98536fbccf71fb49b3a0 (diff)
downloadturbine-314e9abfc556d3b85206639ddf73738e4396fe0b.tar.gz
Save non-class resources from the classpath
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=260323424
Diffstat (limited to 'java/com/google/turbine/binder/ClassPathBinder.java')
-rw-r--r--java/com/google/turbine/binder/ClassPathBinder.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/java/com/google/turbine/binder/ClassPathBinder.java b/java/com/google/turbine/binder/ClassPathBinder.java
index 5d8db86..8aead80 100644
--- a/java/com/google/turbine/binder/ClassPathBinder.java
+++ b/java/com/google/turbine/binder/ClassPathBinder.java
@@ -53,6 +53,7 @@ public class ClassPathBinder {
Map<ClassSymbol, BytecodeBoundClass> transitive = new LinkedHashMap<>();
Map<ClassSymbol, BytecodeBoundClass> map = new HashMap<>();
Map<ModuleSymbol, ModuleInfo> modules = new HashMap<>();
+ Map<String, Supplier<byte[]>> resources = new HashMap<>();
Env<ClassSymbol, BytecodeBoundClass> benv =
new Env<ClassSymbol, BytecodeBoundClass>() {
@Override
@@ -62,7 +63,7 @@ public class ClassPathBinder {
};
for (Path path : paths) {
try {
- bindJar(path, map, modules, benv, transitive);
+ bindJar(path, map, modules, benv, transitive, resources);
} catch (IOException e) {
throw new IOException("error reading " + path, e);
}
@@ -89,6 +90,11 @@ public class ClassPathBinder {
public TopLevelIndex index() {
return index;
}
+
+ @Override
+ public Supplier<byte[]> resource(String path) {
+ return resources.get(path);
+ }
};
}
@@ -97,12 +103,14 @@ public class ClassPathBinder {
Map<ClassSymbol, BytecodeBoundClass> env,
Map<ModuleSymbol, ModuleInfo> modules,
Env<ClassSymbol, BytecodeBoundClass> benv,
- Map<ClassSymbol, BytecodeBoundClass> transitive)
+ Map<ClassSymbol, BytecodeBoundClass> transitive,
+ Map<String, Supplier<byte[]>> resources)
throws IOException {
// TODO(cushon): don't leak file descriptors
for (Zip.Entry ze : new Zip.ZipIterable(path)) {
String name = ze.name();
if (!name.endsWith(".class")) {
+ resources.put(name, toByteArrayOrDie(ze));
continue;
}
if (name.startsWith(TRANSITIVE_PREFIX)) {