diff --git a/build.gradle.kts b/build.gradle.kts index ac2d6761768..15a0bb8d726 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import kotlinx.coroutines.runBlocking +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -27,14 +28,15 @@ subprojects { } tasks.withType { - kotlinOptions { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) allWarningsAsErrors = true } } afterEvaluate { this.configure { - targetCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_17 } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 39577a15605..06404b57448 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java") - kotlin("jvm").version("1.7.22") + kotlin("jvm").version("2.0.21") } repositories { diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index d47ea75c2bf..97d5ba96046 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -1,8 +1,8 @@ object Versions { - const val coroutines = "1.5.0" - const val kotlin = "1.7.22" - const val apollo = "2.5.7" - const val okhttp = "3.8.1" + const val coroutines = "1.7.3" + const val kotlin = "2.0.21" + const val apollo = "4.0.1" + const val okhttp = "4.12.0" const val dokka = "1.4.32" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 943f0cbfa75..e6441136f3d 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b22d057a07..b82aa23a4f0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 65dcd68d65c..1aa94a42690 100755 --- a/gradlew +++ b/gradlew @@ -83,10 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f135..25da30dbdee 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/kinta-cli/build.gradle.kts b/kinta-cli/build.gradle.kts index 58a83857b1e..aa99f4f7c84 100644 --- a/kinta-cli/build.gradle.kts +++ b/kinta-cli/build.gradle.kts @@ -30,6 +30,6 @@ dependencies { } application { - mainClassName = "com.dailymotion.kinta.MainKt" + mainClass.set("com.dailymotion.kinta.MainKt") applicationName = "kinta" } \ No newline at end of file diff --git a/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Constants.kt b/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Constants.kt index b428832903a..106a5223e6e 100644 --- a/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Constants.kt +++ b/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Constants.kt @@ -16,7 +16,7 @@ object Constants { .get() .build() .let { - OkHttpClient().newCall(it).execute().body()!!.string() + OkHttpClient().newCall(it).execute().body!!.string() }.let { Version(it) } diff --git a/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Downloader.kt b/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Downloader.kt index afbfb1df17b..0b6c859bbbd 100644 --- a/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Downloader.kt +++ b/kinta-cli/src/main/kotlin/com/dailymotion/kinta/infra/Downloader.kt @@ -1,6 +1,5 @@ package com.dailymotion.kinta.infra -import kotlinx.serialization.json.Json import okhttp3.OkHttpClient import okhttp3.Request import java.io.File @@ -11,7 +10,7 @@ object Downloader { .get() .build() .let { - OkHttpClient().newCall(it).execute().body()!!.byteStream().use {inputStream -> + OkHttpClient().newCall(it).execute().body!!.byteStream().use {inputStream -> output.outputStream().use { outputStream -> inputStream.copyTo(outputStream) } diff --git a/kinta-cli/src/main/resources/build.gradle.kts b/kinta-cli/src/main/resources/build.gradle.kts index d76e4bbb7b4..3f2da6f7d45 100644 --- a/kinta-cli/src/main/resources/build.gradle.kts +++ b/kinta-cli/src/main/resources/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("org.jetbrains.kotlin.jvm").version("1.7.22") + id("org.jetbrains.kotlin.jvm").version("2.0.21") } repositories { diff --git a/kinta-lib/build.gradle.kts b/kinta-lib/build.gradle.kts index 5a0290e0f8a..36ad8214e13 100644 --- a/kinta-lib/build.gradle.kts +++ b/kinta-lib/build.gradle.kts @@ -14,7 +14,6 @@ dependencies { implementation(Libs.coroutines) implementation(Libs.apollo) - implementation(Libs.apolloCoroutinesSupport) implementation(Libs.nanoHttp) @@ -32,8 +31,9 @@ dependencies { } apollo { - generateKotlinModels.set(true) - useSemanticNaming.set(false) + service("service") { + packageName.set("com.dailymotion.kinta") + } } diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/helper/OkHttpHelper.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/helper/OkHttpHelper.kt index f4d77bf6b66..9540a9134ef 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/helper/OkHttpHelper.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/helper/OkHttpHelper.kt @@ -17,12 +17,12 @@ fun newOkHttpClient(): OkHttpClient { } fun Request.executeOrFail( - errorMessage: String = "Cannot execute ${this.url()}", + errorMessage: String = "Cannot execute ${this.url}", okHttpClient: OkHttpClient = newOkHttpClient()): ResponseBody { val response = okHttpClient.newCall(this).execute() - if (response.isSuccessful && response.body() != null) { - return response.body()!! + if (response.isSuccessful && response.body != null) { + return response.body!! } else { - throw IllegalStateException("$errorMessage :\n${response.body()?.string()}") + throw IllegalStateException("$errorMessage :\n${response.body?.string()}") } } \ No newline at end of file diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appcenter/AppCenter.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appcenter/AppCenter.kt deleted file mode 100644 index 47b6373dd85..00000000000 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appcenter/AppCenter.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.dailymotion.kinta.integration.appcenter - -import com.dailymotion.kinta.KintaEnv -import com.dailymotion.kinta.Logger -import com.dailymotion.kinta.helper.executeOrFail -import com.dailymotion.kinta.helper.newOkHttpClient -import kotlinx.serialization.json.* -import okhttp3.* -import java.io.File - -@Suppress("NAME_SHADOWING") -object AppCenter { - val json = Json { - ignoreUnknownKeys = true - } - - fun uploadApp( - token: String? = null, - organization: String? = null, - appId: String, - destinationName: String, - file: File, - changelog: String?) { - - val token = token ?: KintaEnv.getOrFail(KintaEnv.Var.APPCENTER_TOKEN) - val organisation = organization ?: KintaEnv.getOrFail(KintaEnv.Var.APPCENTER_ORGANIZATION) - - val request = Request.Builder() - .header("Content-Type", "application/json") - .header("Accept", "application/json") - .header("X-API-Token", token) - .post(RequestBody.create(null, ByteArray(0))) - .url("https://api.appcenter.ms/v0.1/apps/$organisation/$appId/release_uploads") - .build() - - Logger.i("Getting AppCenter upload url...") - val response = request.executeOrFail() - - val uploadUrlData = json.parseToJsonElement(response.string()).jsonObject - - val fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), file) - val builderUpload = MultipartBody.Builder() - .setType(MediaType.parse("multipart/form-data")!!) - .addFormDataPart("ipa", file.name, fileBody) - val requestUpload = Request.Builder() - .post(builderUpload.build()) - .url(uploadUrlData["upload_url"]?.jsonPrimitive?.content ?: error("cannot find upload_url")) - .build() - - Logger.i("Uploading...") - requestUpload.executeOrFail() - - Logger.i("Upload OK ! Committing...") - val requestCommit = Request.Builder() - .header("Content-Type", "application/json") - .header("Accept", "application/json") - .header("X-API-Token", token) - .patch(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{ \"status\" : \"committed\" }")) - .url("https://api.appcenter.ms/v0.1/apps/$organisation/$appId/release_uploads/${uploadUrlData["upload_id"]?.jsonPrimitive?.content}") - .build() - - val commitBody = requestCommit.executeOrFail() - - val releaseData = json.parseToJsonElement(commitBody.string()).jsonObject - - Logger.i("Commited ! Updating release notes...") - val postData = JsonObject( - mapOf( - "destination_name" to JsonPrimitive(destinationName), - "release_notes" to JsonPrimitive(changelog) - ) - ) - - val requestReleaseNotes = Request.Builder() - .header("Content-Type", "application/json") - .header("Accept", "application/json") - .header("X-API-Token", token) - .patch(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), postData.toString())) - .url("https://api.appcenter.ms/${releaseData["release_url"]?.jsonPrimitive?.content}") - .build() - - requestReleaseNotes.executeOrFail() - Logger.i("Release notes updated") - } - - fun uploadDsym( - token: String? = null, - organization: String? = null, - appId: String, - dsymFile: File - ) { - val token = token ?: KintaEnv.getOrFail(KintaEnv.Var.APPCENTER_TOKEN) - val organisation = organization ?: KintaEnv.getOrFail(KintaEnv.Var.APPCENTER_ORGANIZATION) - - val postData = JsonObject(mapOf( - "symbol_type" to JsonPrimitive("Apple") - )) - val requestBody = RequestBody.create( - MediaType.parse("application/json; charset=utf-8"), - postData.toString() - ) - - val request = Request.Builder() - .header("Content-Type", "application/json") - .header("Accept", "application/json") - .header("X-API-Token", token) - .post(requestBody) - .url("https://api.appcenter.ms/v0.1/apps/$organisation/$appId/symbol_uploads") - .build() - - val body = request.executeOrFail() - - val uploadUrlData = json.parseToJsonElement(body.string()).jsonObject - - val uploadRequest = Request.Builder() - .url(uploadUrlData["upload_url"]?.jsonPrimitive?.content ?: error("no upload_url")) - .put(RequestBody.create(MediaType.parse("application/octet-stream"), dsymFile)) - .header("x-ms-blob-type", "BlockBlob") - .build() - - uploadRequest.executeOrFail() - - val postData2 = JsonObject(mapOf( - "status" to JsonPrimitive("committed") - )) - val requestBody2 = RequestBody.create( - MediaType.parse("application/json; charset=utf-8"), - postData2.toString() - ) - - val symbol_upload_id = uploadUrlData["symbol_upload_id"]?.jsonPrimitive?.content - val url = "https://api.appcenter.ms/v0.1/apps/$organisation/$appId/symbol_uploads/$symbol_upload_id" - - val patchRequest = Request.Builder() - .header("Accept", "application/json") - .header("X-API-Token", token) - .url(url) - .patch(requestBody2) - .build() - - patchRequest.executeOrFail() - } -} \ No newline at end of file diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appgallery/AppGalleryIntegration.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appgallery/AppGalleryIntegration.kt index 2d5dbc3f550..1ee64d549be 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appgallery/AppGalleryIntegration.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/appgallery/AppGalleryIntegration.kt @@ -2,20 +2,30 @@ package com.dailymotion.kinta.integration.appgallery import com.dailymotion.kinta.KintaEnv import com.dailymotion.kinta.Logger +import com.dailymotion.kinta.globalJson import com.dailymotion.kinta.helper.ProgressRequestBody -import com.dailymotion.kinta.integration.appgallery.internal.* +import com.dailymotion.kinta.integration.appgallery.internal.AppGalleryService +import com.dailymotion.kinta.integration.appgallery.internal.ChangelogBody +import com.dailymotion.kinta.integration.appgallery.internal.ListingBody +import com.dailymotion.kinta.integration.appgallery.internal.TokenBody +import com.dailymotion.kinta.integration.appgallery.internal.UploadData import com.dailymotion.kinta.integration.googleplay.internal.GooglePlayIntegration -import com.dailymotion.kinta.globalJson import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.* -import okhttp3.* +import kotlinx.serialization.json.JsonObject +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.MultipartBody +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody import retrofit2.Retrofit import java.io.File object AppGalleryIntegration { - private val JSON = MediaType.parse("application/json; charset=utf-8") + private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull() private const val API_URL = "https://connect-api.cloud.huawei.com/api/" @OptIn(ExperimentalSerializationApi::class) @@ -36,7 +46,7 @@ object AppGalleryIntegration { val retrofit = Retrofit.Builder() .baseUrl(API_URL) .client(okHttpClient) - .addConverterFactory(globalJson.asConverterFactory(MediaType.get("application/json"))) + .addConverterFactory(globalJson.asConverterFactory("application/json".toMediaType())) .build() return retrofit.create(AppGalleryService::class.java) @@ -93,7 +103,9 @@ object AppGalleryIntegration { val token = KintaEnv.get(KintaEnv.Var.APPGALLERY_TOKEN) ?: acquireToken(clientId, clientSecret) Logger.i("Submitting app to AppGallery...") - val result = service(clientId, token).submit(appId, "1", RequestBody.create(JSON, JsonObject(mapOf()).toString())).execute() + val result = service(clientId, token).submit(appId, "1", + JsonObject(mapOf()).toString().toRequestBody(JSON) + ).execute() if(result.body()?.isSuccess() ?: false == false){ val error = result.body()?.ret ?: result.errorBody()?.string() ?: result.code() @@ -259,18 +271,21 @@ object AppGalleryIntegration { fileName: String, file: File ): String { - val mediaType = MediaType.parse("application/vnd.android.package-archive") + val mediaType = "application/vnd.android.package-archive".toMediaTypeOrNull() Logger.i("Uploading file to AppGallery...") val result = service(clientId, token).upload(uploadData.uploadUrl, - MultipartBody.Part.createFormData("file", fileName, ProgressRequestBody(RequestBody.create(mediaType, file), object : ProgressRequestBody.Listener { + MultipartBody.Part.createFormData("file", fileName, ProgressRequestBody( + file.asRequestBody( + mediaType + ), object : ProgressRequestBody.Listener { override fun onProgress(progress: Int) { Logger.d("Upload progress $progress") } })), - RequestBody.create(okhttp3.MultipartBody.FORM, fileName), - RequestBody.create(okhttp3.MultipartBody.FORM, uploadData.authCode), - RequestBody.create(okhttp3.MultipartBody.FORM, "1") + fileName.toRequestBody(MultipartBody.FORM), + uploadData.authCode.toRequestBody(MultipartBody.FORM), + "1".toRequestBody(MultipartBody.FORM) ).execute() result.body()?.result?.uploadFileRsp?.fileInfoList?.let { diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/bitrise/Bitrise.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/bitrise/Bitrise.kt index ea168e742f9..7c3ffd625b0 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/bitrise/Bitrise.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/bitrise/Bitrise.kt @@ -5,11 +5,15 @@ import com.dailymotion.kinta.Logger import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString -import kotlinx.serialization.json.* -import okhttp3.MediaType +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody object Bitrise { @@ -39,7 +43,7 @@ object Bitrise { )) val bodyAsString = body.toString() - val requestBody = RequestBody.create(MediaType.parse("application/json"), bodyAsString) + val requestBody = bodyAsString.toRequestBody("application/json".toMediaTypeOrNull()) val request = Request.Builder() .header("Authorization", "token $token_") @@ -50,9 +54,9 @@ object Bitrise { val response = OkHttpClient().newCall(request).execute() if (!response.isSuccessful) { - throw Exception("cannot trigger build: ${response.code()}: ${response.body()!!.string()}") + throw Exception("cannot trigger build: ${response.code}: ${response.body!!.string()}") } else { - response.body()?.string()?.let { + response.body?.string()?.let { val element = json.parseToJsonElement(it) val buildUrl = element.jsonObject["build_url"]?.jsonPrimitive?.content @@ -73,15 +77,15 @@ object Bitrise { val response = OkHttpClient().newCall(request).execute() if (!response.isSuccessful) { - throw Exception("cannot get app list: ${response.code()}: ${response.body()!!.string()}") + throw Exception("cannot get app list: ${response.code}: ${response.body!!.string()}") } else { - response.body()?.string()?.let { data -> + response.body?.string()?.let { data -> val list: AppsListResponse = json.decodeFromString(data) return list.data.find { it.repo_slug == repoName }?.slug ?: throw Exception("app not found. Current repo is ${repoName}") } } - throw Exception("error parsing app list: ${response.code()}: ${response.body()!!.string()}") + throw Exception("error parsing app list: ${response.code}: ${response.body!!.string()}") } @OptIn(ExperimentalSerializationApi::class) @@ -102,14 +106,14 @@ object Bitrise { val response = OkHttpClient().newCall(request).execute() if (!response.isSuccessful) { - throw Exception("cannot get workflows list: ${response.code()}: ${response.body()!!.string()}") + throw Exception("cannot get workflows list: ${response.code}: ${response.body!!.string()}") } - response.body()?.string()?.let { data -> + response.body?.string()?.let { data -> val list: WorkflowsResponse = json.decodeFromString(data) return list.data } - throw Exception("error parsing workflows list: ${response.code()}: ${response.body()!!.string()}") + throw Exception("error parsing workflows list: ${response.code}: ${response.body!!.string()}") } @Serializable diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/GithubIntegration.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/GithubIntegration.kt index 65786ea8408..8369ba3d087 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/GithubIntegration.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/GithubIntegration.kt @@ -1,10 +1,10 @@ package com.dailymotion.kinta.integration.github import com.apollographql.apollo.ApolloClient -import com.apollographql.apollo.coroutines.await -import com.dailymotion.kinta.GetPullRequestWithBase -import com.dailymotion.kinta.GetPullRequestWithHead -import com.dailymotion.kinta.GetRefs +import com.apollographql.apollo.network.okHttpClient +import com.dailymotion.kinta.GetPullRequestWithBaseQuery +import com.dailymotion.kinta.GetPullRequestWithHeadQuery +import com.dailymotion.kinta.GetRefsQuery import com.dailymotion.kinta.GitTool import com.dailymotion.kinta.KintaEnv import com.dailymotion.kinta.Logger @@ -26,10 +26,11 @@ import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.asRequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okio.ByteString.Companion.encodeUtf8 import org.eclipse.jgit.api.Git import org.eclipse.jgit.transport.URIish @@ -71,7 +72,7 @@ object GithubIntegration : GitTool { ) ) - val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()) + val body = jsonObject.toString().toRequestBody("application/json".toMediaTypeOrNull()) val request = Request.Builder() .url("https://api.github.com/repos/$owner/$repo/pulls") @@ -81,10 +82,10 @@ object GithubIntegration : GitTool { Logger.i("creating pull request to merge $head into $base") val response = httpClient(token).newCall(request).execute() if (!response.isSuccessful) { - throw Exception(response.body()?.string() ?: "") + throw Exception(response.body?.string() ?: "") } - return response.body()?.charStream()?.let { + return response.body?.charStream()?.let { try { val htmlUrl = json.parseToJsonElement(it.readText()).jsonObject["html_url"]?.jsonPrimitive?.content Logger.i("-> $htmlUrl") @@ -110,17 +111,17 @@ object GithubIntegration : GitTool { val repo_ = repo ?: repository(remote).name val depdendentPullRequestsData = runBlocking { - val query = GetPullRequestWithBase(owner_, repo_, branch) + val query = GetPullRequestWithBaseQuery(owner_, repo_, branch) apolloClient(token_).query(query) - .await() + .execute() .data ?.repository } val pullRequestsData = runBlocking { - val query = GetPullRequestWithHead(owner_, repo_, branch) + val query = GetPullRequestWithHeadQuery(owner_, repo_, branch) apolloClient(token_).query(query) - .await() + .execute() .data ?.repository } @@ -155,7 +156,7 @@ object GithubIntegration : GitTool { val response = httpClient(token_).newCall(request).execute() if (!response.isSuccessful) { - throw Exception(response.body()?.string() ?: "") + throw Exception(response.body?.string() ?: "") } } @@ -170,9 +171,9 @@ object GithubIntegration : GitTool { val repo = repo ?: repository().name return runBlocking { - val query = GetRefs(owner, repo) + val query = GetRefsQuery(owner, repo) apolloClient(token).query(query) - .await() + .execute() .data ?.repository ?.refs @@ -184,7 +185,7 @@ object GithubIntegration : GitTool { } fun apolloClient(token: String): ApolloClient { - return ApolloClient.builder() + return ApolloClient.Builder() .serverUrl("https://api.github.com/graphql") .okHttpClient(httpClient(token)) .build() @@ -256,16 +257,16 @@ object GithubIntegration : GitTool { ) val request = Request.Builder() - .post(RequestBody.create(MediaType.parse("application/json"), JsonObject(input).toString())) + .post(JsonObject(input).toString().toRequestBody("application/json".toMediaTypeOrNull())) .url("https://api.github.com/repos/$owner/$repo/releases") .build() val response = httpClient(token).newCall(request).execute() if (!response.isSuccessful) { - throw Exception("cannot create github release: ${response.body()?.string()}") + throw Exception("cannot create github release: ${response.body?.string()}") } - val responseString = response.body()!!.string() + val responseString = response.body!!.string() val release = json.parseToJsonElement(responseString).jsonObject @@ -276,13 +277,13 @@ object GithubIntegration : GitTool { .expand() val request2 = Request.Builder() - .post(RequestBody.create(MediaType.parse("application/zip"), asset)) + .post(asset.asRequestBody("application/zip".toMediaTypeOrNull())) .url(uploadUrl) .build() val response2 = httpClient(token).newCall(request2).execute() check(response2.isSuccessful) { - "cannot upload asset: ${response2.body()?.string()}" + "cannot upload asset: ${response2.body?.string()}" } } } @@ -309,10 +310,10 @@ object GithubIntegration : GitTool { } check(response.isSuccessful) { - "cannot retrieve key: ${response.body()?.byteStream()?.reader()?.readText()}" + "cannot retrieve key: ${response.body?.byteStream()?.reader()?.readText()}" } - val json = response.body()?.byteStream()?.reader()?.readText() ?: "" + val json = response.body?.byteStream()?.reader()?.readText() ?: "" return this.json.decodeFromString(json) } @@ -349,7 +350,7 @@ object GithubIntegration : GitTool { )) val response = Request.Builder() - .put(RequestBody.create(MediaType.parse("application/json"), jsonObject.toString())) + .put(jsonObject.toString().toRequestBody("application/json".toMediaTypeOrNull())) .url("https://api.github.com/repos/$owner/$repo/actions/secrets/$name") .build() .let { @@ -357,7 +358,7 @@ object GithubIntegration : GitTool { } check(response.isSuccessful) { - "cannot set secret $name: ${response.body()?.byteStream()?.reader()?.readText()}" + "cannot set secret $name: ${response.body?.byteStream()?.reader()?.readText()}" } } @@ -380,7 +381,7 @@ object GithubIntegration : GitTool { } check(response.isSuccessful) { - "cannot delete secret $name: ${response.body()?.byteStream()?.reader()?.readText()}" + "cannot delete secret $name: ${response.body?.byteStream()?.reader()?.readText()}" } } @@ -399,7 +400,7 @@ object GithubIntegration : GitTool { mapOf("assignees" to JsonArray(assignees.map { JsonPrimitive(it) })) ) - val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()) + val body = jsonObject.toString().toRequestBody("application/json".toMediaTypeOrNull()) val request = Request.Builder() .url("https://api.github.com/repos/$owner/$repo/issues/$issue/assignees") @@ -409,7 +410,7 @@ object GithubIntegration : GitTool { Logger.i("Assigning...") val response = httpClient(token).newCall(request).execute() if (!response.isSuccessful) { - throw Exception(response.body()?.string() ?: "") + throw Exception(response.body?.string() ?: "") } } } \ No newline at end of file diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/internal/GithubOauthClient.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/internal/GithubOauthClient.kt index a65f7f50d01..13a8ca8e91e 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/internal/GithubOauthClient.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/github/internal/GithubOauthClient.kt @@ -6,10 +6,10 @@ import fi.iki.elonen.NanoHTTPD import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider import java.io.File import java.security.SecureRandom @@ -68,7 +68,7 @@ object GithubOauthClient { "&code=$code" val request = Request.Builder() - .post(RequestBody.create(MediaType.parse("text/plain"), "")) + .post("".toRequestBody("text/plain".toMediaTypeOrNull())) .url(postUrl) .header("Accept", "application/json") .build() @@ -88,9 +88,10 @@ object GithubOauthClient { if (!response.isSuccessful) { throw Exception("cannot exchange code") } + val json = Json { ignoreUnknownKeys = true } synchronized(lock) { - token = Json { ignoreUnknownKeys = true }.parseToJsonElement(response.body()!!.string()) + token = json.parseToJsonElement(response.body!!.string()) .jsonObject["access_token"] ?.jsonPrimitive ?.content diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/gitlab/GitlabIntegration.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/gitlab/GitlabIntegration.kt index 87cac2783cf..e99b71c4462 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/gitlab/GitlabIntegration.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/gitlab/GitlabIntegration.kt @@ -15,7 +15,7 @@ import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.Interceptor -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Response import org.eclipse.jgit.api.Git @@ -39,7 +39,7 @@ object GitlabIntegration : GitTool { val retrofit = Retrofit.Builder() .baseUrl(GITLAB_API) .client(okHttpClient) - .addConverterFactory(json.asConverterFactory(MediaType.get("application/json"))) + .addConverterFactory(json.asConverterFactory("application/json".toMediaType())) .build() return retrofit.create(GitlabService::class.java) diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/jira/Jira.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/jira/Jira.kt index d8b46341664..53981e5917c 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/jira/Jira.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/jira/Jira.kt @@ -3,15 +3,20 @@ package com.dailymotion.kinta.integration.jira import com.dailymotion.kinta.KintaEnv import com.dailymotion.kinta.Logger import com.dailymotion.kinta.globalJson -import com.dailymotion.kinta.integration.jira.internal.* +import com.dailymotion.kinta.integration.jira.internal.AssignBody +import com.dailymotion.kinta.integration.jira.internal.CommentBody +import com.dailymotion.kinta.integration.jira.internal.Issue +import com.dailymotion.kinta.integration.jira.internal.JiraService +import com.dailymotion.kinta.integration.jira.internal.Transition +import com.dailymotion.kinta.integration.jira.internal.TransitionBody import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import kotlinx.serialization.ExperimentalSerializationApi import okhttp3.Interceptor -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient import okhttp3.Response import retrofit2.Retrofit -import java.util.* +import java.util.Base64 object Jira { @@ -32,7 +37,7 @@ object Jira { val retrofit = Retrofit.Builder() .baseUrl(jiraUrl_) .client(okHttpClient) - .addConverterFactory(globalJson.asConverterFactory(MediaType.get("application/json"))) + .addConverterFactory(globalJson.asConverterFactory("application/json".toMediaType())) .build() return retrofit.create(JiraService::class.java) diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/lokalise/Lokalise.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/lokalise/Lokalise.kt index a0033e43120..4fa73039574 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/lokalise/Lokalise.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/lokalise/Lokalise.kt @@ -14,9 +14,9 @@ import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFact import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import java.io.Closeable @@ -102,7 +102,7 @@ object Lokalise { projectId: String, payload: LkUploadPayload, ) { - val requestBody = RequestBody.create(MediaType.get("application/json"), Gson().toJson(payload)) + val requestBody = Gson().toJson(payload).toRequestBody("application/json".toMediaType()) val response = service(token).requestUpload( projectId = projectId, requestBody = requestBody, @@ -119,7 +119,7 @@ object Lokalise { payload: LkDownloadPayload, ): LokaliseDownloadResponse { - val requestBody = RequestBody.create(MediaType.get("application/json"), Gson().toJson(payload)) + val requestBody = Gson().toJson(payload).toRequestBody("application/json".toMediaType()) val response = service(token).requestDownload( projectId = project, requestBody = requestBody @@ -185,7 +185,7 @@ object Lokalise { val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .client(okHttpClient) - .addConverterFactory(globalJson.asConverterFactory(MediaType.get("application/json"))) + .addConverterFactory(globalJson.asConverterFactory("application/json".toMediaType())) .build() return retrofit.create(LokaliseService::class.java) diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/slack/Slack.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/slack/Slack.kt index 8e4f2672aae..a4d4dd303b6 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/slack/Slack.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/slack/Slack.kt @@ -2,13 +2,12 @@ package com.dailymotion.kinta.integration.slack import com.dailymotion.kinta.KintaEnv import com.dailymotion.kinta.Logger -import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonPrimitive -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.OkHttpClient import okhttp3.Request -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody object Slack { @@ -38,7 +37,7 @@ object Slack { ) ) - val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()) + val body = jsonObject.toString().toRequestBody("application/json".toMediaTypeOrNull()) Logger.i("Sending slack notification") @@ -53,7 +52,7 @@ object Slack { .execute() if (!response.isSuccessful) { - Logger.e("cannot send notif ${response.code()}:\n${response.body()?.string()}") + Logger.e("cannot send notif ${response.code}:\n${response.body?.string()}") } } } \ No newline at end of file diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/transifex/Transifex.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/transifex/Transifex.kt index 16ca4db3630..ffad1c5922e 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/transifex/Transifex.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/transifex/Transifex.kt @@ -11,9 +11,9 @@ import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFact import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive -import okhttp3.MediaType +import okhttp3.MediaType.Companion.toMediaType import okhttp3.OkHttpClient -import okhttp3.RequestBody +import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import java.util.concurrent.TimeUnit @@ -81,7 +81,7 @@ object Transifex { * automatically added, and the API will return a 500 error. * By converting the data to byteArray, we avoid this behavior **/ val dataByteArray = Gson().toJson(payload).toByteArray() - val requestBody = RequestBody.create(MediaType.get("application/vnd.api+json"), dataByteArray) + val requestBody = dataByteArray.toRequestBody("application/vnd.api+json".toMediaType(), 0, dataByteArray.size) val response = service(token).requestUploadResource(payload.data.type, requestBody).execute() check (response.isSuccessful) { @@ -229,7 +229,7 @@ object Transifex { * automatically added, and the API will return a 500 error. * By converting the data to byteArray, we avoid this behavior **/ val dataByteArray = Gson().toJson(payload).toByteArray() - val requestBody = RequestBody.create(MediaType.get("application/vnd.api+json"), dataByteArray) + val requestBody = dataByteArray.toRequestBody("application/vnd.api+json".toMediaType(), 0, dataByteArray.size) val response = service(token).requestDownloadTranslation(payload.data.type, requestBody).execute() check (response.isSuccessful) { @@ -309,7 +309,7 @@ object Transifex { val retrofit = Retrofit.Builder() .baseUrl("https://rest.api.transifex.com/") .client(okHttpClient) - .addConverterFactory(globalJson.asConverterFactory(MediaType.get("application/json"))) + .addConverterFactory(globalJson.asConverterFactory("application/json".toMediaType())) .build() return retrofit.create(TransifexService::class.java) diff --git a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/travis/TravisIntegration.kt b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/travis/TravisIntegration.kt index aabb3ab9eca..7c5619c4025 100644 --- a/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/travis/TravisIntegration.kt +++ b/kinta-lib/src/main/kotlin/com/dailymotion/kinta/integration/travis/TravisIntegration.kt @@ -1,14 +1,13 @@ package com.dailymotion.kinta.integration.travis import com.dailymotion.kinta.globalJson -import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.OkHttpClient import okhttp3.Request import java.security.KeyFactory import java.security.spec.X509EncodedKeySpec -import java.util.* +import java.util.Base64 import javax.crypto.Cipher object TravisIntegration { @@ -30,7 +29,7 @@ object TravisIntegration { return "https://api.travis-ci.org/repos/$repoOwner/$repoName/key".let { Request.Builder().get().url(it) }.let { - OkHttpClient().newCall(it.build()).execute().body()!!.string() + OkHttpClient().newCall(it.build()).execute().body!!.string() }.let { globalJson.parseToJsonElement(it).jsonObject["key"]?.jsonPrimitive?.content!! } diff --git a/settings.gradle.kts b/settings.gradle.kts index d48caee884e..fb75c0c7e28 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,7 +11,7 @@ pluginManagement { resolutionStrategy { eachPlugin { - if (requested.id.namespace == "com.apollographql") { + if (requested.id.namespace == "com.apollographql.apollo") { useModule("com.apollographql.apollo:apollo-gradle-plugin:${requested.version}") } if (requested.id.id == "org.jetbrains.dokka") {