Run tests in tests_java_11 module when running test.py

Bug: b/337801526
Change-Id: I77969a2ed5d0cba83087d1fe1ca8a20aeb727e9a
diff --git a/d8_r8/test/build.gradle.kts b/d8_r8/test/build.gradle.kts
index 7b2de4e..f6ba92c 100644
--- a/d8_r8/test/build.gradle.kts
+++ b/d8_r8/test/build.gradle.kts
@@ -31,6 +31,7 @@
 val javaTestBaseJarTask = projectTask("testbase", "testJar")
 val javaTestBaseDepsJar = projectTask("testbase", "depsJar")
 val java8TestJarTask = projectTask("tests_java_8", "testJar")
+val java11TestJarTask = projectTask("tests_java_11", "testJar")
 val bootstrapTestsDepsJarTask = projectTask("tests_bootstrap", "depsJar")
 val bootstrapTestJarTask = projectTask("tests_bootstrap", "testJar")
 val testsJava8SourceSetDependenciesTask = projectTask("tests_java_8", "sourceSetDependencyTask")
@@ -61,8 +62,10 @@
 
   val packageTests by registering(Jar::class) {
     dependsOn(java8TestJarTask)
+    dependsOn(java11TestJarTask)
     dependsOn(bootstrapTestJarTask)
     from(java8TestJarTask.outputs.files.map(::zipTree))
+    from(java11TestJarTask.outputs.files.map(::zipTree))
     from(bootstrapTestJarTask.outputs.files.map(::zipTree))
     exclude("META-INF/*.kotlin_module", "**/*.kotlin_metadata")
     destinationDirectory.set(getRoot().resolveAll("build", "libs"))
@@ -136,18 +139,17 @@
             targetJarProvider)
     testJarProviders.forEach(::dependsOn)
     val mainDepsJar = mainDepsJarTask.getSingleOutputFile()
-    val rtJar = resolve(ThirdPartyDeps.java8Runtime, "rt.jar").getSingleFile()
     val r8WithRelocatedDepsJar = r8WithRelocatedDepsTask.getSingleOutputFile()
     val targetJar = targetJarProvider.getSingleOutputFile()
     val testDepsJar = packageTestDeps.getSingleOutputFile()
-    inputs.files(mainDepsJar, rtJar, r8WithRelocatedDepsJar, targetJar, testDepsJar)
+    inputs.files(mainDepsJar, r8WithRelocatedDepsJar, targetJar, testDepsJar)
     inputs.files(testJarProviders.map{it.getSingleOutputFile()})
     val output = file(Paths.get("build", "libs", artifactName))
     outputs.file(output)
     val argList = mutableListOf("--keep-rules",
                     "--allowobfuscation",
                     "--lib",
-                    "$rtJar",
+                    "${org.gradle.internal.jvm.Jvm.current().getJavaHome()}",
                     "--lib",
                     "$mainDepsJar",
                     "--lib",
@@ -285,20 +287,19 @@
             testJarProvider,
             packageTestBaseExcludeKeep)
     val keepRulesFile = keepRulesFileProvider.getSingleOutputFile()
-    val rtJar = resolve(ThirdPartyDeps.java8Runtime, "rt.jar").getSingleFile()
     val r8Jar = r8JarProvider.getSingleOutputFile()
     val r8WithRelocatedDepsJar = r8WithRelocatedDepsTask.getSingleOutputFile()
     val testBaseJar = packageTestBaseExcludeKeep.getSingleOutputFile()
     val testDepsJar = packageTestDeps.getSingleOutputFile()
     val testJar = testJarProvider.getSingleOutputFile()
-    inputs.files(keepRulesFile, rtJar, r8Jar, r8WithRelocatedDepsJar, testDepsJar, testJar)
+    inputs.files(keepRulesFile, r8Jar, r8WithRelocatedDepsJar, testDepsJar, testJar)
     val outputJar = getRoot().resolveAll("build", "libs", artifactName)
     outputs.file(outputJar)
     val args = mutableListOf(
       "--classfile",
       "--debug",
       "--lib",
-      "$rtJar",
+      "${org.gradle.internal.jvm.Jvm.current().getJavaHome()}",
       "--classpath",
       "$r8Jar",
       "--classpath",
diff --git a/d8_r8/test_modules/tests_java_11/build.gradle.kts b/d8_r8/test_modules/tests_java_11/build.gradle.kts
index f0748b2..bb30566 100644
--- a/d8_r8/test_modules/tests_java_11/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_11/build.gradle.kts
@@ -56,5 +56,13 @@
     systemProperty("TESTBASE_DATA_LOCATION",
                    testbaseJavaCompileTask.outputs.files.getAsPath().split(File.pathSeparator)[0])
   }
+
+  val testJar by registering(Jar::class) {
+    from(sourceSets.test.get().output)
+    // TODO(b/296486206): Seems like IntelliJ has a problem depending on test source sets. Renaming
+    //  this from the default name (tests_java_8.jar) will allow IntelliJ to find the resources in
+    //  the jar and not show red underlines. However, navigation to base classes will not work.
+    archiveFileName.set("not_named_tests_java_11.jar")
+  }
 }
 
