(minor) Fixes for review KT-MR-1290

This commit is contained in:
Sergey Igushkin
2020-06-19 12:19:19 +03:00
parent 10cae9bc5d
commit f7b660b573
14 changed files with 43 additions and 41 deletions
@@ -32,12 +32,12 @@ class AllOpenGradleSubplugin @Inject internal constructor(private val registry:
private const val ALLOPEN_ARTIFACT_NAME = "kotlin-allopen"
private val ANNOTATION_ARG_NAME = "annotation"
private val PRESET_ARG_NAME = "preset"
private const val ANNOTATION_ARG_NAME = "annotation"
private const val PRESET_ARG_NAME = "preset"
}
override fun apply(project: Project) {
project.extensions.create("allOpen", AllOpenExtension::class.java)
override fun apply(target: Project) {
target.extensions.create("allOpen", AllOpenExtension::class.java)
registry.register(AllOpenModelBuilder())
}
@@ -68,7 +68,8 @@ open class InternalSubpluginOption(key: String, value: String) : SubpluginOption
// Deprecated because most calls require the tasks to be instantiated, which is not compatible with Gradle task configuration avoidance.
@Deprecated(
message = "This interface will be removed due to performance considerations. " +
"Please use the KotlinCompilerPluginSupportPlugin interface instead.",
"Please use the KotlinCompilerPluginSupportPlugin interface instead " +
"and remove the META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin entry.",
replaceWith = ReplaceWith("KotlinCompilerPluginSupportPlugin")
)
interface KotlinGradleSubplugin<in KotlinCompile : AbstractCompile> {
@@ -43,13 +43,13 @@ import javax.inject.Inject
class Kapt3GradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) :
KotlinCompilerPluginSupportPlugin {
override fun apply(project: Project) {
project.extensions.create("kapt", KaptExtension::class.java)
override fun apply(target: Project) {
target.extensions.create("kapt", KaptExtension::class.java)
project.configurations.create(KAPT_WORKER_DEPENDENCIES_CONFIGURATION_NAME).apply {
project.getKotlinPluginVersion()?.let { kotlinPluginVersion ->
target.configurations.create(KAPT_WORKER_DEPENDENCIES_CONFIGURATION_NAME).apply {
target.getKotlinPluginVersion()?.let { kotlinPluginVersion ->
val kaptDependency = getPluginArtifact().run { "$groupId:$artifactId:$kotlinPluginVersion" }
dependencies.add(project.dependencies.create(kaptDependency))
dependencies.add(target.dependencies.create(kaptDependency))
} ?: throw GradleException("Kotlin plugin should be enabled before 'kotlin-kapt'")
}
@@ -482,7 +482,7 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
}
}
if (taskClass == KaptWithKotlincTask::class.java) {
if (KaptWithKotlincTask::class.java.isAssignableFrom(taskClass)) {
val subpluginOptions = buildOptions("apt", dslJavacOptions)
registerSubpluginOptions(kaptTaskProvider, subpluginOptions)
}
@@ -33,6 +33,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
import org.jetbrains.kotlin.gradle.tasks.locateTask
import org.jetbrains.kotlin.gradle.tasks.registerTask
import org.jetbrains.kotlin.gradle.tasks.withType
import org.jetbrains.kotlin.gradle.utils.COMPILE
@@ -130,7 +132,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
) {
val project = compilation.target.project
project.registerTask<ProcessResources>(compilation.processResourcesTaskName) { resourcesTask ->
project.locateOrRegisterTask<ProcessResources>(compilation.processResourcesTaskName) { resourcesTask ->
resourcesTask.description = "Processes $resourceSet."
DslObject(resourcesTask).conventionMapping.map("destinationDir") { project.file(compilation.output.resourcesDir) }
resourcesTask.from(resourceSet)
@@ -37,6 +37,8 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
import org.jetbrains.kotlin.gradle.tasks.locateTask
import org.jetbrains.kotlin.gradle.tasks.registerTask
import org.jetbrains.kotlin.gradle.tasks.withType
import org.jetbrains.kotlin.gradle.utils.*
@@ -351,9 +353,8 @@ internal fun sourcesJarTask(
): TaskProvider<Jar> {
val taskName = lowerCamelCaseName(componentName, "sourcesJar")
project.tasks.withType<Jar>().run {
if (taskName in names)
return named(taskName)
project.locateTask<Jar>(taskName)?.let {
return it
}
val result = project.registerTask<Jar>(taskName) { sourcesJar ->
@@ -99,16 +99,8 @@ abstract class AbstractKotlinCompilation<T : KotlinCommonOptions>(
})
}
// Note! Invocation of withType-all results in preliminary task instantiation.
// After fix of this issue the following code should be uncommented:
// if (useLazyTaskConfiguration) {
// (target.project.tasks.named(compileKotlinTaskName) as TaskProvider<AbstractKotlinCompile<*>>).configure {
// it.configureAction()
// }
// }
target.project.tasks
// To configure a task that may have not yet been created at this point, use 'withType-matching-all`:
// To configure a task that may have not yet been created at this point, use 'withType-matching-configureEach`:
.withType(AbstractKotlinCompile::class.java)
.matching { it.name == compileKotlinTaskName }
.configureEach { compileKotlinTask ->
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.gradle.targets.js
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.attributes.Usage
import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
@@ -13,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
import org.jetbrains.kotlin.gradle.tasks.locateTask
import org.jetbrains.kotlin.gradle.tasks.registerTask
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
import org.jetbrains.kotlin.gradle.testing.testTaskName
@@ -75,10 +77,12 @@ open class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
compilation.output.classesDirs.from(project.files().builtBy(compilation.compileAllTaskName))
val compileAllTask = project.tasks.findByPath(compilation.compileAllTaskName)
val compileAllTask = project.locateTask<Task>(compilation.compileAllTaskName)
if (compileAllTask != null) {
compileAllTask.dependsOn(compilation.compileKotlinTaskName)
compileAllTask.dependsOn(compilation.processResourcesTaskName)
compileAllTask.configure {
it.dependsOn(compilation.compileKotlinTaskName)
it.dependsOn(compilation.processResourcesTaskName)
}
} else {
project.registerTask<DefaultTask>(compilation.compileAllTaskName) {
it.group = LifecycleBasePlugin.BUILD_GROUP
@@ -196,9 +196,7 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
val generateMetadata = project.createGenerateProjectStructureMetadataTask()
allMetadataJar.configure {
it.from(
project.files(Callable { generateMetadata.get().resultXmlFile }).builtBy(generateMetadata)
) { spec ->
it.from(generateMetadata.map { it.resultXmlFile }) { spec ->
spec.into("META-INF").rename { MULTIPLATFORM_PROJECT_METADATA_FILE_NAME }
}
}
@@ -57,9 +57,13 @@ open class DefaultCInteropSettings @Inject constructor(
target.disambiguationClassifier
)
val defFile: Property<File> = project.objects.property(File::class.java)
val defFileProperty: Property<File> = project.objects.property(File::class.java)
.apply { set(project.projectDir.resolve("src/nativeInterop/cinterop/$name.def")) }
var defFile: File
get() = defFileProperty.get()
set(value) { defFileProperty.set(value) }
var packageName: String? = null
val compilerOpts = mutableListOf<String>()
@@ -72,7 +76,7 @@ open class DefaultCInteropSettings @Inject constructor(
// DSL methods.
override fun defFile(file: Any) {
defFile.set(project.file(file))
defFileProperty.set(project.file(file))
}
override fun packageName(value: String) {
@@ -195,7 +195,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
interopTask.dependsOn(defTask)
interop.defFile.set(defTask.map { it.outputFile })
interop.defFileProperty.set(defTask.map { it.outputFile })
interop.packageName = "cocoapods.${pod.moduleName}"
@@ -951,7 +951,7 @@ open class CInteropProcess : DefaultTask() {
project.provider { destinationDir.get().resolve(outputFileName) }
val defFile: File
@InputFile get() = settings.defFile.get()
@InputFile get() = settings.defFileProperty.get()
val packageName: String?
@Optional @Input get() = settings.packageName
@@ -45,7 +45,7 @@ internal fun Project.newFileProperty(initialize: (() -> File)? = null): RegularF
return regularFileProperty.apply {
if (initialize != null) {
set(provider { RegularFile(initialize) })
set(project.layout.file(project.provider(initialize)))
}
}
}
@@ -38,8 +38,8 @@ class NoArgGradleSubplugin @Inject internal constructor(private val registry: To
private const val INVOKE_INITIALIZERS_ARG_NAME = "invokeInitializers"
}
override fun apply(project: Project) {
project.extensions.create("noArg", NoArgExtension::class.java)
override fun apply(target: Project) {
target.extensions.create("noArg", NoArgExtension::class.java)
registry.register(NoArgModelBuilder())
}
@@ -24,16 +24,16 @@ import org.jetbrains.kotlin.noarg.gradle.model.builder.SamWithReceiverModelBuild
import javax.inject.Inject
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : KotlinCompilerPluginSupportPlugin {
override fun apply(project: Project) {
project.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java)
override fun apply(target: Project) {
target.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java)
registry.register(SamWithReceiverModelBuilder())
}
companion object {
const val SAM_WITH_RECEIVER_ARTIFACT_NAME = "kotlin-sam-with-receiver"
private val ANNOTATION_ARG_NAME = "annotation"
private val PRESET_ARG_NAME = "preset"
private const val ANNOTATION_ARG_NAME = "annotation"
private const val PRESET_ARG_NAME = "preset"
}
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true