Skip to content

Commit a2ef9b3

Browse files
committed
fix: update codebase, including to Kotlin v2
1 parent c6ccaf7 commit a2ef9b3

File tree

8 files changed

+95
-98
lines changed

8 files changed

+95
-98
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
branches: [ main ]
66
pull_request:
77

8+
env:
9+
ORG_GRADLE_PROJECT_version: ${{ github.sha }}
10+
811
jobs:
912

1013
build:

.github/workflows/release.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ name: Release
22

33
on:
44
release:
5-
types: [published]
5+
types: [ published ]
6+
7+
env:
8+
ORG_GRADLE_PROJECT_version: ${{ github.event.release.tag_name }}
9+
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
10+
GRADLE_OPTS: -Dorg.gradle.configuration-cache=false
611

712
jobs:
813
release:
@@ -30,14 +35,11 @@ jobs:
3035
run: ./gradlew clean dependencies
3136
- name: Assemble Artefacts
3237
run: ./gradlew assemble
33-
env:
34-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
3538
- name: Release Artefacts
3639
run: ./gradlew release
3740
env:
3841
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PACKAGE_SIGNING_KEY }}
3942
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.PACKAGE_SIGNING_KEY_PASSWORD }}
40-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
4143
ORG_GRADLE_PROJECT_githubToken: ${{ secrets.RELEASE_GITHUB_TOKEN }}
4244
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
4345
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
@@ -66,9 +68,7 @@ jobs:
6668
- name: Prepare
6769
run: ./gradlew clean dependencies
6870
- name: Generate Documentation
69-
run: ./gradlew dokkaHtml
70-
env:
71-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
71+
run: ./gradlew dokkaGenerate
7272
- name: Publish Documentation
7373
uses: peaceiris/[email protected]
7474
with:

build.gradle.kts

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import io.github.gradlenexus.publishplugin.NexusRepository
22
import org.gradle.api.JavaVersion.VERSION_1_8
3-
import org.jetbrains.dokka.gradle.DokkaTask
4-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
54

65
plugins {
7-
kotlin("jvm") version "1.9.25"
8-
id("com.palantir.git-version") version "3.2.0"
9-
id("org.jetbrains.dokka") version "1.9.20"
6+
kotlin("jvm") version "2.1.10"
7+
id("org.jetbrains.dokka-javadoc") version "2.0.0"
8+
id("org.jetbrains.dokka") version "2.0.0"
109
`maven-publish`
1110
signing
12-
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
13-
idea
11+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
1412
}
1513

1614
group = "de.joshuagleitze"
17-
version = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag.drop("v")
18-
status = if (isSnapshot) "snapshot" else "release"
15+
version = if (version == "unspecified") "local" else version.toString().drop("v")
16+
status = if (version == "local") "snapshot" else "release"
1917

2018
repositories {
2119
mavenCentral()
@@ -30,29 +28,23 @@ dependencies {
3028
testImplementation(kotlin("reflect", KotlinVersion.CURRENT.toString()))
3129
}
3230

31+
testRuntimeOnly(name = "junit-platform-launcher", group = "org.junit.platform", version = "1.12.1")
3332
testRuntimeOnly(name = "junit-jupiter-engine", group = "org.junit.jupiter", version = "5.7.2")
3433
}
3534

