Skip to content

Commit e55b49b

Browse files
authored
Merge pull request #287 from adamint/dev
circleci
2 parents 1b3f534 + ffb0966 commit e55b49b

39 files changed

+610
-566
lines changed

.circleci/config.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Java Gradle CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2
6+
orbs:
7+
gradle: circleci/[email protected]
8+
win: circleci/[email protected]
9+
jobs:
10+
test_linux:
11+
docker:
12+
- image: mingc/android-build-box
13+
working_directory: ~/repo
14+
environment:
15+
JVM_OPTS: -Xmx3200m
16+
TERM: dumb
17+
18+
steps:
19+
- checkout
20+
- restore_cache:
21+
keys:
22+
- v1-dependencies-{{ checksum "build.gradle.kts" }}
23+
# fallback to using the latest cache if no exact match is found
24+
- v1-dependencies-
25+
- run: gradle dependencies
26+
- save_cache:
27+
paths:
28+
- ~/.gradle
29+
key: v1-dependencies-{{ checksum "build.gradle.kts" }}
30+
- run: gradle linuxX64Test
31+
test_js:
32+
docker:
33+
- image: mingc/android-build-box
34+
working_directory: ~/repo
35+
environment:
36+
JVM_OPTS: -Xmx3200m
37+
TERM: dumb
38+
39+
steps:
40+
- checkout
41+
- restore_cache:
42+
keys:
43+
- v1-dependencies-{{ checksum "build.gradle.kts" }}
44+
# fallback to using the latest cache if no exact match is found
45+
- v1-dependencies-
46+
- run: gradle dependencies
47+
- save_cache:
48+
paths:
49+
- ~/.gradle
50+
key: v1-dependencies-{{ checksum "build.gradle.kts" }}
51+
- run: gradle jsIrTest jsLegacyTest
52+
test_jvm:
53+
docker:
54+
- image: circleci/openjdk:11-jdk
55+
working_directory: ~/repo
56+
environment:
57+
JVM_OPTS: -Xmx3200m
58+
TERM: dumb
59+
60+
steps:
61+
- checkout
62+
- restore_cache:
63+
keys:
64+
- v1-dependencies-{{ checksum "build.gradle.kts" }}
65+
# fallback to using the latest cache if no exact match is found
66+
- v1-dependencies-
67+
- run: gradle dependencies
68+
- save_cache:
69+
paths:
70+
- ~/.gradle
71+
key: v1-dependencies-{{ checksum "build.gradle.kts" }}
72+
- run: gradle jvmTest
73+
74+
workflows:
75+
version: 2
76+
run_tests:
77+
jobs:
78+
- test_jvm
79+
- test_js
80+
- test_linux

build.gradle.kts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
55

66
plugins {
77
id("lt.petuska.npm.publish") version "1.1.2"
8-
kotlin("multiplatform") version "1.5.0"
8+
kotlin("multiplatform") version "1.5.21"
99
`maven-publish`
1010
signing
1111
id("io.codearte.nexus-staging") version "0.30.0"
1212
id("com.android.library")
13-
kotlin("plugin.serialization") version "1.5.0"
14-
id("com.diffplug.spotless") version "5.12.4"
13+
kotlin("plugin.serialization") version "1.5.21"
14+
id("com.diffplug.spotless") version "5.14.2"
1515
id("com.moowork.node") version "1.3.1"
1616
id("org.jetbrains.dokka") version "1.4.30"
1717
id("kotlin-android-extensions")
1818
}
1919

2020
repositories {
2121
google()
22-
maven("https://kotlin.bintray.com/kotlinx")
2322
mavenCentral()
2423
}
2524

@@ -29,8 +28,8 @@ buildscript {
2928
mavenCentral()
3029
}
3130
dependencies {
32-
classpath("com.android.tools.build:gradle:3.5.4")
33-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0")
31+
classpath("com.android.tools.build:gradle:4.2.2")
32+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
3433
}
3534
}
3635

