diff --git a/java/com/google/turbine/binder/ClassPathBinder.java b/java/com/google/turbine/binder/ClassPathBinder.java index 9efe7531..af59bcac 100644 --- a/java/com/google/turbine/binder/ClassPathBinder.java +++ b/java/com/google/turbine/binder/ClassPathBinder.java @@ -47,6 +47,12 @@ public final class ClassPathBinder { */ public static final String TRANSITIVE_PREFIX = "META-INF/TRANSITIVE/"; + /** + * The suffix for repackaged transitive dependencies; see {@link + * com.google.turbine.deps.Transitive}. + */ + public static final String TRANSITIVE_SUFFIX = ".turbine"; + /** Creates an environment containing symbols in the given classpath. */ public static ClassPath bindClasspath(Collection paths) throws IOException { // TODO(cushon): this is going to require an env eventually, @@ -110,14 +116,14 @@ private static void bindJar( // 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)) { + if (!name.endsWith(TRANSITIVE_SUFFIX)) { + continue; + } ClassSymbol sym = new ClassSymbol( - name.substring(TRANSITIVE_PREFIX.length(), name.length() - ".class".length())); + name.substring( + TRANSITIVE_PREFIX.length(), name.length() - TRANSITIVE_SUFFIX.length())); transitive.computeIfAbsent( sym, new Function() { @@ -128,6 +134,10 @@ public BytecodeBoundClass apply(ClassSymbol sym) { }); continue; } + if (!name.endsWith(".class")) { + resources.put(name, toByteArrayOrDie(ze)); + continue; + } if (name.substring(name.lastIndexOf('/') + 1).equals("module-info.class")) { ModuleInfo moduleInfo = BytecodeBinder.bindModuleInfo(path.toString(), toByteArrayOrDie(ze)); diff --git a/java/com/google/turbine/main/Main.java b/java/com/google/turbine/main/Main.java index 3725834d..226686fe 100644 --- a/java/com/google/turbine/main/Main.java +++ b/java/com/google/turbine/main/Main.java @@ -421,7 +421,9 @@ private static void writeOutput( } for (Map.Entry entry : transitive.entrySet()) { addEntry( - jos, ClassPathBinder.TRANSITIVE_PREFIX + entry.getKey() + ".class", entry.getValue()); + jos, + ClassPathBinder.TRANSITIVE_PREFIX + entry.getKey() + ClassPathBinder.TRANSITIVE_SUFFIX, + entry.getValue()); } for (Map.Entry entry : lowered.entrySet()) { addEntry(jos, entry.getKey() + ".class", entry.getValue()); diff --git a/javatests/com/google/turbine/deps/TransitiveTest.java b/javatests/com/google/turbine/deps/TransitiveTest.java index aab729a1..69d719b6 100644 --- a/javatests/com/google/turbine/deps/TransitiveTest.java +++ b/javatests/com/google/turbine/deps/TransitiveTest.java @@ -127,13 +127,13 @@ public void transitive() throws Exception { .containsExactly( "META-INF/", "META-INF/MANIFEST.MF", - "META-INF/TRANSITIVE/a/A.class", - "META-INF/TRANSITIVE/a/A$Anno.class", - "META-INF/TRANSITIVE/a/A$Inner.class", + "META-INF/TRANSITIVE/a/A.turbine", + "META-INF/TRANSITIVE/a/A$Anno.turbine", + "META-INF/TRANSITIVE/a/A$Inner.turbine", "b/B.class") .inOrder(); - ClassFile a = ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A.class")); + ClassFile a = ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A.turbine")); // methods and non-constant fields are removed assertThat(getOnlyElement(a.fields()).name()).isEqualTo("CONST"); assertThat(a.methods()).isEmpty(); @@ -142,7 +142,7 @@ public void transitive() throws Exception { // annotation interface methods are preserved assertThat( - ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A$Anno.class")) + ClassReader.read(null, readJar(libb).get("META-INF/TRANSITIVE/a/A$Anno.turbine")) .methods()) .hasSize(1); @@ -186,10 +186,10 @@ public void transitive() throws Exception { .containsExactly( "META-INF/", "META-INF/MANIFEST.MF", - "META-INF/TRANSITIVE/b/B.class", - "META-INF/TRANSITIVE/a/A.class", - "META-INF/TRANSITIVE/a/A$Anno.class", - "META-INF/TRANSITIVE/a/A$Inner.class", + "META-INF/TRANSITIVE/b/B.turbine", + "META-INF/TRANSITIVE/a/A.turbine", + "META-INF/TRANSITIVE/a/A$Anno.turbine", + "META-INF/TRANSITIVE/a/A$Inner.turbine", "c/C.class") .inOrder(); @@ -256,8 +256,8 @@ public void anonymous() throws Exception { .containsExactly( "META-INF/", "META-INF/MANIFEST.MF", - "META-INF/TRANSITIVE/a/A.class", - "META-INF/TRANSITIVE/a/A$I.class", + "META-INF/TRANSITIVE/a/A.turbine", + "META-INF/TRANSITIVE/a/A$I.turbine", "b/B.class") .inOrder(); } @@ -297,9 +297,9 @@ public void childClass() throws Exception { .containsExactly( "META-INF/", "META-INF/MANIFEST.MF", - "META-INF/TRANSITIVE/a/A$I.class", - "META-INF/TRANSITIVE/a/S.class", - "META-INF/TRANSITIVE/a/A.class", + "META-INF/TRANSITIVE/a/A$I.turbine", + "META-INF/TRANSITIVE/a/S.turbine", + "META-INF/TRANSITIVE/a/A.turbine", "b/B$I.class", "b/B.class") .inOrder(); @@ -338,7 +338,7 @@ public void packageInfo() throws Exception { .containsExactly( "META-INF/", "META-INF/MANIFEST.MF", - "META-INF/TRANSITIVE/p/package-info.class", + "META-INF/TRANSITIVE/p/package-info.turbine", "p/P.class") .inOrder(); }