diff --git a/src/test/examplesJava11/com/android/tools/r8/AlwaysInline.java b/src/test/examplesJava11/com/android/tools/r8/AlwaysInline.java
deleted file mode 100644
index f76ecf0..0000000
--- a/src/test/examplesJava11/com/android/tools/r8/AlwaysInline.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-
-@Target({ElementType.METHOD})
-public @interface AlwaysInline {}
diff --git a/src/test/examplesJava11/com/android/tools/r8/NeverClassInline.java b/src/test/examplesJava11/com/android/tools/r8/NeverClassInline.java
deleted file mode 100644
index 19c4504..0000000
--- a/src/test/examplesJava11/com/android/tools/r8/NeverClassInline.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8;
-
-public @interface NeverClassInline {}
diff --git a/src/test/examplesJava11/com/android/tools/r8/NeverInline.java b/src/test/examplesJava11/com/android/tools/r8/NeverInline.java
deleted file mode 100644
index f41f718..0000000
--- a/src/test/examplesJava11/com/android/tools/r8/NeverInline.java
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright (c) 2024, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.CLASS)
-@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
-public @interface NeverInline {}
diff --git a/src/test/examplesJava11/com/android/tools/r8/NeverPropagateValue.java b/src/test/examplesJava11/com/android/tools/r8/NeverPropagateValue.java
deleted file mode 100644
index b28eece..0000000
--- a/src/test/examplesJava11/com/android/tools/r8/NeverPropagateValue.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-
-@Target({ElementType.METHOD, ElementType.FIELD})
-public @interface NeverPropagateValue {}
diff --git a/src/test/java/com/android/tools/r8/shaking/b169045091/NestMemberAccessibilityTest.java b/src/test/examplesJava11/nesthostexample/b169045091/NestMemberAccessibilityTest.java
similarity index 78%
rename from src/test/java/com/android/tools/r8/shaking/b169045091/NestMemberAccessibilityTest.java
rename to src/test/examplesJava11/nesthostexample/b169045091/NestMemberAccessibilityTest.java
index 0b69df7..71e5b47 100644
--- a/src/test/java/com/android/tools/r8/shaking/b169045091/NestMemberAccessibilityTest.java
+++ b/src/test/examplesJava11/nesthostexample/b169045091/NestMemberAccessibilityTest.java
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-package com.android.tools.r8.shaking.b169045091;
+package nesthostexample.b169045091;
 
 import static com.android.tools.r8.references.Reference.INT;
 import static org.junit.Assert.assertTrue;
@@ -17,16 +17,10 @@
 import com.android.tools.r8.graph.DexProgramClass;
 import com.android.tools.r8.references.Reference;
 import com.android.tools.r8.shaking.AppInfoWithLiveness;
-import com.android.tools.r8.shaking.b169045091.B169045091.TestClass;
 import com.android.tools.r8.shaking.b169045091.examples.NestHost;
 import com.android.tools.r8.shaking.b169045091.examples.NestHost.NestMember;
 import com.android.tools.r8.shaking.b169045091.examples.NonNestMember;
 import com.android.tools.r8.utils.AndroidApp;
-import com.android.tools.r8.utils.DescriptorUtils;
-import com.google.common.collect.ImmutableList;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -35,11 +29,6 @@
 @RunWith(Parameterized.class)
 public class NestMemberAccessibilityTest extends TestBase {
 
-  private final Path TEST_DIRECTORY =
-      Paths.get(ToolHelper.getExamplesJava11BuildDir())
-          .resolve(
-              DescriptorUtils.getBinaryNameFromJavaType(NestHost.class.getPackage().getName()));
-
   @Parameters(name = "{0}")
   public static TestParametersCollection data() {
     return getTestParameters().withNoneRuntime().build();
@@ -54,8 +43,9 @@
     AppView<AppInfoWithLiveness> appView =
         computeAppViewWithLiveness(
             AndroidApp.builder()
-                .addProgramFiles(getProgramFiles())
-                .addClassProgramData(getNestHostClassFileData())
+                .addClassProgramData(ToolHelper.getClassAsBytes(NestHost.NestMember.class))
+                .addClassProgramData(ToolHelper.getClassAsBytes(NonNestMember.class))
+                .addClassProgramData(getNestHostClassTransformed())
                 .build(),
             TestClass.class);
     AppInfoWithLiveness appInfo = appView.appInfo();
@@ -117,16 +107,12 @@
             .isFalse());
   }
 
-  private List<Path> getProgramFiles() {
-    return ImmutableList.of(
-        TEST_DIRECTORY.resolve("NestHost$NestMember.class"),
-        TEST_DIRECTORY.resolve("NonNestMember.class"));
+  private byte[] getNestHostClassTransformed() throws Exception {
+    return transformer(NestHost.class).setPrivate(NestHost.class.getDeclaredField("f")).transform();
   }
 
-  private byte[] getNestHostClassFileData() throws Exception {
-    return transformer(
-            TEST_DIRECTORY.resolve("NestHost.class"), Reference.classFromClass(NestHost.class))
-        .setPrivate(NestHost.class.getDeclaredField("f"))
-        .transform();
+  public static class TestClass {
+
+    public static void main(String[] args) {}
   }
 }
diff --git a/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NestHost.java b/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NestHost.java
deleted file mode 100644
index 872e37b..0000000
--- a/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NestHost.java
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.shaking.b169045091.examples;
-
-/**
- * Mirror of src/test/examplesJava11/com/android/tools/r8/shaking/b169045091/examples/NestHost.java
- */
-public class NestHost {
-
-  public int f;
-
-  public static class NestMember {}
-}
diff --git a/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NonNestMember.java b/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NonNestMember.java
deleted file mode 100644
index 26de699..0000000
--- a/src/test/java/com/android/tools/r8/shaking/b169045091/examples/NonNestMember.java
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.shaking.b169045091.examples;
-
-/**
- * Mirror of
- * src/test/examplesJava11/com/android/tools/r8/shaking/b169045091/examples/NonNestMember.java.
- */
-public class NonNestMember {}