Skip to content

Commit

Permalink
Update formatters to latest
Browse files Browse the repository at this point in the history
Ensure renovate can bump them by specifying full coordinates in toml.
  • Loading branch information
JakeWharton authored and ZacSweers committed Jan 29, 2024
1 parent 84ca5cf commit 2cc9ebb
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 90 deletions.
16 changes: 9 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import java.net.URI

buildscript {
dependencies {
val kotlinVersion = System.getenv("MOSHI_KOTLIN_VERSION")
?: libs.versions.kotlin.get()
val kspVersion = System.getenv("MOSHI_KSP_VERSION")
?: libs.versions.ksp.get()
val kotlinVersion =
System.getenv("MOSHI_KOTLIN_VERSION")
?: libs.versions.kotlin.get()
val kspVersion =
System.getenv("MOSHI_KSP_VERSION")
?: libs.versions.ksp.get()
classpath(kotlin("gradle-plugin", version = kotlinVersion))
classpath("com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion")
// https://github.com/melix/japicmp-gradle-plugin/issues/36
Expand Down Expand Up @@ -44,15 +46,15 @@ spotless {
endWithNewline()
}
val configureCommonJavaFormat: JavaExtension.() -> Unit = {
googleJavaFormat(libs.versions.gjf.get())
googleJavaFormat(libs.googleJavaFormat.get().version)
}
java {
configureCommonJavaFormat()
target("**/*.java")
targetExclude("**/build/**")
}
kotlin {
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
ktlint(libs.ktlint.get().version).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
)
target("**/*.kt")
Expand All @@ -61,7 +63,7 @@ spotless {
targetExclude("**/Dependencies.kt", "**/build/**")
}
kotlinGradle {
ktlint(libs.versions.ktlint.get())
ktlint(libs.ktlint.get().version)
target("**/*.gradle.kts")
trimTrailingWhitespace()
endWithNewline()
Expand Down
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[versions]
autoService = "1.1.1"
gjf = "1.15.0"
jvmTarget = "1.8"
kotlin = "1.9.21"
kotlinCompileTesting = "0.4.0"
kotlinpoet = "1.14.2"
ksp = "1.9.22-1.0.17"
ktlint = "0.48.2"

[plugins]
dokka = { id = "org.jetbrains.dokka", version = "1.9.10" }
Expand All @@ -33,10 +31,10 @@ kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.7.0"
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
okio = "com.squareup.okio:okio:3.7.0"

# Test libs
assertj = "org.assertj:assertj-core:3.25.2"
junit = "junit:junit:4.13.2"
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
truth = "com.google.truth:truth:1.3.0"
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.19.2"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.1.1"
21 changes: 11 additions & 10 deletions moshi-adapters/japicmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ dependencies {
latest(project(":moshi-adapters"))
}

val japicmp = tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
onlyBinaryIncompatibleModified.set(true)
failOnModification.set(true)
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
}
val japicmp =
tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
onlyBinaryIncompatibleModified.set(true)
failOnModification.set(true)
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
}

tasks.named("check").configure {
dependsOn(japicmp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,40 @@ internal fun String.parseIsoDate(): Date {
var offset = 0

// extract year
val year = parseInt(this, offset, 4.let { offset += it; offset })
val year = parseInt(
this,
offset,
4.let {
offset += it
offset
},
)
if (checkOffset(this, offset, '-')) {
offset += 1
}

// extract month
val month = parseInt(this, offset, 2.let { offset += it; offset })
val month = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, '-')) {
offset += 1
}

// extract day
val day = parseInt(this, offset, 2.let { offset += it; offset })
val day = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
// default time value
var hour = 0
var minutes = 0
Expand All @@ -108,19 +129,43 @@ internal fun String.parseIsoDate(): Date {
}
if (hasT) {
// extract hours, minutes, seconds and milliseconds
hour = parseInt(this, 1.let { offset += it; offset }, 2.let { offset += it; offset })
hour = parseInt(
this,
1.let {
offset += it
offset
},
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, ':')) {
offset += 1
}
minutes = parseInt(this, offset, 2.let { offset += it; offset })
minutes = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (checkOffset(this, offset, ':')) {
offset += 1
}
// second and milliseconds can be optional
if (this.length > offset) {
val c = this[offset]
if (c != 'Z' && c != '+' && c != '-') {
seconds = parseInt(this, offset, 2.let { offset += it; offset })
seconds = parseInt(
this,
offset,
2.let {
offset += it
offset
},
)
if (seconds in 60..62) seconds = 59 // truncate up to 3 leap seconds
// milliseconds can be optional in the format
if (checkOffset(this, offset, '.')) {
Expand Down
25 changes: 13 additions & 12 deletions moshi-kotlin-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@ dependencies {
testImplementation(libs.kotlinCompileTesting)
}

val shadowJar = tasks.shadowJar.apply {
configure {
archiveClassifier.set("")
configurations = listOf(shade)
relocate("com.squareup.kotlinpoet.metadata", "com.squareup.moshi.kotlinpoet.metadata")
relocate(
"com.squareup.kotlinpoet.classinspector",
"com.squareup.moshi.kotlinpoet.classinspector",
)
relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata")
transformers.add(ServiceFileTransformer())
val shadowJar =
tasks.shadowJar.apply {
configure {
archiveClassifier.set("")
configurations = listOf(shade)
relocate("com.squareup.kotlinpoet.metadata", "com.squareup.moshi.kotlinpoet.metadata")
relocate(
"com.squareup.kotlinpoet.classinspector",
"com.squareup.moshi.kotlinpoet.classinspector",
)
relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata")
transformers.add(ServiceFileTransformer())
}
}
}

artifacts {
runtimeOnly(shadowJar)
Expand Down
11 changes: 7 additions & 4 deletions moshi-kotlin-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ plugins {
}

enum class TestMode {
REFLECT, KAPT, KSP
REFLECT,
KAPT,
KSP,
}

val testMode = findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: REFLECT
val testMode =
findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: REFLECT

when (testMode) {
REFLECT -> {
Expand Down
11 changes: 7 additions & 4 deletions moshi-kotlin-tests/codegen-only/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ plugins {
}

enum class TestMode {
REFLECT, KAPT, KSP
REFLECT,
KAPT,
KSP,
}

val testMode = findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: KSP
val testMode =
findProperty("kotlinTestMode")?.toString()
?.let(TestMode::valueOf)
?: KSP

when (testMode) {
REFLECT -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ class GeneratedAdaptersTest {
}

@JsonClass(generateAdapter = true)
@Suppress("ktlint:standard:property-naming")
class MutableUppercasePropertyName {
var AAA: Int = -1
var BBB: Int = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.squareup.moshi.JsonWriter
import com.squareup.moshi.kotlin.codegen.GeneratedAdaptersTest.CustomGeneratedClass

// This also tests custom generated types with no moshi constructor
@Suppress("ktlint:standard:class-naming")
class GeneratedAdaptersTest_CustomGeneratedClassJsonAdapter : JsonAdapter<CustomGeneratedClass>() {
override fun fromJson(reader: JsonReader): CustomGeneratedClass? {
TODO()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ class KotlinJsonAdapterTest {
data class UsingEnum(val e: KotlinEnum)

enum class KotlinEnum {
A, B
A,
B,
}

@Test fun interfacesNotSupported() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ internal class KotlinJsonAdapter<T>(
}

public class KotlinJsonAdapterFactory : JsonAdapter.Factory {
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi):
JsonAdapter<*>? {
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi): JsonAdapter<*>? {
if (annotations.isNotEmpty()) return null

val rawType = type.rawType
Expand Down
7 changes: 4 additions & 3 deletions moshi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ val java16: SourceSet by sourceSets.creating {

// We use JDK 17 for latest but target 16 for maximum compatibility
val service = project.extensions.getByType<JavaToolchainService>()
val customLauncher = service.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
val customLauncher =
service.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}

tasks.named<JavaCompile>("compileJava16Java") {
options.release.set(16)
Expand Down
79 changes: 43 additions & 36 deletions moshi/japicmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,49 @@ dependencies {
latest(project(":moshi"))
}

val japicmp = tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
onlyBinaryIncompatibleModified.set(true)
failOnModification.set(true)
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
classExcludes.addAll(
"com.squareup.moshi.AdapterMethodsFactory", // Internal.
"com.squareup.moshi.ClassJsonAdapter", // Internal.
"com.squareup.moshi.RecordJsonAdapter\$ComponentBinding", // Package-private
"com.squareup.moshi.StandardJsonAdapters", // Package-private
"com.squareup.moshi.internal.NonNullJsonAdapter", // Internal.
"com.squareup.moshi.internal.NullSafeJsonAdapter", // Internal.
"com.squareup.moshi.internal.Util\$GenericArrayTypeImpl", // Internal.
"com.squareup.moshi.internal.Util\$ParameterizedTypeImpl", // Internal.
"com.squareup.moshi.internal.Util\$WildcardTypeImpl", // Internal.
)
methodExcludes.addAll(
"com.squareup.moshi.JsonAdapter#indent(java.lang.String)", // Was unintentionally open before
"com.squareup.moshi.internal.Util#hasNullable(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.reflect.AnnotatedElement)",
"com.squareup.moshi.internal.Util#jsonName(java.lang.String, com.squareup.moshi.Json)",
"com.squareup.moshi.internal.Util#jsonName(java.lang.String, java.lang.reflect.AnnotatedElement)",
"com.squareup.moshi.internal.Util#resolve(java.lang.reflect.Type, java.lang.Class, java.lang.reflect.Type)",
"com.squareup.moshi.internal.Util#typeAnnotatedWithAnnotations(java.lang.reflect.Type, java.util.Set)",
)
fieldExcludes.addAll(
"com.squareup.moshi.CollectionJsonAdapter#FACTORY", // False-positive, class is not public anyway
"com.squareup.moshi.MapJsonAdapter#FACTORY", // Class is not public
"com.squareup.moshi.ArrayJsonAdapter#FACTORY", // Class is not public
)
}
val japicmp =
tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath.from(baseline)
newClasspath.from(latest)
onlyBinaryIncompatibleModified.set(true)
failOnModification.set(true)
txtOutputFile.set(layout.buildDirectory.file("reports/japi.txt"))
ignoreMissingClasses.set(true)
includeSynthetic.set(true)
classExcludes.addAll(
// Internal.
"com.squareup.moshi.AdapterMethodsFactory",
"com.squareup.moshi.ClassJsonAdapter",
"com.squareup.moshi.internal.NonNullJsonAdapter",
"com.squareup.moshi.internal.NullSafeJsonAdapter",
"com.squareup.moshi.internal.Util\$GenericArrayTypeImpl",
"com.squareup.moshi.internal.Util\$ParameterizedTypeImpl",
"com.squareup.moshi.internal.Util\$WildcardTypeImpl",
// Package-private
"com.squareup.moshi.RecordJsonAdapter\$ComponentBinding",
"com.squareup.moshi.StandardJsonAdapters",
)
methodExcludes.addAll(
// Was unintentionally open before
"com.squareup.moshi.JsonAdapter#indent(java.lang.String)",
"com.squareup.moshi.internal.Util#hasNullable(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.annotation.Annotation[])",
"com.squareup.moshi.internal.Util#jsonAnnotations(java.lang.reflect.AnnotatedElement)",
"com.squareup.moshi.internal.Util#jsonName(java.lang.String, com.squareup.moshi.Json)",
"com.squareup.moshi.internal.Util#jsonName(java.lang.String, java.lang.reflect.AnnotatedElement)",
"com.squareup.moshi.internal.Util#resolve(java.lang.reflect.Type, java.lang.Class, java.lang.reflect.Type)",
"com.squareup.moshi.internal.Util#typeAnnotatedWithAnnotations(java.lang.reflect.Type, java.util.Set)",
)
fieldExcludes.addAll(
// False-positive, class is not public anyway
"com.squareup.moshi.CollectionJsonAdapter#FACTORY",
// Class is not public
"com.squareup.moshi.MapJsonAdapter#FACTORY",
// Class is not public
"com.squareup.moshi.ArrayJsonAdapter#FACTORY",
)
}

tasks.named("check").configure {
dependsOn(japicmp)
Expand Down
Loading

0 comments on commit 2cc9ebb

Please sign in to comment.