Skip to content

Commit

Permalink
check for Android kotlin sources
Browse files Browse the repository at this point in the history
fixes #172
  • Loading branch information
RBusarow authored and kodiakhq[bot] committed Sep 30, 2021
1 parent e5228c8 commit e0c035a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ class GradleProjectProvider(
.distinctBy { it.name }
.map { sourceProvider ->

val jvmFiles = sourceProvider
.javaDirectories
val jvmFiles = with(sourceProvider) {
javaDirectories + kotlinDirectories
}
.flatMap { it.listFiles().orEmpty().toList() }
.toSet()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,91 @@ class UnusedDependenciesTest : BaseTest() {
ProjectSpec("lib-1") {
addSrcSpec(
ProjectSrcSpec(Path.of("src/main/java")) {
addFileSpec(
FileSpec.builder("com.example.lib1", "Lib1View")
.addType(
TypeSpec.classBuilder("Lib1View")
.addAnnotation(
AnnotationSpec
.builder(ClassName.bestGuess("com.squareup.anvil.annotations.ContributesMultibinding"))
.addMember("%T", ClassName.bestGuess("com.example.lib1.AppScope"))
.build()
)
.build()
)
.build()
addRawFile(
"Lib1View.kt", """
package com.example.lib1
import com.squareup.anvil.annotations.ContributesMultibinding
@ContributesMultibinding(AppScope)
public class Lib1View
""".trimIndent()
)
}
)
addBuildSpec(
ProjectBuildSpec {
addPlugin("kotlin(\"jvm\")")
addProjectDependency("api", jvmSub1)
}
)
}
)
addSettingsSpec(projectSettings.build())
addBuildSpec(
projectBuild
.addBlock(
"""moduleCheck {
| autoCorrect = false
|}
""".trimMargin()
).build()
)
}
.writeIn(testProjectDir.toPath())

build("moduleCheckUnusedDependency").shouldSucceed()
}

@Test
fun `module with a declaration used in an android module with kotlin source directory should not be unused`() {
val appProject = ProjectSpec("app") {
addBuildSpec(
ProjectBuildSpec {
addPlugin("""id("com.android.library")""")
addPlugin("kotlin(\"android\")")
android = true
addProjectDependency("api", jvmSub1)
}
)
addSrcSpec(
ProjectSrcSpec(Path.of("src/main/kotlin")) {
addRawFile(
"MyModule.kt",
"""
package com.example.app
import com.example.lib1.AppScope
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
@Module
@ContributesTo(AppScope::class)
object MyModule
""".trimIndent()
)
}
)
}

ProjectSpec("project") {
applyEach(projects) { project ->
addSubproject(project)
}
addSubproject(appProject)
addSubproject(
ProjectSpec("lib-1") {
addSrcSpec(
ProjectSrcSpec(Path.of("src/main/java")) {
addRawFile(
"AppScope.kt", """
package com.example.lib1
import javax.inject.Scope
import kotlin.reflect.KClass
abstract class AppScope private constructor()
""".trimIndent()
)
}
)
Expand Down

0 comments on commit e0c035a

Please sign in to comment.