aboutsummaryrefslogtreecommitdiff
path: root/build-logic/kotlin-plugins/src
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-12-02 01:57:02 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-12-02 01:57:02 +0530
commitafd0eebdd3287d932c53879fa1ac88f430080ef5 (patch)
tree141b9147325b96f4ab3a49927e4a1d997f3c37be /build-logic/kotlin-plugins/src
parent54bb4676a7c16d959769e522ac018f3e3e822797 (diff)
refactor(build-logic): move all code to a single top-level project
Diffstat (limited to 'build-logic/kotlin-plugins/src')
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt33
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt22
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinCommonPlugin.kt68
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt55
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinLibraryPlugin.kt27
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt32
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt68
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffEntry.kt3
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffer.kt35
-rw-r--r--build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtFormatTask.kt56
10 files changed, 0 insertions, 399 deletions
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt
deleted file mode 100644
index 6dff57a1..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/DependencyUpdatesPlugin.kt
+++ /dev/null
@@ -1,33 +0,0 @@
-package app.passwordstore.gradle
-
-import com.github.benmanes.gradle.versions.VersionsPlugin
-import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
-import nl.littlerobots.vcu.plugin.VersionCatalogUpdateExtension
-import nl.littlerobots.vcu.plugin.VersionCatalogUpdatePlugin
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.apply
-import org.gradle.kotlin.dsl.getByType
-import org.gradle.kotlin.dsl.withType
-
-@Suppress("Unused")
-class DependencyUpdatesPlugin : Plugin<Project> {
- override fun apply(project: Project) {
- project.pluginManager.apply(VersionsPlugin::class)
- project.pluginManager.apply(VersionCatalogUpdatePlugin::class)
- project.tasks.withType<DependencyUpdatesTask>().configureEach {
- rejectVersionIf {
- when (candidate.group) {
- "commons-codec",
- "com.android.tools.build",
- "org.eclipse.jgit" -> true
- else -> false
- }
- }
- checkForGradleUpdate = false
- }
- project.extensions.getByType<VersionCatalogUpdateExtension>().run {
- keep.keepUnusedLibraries.set(true)
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt
deleted file mode 100644
index 49f207a1..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinAndroidPlugin.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package app.passwordstore.gradle
-
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.apply
-import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
-
-@Suppress("Unused")
-class KotlinAndroidPlugin : Plugin<Project> {
-
- override fun apply(project: Project) {
- project.pluginManager.run {
- apply(KotlinAndroidPluginWrapper::class)
- apply(KotlinCommonPlugin::class)
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinCommonPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinCommonPlugin.kt
deleted file mode 100644
index 34d4675b..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinCommonPlugin.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package app.passwordstore.gradle
-
-import io.gitlab.arturbosch.detekt.DetektPlugin
-import io.gitlab.arturbosch.detekt.extensions.DetektExtension
-import org.gradle.api.JavaVersion
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.api.tasks.compile.JavaCompile
-import org.gradle.api.tasks.testing.Test
-import org.gradle.api.tasks.testing.logging.TestLogEvent
-import org.gradle.kotlin.dsl.configure
-import org.gradle.kotlin.dsl.withType
-import org.gradle.language.base.plugins.LifecycleBasePlugin
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-
-@Suppress("Unused")
-class KotlinCommonPlugin : Plugin<Project> {
-
- override fun apply(project: Project) {
- project.pluginManager.apply(DetektPlugin::class.java)
- project.extensions.configure<DetektExtension> {
- parallel = true
- ignoredBuildTypes = listOf("release")
- ignoredFlavors = listOf("free")
- basePath = project.layout.projectDirectory.toString()
- baseline =
- project.rootProject.layout.projectDirectory
- .dir("detekt-baselines")
- .file("${project.name}.xml")
- .asFile
- }
- project.tasks.run {
- project.pluginManager.withPlugin("base") {
- named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { this.dependsOn(named("detekt")) }
- }
- withType<JavaCompile>().configureEach {
- sourceCompatibility = JavaVersion.VERSION_11.toString()
- targetCompatibility = JavaVersion.VERSION_11.toString()
- }
- withType<KotlinCompile>().configureEach {
- kotlinOptions {
- allWarningsAsErrors = true
- jvmTarget = JavaVersion.VERSION_11.toString()
- freeCompilerArgs = freeCompilerArgs + ADDITIONAL_COMPILER_ARGS
- languageVersion = "1.5"
- }
- }
- withType<Test>().configureEach {
- maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
- testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) }
- }
- }
- }
-
- private companion object {
- private val ADDITIONAL_COMPILER_ARGS =
- listOf(
- "-opt-in=kotlin.RequiresOptIn",
- "-P",
- "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=1.7.22",
- )
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt
deleted file mode 100644
index a798ec8e..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinKaptPlugin.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package app.passwordstore.gradle
-
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.apply
-import org.gradle.kotlin.dsl.getByType
-import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin
-import org.jetbrains.kotlin.gradle.plugin.KaptExtension
-import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
-
-@Suppress("Unused")
-class KotlinKaptPlugin : Plugin<Project> {
-
- override fun apply(project: Project) {
- project.pluginManager.run {
- apply(KotlinAndroidPluginWrapper::class)
- apply(Kapt3GradleSubplugin::class)
- }
- project.afterEvaluate {
- project.extensions.getByType<KaptExtension>().run {
- javacOptions {
- if (hasDaggerCompilerDependency()) {
- // https://dagger.dev/dev-guide/compiler-options#fastinit-mode
- option("-Adagger.fastInit=enabled")
- // Enable the better, experimental error messages
- // https://github.com/google/dagger/commit/0d2505a727b54f47b8677f42dd4fc5c1924e37f5
- option("-Adagger.experimentalDaggerErrorMessages=enabled")
- // Share test components for when we start leveraging Hilt for tests
- // https://github.com/google/dagger/releases/tag/dagger-2.34
- option("-Adagger.hilt.shareTestComponents=true")
- // KAPT nests errors causing real issues to be suppressed in CI logs
- option("-Xmaxerrs", 500)
- // Enables per-module validation for faster error detection
- // https://github.com/google/dagger/commit/325b516ac6a53d3fc973d247b5231fafda9870a2
- option("-Adagger.moduleBindingValidation=ERROR")
- }
- }
- }
- }
- project.tasks
- .matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") }
- .configureEach { enabled = false }
- }
-
- private fun Project.hasDaggerCompilerDependency(): Boolean {
- return configurations.any {
- it.dependencies.any { dependency -> dependency.name == "hilt-compiler" }
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinLibraryPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinLibraryPlugin.kt
deleted file mode 100644
index ad6ffc0b..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KotlinLibraryPlugin.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package app.passwordstore.gradle
-
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.apply
-import org.gradle.kotlin.dsl.withType
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-
-@Suppress("Unused")
-class KotlinLibraryPlugin : Plugin<Project> {
-
- override fun apply(project: Project) {
- project.pluginManager.apply(KotlinCommonPlugin::class)
- project.tasks.withType<KotlinCompile>().configureEach {
- kotlinOptions {
- if (!name.contains("test", ignoreCase = true)) {
- freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict")
- }
- }
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt
deleted file mode 100644
index 74e8ba95..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/KtfmtPlugin.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package app.passwordstore.gradle
-
-import app.passwordstore.gradle.ktfmt.KtfmtCheckTask
-import app.passwordstore.gradle.ktfmt.KtfmtFormatTask
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.register
-
-class KtfmtPlugin : Plugin<Project> {
-
- override fun apply(target: Project) {
- target.tasks.register<KtfmtFormatTask>("ktfmtFormat") {
- source =
- project.layout.projectDirectory.asFileTree
- .filter { file ->
- file.extension == "kt" ||
- file.extension == "kts" && !file.canonicalPath.contains("build")
- }
- .asFileTree
- }
- target.tasks.register<KtfmtCheckTask>("ktfmtCheck") {
- source =
- project.layout.projectDirectory.asFileTree
- .filter { file ->
- file.extension == "kt" ||
- file.extension == "kts" && !file.canonicalPath.contains("build")
- }
- .asFileTree
- projectDirectory.set(target.layout.projectDirectory)
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt
deleted file mode 100644
index a50c8494..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtCheckTask.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-package app.passwordstore.gradle.ktfmt
-
-import com.facebook.ktfmt.format.Formatter
-import com.facebook.ktfmt.format.FormattingOptions
-import java.io.File
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.runBlocking
-import org.gradle.api.file.DirectoryProperty
-import org.gradle.api.file.FileCollection
-import org.gradle.api.tasks.IgnoreEmptyDirectories
-import org.gradle.api.tasks.InputFiles
-import org.gradle.api.tasks.Internal
-import org.gradle.api.tasks.PathSensitive
-import org.gradle.api.tasks.PathSensitivity
-import org.gradle.api.tasks.SourceTask
-import org.gradle.api.tasks.TaskAction
-
-@OptIn(ExperimentalCoroutinesApi::class)
-abstract class KtfmtCheckTask : SourceTask() {
-
- @get:PathSensitive(PathSensitivity.RELATIVE)
- @get:InputFiles
- @get:IgnoreEmptyDirectories
- protected val inputFiles: FileCollection
- get() = super.getSource()
-
- @get:Internal abstract val projectDirectory: DirectoryProperty
-
- @TaskAction
- fun execute() {
- runBlocking(Dispatchers.IO.limitedParallelism(PARALLEL_TASK_LIMIT)) {
- coroutineScope {
- val results = inputFiles.map { async { checkFile(it) } }.awaitAll()
- if (results.any { (notFormatted, _) -> notFormatted }) {
- results
- .map { (_, diffs) -> diffs }
- .forEach { diffs -> KtfmtDiffer.printDiff(diffs, logger) }
- error("[ktfmt] Found unformatted files")
- }
- }
- }
- }
-
- private fun checkFile(input: File): Pair<Boolean, List<KtfmtDiffEntry>> {
- val originCode = input.readText()
- val formattedCode =
- Formatter.format(
- FormattingOptions(
- style = FormattingOptions.Style.GOOGLE,
- maxWidth = 100,
- continuationIndent = 2,
- ),
- originCode
- )
- val pathNormalizer = { file: File -> file.toRelativeString(projectDirectory.asFile.get()) }
- return (originCode != formattedCode) to
- KtfmtDiffer.computeDiff(input, formattedCode, pathNormalizer)
- }
-
- companion object {
-
- private const val PARALLEL_TASK_LIMIT = 4
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffEntry.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffEntry.kt
deleted file mode 100644
index 44d1a967..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffEntry.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package app.passwordstore.gradle.ktfmt
-
-data class KtfmtDiffEntry(val input: String, val lineNumber: Int, val message: String)
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffer.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffer.kt
deleted file mode 100644
index 936596cd..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtDiffer.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package app.passwordstore.gradle.ktfmt
-
-import com.github.difflib.DiffUtils
-import com.github.difflib.patch.ChangeDelta
-import com.github.difflib.patch.DeleteDelta
-import com.github.difflib.patch.InsertDelta
-import java.io.File
-import org.gradle.api.logging.Logger
-
-object KtfmtDiffer {
- fun computeDiff(
- inputFile: File,
- formattedCode: String,
- pathNormalizer: (File) -> String
- ): List<KtfmtDiffEntry> {
- val originCode = inputFile.readText()
- return DiffUtils.diff(originCode, formattedCode, null).deltas.map {
- val line = it.source.position + 1
- val message: String =
- when (it) {
- is ChangeDelta -> "Line changed: ${it.source.lines.first()}"
- is DeleteDelta -> "Line deleted"
- is InsertDelta -> "Line added"
- else -> ""
- }
- KtfmtDiffEntry(pathNormalizer(inputFile), line, message)
- }
- }
-
- fun printDiff(entries: List<KtfmtDiffEntry>, logger: Logger) {
- entries.forEach { entry ->
- logger.error("${entry.input}:${entry.lineNumber} - ${entry.message}")
- }
- }
-}
diff --git a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtFormatTask.kt b/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtFormatTask.kt
deleted file mode 100644
index 82ce4ca3..00000000
--- a/build-logic/kotlin-plugins/src/main/kotlin/app/passwordstore/gradle/ktfmt/KtfmtFormatTask.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package app.passwordstore.gradle.ktfmt
-
-import com.facebook.ktfmt.format.Formatter
-import com.facebook.ktfmt.format.FormattingOptions
-import java.io.File
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.async
-import kotlinx.coroutines.awaitAll
-import kotlinx.coroutines.coroutineScope
-import kotlinx.coroutines.runBlocking
-import org.gradle.api.file.FileCollection
-import org.gradle.api.tasks.IgnoreEmptyDirectories
-import org.gradle.api.tasks.InputFiles
-import org.gradle.api.tasks.PathSensitive
-import org.gradle.api.tasks.PathSensitivity
-import org.gradle.api.tasks.SourceTask
-import org.gradle.api.tasks.TaskAction
-
-@OptIn(ExperimentalCoroutinesApi::class)
-abstract class KtfmtFormatTask : SourceTask() {
-
- @get:PathSensitive(PathSensitivity.RELATIVE)
- @get:InputFiles
- @get:IgnoreEmptyDirectories
- protected val inputFiles: FileCollection
- get() = super.getSource()
-
- @TaskAction
- fun execute() {
- runBlocking(Dispatchers.IO.limitedParallelism(PARALLEL_TASK_LIMIT)) {
- coroutineScope { inputFiles.map { async { formatFile(it) } }.awaitAll() }
- }
- }
-
- private fun formatFile(input: File) {
- val originCode = input.readText()
- val formattedCode =
- Formatter.format(
- FormattingOptions(
- style = FormattingOptions.Style.GOOGLE,
- maxWidth = 100,
- continuationIndent = 2,
- ),
- originCode
- )
- if (originCode != formattedCode) {
- input.writeText(formattedCode)
- }
- }
-
- companion object {
-
- private const val PARALLEL_TASK_LIMIT = 4
- }
-}