Skip to content

Commit

Permalink
Use the gradle plugin in the SQLDelight tests. (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpawliszyn authored Oct 28, 2024
1 parent 5d9f39a commit fab304f
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 108 deletions.
19 changes: 19 additions & 0 deletions build-support/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath(libs.kotlinGradlePlugin)
classpath(libs.mavenPublishGradlePlugin)
classpath(libs.buildConfigPlugin)
}
}

allprojects {
repositories {
mavenCentral()
}
}


12 changes: 12 additions & 0 deletions build-support/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rootProject.name = "build-support"

include(":client-sqldelight-gradle-plugin")
project(":client-sqldelight-gradle-plugin").projectDir = File("../client-sqldelight-gradle-plugin")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ buildscript {
classpath(libs.wireGradlePlugin)
classpath(libs.buildConfigPlugin)
classpath(libs.shadowJarPlugin)
classpath("app.cash.backfila:client-sqldelight-gradle-plugin")
}
}

Expand Down
84 changes: 33 additions & 51 deletions client-sqldelight-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,65 +1,46 @@
import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-gradle-plugin")
kotlin("jvm")
`java-library`
id("com.github.gmazzo.buildconfig")
id("com.vanniktech.maven.publish.base")
}

// This module is used in two places:
//
// - In the root project, so we can:
// - publish the plugin
// - run the plugin's own unit test
//
// - In build-support project
// - In this project, we consume it internally.
//
// We only want to publish when it's being built in the root project.
if (rootProject.name == "backfila") {
configure<MavenPublishBaseExtension> {
configure(
GradlePlugin(
javadocJar = JavadocJar.Empty()
)
)
}
} else {
// Move the build directory when included in build-support so as to not poison the real build.
// If we don't there's a chance incorrect build config values (configured below) will be used.
layout.buildDirectory.set(File(rootDir, "build/internal"))
}

dependencies {
implementation(libs.guava)
implementation(libs.kotlinGradlePlugin)
implementation(libs.kotlinPoet)
implementation(libs.moshiCore)
implementation(libs.moshiKotlin)
implementation(libs.wireRuntime)
implementation(libs.guice)
implementation(libs.kotlinStdLib)
implementation(libs.sqldelightJdbcDriver)
implementation(libs.sqldelightGradlePlugin)
implementation(libs.okHttp)
implementation(libs.okio)
implementation(libs.retrofit)
implementation(libs.retrofitMock)
implementation(libs.retrofitMoshi)
implementation(libs.retrofitWire)
implementation(libs.wireMoshiAdapter)

api(project(":client"))
// We do not want to leak client-base implementation details to customers.
implementation(project(":client-base"))


testImplementation(libs.assertj)
testImplementation(libs.junitEngine)
testImplementation(libs.kotlinTest)

testImplementation(project(":backfila-embedded"))
testImplementation(project(":client-testing"))

// ****************************************
// For TESTING purposes only. We only want Misk for easy testing.
// DO NOT turn these into regular dependencies.
// ****************************************
testImplementation(libs.misk)
testImplementation(libs.miskActions)
testImplementation(libs.miskInject)
testImplementation(libs.miskJdbc)
testImplementation(testFixtures(libs.miskJdbc))
testImplementation(libs.miskTesting)
testImplementation(project(":client-misk"))
}

tasks.withType<KotlinCompile> {
dependsOn("spotlessKotlinApply")
kotlinOptions {
jvmTarget = "17"
}
}

