Skip to content

Commit

Permalink
build.gradle.kts
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Apr 30, 2024
1 parent 219aad1 commit 4e01373
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 77 deletions.
8 changes: 1 addition & 7 deletions buildSrc/src/main/kotlin/BuildConstants.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
object TestFolders {
const val Integration = "test-int"
const val e2e = "test-e2e"
}

object TaskNames {
const val testAggregateReports = "testAggregateReports"
const val codeCoverageReport = "codeCoverageReport"
const val e2e = "test-e2e"
}
82 changes: 16 additions & 66 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
@@ -1,89 +1,39 @@
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.invoke

fun Project.subprojectsOf(
vararg parentProjects: String,
action: Action<Project>,
): Unit = subprojects.filter { parentProjects.contains(it.parent?.name) }.forEach { action(it) }

fun Collection<Project>.of(
vararg parentProjects: String,
except: List<String> = emptyList(),
action: Action<Project>,
vararg parentProjects: String,
except: List<String> = emptyList(),
action: Action<Project>
): Unit = this.filter {
parentProjects.contains(it.parent?.name) && !except.contains(it.name)
parentProjects.contains(it.parent?.name) && !except.contains(it.name)
}.forEach { action(it) }

fun Collection<Project>.of(
vararg parentProjects: String,
except: List<String> = emptyList(),
vararg parentProjects: String,
except: List<String> = emptyList()
): List<Project> = this.filter {
parentProjects.contains(it.parent?.name) && !except.contains(it.name)
parentProjects.contains(it.parent?.name) && !except.contains(it.name)
}

fun Collection<Project>.of(
vararg parentProjects: String,
action: Action<Project>
vararg parentProjects: String,
action: Action<Project>
): Unit = this.filter { parentProjects.contains(it.parent?.name) }.forEach { action(it) }

fun Collection<Project>.of(
vararg parentProjects: String,
filter: (Project) -> Boolean,
action: Action<Project>
vararg parentProjects: String,
filter: (Project) -> Boolean,
action: Action<Project>
): Unit = this.filter { parentProjects.contains(it.parent?.name) && filter(it) }.forEach { action(it) }

infix fun <T> Property<T>.by(value: T) {
set(value)
}

fun Project.testProjects(): List<Task> = listOfNotNull(
this.tasks.firstOrNull { it.name.contains("test") },
tasks.firstOrNull { it.name.contains("e2eTest") },
tasks.firstOrNull { it.name.contains("integrationTest") }
)

fun Project.compilationTasks(): List<Task> = this.tasks.filter { it.name.contains("compile") }

fun Project.findTestProjectsRecursively(): List<Task> {
val tasks = this.testProjects()
if (tasks.isNotEmpty()) return tasks
return this.subprojects.flatMap { it.findTestProjectsRecursively() }
set(value)
}

fun Project.recursivelyContainsTask(name: String): Task? {
val task = this.tasks.firstOrNull { it.name.contains(name) }
if (task != null) return task
return this.subprojects.firstNotNullOfOrNull { it.recursivelyContainsTask(name) }
fun nextPatchSnapshot(version: String): String {
val (major, minor, patch) = version.split(".")
return "$major.$minor.${patch.toInt() + 1}-SNAPSHOT"
}

fun Project.whenService(action: (Project) -> Unit): Unit = if (this.parent != null && this.parent!!.name == "projects") {
action(this)
} else Unit

fun Project.goToService(): Project {
if (this.parent != null && this.parent!!.name != "projects") {
return this.parent!!.goToService()
}

if (this.parent != null && this.parent!!.name == "projects") {
return this
}

throw IllegalStateException("Project is not a service")
}

fun Project.goToProjectLevel(of: String): Project {
if (this.parent != null && this.parent!!.name != of) {
return this.parent!!.goToProjectLevel(of)
}

if (this.parent != null && this.parent!!.name == of) {
return this
}

throw IllegalStateException("Project is not a library")
}

4 changes: 0 additions & 4 deletions buildSrc/src/main/kotlin/VersionPreDef.kt

This file was deleted.

0 comments on commit 4e01373

Please sign in to comment.