From 5df23f185e0393981cc4d4ff3c5f3f7c98e2ab55 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 27 Aug 2024 12:57:01 -0700 Subject: [PATCH] Include package-infos in repackaged transitive classes This is related to unknown commit, which ensured that jdeps include package-infos. PiperOrigin-RevId: 668103888 --- .../com/google/turbine/deps/Dependencies.java | 2 +- java/com/google/turbine/deps/Transitive.java | 4 +- .../google/turbine/deps/TransitiveTest.java | 38 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/java/com/google/turbine/deps/Dependencies.java b/java/com/google/turbine/deps/Dependencies.java index 3dd008c9..5ce9b5de 100644 --- a/java/com/google/turbine/deps/Dependencies.java +++ b/java/com/google/turbine/deps/Dependencies.java @@ -165,7 +165,7 @@ private static void addSuperTypes( } } - private static void addPackageInfos(Set closure, BindingResult bound) { + static void addPackageInfos(Set closure, BindingResult bound) { Set packages = new LinkedHashSet<>(); for (ClassSymbol sym : closure) { String packageName = sym.packageName(); diff --git a/java/com/google/turbine/deps/Transitive.java b/java/com/google/turbine/deps/Transitive.java index 0a18f2be..22f49839 100644 --- a/java/com/google/turbine/deps/Transitive.java +++ b/java/com/google/turbine/deps/Transitive.java @@ -45,7 +45,9 @@ public final class Transitive { public static ImmutableMap collectDeps( ClassPath bootClassPath, BindingResult bound) { ImmutableMap.Builder transitive = ImmutableMap.builder(); - for (ClassSymbol sym : superClosure(bound)) { + Set closure = superClosure(bound); + Dependencies.addPackageInfos(closure, bound); + for (ClassSymbol sym : closure) { BytecodeBoundClass info = bound.classPathEnv().get(sym); if (info == null) { // the symbol wasn't loaded from the classpath diff --git a/javatests/com/google/turbine/deps/TransitiveTest.java b/javatests/com/google/turbine/deps/TransitiveTest.java index 6c3bfa05..aab729a1 100644 --- a/javatests/com/google/turbine/deps/TransitiveTest.java +++ b/javatests/com/google/turbine/deps/TransitiveTest.java @@ -305,6 +305,44 @@ public void childClass() throws Exception { .inOrder(); } + @Test + public void packageInfo() throws Exception { + Path libPackageInfo = + runTurbine( + new SourceBuilder() + .addSourceLines( + "p/Anno.java", + "package p;", + "import java.lang.annotation.Retention;", + "import static java.lang.annotation.RetentionPolicy.RUNTIME;", + "@Retention(RUNTIME)", + "@interface Anno {}") + .addSourceLines( + "p/package-info.java", // + "@Anno", + "package p;") + .build(), + ImmutableList.of()); + + Path liba = + runTurbine( + new SourceBuilder() + .addSourceLines( + "p/P.java", // + "package p;", + "public class P {}") + .build(), + ImmutableList.of(libPackageInfo)); + + assertThat(readJar(liba).keySet()) + .containsExactly( + "META-INF/", + "META-INF/MANIFEST.MF", + "META-INF/TRANSITIVE/p/package-info.class", + "p/P.class") + .inOrder(); + } + private Path runTurbine(ImmutableList sources, ImmutableList classpath) throws IOException { Path out = temporaryFolder.newFolder().toPath().resolve("out.jar");