Skip to content

Commit 8f2758f

Browse files
committed
chore: update codebase
1 parent c6ccaf7 commit 8f2758f

File tree

8 files changed

+69
-73
lines changed

8 files changed

+69
-73
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
release:
55
types: [published]
66

7+
env:
8+
ORG_GRADLE_PROJECT_version: ${{ github.event.release.tag_name }}
9+
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
10+
711
jobs:
812
release:
913
name: Release Artefacts
@@ -30,14 +34,11 @@ jobs:
3034
run: ./gradlew clean dependencies
3135
- name: Assemble Artefacts
3236
run: ./gradlew assemble
33-
env:
34-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
3537
- name: Release Artefacts
3638
run: ./gradlew release
3739
env:
3840
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PACKAGE_SIGNING_KEY }}
3941
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.PACKAGE_SIGNING_KEY_PASSWORD }}
40-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
4142
ORG_GRADLE_PROJECT_githubToken: ${{ secrets.RELEASE_GITHUB_TOKEN }}
4243
ORG_GRADLE_PROJECT_ossrhUsername: ${{ secrets.OSSRH_USERNAME }}
4344
ORG_GRADLE_PROJECT_ossrhPassword: ${{ secrets.OSSRH_PASSWORD }}
@@ -66,9 +67,7 @@ jobs:
6667
- name: Prepare
6768
run: ./gradlew clean dependencies
6869
- name: Generate Documentation
69-
run: ./gradlew dokkaHtml
70-
env:
71-
ORG_GRADLE_PROJECT_githubRepository: ${{ github.repository }}
70+
run: ./gradlew dokkaGenerate
7271
- name: Publish Documentation
7372
uses: peaceiris/[email protected]
7473
with:

build.gradle.kts

Lines changed: 21 additions & 32 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
1211
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
13-
idea
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
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"
6860
archiveClassifier.set("sources")
6961
from(sourceSets.main.get().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 {
@@ -166,15 +158,12 @@ signing {
166158
val closeAndReleaseStagingRepository by project.tasks
167159
closeAndReleaseStagingRepository.mustRunAfter(mavenCentral.publishTask)
168160

169-
task("release") {
161+
val release by tasks.registering {
170162
group = "release"
171163
description = "Releases the project to Maven Central"
172164
dependsOn(githubPackages.publishTask, mavenCentral.publishTask, closeAndReleaseStagingRepository)
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 {

src/main/kotlin/Notations.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ internal val camelCaseSplitRegex = Regex("(?<=.)(?=\\p{Lu})")
99
*
1010
* @see JavaTypeName
1111
*/
12-
object UpperCamelCase: BaseStringNotation(camelCaseSplitRegex) {
13-
override fun transformPartAfterParse(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
12+
object UpperCamelCase : BaseStringNotation(camelCaseSplitRegex) {
13+
override fun transformPartAfterParse(index: Int, part: String) = part.lowercase(Locale.ROOT)
1414

15-
public override fun transformPartToPrint(index: Int, part: String) = part.toFirstUpperOtherLowerCase()
15+
public override fun transformPartToPrint(index: Int, part: String) = part.firstUpperThenLowerCase()
1616
}
1717

1818
/**
1919
* The `lowerCamelCase` notation.
2020
*
2121
* @see JavaMemberName
2222
*/
23-
object LowerCamelCase: BaseStringNotation(camelCaseSplitRegex) {
24-
override fun transformPartAfterParse(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
23+
object LowerCamelCase : BaseStringNotation(camelCaseSplitRegex) {
24+
override fun transformPartAfterParse(index: Int, part: String) = part.lowercase(Locale.ROOT)
2525

26-
override fun transformPartToPrint(index: Int, part: String) = if (index == 0) part.toLowerCase() else part.toFirstUpperOtherLowerCase()
26+
override fun transformPartToPrint(index: Int, part: String) =
27+
if (index == 0) part.lowercase(Locale.ROOT) else part.firstUpperThenLowerCase()
2728
}
2829

2930
/**
3031
* The `SCREAMING_SNAKE_CASE` notation.
3132
*/
32-
object ScreamingSnakeCase: BaseStringNotation(Regex("_")) {
33-
override fun transformPartAfterParse(index: Int, part: String) = part.toLowerCase(Locale.ROOT)
33+
object ScreamingSnakeCase : BaseStringNotation(Regex("_")) {
34+
override fun transformPartAfterParse(index: Int, part: String) = part.lowercase(Locale.ROOT)
3435

3536
override fun printBeforeInnerPart(index: Int, part: String) = "_"
3637

37-
override fun transformPartToPrint(index: Int, part: String) = part.toUpperCase()
38+
override fun transformPartToPrint(index: Int, part: String) = part.uppercase(Locale.ROOT)
3839
}
3940

4041
/**
@@ -49,9 +50,10 @@ object SnakeCase: BaseStringNotation(Regex("_")) {
4950
* one or more characters of whitespace as a [part][Word.parts]. [Printing][StringNotation.print] will print the parts separated by one
5051
* space.
5152
*/
52-
object NormalWords: BaseStringNotation(Regex("[\\s]+")) {
53+
object NormalWords: BaseStringNotation(Regex("\\s+")) {
5354
override fun printBeforeInnerPart(index: Int, part: String) = " "
5455
}
5556

56-
internal fun String.toFirstUpperOtherLowerCase() = if (isNotEmpty()) this[0].toUpperCase() + substring(1).toLowerCase() else this
57+
internal fun String.firstUpperThenLowerCase() =
58+
if (isNotEmpty()) this[0].uppercaseChar() + substring(1).lowercase(Locale.ROOT) else this
5759

src/test/kotlin/WordTest.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package de.joshuagleitze.stringnotation
22

3-
import ch.tutteli.atrium.api.fluent.en_GB.asIterable
4-
import ch.tutteli.atrium.api.fluent.en_GB.containsExactly
5-
import ch.tutteli.atrium.api.fluent.en_GB.feature
6-
import ch.tutteli.atrium.api.fluent.en_GB.notToBe
7-
import ch.tutteli.atrium.api.fluent.en_GB.toBe
3+
import ch.tutteli.atrium.api.fluent.en_GB.*
84
import ch.tutteli.atrium.api.verbs.expect
95
import org.junit.jupiter.api.Test
106

@@ -55,7 +51,7 @@ class WordTest {
5551
@Test
5652
fun `allows to map parts`() {
5753
expect(Word("a", "b", "c"))
58-
.feature(Word::mapParts, String::toUpperCase)
54+
.feature(Word::mapParts, String::uppercase)
5955
.toBe(Word("A", "B", "C"))
6056
}
6157

0 commit comments

Comments
 (0)