Merge "Return full classpath from compile files helper" into androidx-main
diff --git a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
index 64b77f4..6b53b5c 100644
--- a/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
+++ b/room/room-compiler-processing-testing/src/main/java/androidx/room/compiler/processing/util/ProcessorTestExt.kt
@@ -183,7 +183,7 @@
     runTests(
         params = TestCompilationParameters(
             sources = sources,
-            classpath = classpath,
+            classpath = classpath.distinct(),
             options = options,
             handlers = handlers
         ),
@@ -306,8 +306,9 @@
 }
 
 /**
- * Compiles the given set of sources into a temporary folder and returns the output classes
- * directory.
+ * Compiles the given set of sources into a temporary folder and returns the full classpath that
+ * includes both the compilation output and dependencies.
+ *
  * @param sources The list of source files to compile
  * @param options The annotation processor arguments
  * @param annotationProcessors The list of Java annotation processors to run with compilation
@@ -321,7 +322,7 @@
     annotationProcessors: List<Processor> = emptyList(),
     symbolProcessorProviders: List<SymbolProcessorProvider> = emptyList(),
     javacArguments: List<String> = emptyList()
-): File {
+): List<File> {
     val outputStream = ByteArrayOutputStream()
     val compilation = KotlinCompilationUtil.prepareCompilation(
         sources = sources,
@@ -340,5 +341,5 @@
     check(result.exitCode == KotlinCompilation.ExitCode.OK) {
         "compilation failed: ${outputStream.toString(Charsets.UTF_8)}"
     }
-    return compilation.classesDir
+    return listOf(compilation.classesDir) + compilation.classpaths
 }
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
index cd71d87..b4cbf09 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/FallbackLocationInformationTest.kt
@@ -62,7 +62,7 @@
         val dependency = compileFiles(listOf(kotlinSource, javaSource))
         runProcessorTest(
             sources = listOf(placeholder),
-            classpath = listOf(dependency)
+            classpath = dependency
         ) { invocation ->
             val kotlinSubject = invocation.processingEnv.requireTypeElement("foo.bar.KotlinSubject")
             assertThat(
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
index 857cf36..47f2747 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/KspClassFileUtilityTest.kt
@@ -49,7 +49,7 @@
         val classpath = compileFiles(listOf(libSource))
         runProcessorTest(
             sources = emptyList(),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             val element = invocation.processingEnv.requireTypeElement("KotlinClass")
             assertThat(element.getAllFieldNames())
@@ -76,7 +76,7 @@
         val classpath = compileFiles(listOf(libSource))
         runProcessorTest(
             sources = emptyList(),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             val element = invocation.processingEnv.requireTypeElement("JavaClass")
             assertThat(element.getAllFieldNames())
@@ -103,7 +103,7 @@
         val classpath = compileFiles(listOf(libSource))
         runProcessorTest(
             sources = listOf(Source.kotlin("Placeholder.kt", "")),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             val element = invocation.processingEnv.requireTypeElement("KotlinClass")
             assertThat(element.getDeclaredMethods().map { it.name })
@@ -130,7 +130,7 @@
         val classpath = compileFiles(listOf(libSource))
         runProcessorTest(
             sources = listOf(Source.kotlin("Placeholder.kt", "")),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             val element = invocation.processingEnv.requireTypeElement("JavaClass")
             assertThat(element.getDeclaredMethods().map { it.name })
@@ -168,7 +168,7 @@
         )
         runKspTest(
             sources = createSources("main"),
-            classpath = listOf(preCompiled)
+            classpath = preCompiled
         ) { invocation ->
             assertThat(
                 invocation.findOrigin("lib.JavaClass")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
index 3e6dd30..39c6f387 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/MethodSpecHelperTest.kt
@@ -384,7 +384,7 @@
         ignoreInheritedMethods: Boolean = false
     ) {
         val (sources: List<Source>, classpath: List<File>) = if (preCompiledCode) {
-            emptyList<Source>() to listOf(compileFiles(sources.toList()))
+            emptyList<Source>() to compileFiles(sources.toList())
         } else {
             sources.toList() to emptyList()
         }
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TopLevelMembersTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TopLevelMembersTest.kt
index 3081982..5582ac2 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TopLevelMembersTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TopLevelMembersTest.kt
@@ -59,7 +59,7 @@
         )
         runKspTest(
             sources = listOf(appSrc),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             // b/188822146
             // TODO add lib package here once Room updates to a version that includes the
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
index 8b864c2..a24ad96 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/TypeAliasTest.kt
@@ -51,7 +51,7 @@
         val lib = compileFiles(listOf(produceSource("lib")))
         runProcessorTest(
             sources = listOf(produceSource("app")),
-            classpath = listOf(lib)
+            classpath = lib
         ) { invocation ->
             listOf("lib", "app").forEach { pkg ->
                 val elm = invocation.processingEnv.requireTypeElement("$pkg.Subject")
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
index e0c3ef4..d7ce271 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationBoxTest.kt
@@ -30,7 +30,6 @@
 import androidx.room.compiler.processing.util.getField
 import androidx.room.compiler.processing.util.getMethod
 import androidx.room.compiler.processing.util.getParameter
-import androidx.room.compiler.processing.util.getSystemClasspathFiles
 import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
 import androidx.room.compiler.processing.util.typeName
@@ -70,7 +69,7 @@
             runProcessorTest(
                 sources = newSources,
                 handler = handler,
-                classpath = listOf(compiled) + getSystemClasspathFiles()
+                classpath = compiled
             )
         } else {
             runProcessorTest(
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
index 44f0e8b..6f0b907 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XAnnotationTest.kt
@@ -30,7 +30,6 @@
 import androidx.room.compiler.processing.util.getField
 import androidx.room.compiler.processing.util.getMethod
 import androidx.room.compiler.processing.util.getParameter
-import androidx.room.compiler.processing.util.getSystemClasspathFiles
 import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.compiler.processing.util.runProcessorTestWithoutKsp
 import androidx.room.compiler.processing.util.typeName
@@ -69,7 +68,7 @@
             runProcessorTest(
                 sources = newSources,
                 handler = handler,
-                classpath = listOf(compiled) + getSystemClasspathFiles()
+                classpath = compiled
             )
         } else {
             runProcessorTest(
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
index 43311ca..8ea3fae 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeElementTest.kt
@@ -511,7 +511,7 @@
         )
         runProcessorTest(
             listOf(javaSource, kotlinSource),
-            classpath = listOf(dependency)
+            classpath = dependency
         ) { invocation ->
             listOf(
                 "JavaSubject", "DependencyJavaSubject",
@@ -949,7 +949,7 @@
         )
         runProcessorTest(
             sources = createSources("app"),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             listOf(
                 "lib.KotlinEnum", "lib.JavaEnum",
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
index 7251136..6825149 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/javac/kotlin/KotlinMetadataElementTest.kt
@@ -18,6 +18,8 @@
 
 import androidx.room.compiler.processing.javac.JavacProcessingEnv
 import androidx.room.compiler.processing.util.Source
+import androidx.room.compiler.processing.util.compileFiles
+import androidx.room.compiler.processing.util.runJavaProcessorTest
 import androidx.room.compiler.processing.util.runKaptTest
 import com.google.common.truth.Truth.assertThat
 import org.junit.AssumptionViolatedException
@@ -466,6 +468,35 @@
         }
     }
 
+    @Test
+    fun withoutKotlinInClasspath() {
+        val libSource = Source.kotlin(
+            "lib.kt",
+            """
+            class KotlinClass {
+                val b: String = TODO()
+                val a: String = TODO()
+                val c: String = TODO()
+                val isB:String = TODO()
+                val isA:String = TODO()
+                val isC:String = TODO()
+            }
+            """.trimIndent()
+        )
+        val classpath = compileFiles(listOf(libSource))
+        runJavaProcessorTest(
+            sources = emptyList(),
+            classpath = classpath
+        ) { invocation ->
+            val (_, metadata) =
+                getMetadataElement(
+                    (invocation.processingEnv as JavacProcessingEnv).delegate,
+                    "KotlinClass"
+                )
+            assertThat(metadata).isNotNull()
+        }
+    }
+
     private fun TypeElement.getDeclaredMethods() = ElementFilter.methodsIn(enclosedElements)
 
     private fun TypeElement.getDeclaredMethod(name: String) = getDeclaredMethods().first {
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSTypeExtTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSTypeExtTest.kt
index c9de74e..bf769fe 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSTypeExtTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KSTypeExtTest.kt
@@ -63,7 +63,7 @@
 
         val subjectSrc = createSubject(pkg = "main")
         val classpath = compileFiles(listOf(createSubject(pkg = "lib")))
-        runKspTest(sources = listOf(subjectSrc), classpath = listOf(classpath)) { invocation ->
+        runKspTest(sources = listOf(subjectSrc), classpath = classpath) { invocation ->
             listOf("main", "lib").map {
                 it to invocation.kspResolver.requireClass("$it.Baz")
             }.forEach { (pkg, subject) ->
@@ -115,7 +115,7 @@
 
         val subjectSrc = createSubject(pkg = "main")
         val classpath = compileFiles(listOf(createSubject(pkg = "lib")))
-        runKspTest(sources = listOf(subjectSrc), classpath = listOf(classpath)) { invocation ->
+        runKspTest(sources = listOf(subjectSrc), classpath = classpath) { invocation ->
             listOf("main.Baz", "lib.Baz").map {
                 invocation.kspResolver.requireClass(it)
             }.forEach { subject ->
@@ -235,7 +235,7 @@
         // classQName.methodName -> returnType, ...paramTypes
         val golden = mutableMapOf<String, List<TypeName>>()
         runKaptTest(
-            sources = listOf(src), classpath = listOf(classpath)
+            sources = listOf(src), classpath = classpath
         ) { invocation ->
             listOf("main.Subject", "lib.Subject").map {
                 val env = (invocation.processingEnv as JavacProcessingEnv)
@@ -253,7 +253,7 @@
         }
         val kspResults = mutableMapOf<String, List<TypeName>>()
         runKspTest(
-            sources = listOf(src), classpath = listOf(classpath)
+            sources = listOf(src), classpath = classpath
         ) { invocation ->
             listOf("main.Subject", "lib.Subject").map {
                 val env = (invocation.processingEnv as KspProcessingEnv)
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspFieldElementTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspFieldElementTest.kt
index b173871..a246983 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspFieldElementTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/ksp/KspFieldElementTest.kt
@@ -205,7 +205,7 @@
         val classpath = compileFiles(sources)
         runProcessorTest(
             sources = emptyList(),
-            classpath = listOf(classpath)
+            classpath = classpath
         ) { invocation ->
             if (invocation.isKsp) {
                 // TODO: https://github.com/google/ksp/issues/159
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
index c306ce1..d2d670a 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/ext/ElementExtTest.kt
@@ -247,7 +247,7 @@
         handler: (XTestInvocation) -> Unit
     ) {
         val (sources, classpath) = if (preCompile && sources.isNotEmpty()) {
-            emptyList<Source>() to listOf(compileFiles(sources))
+            emptyList<Source>() to compileFiles(sources)
         } else {
             sources to emptyList()
         }
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
index 3a35d15..9600800 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DaoProcessorTest.kt
@@ -21,7 +21,6 @@
 import androidx.room.compiler.processing.util.Source
 import androidx.room.compiler.processing.util.XTestInvocation
 import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.getSystemClasspathFiles
 import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.ext.RoomTypeNames
 import androidx.room.testing.context
@@ -113,7 +112,7 @@
         )
         singleDao(
             "@Dao public interface MyDao extends test.library.MissingAnnotationsBaseDao {}",
-            classpathFiles = listOf(libraryClasspath) + getSystemClasspathFiles()
+            classpathFiles = libraryClasspath
         ) { _, invocation ->
             invocation.assertCompilationResult {
                 hasRawOutputContaining(
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
index 96c7a93..b6a62d0 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseProcessorTest.kt
@@ -24,7 +24,6 @@
 import androidx.room.compiler.processing.util.Source
 import androidx.room.compiler.processing.util.XTestInvocation
 import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.getSystemClasspathFiles
 import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.parser.ParsedQuery
 import androidx.room.parser.QueryType
@@ -333,7 +332,7 @@
                 @Database(entities = {test.library.MissingEntityAnnotationPojo.class}, version = 1)
                 public abstract class MyDb extends RoomDatabase {}
                 """,
-            classpath = listOf(libraryClasspath) + getSystemClasspathFiles()
+            classpath = libraryClasspath
         ) { _, invocation ->
             invocation.assertCompilationResult {
                 compilationDidFail()
@@ -367,7 +366,7 @@
                     abstract test.library.MissingAnnotationsBaseDao getBadDao();
                 }
                 """,
-            USER, classpath = listOf(libraryClasspath) + getSystemClasspathFiles()
+            USER, classpath = libraryClasspath
         ) { _, invocation ->
             invocation.assertCompilationResult {
                 compilationDidFail()
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
index 79f15d2..a880cb0 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/TableEntityProcessorTest.kt
@@ -19,7 +19,6 @@
 import COMMON
 import androidx.room.compiler.processing.util.Source
 import androidx.room.compiler.processing.util.compileFiles
-import androidx.room.compiler.processing.util.getSystemClasspathFiles
 import androidx.room.compiler.processing.util.runProcessorTest
 import androidx.room.parser.SQLTypeAffinity
 import androidx.room.processor.ProcessorErrors.RELATION_IN_ENTITY
@@ -113,7 +112,7 @@
         singleEntity(
             "",
             baseClass = "test.library.MissingGetterEntity",
-            classpathFiles = listOf(libraryClasspath) + getSystemClasspathFiles()
+            classpathFiles = libraryClasspath
         ) { _, invocation ->
             invocation.assertCompilationResult {
                 hasError(ProcessorErrors.CANNOT_FIND_GETTER_FOR_FIELD)
diff --git a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
index 86b0b45..cb7c91a 100644
--- a/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
+++ b/room/room-compiler/src/test/kotlin/androidx/room/processor/autovalue/AutoValuePojoProcessorDelegateTest.kt
@@ -114,7 +114,7 @@
         )
         runProcessorTest(
             sources = emptyList(),
-            classpath = listOf(libraryClasspath),
+            classpath = libraryClasspath,
         ) { invocation: XTestInvocation ->
             PojoProcessor.createFor(
                 context = invocation.context,