Skip to content

Commit 20a107f

Browse files
committed
update to gradle 9.0.0
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent 2169cdc commit 20a107f

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

buildSrc/src/main/kotlin/DBMigration.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import java.io.File
22
import java.io.FileInputStream
33
import java.net.HttpURLConnection
44
import java.net.URI
5-
import java.util.Properties
5+
import java.util.*
66

77
/**
88
* @author neo
@@ -20,10 +20,16 @@ object DBMigration {
2020
}
2121

2222
// refer to core.framework.internal.db.cloud.GCloudAuthProvider
23-
fun iamUser(): String {
23+
fun iamUser(dialect: String): String {
2424
val email = metadata("email")
25-
val regex = """([^@]*)@[^@]*""".toRegex()
26-
return regex.matchEntire(email)!!.groups[1]!!.value
25+
if (dialect == "postgresql" && email.endsWith(".gserviceaccount.com")) {
26+
return email.substring(0, email.length - 20) // remove ".gserviceaccount.com"
27+
} else if (dialect == "mysql") {
28+
val index = email.indexOf('@')
29+
return email.substring(0, index)
30+
} else {
31+
throw Error("unsupported gcloud iam user, dialect=${dialect}, email=${email}")
32+
}
2733
}
2834

2935
fun iamAccessToken(): String {

buildSrc/src/main/kotlin/db-migration.gradle.kts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ plugins {
55
}
66

77
tasks.withType<AbstractFlywayTask> {
8+
val migrationDir = file("src/main/resources/db/migration")
9+
if (!migrationDir.exists()) throw Error("$migrationDir does not exist")
10+
val env = properties["env"] // use gradlew -Penv=${env} to pass
11+
val propertyFile = if (env == null) file("src/main/resources/flyway.properties") else file("conf/${env}/resources/flyway.properties")
12+
val properties = DBMigration.loadProperties(propertyFile)
13+
814
doFirst {
915
flyway {
1016
configurations = arrayOf("runtimeClasspath") // use runtimeOnly scope in actual db-migration project
1117
placeholderReplacement = false
12-
val migrationDir = file("src/main/resources/db/migration")
13-
if (!migrationDir.exists()) throw Error("$migrationDir does not exist")
14-
15-
val env = project.properties["env"] // use gradlew -Penv=${env} to pass
16-
val propertyFile = if (env == null) file("src/main/resources/flyway.properties") else file("conf/${env}/resources/flyway.properties")
17-
val properties = DBMigration.loadProperties(propertyFile)
18-
1918
url = properties["flyway.url"]
20-
2119
val userValue = properties["flyway.user"]
2220
if (userValue == "iam/gcloud") {
23-
user = DBMigration.iamUser()
21+
val dialect = """jdbc:(\w+)://.+""".toRegex().matchEntire(url)!!.groups[1]!!.value
22+
user = DBMigration.iamUser(dialect)
2423
password = DBMigration.iamAccessToken()
2524
} else {
2625
user = userValue

buildSrc/src/main/kotlin/frontend.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ interface ExecSupport {
1212
afterEvaluate {
1313
if (!project.extensions.extraProperties.has("frontendDir")) throw Error("project does not have frontendDir property, assign by project.ext[\"frontendDir\"]")
1414
val frontendDir = file(project.extensions.extraProperties.get("frontendDir") as String)
15+
val support = project.objects.newInstance<ExecSupport>()
1516

1617
tasks.register("buildFrontend") {
1718
group = "build"
1819
doLast {
1920
if (!frontendDir.exists()) throw Error("$frontendDir does not exist")
2021

21-
val support = project.objects.newInstance<ExecSupport>()
2222
support.operation.exec {
2323
workingDir(frontendDir)
2424
commandLine(Frontend.commandLine(listOf("pnpm", "install")))

0 commit comments

Comments
 (0)