-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ADT 3.0 and ktlin tasks for multidimension projects #32
Changes from 5 commits
b5cf65e
f9f6ad4
efb1879
d0eedb0
7ddc8b0
d26f377
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package org.jlleitschuh.gradle.ktlint | ||
|
||
import com.android.build.gradle.BaseExtension | ||
import com.android.build.gradle.AppPlugin | ||
import com.android.build.gradle.FeaturePlugin | ||
import com.android.build.gradle.InstantAppPlugin | ||
import com.android.build.gradle.LibraryPlugin | ||
import com.android.build.gradle.TestPlugin | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
|
@@ -11,6 +15,7 @@ import org.gradle.api.internal.HasConvention | |
import org.gradle.api.plugins.Convention | ||
import org.gradle.api.plugins.JavaPluginConvention | ||
import org.gradle.api.tasks.JavaExec | ||
import org.gradle.api.tasks.StopExecutionException | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | ||
import kotlin.reflect.KClass | ||
import net.swiftzer.semver.SemVer | ||
|
@@ -63,28 +68,37 @@ open class KtlintPlugin : Plugin<Project> { | |
} | ||
} | ||
|
||
private fun addKtLintTasksToAndroidKotlinPlugin(target: Project, | ||
extension: KtlintExtension) { | ||
private fun addKtLintTasksToAndroidKotlinPlugin(target: Project, extension: KtlintExtension) { | ||
target.pluginManager.withPlugin("kotlin-android") { | ||
target.afterEvaluate { | ||
val ktLintConfig = createConfiguration(target, extension) | ||
|
||
target.extensions.findByType(BaseExtension::class.java)?.sourceSets?.forEach { | ||
val kotlinSourceDir = it.java.sourceFiles | ||
val runArgs = it.java.srcDirs.map { "${it.path}/**/*.kt" }.toMutableSet() | ||
val variantManager = when { | ||
target.plugins.hasPlugin(AppPlugin::class.java) -> target.plugins.findPlugin(AppPlugin::class.java)?.variantManager | ||
target.plugins.hasPlugin(LibraryPlugin::class.java) -> target.plugins.findPlugin(LibraryPlugin::class.java)?.variantManager | ||
target.plugins.hasPlugin(InstantAppPlugin::class.java) -> target.plugins.findPlugin(InstantAppPlugin::class.java)?.variantManager | ||
target.plugins.hasPlugin(FeaturePlugin::class.java) -> target.plugins.findPlugin(FeaturePlugin::class.java)?.variantManager | ||
target.plugins.hasPlugin(TestPlugin::class.java) -> target.plugins.findPlugin(TestPlugin::class.java)?.variantManager | ||
else -> throw StopExecutionException("Must be applied with 'android' or 'android-library' plugin.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all of these types guaranteed to be on the classpath when either the If only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, everything is ok. I've tested on my local test project. |
||
} | ||
|
||
variantManager?.variantScopes?.forEach { | ||
val kotlinSourceDir = target.files(it.variantData.javaSources) | ||
val runArgs = it.variantData.javaSources.map { "${it.dir.path}/**/*.kt" }.toMutableSet() | ||
addAdditionalRunArgs(extension, runArgs) | ||
|
||
val checkTask = createCheckTask(target, extension, it.name, ktLintConfig, kotlinSourceDir, runArgs) | ||
val checkTask = createCheckTask(target, extension, it.fullVariantName, ktLintConfig, kotlinSourceDir, runArgs) | ||
addKtlintCheckTaskToProjectMetaCheckTask(target, checkTask) | ||
setCheckTaskDependsOnKtlintCheckTask(target, checkTask) | ||
|
||
val ktlintSourceSetFormatTask = createFormatTask(target, it.name, ktLintConfig, kotlinSourceDir, runArgs) | ||
val ktlintSourceSetFormatTask = createFormatTask(target, it.fullVariantName, ktLintConfig, kotlinSourceDir, runArgs) | ||
addKtlintFormatTaskToProjectMetaFormatTask(target, ktlintSourceSetFormatTask) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
private fun createConfiguration(target: Project, extension: KtlintExtension) = | ||
target.configurations.maybeCreate("ktlint").apply { | ||
target.dependencies.add(this.name, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary whitespace change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, damn, will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this commit d26f377