diff options
author | cushon <cushon@google.com> | 2018-03-22 20:09:26 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-22 20:10:43 -0700 |
commit | fd953707f7404cb006f33ae59c44d624048f69c8 (patch) | |
tree | 3303961d85070136a0fc01bbcc842e55f90c220c /third_party/ijar | |
parent | ebf7dc4d19cad4dc16dbf2532d1614fd8b2bd89d (diff) |
Write manifests at the beginning of the jar, not at the end
This is the convention, and tools that only read manifests may optimize
assuming that the manifest is at the beginning.
PiperOrigin-RevId: 190167351
Diffstat (limited to 'third_party/ijar')
-rw-r--r-- | third_party/ijar/ijar.cc | 3 | ||||
-rw-r--r-- | third_party/ijar/test/IjarTests.java | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/third_party/ijar/ijar.cc b/third_party/ijar/ijar.cc index 2ed559dad2..bcbe242775 100644 --- a/third_party/ijar/ijar.cc +++ b/third_party/ijar/ijar.cc @@ -198,12 +198,13 @@ static void OpenFilesAndProcessJar(const char *file_out, const char *file_in, } processor.SetZipBuilder(out.get()); + WriteManifest(out.get(), target_label, injecting_rule_kind); + // Process all files in the zip if (in->ProcessAll() < 0) { fprintf(stderr, "%s\n", in->GetError()); abort(); } - WriteManifest(out.get(), target_label, injecting_rule_kind); // Add dummy file, since javac doesn't like truly empty jars. if (out->GetNumberFiles() == 0) { diff --git a/third_party/ijar/test/IjarTests.java b/third_party/ijar/test/IjarTests.java index dc6c02062a..f88616f469 100644 --- a/third_party/ijar/test/IjarTests.java +++ b/third_party/ijar/test/IjarTests.java @@ -12,12 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.io.ByteStreams; import com.google.devtools.build.java.bazel.BazelJavaCompiler; @@ -283,6 +285,9 @@ public class IjarTests { public void testTargetLabel() throws Exception { try (JarFile jf = new JarFile("third_party/ijar/test/interface_ijar_testlib_with_target_label.jar")) { + ImmutableList<String> entries = jf.stream().map(JarEntry::getName).collect(toImmutableList()); + assertThat(entries.get(0)).isEqualTo("META-INF/"); + assertThat(entries.get(1)).isEqualTo("META-INF/MANIFEST.MF"); Manifest manifest = jf.getManifest(); Attributes attributes = manifest.getMainAttributes(); assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo"); |