-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from sergei-lapin/ignore-plugin-order
Ignore plugin order
- Loading branch information
Showing
37 changed files
with
245 additions
and
150 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
plugins/gradle/src/main/java/com/slapin/napt/ConfigurationUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.slapin.napt | ||
|
||
import org.gradle.api.Project | ||
|
||
private const val CompilerPlugin = "io.github.sergei-lapin.napt:javac:1.2" | ||
private const val AnnotationProcessor = "annotationProcessor" | ||
|
||
internal fun Project.configureCompilerPluginDependency() { | ||
val compilerPluginDependency = dependencies.create(CompilerPlugin) | ||
configurations.all { configuration -> | ||
if (configuration.name.contains(AnnotationProcessor, ignoreCase = true)) { | ||
configuration.dependencies.add(compilerPluginDependency) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.slapin.napt | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.plugins.ide.idea.GenerateIdeaModule | ||
import org.gradle.plugins.ide.idea.model.IdeaModel | ||
|
||
internal fun Project.registerTriggerDirInIdea( | ||
triggerDir: Provider<Directory>, | ||
) { | ||
plugins.withId("idea") { | ||
val triggerDirFile = triggerDir.get().asFile | ||
extensions.findByType(IdeaModel::class.java)?.module?.let { module -> | ||
module.sourceDirs.plusAssign(triggerDirFile) | ||
module.generatedSourceDirs.plusAssign(triggerDirFile) | ||
} | ||
tasks.withType(GenerateIdeaModule::class.java).forEach { task -> | ||
task.doFirst { triggerDirFile.mkdirs() } | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
plugins/gradle/src/main/java/com/slapin/napt/JavaCompileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.slapin.napt | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.compile.JavaCompile | ||
import org.gradle.process.CommandLineArgumentProvider | ||
import java.io.File | ||
|
||
internal fun Project.configureJavaCompileTasks( | ||
kotlinClassesDir: Provider<Directory>, | ||
extension: NaptGradleExtension, | ||
) { | ||
val rootDir = rootDir | ||
tasks.withType(JavaCompile::class.java).configureEach { javaCompile -> | ||
javaCompile.options.compilerArgumentProviders.add( | ||
NaptCompilerArgumentsProvider( | ||
kotlinClassesDirPath = kotlinClassesDir.map { it.asFile.relativeTo(rootDir).toString() }, | ||
) | ||
) | ||
javaCompile.options.isFork = true | ||
@Suppress("UnstableApiUsage") | ||
javaCompile.options.forkOptions.jvmArgumentProviders.add( | ||
NaptForkOptionsJvmArgumentsProvider( | ||
forkJvmArgs = extension.forkJvmArgs, | ||
jvmArgsStrongEncapsulation = | ||
objects.listProperty(String::class.java).convention(JvmArgsStrongEncapsulation), | ||
) | ||
) | ||
} | ||
} | ||
|
||
private class NaptCompilerArgumentsProvider( | ||
@get:Input val kotlinClassesDirPath: Provider<String>, | ||
) : CommandLineArgumentProvider { | ||
|
||
override fun asArguments(): Iterable<String> { | ||
return listOf( | ||
"-Xplugin:Napt", | ||
"-XDKotlinClassesDir=${File(kotlinClassesDirPath.get())}", | ||
) | ||
} | ||
} | ||
|
||
private class NaptForkOptionsJvmArgumentsProvider( | ||
@get:Input val forkJvmArgs: ListProperty<String>, | ||
@get:Input val jvmArgsStrongEncapsulation: ListProperty<String>, | ||
) : CommandLineArgumentProvider { | ||
|
||
override fun asArguments(): Iterable<String> { | ||
return (forkJvmArgs.get() + jvmArgsStrongEncapsulation.get()).toSet() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
plugins/gradle/src/main/java/com/slapin/napt/SourceSetUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.slapin.napt | ||
|
||
import com.slapin.napt.task.CreateNaptTrigger | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.TaskProvider | ||
|
||
private const val MainSourceSet = "main" | ||
|
||
internal fun Project.configureNaptForSourceSet( | ||
sourceSetName: String, | ||
extension: NaptGradleExtension, | ||
): TaskProvider<CreateNaptTrigger> { | ||
val triggerDir = getNaptTriggerDirForSourceSet(sourceSetName) | ||
val createTrigger = | ||
registerCreateTriggerTaskForSourceSet( | ||
sourceSetName = sourceSetName, | ||
triggerDir = triggerDir, | ||
extension = extension, | ||
) | ||
afterEvaluate { registerTriggerDirInIdea(triggerDir) } | ||
return createTrigger | ||
} | ||
|
||
private fun Project.getNaptTriggerDirForSourceSet(sourceSetName: String): Provider<Directory> = | ||
layout.buildDirectory.dir("generated/source/napt_trigger/$sourceSetName/java") | ||
|
||
private fun Project.registerCreateTriggerTaskForSourceSet( | ||
sourceSetName: String, | ||
triggerDir: Provider<Directory>, | ||
extension: NaptGradleExtension, | ||
): TaskProvider<CreateNaptTrigger> = | ||
tasks.register( | ||
"createNaptTrigger${sourceSetName.replaceFirstChar(Char::uppercaseChar)}", | ||
CreateNaptTrigger::class.java, | ||
) { task -> | ||
task.triggerDir.set(triggerDir) | ||
task.projectName.set(name) | ||
task.packagePrefix.set( | ||
extension.naptTriggerPackagePrefix.orElse("").map { packagePrefix -> | ||
buildString { | ||
if (packagePrefix.isNotBlank()) { | ||
append(packagePrefix) | ||
append('.') | ||
} | ||
append(sourceSetName) | ||
} | ||
} | ||
) | ||
task.onlyIf { | ||
shouldGenerateNaptTriggerForSourceSet(sourceSetName, extension) && | ||
extension.generateNaptTrigger.get() | ||
} | ||
task.group = "napt" | ||
task.description = | ||
"Creates NaptTrigger.java for '$sourceSetName' source set in order to trigger java compilation" | ||
} | ||
|
||
private fun shouldGenerateNaptTriggerForSourceSet( | ||
sourceSetName: String, | ||
extension: NaptGradleExtension, | ||
): Boolean = | ||
sourceSetName == MainSourceSet || | ||
sourceSetName in extension.additionalSourceSetsForTriggerGeneration.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
...pt/sample/dagger/MainActivityComponent.kt → ...pt/sample/dagger/MainActivityComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.