diff options
-rw-r--r-- | buildSrc/build.gradle.kts | 1 | ||||
-rw-r--r-- | buildSrc/src/main/java/CrowdinDownloadPlugin.kt | 18 | ||||
-rw-r--r-- | gradle/libs.versions.toml | 1 |
3 files changed, 20 insertions, 0 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index abdc6def..003bbd6f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -45,5 +45,6 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0") implementation("com.ncorti.ktfmt.gradle:plugin:0.5.0") implementation("com.vanniktech:gradle-maven-publish-plugin:0.13.0") + implementation("com.squareup.okhttp3:okhttp:4.9.0") implementation("com.vdurmont:semver4j:3.1.0") } diff --git a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt index 7a0f9d95..e8bf7b5b 100644 --- a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt +++ b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt @@ -6,6 +6,8 @@ import de.undercouch.gradle.tasks.download.Download import java.io.File import javax.xml.parsers.DocumentBuilderFactory +import okhttp3.OkHttpClient +import okhttp3.Request import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project @@ -16,6 +18,7 @@ import org.w3c.dom.Document private const val EXCEPTION_MESSAGE = """Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension.""" +private const val CROWDIN_BUILD_API_URL = "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s" class CrowdinDownloadPlugin : Plugin<Project> { @@ -27,7 +30,22 @@ class CrowdinDownloadPlugin : Plugin<Project> { if (projectName.isEmpty()) { throw GradleException(EXCEPTION_MESSAGE) } + tasks.register("buildOnApi") { + 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() + val url = CROWDIN_BUILD_API_URL.format(projectName, login.get(), key.get()) + val request = Request.Builder().url(url).get().build() + client.newCall(request).execute() + } tasks.register<Download>("downloadCrowdin") { + setDependsOn(setOf("buildOnApi")) src("https://crowdin.com/backend/download/project/$projectName.zip") dest("$buildDir/translations.zip") overwrite(true) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 65d8efdc..243acd67 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,7 @@ hiltGradlePlugin = { module = "com.google.dagger:hilt-android-gradle-plugin", ve kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } ktfmtGradlePlugin = "com.ncorti.ktfmt.gradle:plugin:0.5.0" mavenPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.13.0" +okhttp = "com.squareup.okhttp3:okhttp:4.9.0" semver4j = "com.vdurmont:semver4j:3.1.0" # Kotlin dependencies |