Skip to content

Commit

Permalink
⬆️ Upgrade to Kotlin 1.9.10
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Oct 24, 2023
1 parent bf1463d commit 5f5601f
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 97 deletions.
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[versions]
kotlin = "1.9.0"
spring-boot = "3.1.2"
gradle-docker = "9.3.4"
kotlin = "1.9.10"
ktlint = "4.0.0"
nebula-contacts = "7.0.1"
nebula-info = "12.1.6"
nebula-publishing = "20.3.0"
gradle-docker = "9.3.2"
plugin-publishing = "1.2.0"
ktlint = "11.5.0"
plugin-publishing = "1.2.1"
spring-boot = "3.1.2"

[libraries]
nebula-info = { module = "com.netflix.nebula:gradle-info-plugin", version.ref = "nebula-info" }
nebula-publishing = { module = "com.netflix.nebula:nebula-publishing-plugin", version.ref = "nebula-publishing" }
nebula-contacts = { module = "com.netflix.nebula:gradle-contacts-plugin", version.ref = "nebula-contacts" }
gradle-docker = { module = "com.bmuschko:gradle-docker-plugin", version.ref = "gradle-docker" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
gradle-ktlint = { module = "org.jmailen.gradle:kotlinter-gradle", version.ref = "ktlint" }
gradle-spring = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "spring-boot" }
gradle-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
nebula-contacts = { module = "com.netflix.nebula:gradle-contacts-plugin", version.ref = "nebula-contacts" }
nebula-info = { module = "com.netflix.nebula:gradle-info-plugin", version.ref = "nebula-info" }
nebula-publishing = { module = "com.netflix.nebula:nebula-publishing-plugin", version.ref = "nebula-publishing" }

