Skip to content

Commit cec95dd

Browse files
committed
check all custom defined additionalKaptMatchers
fixes #677
1 parent a650961 commit cec95dd

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

modulecheck-core/src/main/kotlin/modulecheck/core/context/UnusedKaptProcessors.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ data class UnusedKaptProcessors(
6060

6161
return delegate.getOrPut(configurationName) {
6262

63-
val generatorBindings = settings.additionalCodeGenerators + defaultCodeGeneratorBindings()
63+
@Suppress("DEPRECATION")
64+
val generatorBindings = settings.additionalCodeGenerators
65+
.plus(defaultCodeGeneratorBindings())
66+
.plus(settings.additionalKaptMatchers.map { it.toCodeGeneratorBinding() })
6467

6568
val matchers = generatorBindings.asMap()
6669

modulecheck-core/src/main/kotlin/modulecheck/core/rule/UnusedKaptPluginRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class UnusedKaptPluginRule(
6666
.get(configName, settings)
6767
.filterNot { it.isSuppressed.await() }
6868

69-
unusedAndNotSuppressed.size != processors.size
69+
processors.size - unusedAndNotSuppressed.size != 0
7070
}
7171

7272
return if (processorIsUsed) {

modulecheck-core/src/test/kotlin/modulecheck/core/UnusedKaptPluginTest.kt

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package modulecheck.core
1919
import modulecheck.api.KaptMatcher
2020
import modulecheck.config.CodeGeneratorBinding
2121
import modulecheck.parsing.gradle.model.ConfigurationName
22+
import modulecheck.parsing.gradle.model.SourceSetName
23+
import modulecheck.parsing.gradle.model.asConfigurationName
2224
import modulecheck.runtime.test.ProjectFindingReport.unusedKaptPlugin
2325
import modulecheck.runtime.test.RunnerTest
2426
import org.junit.jupiter.api.Test
@@ -306,7 +308,6 @@ class UnusedKaptPluginTest : RunnerTest() {
306308
}
307309
308310
dependencies {
309-
@Suppress("unused-kapt-processor")
310311
kapt("com.modulecheck:processor:0.0.1")
311312
}
312313
"""
@@ -333,14 +334,72 @@ class UnusedKaptPluginTest : RunnerTest() {
333334
}
334335
335336
dependencies {
336-
@Suppress("unused-kapt-processor")
337337
kapt("com.modulecheck:processor:0.0.1")
338338
}
339339
"""
340340

341341
logger.parsedReport() shouldBe listOf()
342342
}
343343

344+
@Test
345+
fun `used custom processor in test source using KaptMatcher should not make the plugin unused`() {
346+
347+
@Suppress("DEPRECATION")
348+
settings.additionalKaptMatchers = listOf(
349+
KaptMatcher(
350+
name = "Processor",
351+
processor = "com.modulecheck:processor",
352+
annotationImports = listOf(
353+
"com\\.modulecheck\\.annotations\\.TheAnnotation"
354+
)
355+
)
356+
)
357+
358+
val app = kotlinProject(":app") {
359+
hasKapt = true
360+
361+
addExternalDependency("kaptTest".asConfigurationName(), "com.modulecheck:processor:0.0.1")
362+
363+
buildFile {
364+
"""
365+
plugins {
366+
id("kotlin-jvm")
367+
id("kotlin-kapt")
368+
}
369+
370+
dependencies {
371+
kaptTest("com.modulecheck:processor:0.0.1")
372+
}
373+
"""
374+
}
375+
376+
addKotlinSource(
377+
"""
378+
package com.modulecheck.annotations
379+
380+
@TheAnnotation
381+
class Lib1Class
382+
""",
383+
SourceSetName.TEST
384+
)
385+
}
386+
387+
run().isSuccess shouldBe true
388+
389+
app.buildFile shouldHaveText """
390+
plugins {
391+
id("kotlin-jvm")
392+
id("kotlin-kapt")
393+
}
394+
395+
dependencies {
396+
kaptTest("com.modulecheck:processor:0.0.1")
397+
}
398+
"""
399+
400+
logger.parsedReport() shouldBe listOf()
401+
}
402+
344403
@Test
345404
fun `used custom annotation processor using CodeGeneratorBinding should not make the plugin unused`() {
346405

@@ -349,8 +408,7 @@ class UnusedKaptPluginTest : RunnerTest() {
349408
"Processor",
350409
"com.modulecheck:processor",
351410
listOf(
352-
"com\\.modulecheck\\.annotations\\.\\*",
353-
"com\\.modulecheck\\.annotations\\.TheAnnotation"
411+
"com.modulecheck.annotations.TheAnnotation"
354412
)
355413
)
356414
)
@@ -368,7 +426,6 @@ class UnusedKaptPluginTest : RunnerTest() {
368426
}
369427
370428
dependencies {
371-
@Suppress("unused-kapt-processor")
372429
kapt("com.modulecheck:processor:0.0.1")
373430
}
374431
"""
@@ -395,7 +452,6 @@ class UnusedKaptPluginTest : RunnerTest() {
395452
}
396453
397454
dependencies {
398-
@Suppress("unused-kapt-processor")
399455
kapt("com.modulecheck:processor:0.0.1")
400456
}
401457
"""

0 commit comments

Comments
 (0)