Migrate the `JavaInfoStarlarkApiTest.buildHelperCreateJavaInfoWithOutputJarAndStampJar` test to Starlark

The test is removed from Bazel and added in rules_java

PiperOrigin-RevId: 734624934
Change-Id: Ib89f8f0b3990a3bbd4e5582efae4eec577aa0952
diff --git a/java/test/common/java_info_tests.bzl b/java/test/common/java_info_tests.bzl
index 224d763..53f647d 100644
--- a/java/test/common/java_info_tests.bzl
+++ b/java/test/common/java_info_tests.bzl
@@ -711,6 +711,30 @@
 
     assert_java_info.plugins().processor_classes().contains_exactly(["com.google.process.stuff"])
 
+def _with_stamped_jar_test(name):
+    target_name = name + "/my_starlark_rule"
+    util.helper_target(
+        custom_java_info_rule,
+        name = target_name,
+        output_jar = target_name + "/my_starlark_rule_lib.jar",
+        source_jars = ["my_starlark_rule_src.jar"],
+        stamp_jar = True,
+    )
+
+    analysis_test(
+        name = name,
+        impl = _with_stamped_jar_test_impl,
+        target = target_name,
+    )
+
+def _with_stamped_jar_test_impl(env, target):
+    assert_compilation_args = java_info_subject.from_target(env, target).compilation_args()
+
+    assert_compilation_args.full_compile_jars().contains_exactly(["{package}/{name}/my_starlark_rule_lib.jar"])
+    assert_compilation_args.compile_jars().contains_exactly(["{package}/{name}/my_starlark_rule_lib-stamped.jar"])
+    assert_compilation_args.transitive_runtime_jars().contains_exactly(["{package}/{name}/my_starlark_rule_lib.jar"])
+    assert_compilation_args.transitive_compile_time_jars().contains_exactly(["{package}/{name}/my_starlark_rule_lib-stamped.jar"])
+
 def java_info_tests(name):
     test_suite(
         name = name,
@@ -735,5 +759,6 @@
             _with_transitive_deps_and_exports_test,
             _with_plugins_via_exports_test,
             _with_plugins_test,
+            _with_stamped_jar_test,
         ],
     )
diff --git a/java/test/testutil/rules/custom_java_info_rule.bzl b/java/test/testutil/rules/custom_java_info_rule.bzl
index c8138d2..1cd2b06 100644
--- a/java/test/testutil/rules/custom_java_info_rule.bzl
+++ b/java/test/testutil/rules/custom_java_info_rule.bzl
@@ -7,6 +7,8 @@
 load("//java/common:java_semantics.bzl", "semantics")
 
 def _impl(ctx):
+    if ctx.attr.use_ijar and ctx.attr.stamp_jar:
+        fail("only one of use_ijar or stamp_jar may be set")
     ctx.actions.write(ctx.outputs.output_jar, "JavaInfo API Test", is_executable = False)
     dp = [dep[JavaInfo] for dep in ctx.attr.dep]
     dp_runtime = [dep[JavaInfo] for dep in ctx.attr.dep_runtime]
@@ -26,7 +28,14 @@
         ctx.actions,
         jar = ctx.outputs.output_jar,
         java_toolchain = semantics.find_java_toolchain(ctx),
-    ) if ctx.attr.use_ijar else ctx.outputs.output_jar
+    ) if ctx.attr.use_ijar else (
+        java_common.stamp_jar(
+            ctx.actions,
+            jar = ctx.outputs.output_jar,
+            target_label = ctx.label,
+            java_toolchain = semantics.find_java_toolchain(ctx),
+        ) if ctx.attr.stamp_jar else ctx.outputs.output_jar
+    )
 
     return [
         JavaInfo(
@@ -56,6 +65,7 @@
         "use_ijar": attr.bool(default = False),
         "neverlink": attr.bool(default = False),
         "pack_sources": attr.bool(default = False),
+        "stamp_jar": attr.bool(default = False),
     },
     toolchains = [semantics.JAVA_TOOLCHAIN_TYPE],
 )