Skip to content

Commit

Permalink
Include package-infos in repackaged transitive classes
Browse files Browse the repository at this point in the history
This is related to unknown commit, which ensured that jdeps include package-infos.

PiperOrigin-RevId: 668103888
  • Loading branch information
cushon authored and Javac Team committed Aug 28, 2024
1 parent 15ed1be commit 5df23f1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion java/com/google/turbine/deps/Dependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static void addSuperTypes(
}
}

private static void addPackageInfos(Set<ClassSymbol> closure, BindingResult bound) {
static void addPackageInfos(Set<ClassSymbol> closure, BindingResult bound) {
Set<ClassSymbol> packages = new LinkedHashSet<>();
for (ClassSymbol sym : closure) {
String packageName = sym.packageName();
Expand Down
4 changes: 3 additions & 1 deletion java/com/google/turbine/deps/Transitive.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public final class Transitive {
public static ImmutableMap<String, byte[]> collectDeps(
ClassPath bootClassPath, BindingResult bound) {
ImmutableMap.Builder<String, byte[]> transitive = ImmutableMap.builder();
for (ClassSymbol sym : superClosure(bound)) {
Set<ClassSymbol> 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
Expand Down
38 changes: 38 additions & 0 deletions javatests/com/google/turbine/deps/TransitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> sources, ImmutableList<Path> classpath)
throws IOException {
Path out = temporaryFolder.newFolder().toPath().resolve("out.jar");
Expand Down

0 comments on commit 5df23f1

Please sign in to comment.