-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configured Git Hooks & Migrated to Convention Plugin (#1759)
* Configured Git Hooks & Migrated to Convention Plugin * Renamed branch name * updated proguard-rules.pro
- Loading branch information
Showing
42 changed files
with
888 additions
and
304 deletions.
There are no files selected for viewing
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
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
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
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
23 changes: 23 additions & 0 deletions
23
build-logic/convention/src/main/kotlin/MifosDetektConventionPlugin.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,23 @@ | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.mifospay.configureDetekt | ||
import org.mifospay.detektGradle | ||
|
||
class MifosDetektConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
applyPlugins() | ||
|
||
detektGradle { | ||
configureDetekt(this) | ||
} | ||
} | ||
} | ||
|
||
private fun Project.applyPlugins() { | ||
pluginManager.apply { | ||
apply("io.gitlab.arturbosch.detekt") | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
build-logic/convention/src/main/kotlin/MifosGitHooksConventionPlugin.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,54 @@ | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.Copy | ||
import org.gradle.api.tasks.Exec | ||
import org.gradle.kotlin.dsl.register | ||
import java.util.Locale | ||
|
||
class MifosGitHooksConventionPlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
// Define a function to check if the OS is Linux or MacOS | ||
fun isLinuxOrMacOs(): Boolean { | ||
val osName = System.getProperty("os.name").lowercase(Locale.getDefault()) | ||
return osName.contains("linux") || osName.contains("mac os") || osName.contains("macos") | ||
} | ||
|
||
// Define the copyGitHooks task | ||
project.tasks.register<Copy>("copyGitHooks") { | ||
description = "Copies the git hooks from /scripts to the .git/hooks folder." | ||
from("${project.rootDir}/scripts/") { | ||
include("**/*.sh") | ||
rename { it.removeSuffix(".sh") } | ||
} | ||
into("${project.rootDir}/.git/hooks") | ||
} | ||
|
||
// Define the installGitHooks task | ||
project.tasks.register<Exec>("installGitHooks") { | ||
description = "Installs the pre-commit git hooks from the scripts directory." | ||
group = "git hooks" | ||
workingDir = project.rootDir | ||
|
||
if (isLinuxOrMacOs()) { | ||
commandLine("chmod", "-R", "+x", ".git/hooks/") | ||
}else { | ||
commandLine("cmd", "/c", "attrib", "-R", "+X", ".git/hooks/*.*") | ||
} | ||
dependsOn(project.tasks.named("copyGitHooks")) | ||
|
||
doLast { | ||
println("Git hooks installed successfully.") | ||
} | ||
} | ||
|
||
// Configure task dependencies after evaluation | ||
project.afterEvaluate { | ||
project.tasks.matching { | ||
it.name in listOf("preBuild", "build", "assembleDebug", "assembleRelease", "installDebug", "installRelease", "clean") | ||
}.configureEach { | ||
dependsOn(project.tasks.named("installGitHooks")) | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
build-logic/convention/src/main/kotlin/MifosKtlintConventionPlugin.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,16 @@ | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class MifosKtlintConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
applyPlugins() | ||
} | ||
} | ||
|
||
private fun Project.applyPlugins() { | ||
pluginManager.apply { | ||
apply("org.jlleitschuh.gradle.ktlint") | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
build-logic/convention/src/main/kotlin/MifosSpotlessConventionPlugin.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,22 @@ | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.mifospay.configureSpotless | ||
import org.mifospay.spotlessGradle | ||
|
||
class MifosSpotlessConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
applyPlugins() | ||
|
||
spotlessGradle { | ||
configureSpotless(this) | ||
} | ||
} | ||
} | ||
|
||
private fun Project.applyPlugins() { | ||
pluginManager.apply { | ||
apply("com.diffplug.spotless") | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
build-logic/convention/src/main/kotlin/org/mifospay/Detekt.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,23 @@ | ||
package org.mifospay | ||
|
||
import io.gitlab.arturbosch.detekt.Detekt | ||
import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.named | ||
|
||
internal fun Project.configureDetekt(extension: DetektExtension) = extension.apply { | ||
tasks.named<Detekt>("detekt") { | ||
reports { | ||
xml.required.set(true) | ||
html.required.set(true) | ||
txt.required.set(true) | ||
sarif.required.set(true) | ||
md.required.set(true) | ||
} | ||
} | ||
dependencies { | ||
"detektPlugins"(libs.findLibrary("detekt-formatting").get()) | ||
"detektPlugins"(libs.findLibrary("twitter-detekt-compose").get()) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
build-logic/convention/src/main/kotlin/org/mifospay/ProjectExtensions.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 |
---|---|---|
@@ -1,9 +1,22 @@ | ||
package org.mifospay | ||
|
||
import com.diffplug.gradle.spotless.SpotlessExtension | ||
import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalog | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
val Project.libs | ||
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs") | ||
|
||
inline fun Project.detektGradle(crossinline configure: DetektExtension.() -> Unit) = | ||
extensions.configure<DetektExtension> { | ||
configure() | ||
} | ||
|
||
inline fun Project.spotlessGradle(crossinline configure: SpotlessExtension.() -> Unit) = | ||
extensions.configure<SpotlessExtension> { | ||
configure() | ||
} |
31 changes: 31 additions & 0 deletions
31
build-logic/convention/src/main/kotlin/org/mifospay/Spotless.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,31 @@ | ||
package org.mifospay | ||
|
||
import com.diffplug.gradle.spotless.SpotlessExtension | ||
import org.gradle.api.Project | ||
|
||
val ktlintVersion = "1.0.1" | ||
|
||
internal fun Project.configureSpotless(extension: SpotlessExtension) = extension.apply { | ||
kotlin { | ||
target("**/*.kt") | ||
targetExclude("**/build/**/*.kt") | ||
ktlint(ktlintVersion).editorConfigOverride( | ||
mapOf("android" to "true"), | ||
) | ||
licenseHeaderFile(rootProject.file("spotless/copyright.kt")) | ||
} | ||
|
||
format("kts") { | ||
target("**/*.kts") | ||
targetExclude("**/build/**/*.kts") | ||
// Look for the first line that doesn't have a block comment (assumed to be the license) | ||
licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)") | ||
} | ||
|
||
format("xml") { | ||
target("**/*.xml") | ||
targetExclude("**/build/**/*.xml") | ||
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml) | ||
licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])") | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.