Migrate to Gradle (#1159)

* Start gradle root

* Clean up test API ambiguities

These don't compile in gradle anymore and the team[] warns

* Exclude .gradle dirs in git

* Set up moshi module

* Set up moshi-adapters

* Add repositories to subprojects

* Set target/source compatibility

* Set up examples

* Fix location of reflect/test dir

* Set up moshi-kotlin

* Set up code gen

* Opportunistic update code gen deps

* Fix up with code gen

* Set up kotlin tests

* Update snapshots

* Update travis build

* Configure checkstyle

* Cache gradle

* Finish fixing up checkstyle

* Now disable checkstyle until we can fix them all :|

* Update contributing

* Fix tests in codegen

* Remove unnecessary annotation

* Remove maven stuff!

* Suppress warning

* Remove jcenter

* Consolidate dependencies

* Revert "Clean up test API ambiguities"

This reverts commit 3ead69b844b5d7f66134b721e95581f5df1cccd6.

* Fix incap dep

* Opportunistically fix some small kotlinpoet deprecations

* Automatically apply the stdlib to all kotlin projects

* Opportunistic move to opt-in and remove unnecessary annotations

The kotlin maven plugin didn't handle these well in the IDE, gradle does

* Fix Type doc warning

* Fix okio version

* Fix dokka support

* Fix copypasta

* Use new snapshot

* Kotlin 1.4.0
This commit is contained in:
Zac Sweers
2020-08-27 16:50:28 -04:00
committed by GitHub
parent 24c0c49858
commit 4dd4a9d222
48 changed files with 899 additions and 1643 deletions

View File

@@ -1,16 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>javadoc</id>
<formats>
<format>jar</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>target/dokka/moshi-kotlin-codegen</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>

View File

@@ -19,7 +19,6 @@ import com.google.auto.service.AutoService
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.asClassName
import com.squareup.kotlinpoet.classinspector.elements.ElementsClassInspector
import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview
import com.squareup.moshi.JsonClass
import com.squareup.moshi.kotlin.codegen.api.AdapterGenerator
import com.squareup.moshi.kotlin.codegen.api.PropertyGenerator
@@ -45,7 +44,6 @@ import javax.tools.Diagnostic
* The generated class will match the visibility of the given data class (i.e. if it's internal, the
* adapter will also be internal).
*/
@KotlinPoetMetadataPreview
@AutoService(Processor::class)
@IncrementalAnnotationProcessor(ISOLATING)
class JsonClassCodegenProcessor : AbstractProcessor() {

View File

@@ -45,6 +45,7 @@ import com.squareup.moshi.kotlin.codegen.api.TargetParameter
import com.squareup.moshi.kotlin.codegen.api.TargetProperty
import com.squareup.moshi.kotlin.codegen.api.TargetType
import com.squareup.moshi.kotlin.codegen.api.mapTypes
import com.squareup.moshi.kotlin.codegen.api.rawType
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
@@ -365,7 +366,7 @@ private fun declaredProperties(
return result
}
private val TargetProperty.isTransient get() = propertySpec.annotations.any { it.className == Transient::class.asClassName() }
private val TargetProperty.isTransient get() = propertySpec.annotations.any { it.typeName == Transient::class.asClassName() }
private val TargetProperty.isSettable get() = propertySpec.mutable || parameter != null
private val TargetProperty.isVisible: Boolean
get() {
@@ -406,19 +407,20 @@ internal fun TargetProperty.generator(
// Merge parameter and property annotations
val qualifiers = parameter?.qualifiers.orEmpty() + propertySpec.annotations.qualifiers(elements)
for (jsonQualifier in qualifiers) {
val qualifierRawType = jsonQualifier.typeName.rawType()
// Check Java types since that covers both Java and Kotlin annotations.
val annotationElement = elements.getTypeElement(jsonQualifier.className.canonicalName)
val annotationElement = elements.getTypeElement(qualifierRawType.canonicalName)
?: continue
annotationElement.getAnnotation(Retention::class.java)?.let {
if (it.value != RetentionPolicy.RUNTIME) {
messager.printMessage(ERROR,
"JsonQualifier @${jsonQualifier.className.simpleName} must have RUNTIME retention")
"JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention")
}
}
annotationElement.getAnnotation(Target::class.java)?.let {
if (ElementType.FIELD !in it.value) {
messager.printMessage(ERROR,
"JsonQualifier @${jsonQualifier.className.simpleName} must support FIELD target")
"JsonQualifier @${qualifierRawType.simpleName} must support FIELD target")
}
}
}
@@ -436,13 +438,13 @@ internal fun TargetProperty.generator(
private fun List<AnnotationSpec>?.qualifiers(elements: Elements): Set<AnnotationSpec> {
if (this == null) return setOf()
return filterTo(mutableSetOf()) {
elements.getTypeElement(it.className.toString()).getAnnotation(JSON_QUALIFIER) != null
elements.getTypeElement(it.typeName.toString()).getAnnotation(JSON_QUALIFIER) != null
}
}
private fun List<AnnotationSpec>?.jsonName(): String? {
if (this == null) return null
return find { it.className == JSON }?.let { annotation ->
return find { it.typeName == JSON }?.let { annotation ->
val mirror = requireNotNull(annotation.tag<AnnotationMirror>()) {
"Could not get the annotation mirror from the annotation spec"
}

View File

@@ -15,7 +15,6 @@
*/
package com.squareup.moshi.kotlin.codegen
import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.tschuchort.compiletesting.KotlinCompilation
@@ -36,7 +35,6 @@ import kotlin.reflect.full.createType
import kotlin.reflect.full.declaredMemberProperties
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
@OptIn(KotlinPoetMetadataPreview::class)
class JsonClassCodegenProcessorTest {
@Rule @JvmField var temporaryFolder: TemporaryFolder = TemporaryFolder()