Skip to content

Commit

Permalink
Merge pull request #1104 from DataDog/nogorodnikov/merge_develop_into…
Browse files Browse the repository at this point in the history
…_sdkv2_25102022

Merge develop into SDK v2 branch
  • Loading branch information
0xnm authored Oct 25, 2022
2 parents fa58718 + 9b73f57 commit e201ff4
Show file tree
Hide file tree
Showing 114 changed files with 1,466 additions and 438 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2016-Present Datadog, Inc.

[buildSrc/src/test/kotlin/com/example/model/*.kt]
ktlint_disabled_rules = trailing-comma-on-call-site, trailing-comma-on-declaration-site
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ publish:release:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -196,6 +197,7 @@ publish:release-coil:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -211,6 +213,7 @@ publish:release-compose:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -227,6 +230,7 @@ publish:release-fresco:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -242,6 +246,7 @@ publish:release-glide:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -257,6 +262,7 @@ publish:release-ktx:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -272,6 +278,7 @@ publish:release-ndk:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -287,6 +294,7 @@ publish:release-rx:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -302,6 +310,7 @@ publish:release-sqldelight:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -317,6 +326,7 @@ publish:release-timber:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand All @@ -332,6 +342,7 @@ publish:release-android-tv:
tags: [ "runner:main" ]
only:
- tags
- develop
image: $CI_IMAGE_DOCKER
stage: publish
timeout: 30m
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ same feature from a Java source code.
Our coding style is ensured by [KtLint](https://ktlint.github.io/), with the
default settings. A KtLint check is ran on every PR to ensure that all new code
follow this rule.
Current KtLint version: 0.45.1
Current KtLint version: 0.47.1

Classes should group their methods in folding regions named after the declaring
class. Private methods should be grouped in an `Internal` named folding region.
Expand Down
28 changes: 15 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.datadog.gradle.config.AndroidConfig
import com.datadog.gradle.config.nightlyTestsCoverageConfig

/*
Expand All @@ -12,6 +13,8 @@ plugins {
id("org.jetbrains.kotlinx.kover")
}

version = AndroidConfig.VERSION.name

buildscript {
repositories {
google()
Expand Down Expand Up @@ -219,8 +222,8 @@ tasks.register("koverReportAll") {
":dd-sdk-android-sqldelight:koverXmlReport",
":dd-sdk-android-timber:koverXmlReport",
":dd-sdk-android-tv:koverXmlReport",
":library:dd-sdk-android-session-replay:koverXmlReport",
)
":library:dd-sdk-android-session-replay:koverXmlReport"
)
}

tasks.register("instrumentTestAll") {
Expand All @@ -247,17 +250,16 @@ nightlyTestsCoverageConfig(threshold = 0.87f)
kover {
isDisabled = false
disabledProjects = setOf(
"instrumented",
"sample",
"tools",
"integration",
"nightly-tests",
"kotlin",
"detekt",
"javabackport",
"noopfactory",
"unit"
"instrumented",
"sample",
"tools",
"integration",
"nightly-tests",
"kotlin",
"detekt",
"javabackport",
"noopfactory",
"unit"
)
instrumentAndroidPackage = false
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ object AndroidConfig {

const val TARGET_SDK = 31
const val MIN_SDK = 19

// this is temporary, until we bump min sdk. Compose requires min sdk 21.
const val MIN_SDK_FOR_COMPOSE = 21
const val BUILD_TOOLS_VERSION = "31.0.0"

val VERSION = Version(1, 15, 0, Version.Type.Dev)
val VERSION = Version(1, 15, 0, Version.Type.Snapshot)
}

@Suppress("UnstableApiUsage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.gradle.kotlin.dsl.findByType
inline fun <reified T : Any> Project.extensionConfig(
crossinline configure: T.() -> Unit
) {

project.afterEvaluate {
val ext: T? = extensions.findByType(T::class)
ext?.configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.Project

fun Project.dependencyUpdateConfig() {

taskConfig<DependencyUpdatesTask> {
revision = "release"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType

fun Project.detektConfig(excludes: List<String> = emptyList()) {

extensionConfig<DetektExtension> {
source = files("$projectDir/src/main/kotlin")
config = files("${project.rootDir}/detekt.yml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.gradle.api.Project
import org.jetbrains.dokka.gradle.DokkaTask

fun Project.javadocConfig() {

tasks.withType(DokkaTask::class.java).configureEach {
val toOutputDirectory = file("${buildDir.canonicalPath}/reports/javadoc")
outputDirectory.set(toOutputDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File

fun Project.kotlinConfig(evaluateWarningsAsErrors: Boolean = true) {

taskConfig<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fun Project.publishingConfig(projectDescription: String) {
}

publishingExtension.apply {

publications.create(MavenConfig.PUBLICATION, MavenPublication::class.java) {
from(components.getByName("release"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.gradle.api.Project
import org.gradle.api.tasks.Exec

fun Project.nightlyTestsCoverageConfig(threshold: Float) {

tasks.register("checkNightlyTestsCoverage", Exec::class.java) {
this.group = "datadog"
val generateApiTasks = allprojects.mapNotNull { it.tasks.findByName("generateApiSurface") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ open class CheckThirdPartyLicensesTask : DefaultTask() {

@TaskAction
fun applyTask() {

val projectDependencies = provider.getThirdPartyDependencies(
project,
extension.transitiveDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.datadog.gradle.plugin.checklicenses

@Suppress("ktlint:enum-entry-name-case")
enum class SPDXLicense(val csvName: String) {
_0BSD("0BSD"),
AAL("AAL"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class JsonSchemaReader(
typeName: String,
fromFile: File
): TypeDefinition {

if (definition == null) return TypeDefinition.Null()

return when (definition.type) {
Expand Down Expand Up @@ -292,13 +291,32 @@ class JsonSchemaReader(
description: String?,
fromFile: File
): TypeDefinition {
return TypeDefinition.OneOfClass(
typeName,
oneOf.mapIndexed { i, it ->
transform(it, it.title ?: "${typeName}_$i", fromFile)
},
description.orEmpty()
)
val options = oneOf.mapIndexed { i, it ->
transform(it, it.title ?: "${typeName}_$i", fromFile)
}

val asArray = options.filterIsInstance<TypeDefinition.Array>().firstOrNull()

return if (options.isEmpty()) {
TypeDefinition.Null(description.orEmpty())
} else if (options.size == 1) {
options.first()
} else if (asArray != null && options.all { it == asArray || it == asArray.items }) {
// we're in a case with `oneOf(<T>, Array<T>)`
// because we can't make a type matching both, we simplify it to be always an array
asArray
} else if (options.all { it is TypeDefinition.Class }) {
TypeDefinition.OneOfClass(
typeName,
options.filterIsInstance<TypeDefinition.Class>(),
description.orEmpty()
)
} else {
throw UnsupportedOperationException(
"Unable to implement `oneOf` constraint with types:\n " +
options.joinToString("\n ")
)
}
}

private fun generateTypeAllOf(
Expand All @@ -320,7 +338,6 @@ class JsonSchemaReader(
definition: JsonDefinition,
fromFile: File
): TypeDefinition {

val properties = mutableListOf<TypeProperty>()
definition.properties?.forEach { (name, property) ->
val required = (definition.required != null) && (name in definition.required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ sealed class TypeDefinition {
fun renameRecursive(duplicates: Set<String>, parentName: String): TypeDefinition {
val newName = if (name in duplicates) {
"$parentName$name"
} else name
} else {
name
}

val newProperties = properties.map {
if (it.type is Class) {
Expand Down Expand Up @@ -220,7 +222,7 @@ sealed class TypeDefinition {

data class OneOfClass(
val name: String,
val options: List<TypeDefinition>,
val options: List<Class>,
override val description: String = ""
) : TypeDefinition() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ClassDeserializerGenerator(
) {
val opt = if (nullable) "?" else ""
beginControlFlow(
"$assignee = $getter$opt.asJsonArray$opt.let { %L ->",
"$assignee = $getter$opt.asJsonArray$opt.let·{·%L·->",
Identifier.PARAM_JSON_ARRAY
)
val collectionClassName: ClassName = if (arrayType.uniqueItems) {
Expand Down Expand Up @@ -328,7 +328,6 @@ class ClassDeserializerGenerator(
hasKnownProperties: Boolean,
rootTypeName: String
) {

addStatement(
"val %L = mutableMapOf<%T, %T>()",
Identifier.PARAM_ADDITIONAL_PROPS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.squareup.kotlinpoet.ARRAY
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.MAP
import com.squareup.kotlinpoet.MUTABLE_MAP
import com.squareup.kotlinpoet.MemberName
import com.squareup.kotlinpoet.ParameterSpec
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
Expand Down Expand Up @@ -134,12 +134,11 @@ class ClassGenerator(
private fun FunSpec.Builder.appendPropertySerialization(
property: TypeProperty
) {

val propertyName = property.name.variableName()
val isNullable =
property.optional && property.type !is TypeDefinition.Constant && property.type !is TypeDefinition.Null
val refName = if (isNullable) {
beginControlFlow("%L?.let { %LNonNull ->", propertyName, propertyName)
beginControlFlow("%L?.let·{·%LNonNull·->", propertyName, propertyName)
"${propertyName}NonNull"
} else {
propertyName
Expand Down Expand Up @@ -310,7 +309,7 @@ class ClassGenerator(
val mapType = definition.additionalProperties.additionalPropertyType(rootTypeName)
constructorBuilder.addParameter(
ParameterSpec.builder(Identifier.PARAM_ADDITIONAL_PROPS, mapType)
.defaultValue("emptyMap()")
.defaultValue("mutableMapOf()")
.build()
)
}
Expand Down Expand Up @@ -390,7 +389,6 @@ class ClassGenerator(
}

private fun generateReservedPropertiesArray(definition: TypeDefinition.Class): PropertySpec {

val propertyNames = definition.properties.joinToString(", ") { "\"${it.name}\"" }

val propertyBuilder = PropertySpec.builder(
Expand Down Expand Up @@ -447,7 +445,7 @@ class ClassGenerator(
} else {
ANY.copy(nullable = true)
}
return MAP.parameterizedBy(STRING, valueType)
return MUTABLE_MAP.parameterizedBy(STRING, valueType)
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class FileGenerator(
val topLevelTypeBuilder = generateTypeSpec(definition, rootTypeName)

while (knownTypes.any(isUnwrittenClass)) {

val nestedClasses = knownTypes.filter(isUnwrittenClass).toSet()
nestedClasses.forEach {
topLevelTypeBuilder.addType(generateTypeSpec(it.type, rootTypeName).build())
Expand Down
Loading

0 comments on commit e201ff4

Please sign in to comment.