Skip to content

Commit eb33d83

Browse files
committed
Fix Test and Release compiling
1 parent 8ade1e3 commit eb33d83

28 files changed

+323
-286
lines changed

src/SDK/Language/Android.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,11 @@ public function getFiles(): array
339339
];
340340
}
341341

342-
protected function getReturnType(array $method, array $spec, string $namespace, bool $withGeneric = true, string $generic = 'T'): string
342+
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'T', bool $withGeneric = true): string
343343
{
344344
if ($method['type'] === 'webAuth') {
345345
return 'Bool';
346346
}
347-
return parent::getReturnType($method, $spec, $namespace, $withGeneric, $generic);
347+
return parent::getReturnType($method, $spec, $namespace, $generic, $withGeneric);
348348
}
349349
}

src/SDK/Language/KMP.php

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Appwrite\SDK\Language;
44

5+
use Twig\TwigFilter;
6+
57
class KMP extends Kotlin
68
{
79
/**
@@ -12,12 +14,57 @@ public function getName(): string
1214
return 'KMP';
1315
}
1416

15-
protected function getReturnType(array $method, array $spec, string $namespace, bool $withGeneric = true, string $generic = 'T'): string
17+
public function getFilters(): array
18+
{
19+
$filters = parent::getFilters();
20+
21+
$filters[] = new TwigFilter('webAuthServices', function (array $spec) {
22+
return $this->findWebAuthServices($spec);
23+
});
24+
return $filters;
25+
}
26+
27+
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'T', bool $withGeneric = true): string
1628
{
1729
if ($method['type'] === 'webAuth') {
1830
return 'Bool';
1931
}
20-
return parent::getReturnType($method, $spec, $namespace, $withGeneric, $generic);
32+
return parent::getReturnType($method, $spec, $namespace, $generic, $withGeneric);
33+
}
34+
35+
protected function findWebAuthServices(array $spec): array
36+
{
37+
$webAuthServices = [];
38+
foreach ($spec['services'] as $service) {
39+
$webAuthMethods = [];
40+
$hasWebAuth = false;
41+
foreach ($service['methods'] as $method) {
42+
if ($method['type'] === 'webAuth') {
43+
$webAuthMethods[] = [
44+
'methodName' => $method['name'],
45+
'parameters' => $method['parameters']
46+
];
47+
$hasWebAuth = true;
48+
}
49+
}
50+
if ($hasWebAuth) {
51+
$webAuthServices[] = [
52+
'methods' => $webAuthMethods,
53+
'className' => $service['name']
54+
];
55+
}
56+
}
57+
return $webAuthServices;
58+
}
59+
60+
61+
protected function getPropertyType(array $property, array $spec, string $generic = 'T', bool $contextual = false): string
62+
{
63+
$type = parent::getPropertyType($property, $spec, $generic);
64+
if ($contextual && ($type === 'List<Any>' || $type === 'List<Any>?')) {
65+
$type = 'List<@Contextual Any>';
66+
}
67+
return $type;
2168
}
2269

2370
public function getFiles(): array
@@ -65,8 +112,8 @@ public function getFiles(): array
65112
],
66113
[
67114
'scope' => 'default',
68-
'destination' => 'build.gradle',
69-
'template' => '/kmp/build.gradle.twig',
115+
'destination' => 'build.gradle.kts',
116+
'template' => '/kmp/build.gradle.kts.twig',
70117
],
71118
[
72119
'scope' => 'default',
@@ -88,12 +135,27 @@ public function getFiles(): array
88135
'destination' => 'LICENSE.md',
89136
'template' => '/kmp/LICENSE.md.twig',
90137
],
138+
[
139+
'scope' => 'default',
140+
'destination' => 'gradlew',
141+
'template' => '/kmp/gradlew',
142+
],
143+
[
144+
'scope' => 'default',
145+
'destination' => 'gradlew.bat',
146+
'template' => '/kmp/gradlew.bat',
147+
],
148+
[
149+
'scope' => 'default',
150+
'destination' => 'gradle.properties',
151+
'template' => '/kmp/gradle.properties',
152+
],
91153

92154
// Shared module
93155
[
94156
'scope' => 'default',
95-
'destination' => 'shared/build.gradle',
96-
'template' => '/kmp/shared/build.gradle.twig',
157+
'destination' => 'shared/build.gradle.kts',
158+
'template' => '/kmp/shared/build.gradle.kts.twig',
97159
],
98160

99161
// Common Main
@@ -195,11 +257,6 @@ public function getFiles(): array
195257
'destination' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models/InputFile.kt',
196258
'template' => '/kmp/shared/src/commonMain/kotlin/io/package/models/InputFile.kt.twig',
197259
],
198-
[
199-
'scope' => 'definition',
200-
'destination' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models//models/{{ definition.name | caseUcfirst }}.kt',
201-
'template' => '/kmp/shared/src/commonMain/kotlin/io/package/models/Model.kt.twig',
202-
],
203260
[
204261
'scope' => 'default',
205262
'destination' => 'shared/src/commonMain/kotlin/{{ sdk.namespace | caseSlash }}/models/RealtimeModels.kt',
@@ -311,13 +368,8 @@ public function getFiles(): array
311368
// Extensions
312369
[
313370
'scope' => 'default',
314-
'destination' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt',
315-
'template' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig',
316-
],
317-
[
318-
'scope' => 'default',
319-
'destination' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt',
320-
'template' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig',
371+
'destination' => 'shared/src/androidMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt',
372+
'template' => '/kmp/shared/src/androidMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig',
321373
],
322374

323375
// File Operations
@@ -381,13 +433,8 @@ public function getFiles(): array
381433
// Extensions
382434
[
383435
'scope' => 'default',
384-
'destination' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt',
385-
'template' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig',
386-
],
387-
[
388-
'scope' => 'default',
389-
'destination' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt',
390-
'template' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig',
436+
'destination' => 'shared/src/iosMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt',
437+
'template' => '/kmp/shared/src/iosMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig',
391438
],
392439

393440
// File Operations
@@ -443,13 +490,8 @@ public function getFiles(): array
443490
// Extensions
444491
[
445492
'scope' => 'default',
446-
'destination' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Session.kt',
447-
'template' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/createOAuth2Session.kt.twig',
448-
],
449-
[
450-
'scope' => 'default',
451-
'destination' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/createOAuth2Token.kt',
452-
'template' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/createOAuth2Token.kt.twig',
493+
'destination' => 'shared/src/jvmMain/kotlin/{{ sdk.namespace | caseSlash }}/extensions/OAuth2Extensions.kt',
494+
'template' => '/kmp/shared/src/jvmMain/kotlin/io/package/extensions/OAuth2Extensions.kt.twig',
453495
],
454496

455497
// File Operations

src/SDK/Language/Kotlin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ public function getFiles(): array
426426
public function getFilters(): array
427427
{
428428
return [
429-
new TwigFilter('returnType', function (array $method, array $spec, string $namespace, string $generic = 'T') {
430-
return $this->getReturnType($method, $spec, $namespace, $generic);
429+
new TwigFilter('returnType', function (array $method, array $spec, string $namespace, string $generic = 'T', bool $withGeneric = true) {
430+
return $this->getReturnType($method, $spec, $namespace, $generic, $withGeneric);
431431
}),
432432
new TwigFilter('modelType', function (array $property, array $spec, string $generic = 'T') {
433433
return $this->getModelType($property, $spec, $generic);
@@ -447,7 +447,7 @@ public function getFilters(): array
447447
];
448448
}
449449

450-
protected function getReturnType(array $method, array $spec, string $namespace, bool $withGeneric = true, string $generic = 'T'): string
450+
protected function getReturnType(array $method, array $spec, string $namespace, string $generic = 'T', bool $withGeneric = true): string
451451
{
452452
if ($method['type'] === 'webAuth') {
453453
return 'String';
File renamed without changes.

templates/kmp/gradle/libs.versions.toml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
[versions]
22
agp = "8.7.3"
33
appcompat = "1.7.0"
4-
browserVersion = "1.8.0"
54
coreKtx = "1.15.0"
65
espressoCore = "3.6.1"
76
gson = "2.10.1"
87
junit = "4.13.2"
98
junitVersion = "1.2.1"
109
kotlin = "2.1.0"
11-
ktor = "3.0.1"
12-
compose = "1.7.5"
13-
compose-material3 = "1.3.1"
14-
androidx-activityCompose = "1.9.3"
15-
activityKtx = "1.9.3"
10+
ktor = "3.0.3"
11+
activityKtx = "1.10.0"
1612
browser = "1.8.0"
17-
kotlinxCoroutines = "1.9.0"
13+
kotlinxCoroutines = "1.10.1"
1814
kotlinxDatetime = "0.6.1"
1915
kotlinxSerializationJson = "1.7.3"
2016
napier = "2.7.1"
2117
lifecycleLivedataKtx = "2.8.7"
22-
navigationUiKtx = "2.8.4"
18+
navigationUiKtx = "2.8.5"
2319
firebaseCrashlyticsBuildtools = "3.0.2"
20+
robolectric = "4.14.1"
21+
androidx-test = "1.6.1"
22+
coroutines-test = "1.10.1"
23+
test-runner = "1.6.2"
2424

2525

2626
[libraries]
27+
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
28+
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test" }
29+
androidx-test-runner = { module = "androidx.test:runner", version.ref = "test-runner" }
30+
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines-test" }
2731
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
28-
androidx-browser-v170 = { module = "androidx.browser:browser", version.ref = "browserVersion" }
2932
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
3033
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
3134
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
@@ -48,14 +51,8 @@ ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
4851
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
4952
ktor-client-websockets = { module = "io.ktor:ktor-client-websockets", version.ref = "ktor" }
5053
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
51-
ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor" }
54+
ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }
5255
napier = { module = "io.github.aakira:napier", version.ref = "napier" }
53-
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
54-
compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
55-
compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
56-
compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
57-
compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
58-
compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" }
5956
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "activityKtx" }
6057
androidx-browser = { group = "androidx.browser", name = "browser", version.ref = "browser" }
6158
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutines" }
@@ -67,6 +64,5 @@ androidApplication = { id = "com.android.application", version.ref = "agp" }
6764
androidLibrary = { id = "com.android.library", version.ref = "agp" }
6865
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
6966
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
70-
kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
7167
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
7268
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }

templates/kmp/shared/build.gradle.twig renamed to templates/kmp/shared/build.gradle.kts.twig

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ kotlin {
103103
androidMain.dependencies {
104104
implementation(libs.androidx.core.ktx)
105105
implementation(libs.androidx.appcompat)
106-
implementation(libs.androidx.browser.v170)
107106
implementation(libs.androidx.lifecycle.livedata.ktx)
108107
implementation(libs.androidx.lifecycle.viewmodel.ktx)
109108
implementation(libs.androidx.navigation.fragment.ktx)
@@ -126,6 +125,12 @@ kotlin {
126125

127126
androidUnitTest.dependencies {
128127
implementation(libs.junit)
128+
implementation(libs.androidx.test.core)
129+
implementation(libs.androidx.junit)
130+
implementation(libs.androidx.test.runner)
131+
implementation(libs.robolectric)
132+
implementation(libs.kotlinx.coroutines.test)
133+
implementation(libs.ktor.client.mock)
129134
}
130135

131136
androidInstrumentedTest.dependencies {
@@ -184,25 +189,22 @@ publishing {
184189
}
185190
}
186191

187-
signing {
188-
val signingKeyId = System.getenv("SIGNING_KEY_ID")
189-
val signingPassword = System.getenv("SIGNING_PASSWORD")
190-
val signingSecretKeyRingFile = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
191-
useInMemoryPgpKeys(signingKeyId, File(signingSecretKeyRingFile).readText(), signingPassword)
192-
sign(publishing.publications)
193-
}
194-
195-
196192
android {
197193
namespace = "io.appwrite"
198194
compileSdk = 35
199195
defaultConfig {
200196
minSdk = 21
197+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
201198
}
202199
compileOptions {
203200
sourceCompatibility = JavaVersion.VERSION_1_8
204201
targetCompatibility = JavaVersion.VERSION_1_8
205202
}
203+
testOptions {
204+
unitTests {
205+
isIncludeAndroidResources = true
206+
}
207+
}
206208
}
207209
dependencies {
208210
implementation(libs.androidx.activity.ktx)

templates/kmp/shared/src/androidMain/kotlin/io/package/WebAuthComponent.android.kt.twig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlin.collections.set
1717
* Used to authenticate with external OAuth2 providers. Launches browser windows and handles
1818
* suspension until the user completes the process or otherwise returns to the app.
1919
*/
20-
actual class WebAuthComponent {
20+
actual class WebAuthComponent(private val activity: ComponentActivity) {
2121

2222
companion object : DefaultLifecycleObserver {
2323
private var suspended = false
@@ -44,7 +44,7 @@ actual class WebAuthComponent {
4444
*/
4545
suspend fun authenticate(
4646
activity: ComponentActivity,
47-
url: Uri,
47+
url: String,
4848
callbackUrlScheme: String,
4949
onComplete: ((Result<String>) -> Unit)?
5050
) {
@@ -55,7 +55,7 @@ actual class WebAuthComponent {
5555

5656
intent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
5757
intent.intent.putExtra("android.support.customtabs.extra.KEEP_ALIVE", keepAliveIntent)
58-
intent.launchUrl(activity, url)
58+
intent.launchUrl(activity, Uri.parse(url))
5959

6060
activity.runOnUiThread {
6161
activity.lifecycle.addObserver(this)
@@ -80,9 +80,9 @@ actual class WebAuthComponent {
8080
* @param scheme The scheme to match to a callback's key
8181
* @param url The url received through intent data from the [CallbackActivity]
8282
*/
83-
fun onCallback(scheme: String, url: Uri) {
83+
fun onCallback(scheme: String, url: String) {
8484
callbacks.remove(scheme)?.invoke(
85-
Result.success(url.toString())
85+
Result.success(url)
8686
)
8787
suspended = false
8888
}
@@ -97,17 +97,21 @@ actual class WebAuthComponent {
9797
}
9898
}
9999

100+
@Throws(Throwable::class)
100101
actual suspend fun authenticate(
101102
url: String,
102103
callbackUrlScheme: String,
103104
onComplete: ((Result<String>) -> Unit)?
104105
) {
106+
authenticate(
107+
activity,
108+
url,
109+
callbackUrlScheme,
110+
onComplete,
111+
)
105112
}
106113

107114
actual fun onCallback(scheme: String, url: String) {
108-
callbacks.remove(scheme)?.invoke(
109-
Result.success(url)
110-
)
111-
suspended = false
115+
WebAuthComponent.onCallback(scheme, url)
112116
}
113117
}

0 commit comments

Comments
 (0)