aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/ijar/test
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-02-09 10:32:40 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-09 10:34:20 -0800
commit8a56b164facce7844718a0c80554f6c11ba155f2 (patch)
tree0c977e9834d2d67f257dc8db4600ada757bd285f /third_party/ijar/test
parentad32f62952e2b6f8293a26ea5fd677e61975c9ff (diff)
Accept --target_label, --injecting_rule_kind in ijar.
This is a rollforward with fixes. The values (if present) are written into the manifest with this format: Target-Label: <label> Injecting-Rule-Kind: <kind> In the future, JavaBuilder will make sure of this instead of command line arguments to find owners for jars for its add_dep commands. PiperOrigin-RevId: 185159950
Diffstat (limited to 'third_party/ijar/test')
-rw-r--r--third_party/ijar/test/BUILD8
-rw-r--r--third_party/ijar/test/IjarTests.java18
2 files changed, 26 insertions, 0 deletions
diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD
index 455ab29608..6b4eeb908e 100644
--- a/third_party/ijar/test/BUILD
+++ b/third_party/ijar/test/BUILD
@@ -101,6 +101,14 @@ genrule(
tools = ["//third_party/ijar"],
)
+genrule(
+ name = "interface_ijar_testlib_with_target_label",
+ srcs = [":ijar_testlib"],
+ outs = ["interface_ijar_testlib_with_target_label.jar"],
+ cmd = "$(location //third_party/ijar) --target_label //foo:foo --injecting_rule_kind foo_library $< $@",
+ tools = ["//third_party/ijar"],
+)
+
java_library(
name = "typeannotations2",
srcs = glob(["typeannotations2/**/*.java"]),
diff --git a/third_party/ijar/test/IjarTests.java b/third_party/ijar/test/IjarTests.java
index 4e0fb5d839..467680552b 100644
--- a/third_party/ijar/test/IjarTests.java
+++ b/third_party/ijar/test/IjarTests.java
@@ -23,15 +23,19 @@ import com.google.common.io.ByteStreams;
import com.google.devtools.build.java.bazel.BazelJavaCompiler;
import java.io.File;
import java.io.IOException;
+import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.annotation.processing.AbstractProcessor;
@@ -274,4 +278,18 @@ public class IjarTests {
assertThat(new String(lib.get("module-info.class"), UTF_8)).isEqualTo("hello");
assertThat(new String(lib.get("foo/module-info.class"), UTF_8)).isEqualTo("goodbye");
}
+
+ @Test
+ public void testTargetLabel() throws Exception {
+ try (JarFile jf =
+ new JarFile("third_party/ijar/test/interface_ijar_testlib_with_target_label.jar")) {
+ Manifest manifest = jf.getManifest();
+ Attributes attributes = manifest.getMainAttributes();
+ assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo");
+ assertThat(attributes.getValue("Injecting-Rule-Kind")).isEqualTo("foo_library");
+ assertThat(jf.getEntry(JarFile.MANIFEST_NAME).getLastModifiedTime().toInstant())
+ .isEqualTo(
+ Instant.ofEpochMilli(new GregorianCalendar(1980, 0, 1, 0, 0, 0).getTimeInMillis()));
+ }
+ }
}