@@ -60,8 +59,6 @@ android {
6059
minSdkVersion(15)
6160
targetSdkVersion(30)
6261
compileSdkVersion(30)
63-
versionCode = 1
64-
versionName = "1.0"
6562
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
6663
}
6764
buildTypes {
@@ -124,7 +121,7 @@ kotlin {
124121
}
125122

126123
val irOnlyJs = project.hasProperty("irOnly")
127-
js(if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.BOTH) {
124+
js(if (irOnlyJs) KotlinJsCompilerType.IR else KotlinJsCompilerType.LEGACY) {
128125

129126
mavenPublication {
130127
setupPom(artifactId)
@@ -216,14 +213,14 @@ kotlin {
216213

217214
targets {
218215
sourceSets {
219-
val serializationVersion = "1.2.0"
220-
val ktorVersion = "1.5.4"
221-
val korlibsVersion = "2.0.7"
216+
val serializationVersion = "1.2.2"
217+
val ktorVersion = "1.6.2"
218+
val korlibsVersion = "2.2.0"
222219
val sparkVersion = "2.9.3"
223220
val androidSpotifyAuthVersion = "1.2.3"
224-
val androidCryptoVersion = "1.1.0-alpha03"
225-
val coroutineMTVersion = "1.4.3-native-mt"
226-
val kotlinxDatetimeVersion = "0.2.0"
221+
val androidCryptoVersion = "1.0.0"
222+
val coroutineMTVersion = "1.5.1-native-mt"
223+
val kotlinxDatetimeVersion = "0.2.1"
227224

228225
val commonMain by getting {
229226
dependencies {
@@ -255,7 +252,6 @@ kotlin {
255252
dependsOn(commonJvmLikeMain)
256253
repositories {
257254
mavenCentral()
258-
jcenter()
259255
}
260256

261257
dependencies {
@@ -293,15 +289,14 @@ kotlin {
293289

294290
repositories {
295291
mavenCentral()
296-
jcenter()
297292
}
298293

299294
dependencies {
300295
api("com.spotify.android:auth:$androidSpotifyAuthVersion")
301296
implementation("com.pnikosis:materialish-progress:1.7")
302297
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
303298
implementation("androidx.security:security-crypto:$androidCryptoVersion")
304-
implementation("androidx.appcompat:appcompat:1.2.0")
299+
implementation("androidx.appcompat:appcompat:1.3.1")
305300
}
306301
}
307302

@@ -420,7 +415,6 @@ npmPublishing {
420415
repository("npmjs") {
421416
registry = uri("https://registry.npmjs.org")
422417
(project.properties.get("npmauthtoken") as? String)?.let { authToken = it }
423-
println("auth token: $authToken")
424418
}
425419
}
426420
}
@@ -433,7 +427,6 @@ tasks {
433427
repository("npmjs") {
434428
registry = uri("https://registry.npmjs.org")
435429
(project.properties.get("npmauthtoken") as? String)?.let { authToken = it }
436-
println("auth token: $authToken")
437430
}
438431
}
439432

gradle.properties

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
## For more details on how to configure your build environment visit
2+
# http://www.gradle.org/docs/current/userguide/build_environment.html
3+
#
4+
# Specifies the JVM arguments used for the daemon process.
5+
# The setting is particularly useful for tweaking memory settings.
6+
# Default value: -Xmx1024m -XX:MaxPermSize=256m
7+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
8+
#
9+
# When configured, Gradle will run in incubating parallel mode.
10+
# This option should only be used with decoupled projects. More details, visit
11+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
12+
# org.gradle.parallel=true
13+
#Mon Aug 09 00:44:27 PDT 2021
114
systemProp.org.gradle.internal.publish.checksums.insecure=true
215
org.gradle.daemon=true
16+
kotlin.js.generate.externals=true
317
org.gradle.jvmargs=-Xmx8000m
4-
kotlin.mpp.enableGranularSourceSetsMetadata=true
518
kotlin.native.enableDependencyPropagation=false
6-
kotlin.js.generate.externals=true
19+
android.useAndroidX=true
20+
android.enableJetifier=true
21+
kotlin.mpp.enableGranularSourceSetsMetadata=true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pluginManagement {
2121

2222
repositories {
2323
mavenCentral()
24-
jcenter()
2524
gradlePluginPortal()
2625
google()
2726
maven { url = java.net.URI("https://plugins.gradle.org/m2/") }

src/commonMain/kotlin/com.adamratzman.spotify/SpotifyRestAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.adamratzman.spotify
44
import com.adamratzman.spotify.utils.TimeUnit
55
import com.adamratzman.spotify.utils.getCurrentTimeMs
66
import com.adamratzman.spotify.utils.runBlockingOnJvmAndNative
7+
import com.soywiz.korio.async.runBlockingNoJs
78
import kotlin.coroutines.CoroutineContext
89
import kotlin.coroutines.resume
910
import kotlin.coroutines.resumeWithException

src/commonMain/kotlin/com.adamratzman.spotify/http/Endpoints.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract class SpotifyEndpoint(public val api: GenericSpotifyApi) {
6161
}
6262

6363
internal suspend fun get(url: String): String {
64-
return execute(url)
64+
return execute(url).apply { println("body: $url") }
6565
}
6666

6767
internal suspend fun post(url: String, body: String? = null, contentType: String? = null): String {

src/commonTest/kotlin/com.adamratzman/spotify/Common.kt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
22
package com.adamratzman.spotify
33

4-
import kotlin.coroutines.CoroutineContext
54
import kotlin.native.concurrent.ThreadLocal
65
import kotlin.test.assertTrue
76
import kotlinx.coroutines.CoroutineScope
@@ -13,7 +12,6 @@ val tokenString = getEnvironmentVariable("SPOTIFY_TOKEN_STRING")
1312

1413
// https://github.com/Kotlin/kotlinx.coroutines/issues/1996#issuecomment-728562784
1514
expect fun runBlockingTest(block: suspend CoroutineScope.() -> Unit)
16-
expect val testCoroutineContext: CoroutineContext
1715

1816
@ThreadLocal
1917
var instantiationCompleted: Boolean = false
@@ -47,6 +45,33 @@ suspend fun buildSpotifyApi() = when {
4745
else -> null.also { instantiationCompleted = true }
4846
}
4947

48+
fun buildSpotifyApiSync() = when {
49+
tokenString?.isNotBlank() == true -> {
50+
spotifyClientApi {
51+
credentials {
52+
clientId = com.adamratzman.spotify.clientId
53+
clientSecret = com.adamratzman.spotify.clientSecret
54+
redirectUri = com.adamratzman.spotify.redirectUri
55+
}
56+
authorization {
57+
tokenString = com.adamratzman.spotify.tokenString
58+
}
59+
}.buildRestAction().complete().also { instantiationCompleted = true; apiBacking = it }
60+
}
61+
clientId?.isNotBlank() == true -> {
62+
spotifyAppApi {
63+
credentials {
64+
clientId = com.adamratzman.spotify.clientId
65+
clientSecret = com.adamratzman.spotify.clientSecret
66+
}
67+
}.buildRestAction().complete().also {
68+
instantiationCompleted = true; apiBacking = it
69+
}
70+
}
71+
else -> null.also { instantiationCompleted = true }
72+
}
73+
74+
5075
expect fun getEnvironmentVariable(name: String): String?
5176

5277
expect fun Exception.stackTrace()

src/commonTest/kotlin/com.adamratzman/spotify/TestUtilities.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@ package com.adamratzman.spotify
44
abstract class AbstractTest<T : GenericSpotifyApi> {
55
var api: T? = null
66

7-
suspend fun build(): Boolean {
7+
fun testPrereq() = api != null
8+
9+
suspend inline fun <reified Z : T> build(): Boolean {
810
return try {
11+
val f = buildSpotifyApi()
912
@Suppress("UNCHECKED_CAST")
10-
(buildSpotifyApi() as? T)?.let { api = it }
13+
(f as? T)?.let { if (f is Z) api = it }
14+
api != null
15+
} catch (cce: Exception) {
16+
println("here")
17+
false
18+
}
19+
}
20+
21+
fun buildSync(): Boolean {
22+
return try {
23+
@Suppress("UNCHECKED_CAST")
24+
(buildSpotifyApiSync() as? T)?.let { api = it }
1125
api != null
1226
} catch (cce: ClassCastException) {
1327
false
1428
}
1529
}
30+
1631
}
1732

1833
typealias GenericSpotifyApiTest = AbstractTest<GenericSpotifyApi>

src/commonTest/kotlin/com.adamratzman/spotify/priv/ClientEpisodeApiTest.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
11
/* Spotify Web API, Kotlin Wrapper; MIT License, 2017-2021; Original author: Adam Ratzman */
22
package com.adamratzman.spotify.priv
33

4+
import com.adamratzman.spotify.AbstractTest
45
import com.adamratzman.spotify.SpotifyClientApi
56
import com.adamratzman.spotify.SpotifyException.BadRequestException
6-
import com.adamratzman.spotify.assertFailsWithSuspend
7-
import com.adamratzman.spotify.buildSpotifyApi
87
import com.adamratzman.spotify.runBlockingTest
98
import kotlin.test.Test
109
import kotlin.test.assertEquals
10+
import kotlin.test.assertFailsWith
1111
import kotlin.test.assertNotNull
1212
import kotlin.test.assertNull
1313

14-
class ClientEpisodeApiTest {
15-
var api: SpotifyClientApi? = null
16-
17-
init {
18-
runBlockingTest {
19-
(buildSpotifyApi() as? SpotifyClientApi)?.let { api = it }
20-
}
21-
}
22-
23-
fun testPrereq() = api != null
24-
14+
class ClientEpisodeApiTest : AbstractTest<SpotifyClientApi>() {
2515
@Test
2616
fun testGetEpisode() {
27-
runBlockingTest {
17+
return runBlockingTest {
18+
super.build<SpotifyClientApi>()
2819
if (!testPrereq()) return@runBlockingTest else api
2920

3021
assertNull(api!!.episodes.getEpisode("nonexistant episode"))
31-
assertNotNull(api!!.episodes.getEpisode("4IhgnOc8rwMW70agMWVVfh"))
22+
assertNotNull(api!!.episodes.getEpisode("3lMZTE81Pbrp0U12WZe27l"))
3223
}
3324
}
3425

3526
@Test
3627
fun testGetEpisodes() {
37-
runBlockingTest {
28+
return runBlockingTest {
29+
super.build<SpotifyClientApi>()
3830
if (!testPrereq()) return@runBlockingTest else api!!
3931

40-
assertFailsWithSuspend<BadRequestException> { api!!.episodes.getEpisodes("hi", "dad") }
41-
assertFailsWithSuspend<BadRequestException> {
32+
assertFailsWith<BadRequestException> { api!!.episodes.getEpisodes("hi", "dad") }
33+
assertFailsWith<BadRequestException> {
4234
api!!.episodes.getEpisodes("1cfOhXP4GQCd5ZFHoSF8gg", "j").map { it?.name }
4335
}
4436
assertEquals(
45-
listOf("The 'Murder Hornets' And The Honey Bees"),
46-
api!!.episodes.getEpisodes("4IhgnOc8rwMW70agMWVVfh").map { it?.name }
37+
listOf("The Great Inflation (Classic)"),
38+
api!!.episodes.getEpisodes("3lMZTE81Pbrp0U12WZe27l").map { it?.name }
4739
)
4840
}
4941
}

0 commit comments

Comments
 (0)