All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.twisterrob.gradle.common.BaseQualityPlugin.kt Maven / Gradle / Ivy

There is a newer version: 0.17
Show newest version
package net.twisterrob.gradle.common

import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.tasks.SourceTask

open class BaseQualityPlugin(
	private val taskCreatorType: Class>,
	private val extensionName: String,
	private val extensionType: Class>
) : BaseExposedPlugin() {

	override fun apply(target: Project) {
		super.apply(target)

		val quality = project.extensions.findByName("quality") as ExtensionAware?
			?: project.extensions.create("quality", FakeQualityExtension::class.java) as ExtensionAware
		quality.extensions.create(extensionName, extensionType, project)

		// level of indirection with base is to prevent loading classes in project not having Android
		project.plugins.withId("com.android.base") {
			val taskCreator = taskCreatorType.newInstance(project)
			AndroidVariantApplier(project).applyVariants(taskCreator::applyTo)
		}
	}
}

private inline fun  Class.newInstance(p1: P1?): T =
	this.getDeclaredConstructor(P1::class.java).newInstance(p1)

private open class FakeQualityExtension




© 2015 - 2025 Weber Informatics LLC | Privacy Policy