tasks.withType<JavaCompile> {
Expand All @@ -80,13 +61,22 @@ gradlePlugin {

tasks {
test {
// We do not want the tests to run within build-support.
// Note that by default intellij may still try to run them through build support.
if (rootProject.name != "backfila") {
onlyIf { false }
return@test
}

useJUnitPlatform()
// The test in 'src/test/projects/android' needs Java 17+.
javaLauncher.set(
project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
systemProperty("backfilaVersion", rootProject.findProperty("VERSION_NAME") ?: "0.0-SNAPSHOT")

dependsOn(":client:publishAllPublicationsToTestMavenRepository")
dependsOn(":client-base:publishAllPublicationsToTestMavenRepository")
dependsOn(":client-sqldelight:publishAllPublicationsToTestMavenRepository")
Expand All @@ -103,11 +93,3 @@ buildConfig {
packageName("app.cash.backfila.client.sqldelight.plugin")
buildConfigField("String", "VERSION", "\"${project.version}\"")
}

configure<MavenPublishBaseExtension> {
configure(
GradlePlugin(
javadocJar = JavadocJar.Empty()
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ abstract class GenerateBackfilaRecordSourceQueriesTask : DefaultTask() {
).addFunction(
FunSpec.builder("produceInitialBatchFromRange")
.addParameter("rangeStart", keyType)
.addParameter("rangeEnd", keyType)
.addParameter("boundingMax", keyType)
.addParameter("offset", LONG)
.returns(keyQueryType)
.addStatement("return database.%L.produceInitialBatchFromRange(rangeStart, rangeEnd, offset)", queriesFunctionName)
.addStatement("return database.%L.produceInitialBatchFromRange(rangeStart, boundingMax, offset)", queriesFunctionName)
.addModifiers(OVERRIDE)
.build(),
).addFunction(
FunSpec.builder("produceNextBatchFromRange")
.addParameter("previousEndKey", keyType)
.addParameter("rangeEnd", keyType)
.addParameter("boundingMax", keyType)
.addParameter("offset", LONG)
.returns(keyQueryType)
.addStatement("return database.%L.produceNextBatchFromRange(previousEndKey, rangeEnd, offset)", queriesFunctionName)
.addStatement("return database.%L.produceNextBatchFromRange(previousEndKey, boundingMax, offset)", queriesFunctionName)
.addModifiers(OVERRIDE)
.build(),
).addFunction(
Expand All @@ -141,17 +141,17 @@ abstract class GenerateBackfilaRecordSourceQueriesTask : DefaultTask() {
).addFunction(
FunSpec.builder("getInitialStartKeyAndScanCount")
.addParameter("rangeStart", keyType)
.addParameter("rangeEnd", keyType)
.addParameter("batchEnd", keyType)
.returns(minAndCountQueryType)
.addStatement("return database.%L.getInitialStartKeyAndScanCount(rangeStart, rangeEnd) { min, count -> %T(min, count) }", queriesFunctionName, minAndCountType)
.addStatement("return database.%L.getInitialStartKeyAndScanCount(rangeStart, batchEnd) { min, count -> %T(min, count) }", queriesFunctionName, minAndCountType)
.addModifiers(OVERRIDE)
.build(),
).addFunction(
FunSpec.builder("getNextStartKeyAndScanCount")
.addParameter("previousEndKey", keyType)
.addParameter("rangeEnd", keyType)
.addParameter("batchEnd", keyType)
.returns(minAndCountQueryType)
.addStatement("return database.%L.getNextStartKeyAndScanCount(previousEndKey, rangeEnd) { min, count -> %T(min, count) }", queriesFunctionName, minAndCountType)
.addStatement("return database.%L.getNextStartKeyAndScanCount(previousEndKey, batchEnd) { min, count -> %T(min, count) }", queriesFunctionName, minAndCountType)
.addModifiers(OVERRIDE)
.build(),
).addFunction(
Expand Down
16 changes: 15 additions & 1 deletion client-sqldelight-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm")
id("app.cash.sqldelight") version libs.versions.sqldelight.get()
id("app.cash.sqldelight")
id("app.cash.backfila.client.sqldelight")
}

// TODO May have to make the other module dependent on this test module although we would have to avoid cycles.
Expand All @@ -17,6 +18,19 @@ sqldelight {
}
}

backfilaSqlDelight {
addRecordSource(
name = "hockeyPlayersBackfill",
database = "app.cash.backfila.client.sqldelight.hockeydata.HockeyDataDatabase",
tableName = "hockeyPlayer",
keyName = "player_number",
keyType = "kotlin.Int",
keyEncoder = "app.cash.backfila.client.sqldelight.IntKeyEncoder",
recordColumns = "*",
recordType = "app.cash.backfila.client.sqldelight.hockeydata.HockeyPlayer"
)
}

val compileKotlin by tasks.getting {
dependsOn("generateMainHockeyDataDatabaseMigrations")
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.cash.backfila.client.BackfillConfig
import app.cash.backfila.client.PrepareBackfillConfig
import app.cash.backfila.client.sqldelight.hockeydata.HockeyDataDatabase
import app.cash.backfila.client.sqldelight.hockeydata.HockeyPlayer
import app.cash.backfila.client.sqldelight.hockeydata.HockeyPlayersBackfillRecordSourceConfig
import javax.inject.Inject

class PlayerOriginBackfill @Inject constructor(
Expand Down
8 changes: 8 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
rootProject.name = "backfila"

includeBuild("build-support") {
dependencySubstitution {
substitute(module("app.cash.backfila:client-sqldelight-gradle-plugin")).using(project(":client-sqldelight-gradle-plugin"))
}
}

include("backfila-embedded")
include("bom")
include("client")
Expand Down

0 comments on commit fab304f

Please sign in to comment.