Skip to content

Commit

Permalink
Remove duplicated code on LightsaberPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Nov 24, 2023
1 parent 444b7d0 commit 9f93b83
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ private fun Project.apply() {
}

pluginManager.withPlugin("com.google.devtools.ksp") { _ ->
afterEvaluate {
if (configurations.getByName("ksp").dependencies.any { it.isDaggerCompiler() }) {
applyKsp(extension)
}
withDaggerCompiler("ksp") {
applyKsp(extension)
}
}

pluginManager.withPlugin("kotlin-kapt") { _ ->
afterEvaluate {
if (configurations.getByName("kapt").dependencies.any { it.isDaggerCompiler() }) {
applyKapt(extension)
}
withDaggerCompiler("kapt") {
applyKapt(extension)
}
}

pluginManager.withPlugin("java") { _ ->
afterEvaluate {
if (configurations.getByName("annotationProcessor").dependencies.any { it.isDaggerCompiler() }) {
applyAnnotationProcessor(extension)
}
withDaggerCompiler("annotationProcessor") {
applyAnnotationProcessor(extension)
}
}
}
Expand All @@ -71,6 +65,14 @@ private fun Rule.toPropertySeverity(extension: LightsaberExtension): Property<Se
}
}

private fun Project.withDaggerCompiler(configurationName: String, block: Project.() -> Unit) {
afterEvaluate {
if (configurations.getByName(configurationName).dependencies.any { it.isDaggerCompiler() }) {
block()
}
}
}

private fun Dependency.isDaggerCompiler(): Boolean {
return group == "com.google.dagger" && name == "dagger-compiler"
}

0 comments on commit 9f93b83

Please sign in to comment.