36-
idea {
37-
module {
38-
isDownloadSources = true
39-
isDownloadJavadoc = true
40-
}
41-
}
42-
43-
tasks.withType<Test> {
35+
tasks.withType<Test>().configureEach {
4436
useJUnitPlatform()
45-
reports.junitXml.required.set(true)
37+
reports.junitXml.required = true
4638
}
4739

4840
java {
4941
sourceCompatibility = VERSION_1_8
5042
targetCompatibility = VERSION_1_8
5143
}
5244

53-
tasks.withType<KotlinCompile> {
54-
kotlinOptions {
55-
jvmTarget = "1.8"
45+
kotlin {
46+
compilerOptions {
47+
jvmTarget = JvmTarget.JVM_1_8
5648
}
5749
}
5850

@@ -62,28 +54,28 @@ val githubRepository: String? by project
6254
val githubOwner = githubRepository?.split("/")?.get(0)
6355
val githubToken: String? by project
6456

65-
val sourcesJar by tasks.creating(Jar::class) {
57+
val sourcesJar by tasks.registering(Jar::class) {
6658
group = "build"
6759
description = "Assembles the source code into a jar"
68-
archiveClassifier.set("sources")
69-
from(sourceSets.main.get().allSource)
60+
archiveClassifier = "sources"
61+
from(sourceSets.main.map { it.allSource })
7062
}
7163

72-
tasks.withType<DokkaTask> {
73-
dokkaSourceSets.named("main") {
64+
dokka {
65+
dokkaSourceSets.main {
7466
sourceLink {
75-
localDirectory.set(file("src/main/kotlin"))
76-
remoteUrl.set(uri("https://github.com/$githubRepository/blob/main/src/main/kotlin").toURL())
77-
remoteLineSuffix.set("#L")
67+
localDirectory = file("src/main/kotlin")
68+
remoteUrl = uri("https://github.com/$githubRepository/blob/main/src/main/kotlin")
69+
remoteLineSuffix = "#L"
7870
}
7971
}
8072
}
8173

82-
val dokkaJar by tasks.creating(Jar::class) {
74+
val dokkaJar by tasks.registering(Jar::class) {
8375
group = "build"
8476
description = "Assembles the Kotlin docs with Dokka"
8577
archiveClassifier.set("javadoc")
86-
from(tasks.named("dokkaJavadoc"))
78+
from(tasks.named("dokkaGeneratePublicationJavadoc"))
8779
}
8880

8981
artifacts {
@@ -103,34 +95,34 @@ publishing {
10395
artifact(dokkaJar)
10496

10597
pom {
106-
name.set(provider { "$groupId:$artifactId" })
107-
description.set("Convert between different string notations commonly found in programming")
108-
inceptionYear.set("2020")
109-
url.set("https://github.com/$githubRepository")
98+
name = "$groupId:$artifactId"
99+
description = "Convert between different string notations commonly found in programming"
100+
inceptionYear = "2020"
101+
url = "https://github.com/$githubRepository"
110102
ciManagement {
111-
system.set("GitHub Actions")
112-
url.set("https://github.com/$githubRepository/actions")
103+
system = "GitHub Actions"
104+
url = "https://github.com/$githubRepository/actions"
113105
}
114106
issueManagement {
115-
system.set("GitHub Issues")
116-
url.set("https://github.com/$githubRepository/issues")
107+
system = "GitHub Issues"
108+
url = "https://github.com/$githubRepository/issues"
117109
}
118110
developers {
119111
developer {
120-
name.set("Joshua Gleitze")
121-
email.set("[email protected]")
112+
name = "Joshua Gleitze"
113+
122114
}
123115
}
124116
scm {
125-
connection.set("scm:git:https://github.com/$githubRepository.git")
126-
developerConnection.set("scm:git:git://[email protected]:$githubRepository.git")
127-
url.set("https://github.com/$githubRepository")
117+
connection = "scm:git:https://github.com/$githubRepository.git"
118+
developerConnection = "scm:git:git://[email protected]:$githubRepository.git"
119+
url = "https://github.com/$githubRepository"
128120
}
129121
licenses {
130122
license {
131-
name.set("MIT")
132-
url.set("https://opensource.org/licenses/MIT")
133-
distribution.set("repo")
123+
name = "MIT"
124+
url = "https://opensource.org/licenses/MIT"
125+
distribution = "repo"
134126
}
135127
}
136128
}
@@ -150,8 +142,8 @@ publishing {
150142
nexusPublishing {
151143
repositories {
152144
mavenCentral = sonatype {
153-
username.set(ossrhUsername)
154-
password.set(ossrhPassword)
145+
username = ossrhUsername
146+
password = ossrhPassword
155147
}
156148
}
157149
}
@@ -163,18 +155,15 @@ signing {
163155
sign(publication)
164156
}
165157

166-
val closeAndReleaseStagingRepository by project.tasks
167-
closeAndReleaseStagingRepository.mustRunAfter(mavenCentral.publishTask)
158+
val closeAndReleaseStagingRepositories by project.tasks
159+
closeAndReleaseStagingRepositories.mustRunAfter(mavenCentral.publishTask)
168160

169-
task("release") {
161+
val release by tasks.registering {
170162
group = "release"
171163
description = "Releases the project to Maven Central"
172-
dependsOn(githubPackages.publishTask, mavenCentral.publishTask, closeAndReleaseStagingRepository)
164+
dependsOn(githubPackages.publishTask, mavenCentral.publishTask, closeAndReleaseStagingRepositories)
173165
}
174166

175-
val Project.isSnapshot get() = versionDetails.commitDistance != 0
176167
fun String.drop(prefix: String) = if (this.startsWith(prefix)) this.drop(prefix.length) else this
177-
178-
val Project.versionDetails get() = (this.extra["versionDetails"] as groovy.lang.Closure<*>)() as com.palantir.gradle.gitversion.VersionDetails
179168
val ArtifactRepository.publishTask get() = tasks["publishAllPublicationsTo${this.name}Repository"]
180169
val NexusRepository.publishTask get() = "publishTo${this.name.replaceFirstChar { it.titlecase() }}"

gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
org.gradle.parallel=true
2+
org.gradle.configuration-cache=true
3+
org.gradle.configuration-cache.parallel=true
4+
5+
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
6+
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true

src/main/kotlin/BaseStringNotation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ abstract class BaseStringNotation(private val splitAt: Regex): StringNotation {
3535
.foldIndexed(StringBuffer()) { index, existing, part -> existing.append(printBeforePart(index, part)).append(part) }
3636
.toString()
3737

38-
override fun toString() = this::class.java.simpleName!!
38+
override fun toString(): String = this::class.java.simpleName
3939
}

src/main/kotlin/JavaNotations.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ import javax.lang.model.SourceVersion
1111
* Allowed characters are determined using [Character.isJavaIdentifierStart] and [Character.isJavaIdentifierPart]. Keywords are detected
1212
* using [SourceVersion.isKeyword].
1313
*/
14-
object JavaTypeName: StringNotation by UpperCamelCase {
14+
data object JavaTypeName : StringNotation by UpperCamelCase {
1515
override fun print(word: Word) = UpperCamelCase.print(
1616
Word(word.parts.mapIndexed { index, wordPart ->
1717
if (index == 0) wordPart.keepOnlyJavaIdentifierChars()
1818
else wordPart.keepOnlyJavaIdentifierContinuationChars()
1919
})
2020
)
2121
.neutralizeJavaReservedKeywords()
22-
23-
override fun toString() = this::class.java.simpleName!!
2422
}
2523

2624
/**
@@ -30,17 +28,17 @@ object JavaTypeName: StringNotation by UpperCamelCase {
3028
* Allowed characters are determined using [Character.isJavaIdentifierStart] and [Character.isJavaIdentifierPart]. Keywords are detected
3129
* using [SourceVersion.isKeyword].
3230
*/
33-
object JavaMemberName: BaseStringNotation(camelCaseSplitRegex) {
34-
override fun transformPartAfterParse(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
31+
object JavaMemberName : BaseStringNotation(camelCaseSplitRegex) {
32+
override fun transformPartAfterParse(index: Int, part: String) = part.lowercase(Locale.ROOT)
3533

3634
override fun print(word: Word) = word.parts
3735
.foldIndexed(StringBuffer()) { index, existing, part ->
3836
val filteredPart =
3937
if (index == 0) part.keepOnlyJavaIdentifierChars()
4038
else part.keepOnlyJavaIdentifierContinuationChars()
4139
val nextPart =
42-
if (existing.contains(Regex("[a-zA-Z]"))) filteredPart.toFirstUpperOtherLowerCase()
43-
else filteredPart.toLowerCase()
40+
if (existing.contains(Regex("[a-zA-Z]"))) filteredPart.firstUpperThenLowerCase()
41+
else filteredPart.lowercase(Locale.getDefault())
4442
existing.append(printBeforePart(index, nextPart)).append(nextPart)
4543
}.toString().makeValidJavaIdentifier()
4644
}
@@ -54,10 +52,10 @@ object JavaMemberName: BaseStringNotation(camelCaseSplitRegex) {
5452
* Allowed characters are determined using [Character.isJavaIdentifierStart] and [Character.isJavaIdentifierPart]. Keywords are detected
5553
* using [SourceVersion.isKeyword].
5654
*/
57-
object JavaPackagePart: BaseStringNotation(Regex("_|${camelCaseSplitRegex.pattern}")) {
58-
override fun transformPartAfterParse(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
55+
object JavaPackagePart : BaseStringNotation(Regex("_|${camelCaseSplitRegex.pattern}")) {
56+
override fun transformPartAfterParse(index: Int, part: String) = part.lowercase(Locale.ROOT)
5957

60-
override fun transformPartToPrint(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
58+
override fun transformPartToPrint(index: Int, part: String) = part.lowercase(Locale.ROOT)
6159

6260
override fun print(word: Word) = super.print(word).makeValidJavaIdentifier()
6361
}
@@ -69,8 +67,8 @@ object JavaPackagePart: BaseStringNotation(Regex("_|${camelCaseSplitRegex.patter
6967
* Allowed characters are determined using [Character.isJavaIdentifierStart] and [Character.isJavaIdentifierPart]. Keywords are detected
7068
* using [SourceVersion.isKeyword].
7169
*/
72-
object JavaPackageName: BaseStringNotation(Regex("\\.")) {
73-
override fun transformPartToPrint(index: Int, part: String) = part.toLowerCase(Locale.ROOT).makeValidJavaIdentifier()
70+
object JavaPackageName : BaseStringNotation(Regex("\\.")) {
71+
override fun transformPartToPrint(index: Int, part: String) = part.lowercase(Locale.ROOT).makeValidJavaIdentifier()
7472

7573
override fun printBeforeInnerPart(index: Int, part: String) = "."
7674
}
@@ -82,10 +80,8 @@ object JavaPackageName: BaseStringNotation(Regex("\\.")) {
8280
* Allowed characters are determined using [Character.isJavaIdentifierStart] and [Character.isJavaIdentifierPart]. Keywords are detected
8381
* using [SourceVersion.isKeyword].
8482
*/
85-
object JavaConstantName: StringNotation by ScreamingSnakeCase {
83+
data object JavaConstantName : StringNotation by ScreamingSnakeCase {
8684
override fun print(word: Word) = ScreamingSnakeCase.print(word).makeValidJavaIdentifier()
87-
88-
override fun toString() = this::class.java.simpleName!!
8985
}
9086

9187
private fun String.makeValidJavaIdentifier() = this.keepOnlyJavaIdentifierChars().neutralizeJavaReservedKeywords()
@@ -95,10 +91,15 @@ private fun String.keepOnlyJavaIdentifierChars() = this.chars()
9591
.keepOnlyJavaIdentifierContinuationChars()
9692
.collectToString()
9793

98-
private fun String.keepOnlyJavaIdentifierContinuationChars() = this.chars().keepOnlyJavaIdentifierContinuationChars().collectToString()
94+
private fun String.keepOnlyJavaIdentifierContinuationChars() =
95+
this.chars().keepOnlyJavaIdentifierContinuationChars().collectToString()
96+
9997
private fun IntStream.keepOnlyJavaIdentifierContinuationChars() = this.filter { Character.isJavaIdentifierPart(it) }
10098
private fun IntStream.collectToString() =
101-
this.collect({ StringBuilder() }, { left, right -> left.appendCodePoint(right) }, { left, right -> left.append(right) })
99+
this.collect(
100+
{ StringBuilder() },
101+
{ left, right -> left.appendCodePoint(right) },
102+
{ left, right -> left.append(right) })
102103
.toString()
103104

104105
private fun String.neutralizeJavaReservedKeywords() = when {

0 commit comments

Comments
 (0)