Skip to content

Commit

Permalink
Gradle Extensions for uncluttering build files
Browse files Browse the repository at this point in the history
  • Loading branch information
amankgo committed Feb 8, 2022
1 parent a79ec6b commit 7da26c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
42 changes: 4 additions & 38 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import com.voxfinite.logvue.Dependencies
import com.voxfinite.logvue.utils.findPkg
import com.voxfinite.logvue.utils.ghActionOutput
import com.voxfinite.logvue.utils.getMainAppVersion

val pluginsDir: File by rootProject.extra

Expand All @@ -13,7 +16,7 @@ plugins {
val r8: Configuration by configurations.creating

group = "com.voxfinite"
version = appVersion()
version = project.getMainAppVersion()
val appName = "logvue"
val appMainClass = "com.voxfinite.logvue.app.MainKt"

Expand Down Expand Up @@ -154,40 +157,3 @@ gradle.buildFinished {
nativePkg.ghActionOutput("app_pkg")
jarPkg.ghActionOutput("uber_jar")
}

fun File.findPkg(format: String?) = when (format != null) {
true -> walk().firstOrNull { it.isFile && it.name.endsWith(format, ignoreCase = true) }
else -> null
}

fun File?.ghActionOutput(prefix: String) = this?.let {
when (System.getenv("GITHUB_ACTIONS").toBoolean()) {
true -> println(
"""
::set-output name=${prefix}_name::${it.name}
::set-output name=${prefix}_path::${it.absolutePath}
""".trimIndent()
)
else -> println("$prefix: $this")
}
}

fun appVersion() : String {
val key = "APP_VERSION"
return if (project.hasProperty(key)) {
val version = project.property("APP_VERSION").toString()
println("Version = $version")
if (version.isBlank()) {
return "1.0.0"
}
if (version.matches(Regex("^[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,4}"))) {
return version
}
if (version.matches(Regex("^v[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,4}"))) {
return version.removePrefix("v")
}
"1.0.0"
} else {
"1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.voxfinite.logvue.utils

import org.gradle.api.Project
import java.io.File

fun Project.getMainAppVersion() : String {
val key = "APP_VERSION"
return if (hasProperty(key)) {
val version = property("APP_VERSION").toString()
println("Version = $version")
if (version.isBlank()) {
return "1.0.0"
}
if (version.matches(Regex("^[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,4}"))) {
return version
}
if (version.matches(Regex("^v[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,4}"))) {
return version.removePrefix("v")
}
"1.0.0"
} else {
"1.0.0"
}
}

fun File.findPkg(format: String?) = when (format != null) {
true -> walk().firstOrNull { it.isFile && it.name.endsWith(format, ignoreCase = true) }
else -> null
}

fun File?.ghActionOutput(prefix: String) = this?.let {
when (System.getenv("GITHUB_ACTIONS").toBoolean()) {
true -> println(
"""
::set-output name=${prefix}_name::${it.name}
::set-output name=${prefix}_path::${it.absolutePath}
""".trimIndent()
)
else -> println("$prefix: $this")
}
}

0 comments on commit 7da26c4

Please sign in to comment.