From 75cc49d51f3aa4e64a80b81a2b230a5e7563db6e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 23 Dec 2021 12:45:29 +0530 Subject: [PATCH] Increase timeouts for Crowdin API build task (#1602) --- .../src/main/kotlin/crowdin/CrowdinPlugin.kt | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/build-logic/automation-plugins/src/main/kotlin/crowdin/CrowdinPlugin.kt b/build-logic/automation-plugins/src/main/kotlin/crowdin/CrowdinPlugin.kt index 580fc939..c6542725 100644 --- a/build-logic/automation-plugins/src/main/kotlin/crowdin/CrowdinPlugin.kt +++ b/build-logic/automation-plugins/src/main/kotlin/crowdin/CrowdinPlugin.kt @@ -7,6 +7,7 @@ package crowdin import de.undercouch.gradle.tasks.download.Download import java.io.File +import java.util.concurrent.TimeUnit import javax.xml.parsers.DocumentBuilderFactory import okhttp3.OkHttpClient import okhttp3.Request @@ -34,26 +35,33 @@ class CrowdinDownloadPlugin : Plugin { if (projectName.isEmpty()) { throw GradleException(EXCEPTION_MESSAGE) } - tasks.register("buildOnApi") { - doLast { - val login = providers.environmentVariable("CROWDIN_LOGIN").forUseAtConfigurationTime() - val key = - providers.environmentVariable("CROWDIN_PROJECT_KEY").forUseAtConfigurationTime() - if (!login.isPresent) { - throw GradleException("CROWDIN_LOGIN environment variable must be set") + val buildOnApi = + tasks.register("buildOnApi") { + doLast { + val login = providers.environmentVariable("CROWDIN_LOGIN").forUseAtConfigurationTime() + val key = + providers.environmentVariable("CROWDIN_PROJECT_KEY").forUseAtConfigurationTime() + if (!login.isPresent) { + throw GradleException("CROWDIN_LOGIN environment variable must be set") + } + if (!key.isPresent) { + throw GradleException("CROWDIN_PROJECT_KEY environment variable must be set") + } + val client = + OkHttpClient.Builder() + .connectTimeout(5, TimeUnit.SECONDS) + .writeTimeout(5, TimeUnit.SECONDS) + .readTimeout(5, TimeUnit.SECONDS) + .callTimeout(10, TimeUnit.SECONDS) + .build() + val url = CROWDIN_BUILD_API_URL.format(projectName, login.get(), key.get()) + val request = Request.Builder().url(url).get().build() + client.newCall(request).execute() } - if (!key.isPresent) { - throw GradleException("CROWDIN_PROJECT_KEY environment variable must be set") - } - val client = OkHttpClient() - val url = CROWDIN_BUILD_API_URL.format(projectName, login.get(), key.get()) - val request = Request.Builder().url(url).get().build() - client.newCall(request).execute() } - } val downloadCrowdin = tasks.register("downloadCrowdin") { - dependsOn("buildOnApi") + dependsOn(buildOnApi) src("https://crowdin.com/backend/download/project/$projectName.zip") dest("$buildDirectory/translations.zip") overwrite(true)