@@ -4,6 +4,7 @@ import com.google.common.collect.LinkedHashMultimap
44import okio.Buffer
55import okio.buffer
66import okio.sink
7+ import org.apache.commons.io.FileUtils
78import org.jetbrains.kotlin.cli.common.CLITool
89import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
910import permissions.dispatcher.processor.KtProcessorTestSuite
@@ -14,19 +15,18 @@ import java.io.PrintStream
1415import java.net.URLClassLoader
1516import java.net.URLDecoder
1617import java.util.zip.ZipEntry
18+ import java.util.zip.ZipFile
1719import java.util.zip.ZipOutputStream
1820import kotlin.reflect.KClass
1921
20- /* * Prepares an invocation of the Kotlin compiler. */
21- class KotlinCompilerCall (var scratchDir : File ) {
22+ class KotlinCompilerCall (private val scratchDir : File ) {
2223 private val sourcesDir = File (scratchDir, " sources" )
2324 private val classesDir = File (scratchDir, " classes" )
2425 private val servicesJar = File (scratchDir, " services.jar" )
2526 private val args = mutableListOf<String >()
2627 private val kaptArgs = mutableMapOf<String , String >()
2728 private val classpath = mutableListOf<String >()
2829 private val services = LinkedHashMultimap .create<KClass <* >, KClass <* >>()!!
29- private val inheritClasspath = true
3030
3131 /* * Adds a source file to be compiled. */
3232 fun addKt (path : String = "sources.kt", source : String ) {
@@ -83,7 +83,6 @@ class KotlinCompilerCall(var scratchDir: File) {
8383 private fun annotationProcessorArgs (): List <String > {
8484 val kaptSourceDir = File (scratchDir, " kapt/sources" )
8585 val kaptStubsDir = File (scratchDir, " kapt/stubs" )
86-
8786 return listOf (
8887 " -Xplugin=${kapt3Jar()} " ,
8988 " -P" , " plugin:org.jetbrains.kotlin.kapt3:sources=$kaptSourceDir " ,
@@ -100,17 +99,13 @@ class KotlinCompilerCall(var scratchDir: File) {
10099 result.addAll(classpath)
101100
102101 // Copy over the classpath of the running application.
103- if (inheritClasspath) {
104- for (classpathFile in classpathFiles()) {
105- result.add(classpathFile.toString())
106- }
102+ for (classpathFile in classpathFiles()) {
103+ result.add(classpathFile.toString())
107104 }
108-
109105 if (! services.isEmpty) {
110106 writeServicesJar()
111107 result.add(servicesJar.toString())
112108 }
113-
114109 return result.toList()
115110 }
116111
@@ -145,7 +140,17 @@ class KotlinCompilerCall(var scratchDir: File) {
145140 if (url.protocol != " file" ) {
146141 throw UnsupportedOperationException (" unable to handle classpath element $url " )
147142 }
148- result.add(File (URLDecoder .decode(url.path, " UTF-8" )))
143+ if (url.path.endsWith(" .aar" )) {
144+ // extract jar file from aar and add it to classpath
145+ val zipFile = ZipFile (url.path)
146+ val sourceInputStream = zipFile.getInputStream(zipFile.getEntry(" classes.jar" ))
147+ val newFileName = url.path.replace(" .aar" , " .jar" )
148+ val destinationFile = File (File (scratchDir, " unzippedAar" ), newFileName)
149+ FileUtils .copyInputStreamToFile(sourceInputStream, destinationFile)
150+ result.add(destinationFile)
151+ } else {
152+ result.add(File (URLDecoder .decode(url.path, " UTF-8" )))
153+ }
149154 }
150155 return result.toList()
151156 }
0 commit comments