Skip to content

Commit b897878

Browse files
authored
Remove ignore from one kt unit test. (#578)
1 parent 111282c commit b897878

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

processor/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@ artifacts {
2727
}
2828

2929
dependencies {
30-
implementation "androidx.annotation:annotation:$ANDROIDX_LIBRARY_VERSION"
31-
30+
compile "androidx.annotation:annotation:$ANDROIDX_LIBRARY_VERSION"
3231
compile "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
3332
compile "com.squareup:javapoet:$JAVAPOET_VERSION"
3433
compile "com.squareup:kotlinpoet:$KOTLINPOET_VERSION"
3534
compile project(path: ':annotation')
3635

36+
testCompileAar "androidx.legacy:legacy-support-v4:$ANDROIDX_LIBRARY_VERSION"
37+
testCompileAar "com.bluelinelabs:conductor:$CONDUCTOR_VERSION"
38+
testCompileAar project(path: ":library", configuration: "default")
39+
3740
testCompile androidJar()
3841
testCompile files(Jvm.current().getToolsJar())
3942
testCompile "junit:junit:$JUNIT_VERSION"
4043
testCompile "com.google.testing.compile:compile-testing:$COMPILE_TESTING_VERSION"
4144
testCompile "commons-io:commons-io:$COMMONS_IO_VERSION"
4245
testCompile "com.squareup.okio:okio:2.1.0"
46+
// below lines are supposed to be as this order to obtain dependencies in KotlinCompilerCall.classpathFiles
47+
testCompile "androidx.legacy:legacy-support-v4:$ANDROIDX_LIBRARY_VERSION"
48+
testCompile "com.bluelinelabs:conductor:$CONDUCTOR_VERSION"
4349
testCompile "org.jetbrains.kotlin:kotlin-compiler-embeddable:$KOTLIN_COMPILER_LIB_VERSION"
4450
testCompile "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:$KOTLIN_COMPILER_LIB_VERSION"
45-
testCompileAar "androidx.legacy:legacy-support-v4:$ANDROIDX_LIBRARY_VERSION"
46-
testCompileAar "com.bluelinelabs:conductor:$CONDUCTOR_VERSION"
47-
testCompileAar project(path: ":library", configuration: "default")
4851
}
4952

5053
publishing {

processor/src/main/kotlin/permissions/dispatcher/processor/PermissionsProcessor.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class PermissionsProcessor : AbstractProcessor() {
6969
}
7070

7171
private fun processKotlin(element: Element, rpe: RuntimePermissionsElement, requestCodeProvider: RequestCodeProvider) {
72+
val processorUnit = findAndValidateProcessorUnit(kotlinProcessorUnits, element)
7273
// FIXME: weirdly under kaptKotlin files is not recognized as source file on AS or IntelliJ
7374
// so as a workaround we generate .kt file in generated/source/kapt/$sourceSetName
7475
// ref: https://github.com/hotchemi/PermissionsDispatcher/issues/320#issuecomment-316175775
@@ -77,13 +78,10 @@ class PermissionsProcessor : AbstractProcessor() {
7778
processingEnv.messager.printMessage(Diagnostic.Kind.ERROR, "Can't find the target directory for generated Kotlin files.")
7879
return
7980
}
80-
8181
val kaptGeneratedDir = File(kaptGeneratedDirPath)
8282
if (!kaptGeneratedDir.parentFile.exists()) {
8383
kaptGeneratedDir.parentFile.mkdirs()
8484
}
85-
86-
val processorUnit = findAndValidateProcessorUnit(kotlinProcessorUnits, element)
8785
val kotlinFile = processorUnit.createFile(rpe, requestCodeProvider)
8886
kotlinFile.writeTo(kaptGeneratedDir)
8987
}

processor/src/test/java/permissions/dispatcher/processor/KtProcessorTestSuite.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.intellij.lang.annotations.Language
55
import org.jetbrains.kotlin.cli.common.ExitCode
66
import org.junit.Assert.assertEquals
77
import org.junit.Assert.assertThat
8-
import org.junit.Ignore
98
import org.junit.Rule
109
import org.junit.Test
1110
import org.junit.rules.TemporaryFolder
@@ -357,7 +356,6 @@ class KtProcessorTestSuite {
357356
}
358357

359358
@Test
360-
@Ignore("We should fix this validation for Kotlin")
361359
fun wrongAnnotatedClass() {
362360
val call = KotlinCompilerCall(temporaryFolder.root)
363361
call.addService(Processor::class, PermissionsProcessor::class)
@@ -371,9 +369,7 @@ class KtProcessorTestSuite {
371369
372370
@RuntimePermissions
373371
class MyService: Service() {
374-
override fun onBind(p0: Intent?): IBinder? {
375-
TODO("not implemented")
376-
}
372+
override fun onBind(intent: Intent?): IBinder? = null
377373
@NeedsPermission(Manifest.permission.CAMERA)
378374
fun showCamera() {
379375
}

processor/src/test/java/permissions/dispatcher/processor/kotlin/KotlinCompilerCall.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.common.collect.LinkedHashMultimap
44
import okio.Buffer
55
import okio.buffer
66
import okio.sink
7+
import org.apache.commons.io.FileUtils
78
import org.jetbrains.kotlin.cli.common.CLITool
89
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
910
import permissions.dispatcher.processor.KtProcessorTestSuite
@@ -14,19 +15,18 @@ import java.io.PrintStream
1415
import java.net.URLClassLoader
1516
import java.net.URLDecoder
1617
import java.util.zip.ZipEntry
18+
import java.util.zip.ZipFile
1719
import java.util.zip.ZipOutputStream
1820
import 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

Comments
 (0)