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/ClassPath.java | 5 ++++- java/com/google/turbine/binder/ClassPathBinder.java | 12 ++++++++++-- java/com/google/turbine/binder/CtSymClassBinder.java | 5 +++++ java/com/google/turbine/binder/JimageClassBinder.java | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/com/google/turbine/binder/ClassPath.java b/java/com/google/turbine/binder/ClassPath.java index d3461bf..eeea7c5 100644 --- a/java/com/google/turbine/binder/ClassPath.java +++ b/java/com/google/turbine/binder/ClassPath.java @@ -16,6 +16,7 @@ package com.google.turbine.binder; +import com.google.common.base.Supplier; import com.google.turbine.binder.bound.ModuleInfo; import com.google.turbine.binder.bytecode.BytecodeBoundClass; import com.google.turbine.binder.env.Env; @@ -24,7 +25,7 @@ import com.google.turbine.binder.sym.ClassSymbol; import com.google.turbine.binder.sym.ModuleSymbol; /** - * A compilation classpath, e.g. the user or platform class path. Maybe backed by a search path of + * A compilation classpath, e.g. the user or platform class path. May be backed by a search path of * jar files, or a jrtfs filesystem. */ public interface ClassPath { @@ -36,4 +37,6 @@ public interface ClassPath { /** The classpath's top level index. */ TopLevelIndex index(); + + Supplier resource(String path); } 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)) { diff --git a/java/com/google/turbine/binder/CtSymClassBinder.java b/java/com/google/turbine/binder/CtSymClassBinder.java index 84fa966..a6f1b3d 100644 --- a/java/com/google/turbine/binder/CtSymClassBinder.java +++ b/java/com/google/turbine/binder/CtSymClassBinder.java @@ -105,6 +105,11 @@ public class CtSymClassBinder { public TopLevelIndex index() { return index; } + + @Override + public Supplier resource(String input) { + return null; + } }; } diff --git a/java/com/google/turbine/binder/JimageClassBinder.java b/java/com/google/turbine/binder/JimageClassBinder.java index 4c14bd6..53aa634 100644 --- a/java/com/google/turbine/binder/JimageClassBinder.java +++ b/java/com/google/turbine/binder/JimageClassBinder.java @@ -256,5 +256,10 @@ public class JimageClassBinder { public TopLevelIndex index() { return index; } + + @Override + public Supplier resource(String input) { + return null; + } } } -- cgit v1.2.3