Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
782f8e9
Update uniffi & add async_trait
oguzkocer Jun 3, 2024
b063e5a
Remove NetworkHandler, WpNetworkHandler & WpUsersEndpoint from Kotlin…
oguzkocer Jun 3, 2024
1cee277
Add WpRequestExecutor and use it in Kotlin tests
oguzkocer Jun 3, 2024
49e50dd
Add RequestExecutor trait to Rust and use it for users
oguzkocer Jun 3, 2024
f2810d1
Temporarily disable all plugin tests
oguzkocer Jun 3, 2024
e0dee3f
Update users_immut tests for the new executor
oguzkocer Jun 3, 2024
6b364ce
Update users_err tests for request executor
oguzkocer Jun 3, 2024
2efec97
Update users_mut tests for request executor change
oguzkocer Jun 3, 2024
e43bf91
Remove individual parsers
oguzkocer Jun 3, 2024
ac98d29
Remove UsersEndpoint and update Android integration tests
oguzkocer Jun 3, 2024
1a8efbf
Remove WpRequestHandler and move the logic to WpApiClient in Kotlin
oguzkocer Jun 4, 2024
bf5b15e
Update plugins for the new request executor approach
oguzkocer Jun 4, 2024
8882e66
Rename NetworkRequestError to RequestExecutionError and improve error…
oguzkocer Jun 4, 2024
2f8b62d
Move parsing to RequestBuilder
oguzkocer Jun 4, 2024
5c04501
Add build get, post & delete request helpers to RequestBuilder
oguzkocer Jun 4, 2024
55a36ec
Update plugins_immut tests for request execution
oguzkocer Jun 4, 2024
a65fd08
Update plugins_err tests for request execution
oguzkocer Jun 4, 2024
71ea727
Update plugins_mut tests for request execution
oguzkocer Jun 4, 2024
797b1a1
Minor improvements to filter_plugins test
oguzkocer Jun 4, 2024
ab2befd
Adds assert_response helper
oguzkocer Jun 4, 2024
427c555
Remove no longer possible to test error cases from users_err tests
oguzkocer Jun 4, 2024
7becd86
Merge branch 'trunk' into request-executor
oguzkocer Jun 4, 2024
5d54517
Update kotlin version to 2.0.0
oguzkocer Jun 4, 2024
10b563c
Switch to version catalog
oguzkocer Jun 4, 2024
ce885a3
Switch api/kotlin/build.gradle to Kotlin DSL
oguzkocer Jun 4, 2024
d08f0e4
Switch api/android/build.gradle to Kotlin DSL
oguzkocer Jun 5, 2024
16641d7
Merge remote-tracking branch 'origin/trunk' into kotlin-version-catal…
oguzkocer Jun 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions native/kotlin/api/android/build.gradle

This file was deleted.

187 changes: 187 additions & 0 deletions native/kotlin/api/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("org.mozilla.rust-android-gradle.rust-android")
id("com.automattic.android.publish-to-s3")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

android {
namespace = "rs.wordpress.api.android"

compileSdk = libs.versions.android.compileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
buildConfig = true
}

buildTypes {
debug {
readTestCredentials()?.let {
buildConfigField("String", "TEST_SITE_URL", "\"${it.siteUrl}\"")
buildConfigField("String", "TEST_ADMIN_USERNAME", "\"${it.adminUsername}\"")
buildConfigField("String", "TEST_ADMIN_PASSWORD", "\"${it.adminPassword}\"")
buildConfigField(
"String",
"TEST_SUBSCRIBER_USERNAME",
"\"${it.subscriberUsername}\""
)
buildConfigField(
"String",
"TEST_SUBSCRIBER_PASSWORD",
"\"${it.subscriberPassword}\""
)
}
}
}

// There is an incorrect lint error in generated wp_api.kt about the usage of NewApi
// that's related to the usage of `android.system.SystemCleaner`.
//
// At the time of this comment, generated bindings only use this `SystemCleaner` for
// API's above 33 and fallback to Jna cleaner `UniffiJnaCleaner` that's available for
// earlier APIs.
//
// Instead of completely ignoring this issue, we are tracking it through the baseline lint
// file - at least for now.
lint.baseline = file("${project.rootDir}/config/lint/baseline.xml")

