@@ -4,6 +4,7 @@ import com.google.common.collect.LinkedHashMultimap
4
4
import okio.Buffer
5
5
import okio.buffer
6
6
import okio.sink
7
+ import org.apache.commons.io.FileUtils
7
8
import org.jetbrains.kotlin.cli.common.CLITool
8
9
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
9
10
import permissions.dispatcher.processor.KtProcessorTestSuite
@@ -14,19 +15,18 @@ import java.io.PrintStream
14
15
import java.net.URLClassLoader
15
16
import java.net.URLDecoder
16
17
import java.util.zip.ZipEntry
18
+ import java.util.zip.ZipFile
17
19
import java.util.zip.ZipOutputStream
18
20
import kotlin.reflect.KClass
19
21
20
- /* * Prepares an invocation of the Kotlin compiler. */
21
- class KotlinCompilerCall (var scratchDir : File ) {
22
+ class KotlinCompilerCall (private val scratchDir : File ) {
22
23
private val sourcesDir = File (scratchDir, " sources" )
23
24
private val classesDir = File (scratchDir, " classes" )
24
25
private val servicesJar = File (scratchDir, " services.jar" )
25
26
private val args = mutableListOf<String >()
26
27
private val kaptArgs = mutableMapOf<String , String >()
27
28
private val classpath = mutableListOf<String >()
28
29
private val services = LinkedHashMultimap .create<KClass <* >, KClass <* >>()!!
29
- private val inheritClasspath = true
30
30
31
31
/* * Adds a source file to be compiled. */
32
32
fun addKt (path : String = "sources.kt", source : String ) {
@@ -83,7 +83,6 @@ class KotlinCompilerCall(var scratchDir: File) {
83
83
private fun annotationProcessorArgs (): List <String > {
84
84
val kaptSourceDir = File (scratchDir, " kapt/sources" )
85
85
val kaptStubsDir = File (scratchDir, " kapt/stubs" )
86
-
87
86
return listOf (
88
87
" -Xplugin=${kapt3Jar()} " ,
89
88
" -P" , " plugin:org.jetbrains.kotlin.kapt3:sources=$kaptSourceDir " ,
@@ -100,17 +99,13 @@ class KotlinCompilerCall(var scratchDir: File) {
100
99
result.addAll(classpath)
101
100
102
101
// 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())
107
104
}
108
-
109
105
if (! services.isEmpty) {
110
106
writeServicesJar()
111
107
result.add(servicesJar.toString())
112
108
}
113
-
114
109
return result.toList()
115
110
}
116
111
@@ -145,7 +140,17 @@ class KotlinCompilerCall(var scratchDir: File) {
145
140
if (url.protocol != " file" ) {
146
141
throw UnsupportedOperationException (" unable to handle classpath element $url " )
147
142
}
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
+ }
149
154
}
150
155
return result.toList()
151
156
}
0 commit comments