[plugins]
plugin-publishing = { id = "com.gradle.plugin-publish", version.ref = "plugin-publishing" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
ktlint = { id = "org.jmailen.kotlinter", version.ref = "ktlint" }
plugin-publishing = { id = "com.gradle.plugin-publish", version.ref = "plugin-publishing" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ open class SisyphusExtension(val project: Project) {
branchName != null -> "$branchName-SNAPSHOT"
githubRef != null && pullRequestRefRegex.matches(githubRef) ->
"PR-${
pullRequestRefRegex.matchEntire(
githubRef
)?.groupValues?.get(1)
pullRequestRefRegex.matchEntire(
githubRef,
)?.groupValues?.get(1)
}-SNAPSHOT"

else -> null
Expand Down
67 changes: 41 additions & 26 deletions src/main/kotlin/com/bybutter/sisyphus/project/gradle/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ internal fun Project.isRelease(): Boolean {
return !isSnapshot()
}

internal fun Project.ensurePlugin(vararg ids: String, block: (Project) -> Unit): Boolean {
internal fun Project.ensurePlugin(
vararg ids: String,
block: (Project) -> Unit,
): Boolean {
for (id in ids) {
if (!pluginManager.hasPlugin(id)) {
pluginManager.withPlugin(id) {
Expand All @@ -25,7 +28,11 @@ internal fun Project.ensurePlugin(vararg ids: String, block: (Project) -> Unit):
return true
}

internal inline fun Project.ensurePlugin(id: String, noinline block: (Project) -> Unit, returnBlock: () -> Unit) {
internal inline fun Project.ensurePlugin(
id: String,
noinline block: (Project) -> Unit,
returnBlock: () -> Unit,
) {
if (!pluginManager.hasPlugin(id)) {
pluginManager.withPlugin(id) {
block(this)
Expand All @@ -34,7 +41,10 @@ internal inline fun Project.ensurePlugin(id: String, noinline block: (Project) -
}
}

internal fun Project.tryApplyPluginClass(className: String, action: () -> Unit = {}): Boolean {
internal fun Project.tryApplyPluginClass(
className: String,
action: () -> Unit = {},
): Boolean {
return try {
val plugin = Class.forName(className)
action()
Expand All @@ -47,33 +57,38 @@ internal fun Project.tryApplyPluginClass(className: String, action: () -> Unit =

internal fun RepositoryHandler.applyFromRepositoryKeys(
repositories: Map<String, Repository>,
repositoryKeys: Collection<String>
repositoryKeys: Collection<String>,
) {
for (repositoryKey in repositoryKeys) {
val repository = when (repositoryKey) {
"local" -> repositories[repositoryKey] ?: run {
this.mavenLocal()
null
}

"central" -> repositories[repositoryKey] ?: run {
this.mavenCentral()
null
}

"portal" -> repositories[repositoryKey] ?: run {
this.gradlePluginPortal()
null
val repository =
when (repositoryKey) {
"local" ->
repositories[repositoryKey] ?: run {
this.mavenLocal()
null
}

"central" ->
repositories[repositoryKey] ?: run {
this.mavenCentral()
null
}

"portal" ->
repositories[repositoryKey] ?: run {
this.gradlePluginPortal()
null
}

"google" ->
repositories[repositoryKey] ?: run {
this.google()
null
}

else -> repositories[repositoryKey]
}

"google" -> repositories[repositoryKey] ?: run {
this.google()
null
}

else -> repositories[repositoryKey]
}

repository ?: continue

this.maven {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class JavaDependenciesReplacePlugin : Plugin<Project> {

target.configurations.all {
it.resolutionStrategy.eachDependency { detail ->
extension.managedDependencies.getting("${detail.requested.group}:${detail.requested.name}").orNull?.let { moduleStringNotation ->
extension.managedDependencies.getting("${detail.requested.group}:${detail.requested.name}").orNull?.let {
moduleStringNotation ->
detail.useVersion(moduleStringNotation.version)
detail.because("The version of current dependency managed by Sisyphus Property")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ class ProjectLicensePlugin : Plugin<Project> {
}

companion object {
private val licenseRegex = mapOf(
"MIT License" to "MIT License".toRegex(),
"Apache License 2.0" to """Apache License\s+Version 2\.0""".toRegex(),
"Mozilla Public License 2.0" to """Mozilla Public License Version 2\.0""".toRegex(),
"GNU AGPLv3" to """GNU AFFERO GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"GNU GPLv3" to """GNU GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"GNU LGPLv3" to """GNU LESSER GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"Boost Software License 1.0" to """Boost Software License - Version 1\.0""".toRegex(),
"The Unlicense" to """This is free and unencumbered software released into the public domain\.""".toRegex(),
"WTFPL" to "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE".toRegex()
)
private val githubPatterns = listOf(
"""[email protected]:([a-zA-Z0-9-_.]+?):([a-zA-Z0-9-_.]+?).git""".toRegex(),
"""https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+?)\.git""".toRegex(),
"""https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+)""".toRegex()
)
private val licenseRegex =
mapOf(
"MIT License" to "MIT License".toRegex(),
"Apache License 2.0" to """Apache License\s+Version 2\.0""".toRegex(),
"Mozilla Public License 2.0" to """Mozilla Public License Version 2\.0""".toRegex(),
"GNU AGPLv3" to """GNU AFFERO GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"GNU GPLv3" to """GNU GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"GNU LGPLv3" to """GNU LESSER GENERAL PUBLIC LICENSE\s+Version 3""".toRegex(),
"Boost Software License 1.0" to """Boost Software License - Version 1\.0""".toRegex(),
"The Unlicense" to """This is free and unencumbered software released into the public domain\.""".toRegex(),
"WTFPL" to "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE".toRegex(),
)
private val githubPatterns =
listOf(
"""[email protected]:([a-zA-Z0-9-_.]+?):([a-zA-Z0-9-_.]+?).git""".toRegex(),
"""https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+?)\.git""".toRegex(),
"""https?://github.com/([a-zA-Z0-9-_.]+?)/([a-zA-Z0-9-_.]+)""".toRegex(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class SisyphusAntlrKotlinPlugin : Plugin<Project> {
val sourceSets = target.extensions.getByType(SourceSetContainer::class.java)

sourceSets.forEach {
val generateTaskName = when (it.name) {
"main" -> "generateGrammarSource"
else -> "generate${GUtil.toCamelCase(it.name)}GrammarSource"
}
val generateTaskName =
when (it.name) {
"main" -> "generateGrammarSource"
else -> "generate${GUtil.toCamelCase(it.name)}GrammarSource"
}
target.tasks.named(generateTaskName, AntlrTask::class.java).configure { task ->
it.java.setSrcDirs(it.java.srcDirs.filter { task.outputDirectory.absolutePath != it.absolutePath })
it.java.srcDir(task)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,22 @@ class SisyphusDockerPlugin : Plugin<Project> {
}
}

private fun registerExtractLayerTask(target: Project, bootJar: BootJar) {
private fun registerExtractLayerTask(
target: Project,
bootJar: BootJar,
) {
target.tasks.register("extractBootJarLayer", ExtractBootJarLayer::class.java) {
it.dependsOn(bootJar)
it.bootJars = bootJar.outputs.files
it.outputDirectory = target.buildDir.resolve("tmp/extractedBootJarLayer")
}
}

private fun registerDockerfileTask(target: Project, sisyphusDocker: SisyphusDockerExtension, bootJar: BootJar) {
private fun registerDockerfileTask(
target: Project,
sisyphusDocker: SisyphusDockerExtension,
bootJar: BootJar,
) {
target.tasks.register("dockerfile", Dockerfile::class.java) {
it.arg("PROJECT_NAME")
it.arg("PROJECT_VERSION")
Expand Down Expand Up @@ -80,7 +87,7 @@ class SisyphusDockerPlugin : Plugin<Project> {
it.entryPoint(
"java",
*sisyphusDocker.jvmArgs.get().toTypedArray(),
"org.springframework.boot.loader.JarLauncher"
"org.springframework.boot.loader.JarLauncher",
)
}
}
Expand All @@ -105,7 +112,10 @@ class SisyphusDockerPlugin : Plugin<Project> {
}
}

private fun registerDockerBuild(target: Project, sisyphusDocker: SisyphusDockerExtension) {
private fun registerDockerBuild(
target: Project,
sisyphusDocker: SisyphusDockerExtension,
) {
target.tasks.register("dockerBuild", DockerBuildImage::class.java) {
it.dependsOn(target.tasks.named("dockerSync"))
it.group = "docker"
Expand All @@ -121,19 +131,21 @@ class SisyphusDockerPlugin : Plugin<Project> {
private fun registerDockerPush(
target: Project,
sisyphusDocker: SisyphusDockerExtension,
sisyphus: SisyphusExtension
sisyphus: SisyphusExtension,
) {
val registries = sisyphus.dockerPublishRegistries.get().associate {
it to sisyphus.repositories.getting(it).orNull
}
val registries =
sisyphus.dockerPublishRegistries.get().associate {
it to sisyphus.repositories.getting(it).orNull
}

val baseName = "${target.name}:${target.version}"

sisyphusDocker.images.get().forEach { image ->
val repository = registries.entries.firstOrNull {
val url = it.value?.url ?: return@firstOrNull false
image == "$url/$baseName"
} ?: return@forEach
val repository =
registries.entries.firstOrNull {
val url = it.value?.url ?: return@firstOrNull false
image == "$url/$baseName"
} ?: return@forEach

target.tasks.register("dockerPush" + GUtil.toCamelCase(repository.key), DockerPushImage::class.java) {
it.dependsOn(target.tasks.named("dockerBuild"))
Expand Down Expand Up @@ -186,7 +198,8 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt
in 1..7,
in 9..10,
in 12..16,
null -> {
null,
-> {
}

else -> {
Expand All @@ -203,7 +216,7 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt
}.map {
"${it.url}/$baseName"
}
}
},
)
}

Expand All @@ -215,11 +228,17 @@ open class SisyphusDockerExtension(factory: ObjectFactory, sisyphus: SisyphusExt
configure(instructions)
}

fun ListProperty<Instruction>.copyFile(source: String, destination: String) {
fun ListProperty<Instruction>.copyFile(
source: String,
destination: String,
) {
add(Dockerfile.CopyFileInstruction(Dockerfile.CopyFile(source, destination)))
}

fun ListProperty<Instruction>.addFile(source: String, destination: String) {
fun ListProperty<Instruction>.addFile(
source: String,
destination: String,
) {
add(Dockerfile.AddFileInstruction(Dockerfile.File(source, destination)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@ package com.bybutter.sisyphus.project.gradle.threepart
import com.bybutter.sisyphus.project.gradle.ensurePlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import java.io.File
import org.jmailen.gradle.kotlinter.tasks.FormatTask
import org.jmailen.gradle.kotlinter.tasks.LintTask

class SisyphusKtlintPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.ensurePlugin("org.jlleitschuh.gradle.ktlint") {
target.ensurePlugin("org.jmailen.kotlinter") {
apply(it)
}.also {
if (!it) return
}

val extension = target.extensions.getByType(KtlintExtension::class.java)
extension.filter {
val pattern1 = "${File.separatorChar}generated${File.separatorChar}"
val pattern2 = "${File.separatorChar}generated-src${File.separatorChar}"
it.exclude {
it.file.path.contains(pattern1)
}
it.exclude {
it.file.path.contains(pattern2)
}
target.tasks.withType(LintTask::class.java).whenTaskAdded {
it.exclude("**/generated/**")
}
extension.reporters {
it.reporter(ReporterType.CHECKSTYLE)

target.tasks.withType(FormatTask::class.java).whenTaskAdded {
it.exclude("**/generated/**")
}
}
}
Loading

0 comments on commit 5f5601f

Please sign in to comment.