Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ijar: fix manifest sections handling #12771

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ijar test when original MANIFEST contains target label and sections
  • Loading branch information
liucijus committed Jan 29, 2021
commit e0fcc827593c4dbaba64af80025d069799e23bb2
9 changes: 9 additions & 0 deletions third_party/ijar/test/BUILD
Original file line number Diff line number Diff line change
@@ -152,6 +152,14 @@ genrule(
tools = ["//third_party/ijar"],
)

genrule(
name = "jar_with_target_label_and_manifest_sections",
srcs = ["jar-with-target-label-and-manifest-sections.jar"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference:

Archive:  jar-with-target-label-and-manifest-sections.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
     1382  2010-01-01 05:00   AnnotatedClass.class
      476  2010-01-01 05:00   Annotations.class
      381  2010-01-01 05:00   Annotations$ParametersOnlyAnnotation.class
      468  2010-01-01 05:00   Annotations$RuntimeInvisible.class
      561  2010-01-01 05:00   Annotations$RuntimeVisible.class
        0  2010-01-01 05:00   META-INF/
      122  2021-01-29 08:19   META-INF/MANIFEST.MF
       19  2018-03-29 15:53   textfile.txt
---------                     -------
     3409                     8 files
$ cat META-INF/MANIFEST.MF 
Manifest-Version: 1.0
Created-By: test-code
Target-Label: //not:this

Name: foo
Foo: bar

Name: baz
Another: bar

outs = ["jar-with-target-label-and-manifest-sections-nostrip.jar"],
cmd = "$(location //third_party/ijar) --target_label //foo:foo --nostrip_jar $< $@",
tools = ["//third_party/ijar"],
)

genrule(
name = "jar_without_manifest_nostrip_idempotence",
srcs = ["jar-without-manifest-nostrip.jar"],
@@ -324,6 +332,7 @@ java_test(
":jar_with_manifest_and_target_label_nostrip",
":jar_with_manifest_nostrip",
":jar_with_manifest_sections",
":jar_with_target_label_and_manifest_sections",
":jar_without_manifest_nostrip",
":jar_without_manifest_nostrip_idempotence",
":kotlin_module-interface.jar",
21 changes: 21 additions & 0 deletions third_party/ijar/test/IjarTests.java
Original file line number Diff line number Diff line change
@@ -420,6 +420,27 @@ public void testPreserveManifestSections() throws Exception {
}
}

@Test
public void testPreserveManifestSectionsAndUpdateExistingTargetLabel() throws Exception {
try (JarFile stripped = new JarFile(
"third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar")) {
ImmutableList<String> strippedEntries =
stripped.stream().map(JarEntry::getName).collect(toImmutableList());

assertThat(strippedEntries.get(0)).isEqualTo("META-INF/");
assertThat(strippedEntries.get(1)).isEqualTo("META-INF/MANIFEST.MF");
Manifest manifest = stripped.getManifest();
Attributes attributes = manifest.getMainAttributes();
assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo");

Attributes sectionAttributes1 = manifest.getAttributes("foo");
assertThat(sectionAttributes1.getValue("Foo")).isEqualTo("bar");

Attributes sectionAttributes2 = manifest.getAttributes("baz");
assertThat(sectionAttributes2.getValue("Another")).isEqualTo("bar");
}
}

// Tests idempotence of --nostrip
@Test
public void testNoStripIdempotence() throws Exception {
Binary file not shown.