sourceSets["androidTest"].jniLibs.srcDirs.plus("${layout.buildDirectory.get()}/rustJniLibs/android")
}

repositories {
maven {
url = uri("https://a8c-libs.s3.amazonaws.com/android")
content {
includeGroup("rs.wordpress.api")
}
}
mavenCentral()
google()
}

dependencies {
if (project.hasProperty("wpApiKotlinVersion")) {
api("rs.wordpress.api:kotlin:${project.properties["wpApiKotlinVersion"]}") {
exclude(group = "net.java.dev.jna")
}
} else {
api(project(":api:kotlin")) {
exclude(group = "net.java.dev.jna")
}
}
implementation(libs.okhttp)
implementation(libs.androidx.annotation)
implementation(libs.jna) {
artifact {
type = "aar"
}
}

androidTestImplementation(libs.androidx.runner)
androidTestImplementation(libs.androidx.rules)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.kotlin.test)
androidTestImplementation(libs.jna) {
artifact {
type = "aar"
}
}
androidTestImplementation(libs.kotlinx.coroutines.test)

testImplementation(libs.junit)
testImplementation(libs.jna)
}

val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")!!
val moduleName = "wp_api"
cargo {
module = "$cargoProjectRoot/$moduleName/"
libname = moduleName
profile = "release"
targets = listOf("arm", "arm64", "x86", "x86_64", nativeRustTarget())
targetDirectory = "$cargoProjectRoot/target"
exec = { spec: ExecSpec, _: com.nishtahir.Toolchain ->
// https://doc.rust-lang.org/rustc/command-line-arguments.html#-g-include-debug-information
spec.environment("RUSTFLAGS", "-g")
}
}
tasks.matching { it.name.matches("merge.*JniLibFolders".toRegex()) }.configureEach {
inputs.dir(File("${layout.buildDirectory.get()}/rustJniLibs/android"))
dependsOn("cargoBuild")
}

tasks.matching { it.name.matches("test".toRegex()) }.configureEach {
dependsOn("cargoBuild")
}

project.afterEvaluate {
publishing {
publications {
create<MavenPublication>("maven") {
from(components["release"])

groupId = "rs.wordpress.api"
artifactId = "android"
// version is set by 'publish-to-s3' plugin
}
}
}
}

fun nativeRustTarget(): String {
return when (val resourcePrefix = com.sun.jna.Platform.RESOURCE_PREFIX) {
// For unit tests to work in Apple Silicon, we need to return "darwin-aarch64" here
// However, that runs the cargo task as `cargoBuildDarwin-aarch64` which is not properly
// cached by cargo and requires a rebuild every time. This results in a significant
// development time loss, so for now, we are returning "darwin" and using instrumented
// tests instead.
"darwin" -> "darwin"
"darwin-aarch64" -> "darwin-aarch64"
"darwin-x86-64" -> "darwin-x86-64"
"linux-x86-64" -> "linux-x86-64"
"win32-x86-64" -> "win32-x86-64-gnu"
else -> throw GradleException("Unsupported Platform: $resourcePrefix")
}
}

fun readTestCredentials(): TestCredentials? {
val cargoProjectRoot = rootProject.ext.get("cargoProjectRoot")
val credentialsFile = rootProject.file("$cargoProjectRoot/test_credentials")
if (!credentialsFile.exists()) {
return null
}
val lines = credentialsFile.readLines()
// https://developer.android.com/studio/run/emulator-networking
val siteUrl = if (lines[0] == "http://localhost") {
"http://10.0.2.2"
} else {
lines[0]
}
return TestCredentials(
siteUrl = siteUrl,
adminUsername = lines[1],
adminPassword = lines[2],
subscriberUsername = lines[3],
subscriberPassword = lines[4]
)
}

data class TestCredentials(
val siteUrl: String,
val adminUsername: String,
val adminPassword: String,
val subscriberUsername: String,
val subscriberPassword: String,
)
4 changes: 3 additions & 1 deletion native/kotlin/api/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:networkSecurityConfig="@xml/network_security_config" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
Loading