From 314e9abfc556d3b85206639ddf73738e4396fe0b Mon Sep 17 00:00:00 2001 From: cushon Date: Sat, 27 Jul 2019 15:27:51 -0700 Subject: Save non-class resources from the classpath ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=260323424 --- java/com/google/turbine/binder/ClassPathBinder.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'java/com/google/turbine/binder/ClassPathBinder.java') 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 transitive = new LinkedHashMap<>(); Map map = new HashMap<>(); Map modules = new HashMap<>(); + Map> resources = new HashMap<>(); Env benv = new Env() { @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 resource(String path) { + return resources.get(path); + } }; } @@ -97,12 +103,14 @@ public class ClassPathBinder { Map env, Map modules, Env benv, - Map transitive) + Map transitive, + Map> 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)) { -- cgit v1.2.3