├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── values-ja │ │ │ │ └── strings.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── cookpad │ │ │ │ └── android │ │ │ │ └── onesky │ │ │ │ └── app │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── cookpad │ │ │ └── android │ │ │ └── onesky │ │ │ └── app │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── cookpad │ │ └── android │ │ └── onesky │ │ └── app │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── plugin ├── .gitignore ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── gradle-plugins │ │ │ │ └── com.cookpad.android.onesky.plugin.properties │ │ └── java │ │ │ └── com │ │ │ └── cookpad │ │ │ └── android │ │ │ └── onesky │ │ │ └── plugin │ │ │ ├── Files.kt │ │ │ ├── OneskyExtension.kt │ │ │ ├── client │ │ │ ├── HttpClient.kt │ │ │ └── Onesky.kt │ │ │ ├── GsonProvider.kt │ │ │ ├── OneskyPlugin.kt │ │ │ └── tasks │ │ │ ├── UploadTranslationTask.kt │ │ │ ├── UploadTranslationAndMarkAsDeprecatedTask.kt │ │ │ ├── DownloadTranslationTask.kt │ │ │ └── ShowTranslationProgressTask.kt │ └── test │ │ └── java │ │ └── com │ │ └── cookpad │ │ └── android │ │ └── onesky │ │ └── plugin │ │ ├── FilesTest.kt │ │ └── client │ │ └── OneskyTest.kt └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── MIT.LICENSE.txt ├── CHANGES.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /plugin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':plugin', ':app' 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | App 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values-ja/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | アプリ 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /plugin/src/main/resources/META-INF/gradle-plugins/com.cookpad.android.onesky.plugin.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.cookpad.android.onesky.plugin.OneskyPlugin -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cookpad/onesky-gradle-plugin/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .idea 11 | credentials.gradle 12 | repo 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/Files.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin 2 | 3 | internal fun valuesDirNameFromLocale(locale: String): String { 4 | return "values-${locale.replace("id", "in").replace("-", "-r")}" 5 | } 6 | 7 | internal fun localeFromValuesDirName(dirName: String): String { 8 | return dirName.replace("values-", "").replace("in", "id").replace("-r", "-") 9 | } 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/cookpad/android/onesky/app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.app 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | import com.cookpad.android.onesky.app.R 6 | 7 | class MainActivity : AppCompatActivity() { 8 | 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | setContentView(R.layout.activity_main) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/OneskyExtension.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin 2 | 3 | import org.gradle.api.tasks.Input 4 | 5 | internal open class OneskyExtension { 6 | @Input 7 | var apiKey: String = "" 8 | @Input 9 | var apiSecret: String = "" 10 | @Input 11 | var projectId: Int = 0 12 | @Input 13 | var locales: Set = setOf() 14 | 15 | fun locales(locales: Array) { 16 | this.locales = locales.toSet() 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /app/src/test/java/com/cookpad/android/onesky/app/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.app; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/cookpad/android/onesky/app/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.app 2 | 3 | import android.content.Context 4 | import android.support.test.InstrumentationRegistry 5 | import android.support.test.runner.AndroidJUnit4 6 | 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | 10 | import org.junit.Assert.* 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | 15 | * @see [Testing documentation](http://d.android.com/tools/testing) 16 | */ 17 | @RunWith(AndroidJUnit4::class) 18 | class ExampleInstrumentedTest { 19 | @Test 20 | @Throws(Exception::class) 21 | fun useAppContext() { 22 | // Context of the rejasupotaro.onesky.app under test. 23 | val appContext = InstrumentationRegistry.getTargetContext() 24 | 25 | assertEquals("com.cookpad.android.onesky.app", appContext.packageName) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/client/HttpClient.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.client 2 | 3 | import com.github.kittinunf.fuel.Fuel 4 | import com.github.kittinunf.fuel.core.FileDataPart 5 | import com.github.kittinunf.fuel.core.FuelError 6 | import com.github.kittinunf.result.Result 7 | import java.io.File 8 | 9 | open class HttpClient { 10 | 11 | open fun get(url: String, params: List>): Result { 12 | val (_, _, result) = Fuel.get(url, parameters = params) 13 | .responseString() 14 | return result 15 | } 16 | 17 | open fun post( 18 | url: String, 19 | params: List>, 20 | file: File 21 | ): Result { 22 | val (_, _, result) = Fuel.upload(url, parameters = params) 23 | .add { FileDataPart(file = file, name = "file") } 24 | .responseString() 25 | return result 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/GsonProvider.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin 2 | 3 | import com.google.gson.* 4 | import com.google.gson.reflect.TypeToken 5 | import org.joda.time.DateTime 6 | import org.joda.time.format.ISODateTimeFormat 7 | import java.lang.reflect.Type 8 | 9 | 10 | internal val gson = GsonBuilder() 11 | .registerTypeAdapter(object : TypeToken() {}.type, DateTimeConverter()) 12 | .create() 13 | 14 | internal class DateTimeConverter : JsonSerializer, JsonDeserializer { 15 | override fun serialize(src: DateTime, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { 16 | val formatter = ISODateTimeFormat.dateTimeNoMillis() 17 | return JsonPrimitive(formatter.print(src)) 18 | } 19 | 20 | @Throws(JsonParseException::class) 21 | override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): DateTime { 22 | return DateTime(json.asString) 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kentaro-takiguchi/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OneSky Gradle plugin 2 | 3 | [ ![Download](https://api.bintray.com/packages/cookpad-inc/maven/onesky-gradle-plugin/images/download.svg) ](https://bintray.com/cookpad-inc/maven/onesky-gradle-plugin/_latestVersion) 4 | 5 | Gradle Plugin for [OneSky](https://www.oneskyapp.com/) 6 | 7 | ## Tasks 8 | 9 | The below tasks are added when you apply this plugin. 10 | 11 | ``` 12 | Translation tasks 13 | ----------------- 14 | downloadTranslation - Download specified translation files (values-*/strings.xml) 15 | showTranslationProgress - Show translation progress 16 | uploadTranslation - Upload the default translation file (values/strings.xml) 17 | ``` 18 | 19 | 20 | ## Installation 21 | 22 | ```groovy 23 | // build.gradle 24 | buildscript { 25 | dependencies { 26 | classpath 'com.github.cookpad:onesky-gradle-plugin:0.1.9' 27 | } 28 | } 29 | ``` 30 | 31 | ```groovy 32 | // app/build.gradle 33 | apply plugin: 'com.cookpad.android.onesky.plugin' 34 | onesky { 35 | apiKey "" 36 | apiSecret "" 37 | projectId 38 | } 39 | ``` 40 | 41 | # License 42 | MIT 43 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/OneskyPlugin.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import com.cookpad.android.onesky.plugin.tasks.DownloadTranslationTask 6 | import com.cookpad.android.onesky.plugin.tasks.ShowTranslationProgressTask 7 | import com.cookpad.android.onesky.plugin.tasks.UploadTranslationTask 8 | import com.cookpad.android.onesky.plugin.tasks.uploadTranslationAndMarkAsDeprecated 9 | 10 | class OneskyPlugin : Plugin { 11 | override fun apply(project: Project) { 12 | with(project) { 13 | extensions.create("onesky", OneskyExtension::class.java) 14 | tasks.create("downloadTranslation", DownloadTranslationTask::class.java) 15 | tasks.create("uploadTranslation", UploadTranslationTask::class.java) 16 | tasks.create("showTranslationProgress", ShowTranslationProgressTask::class.java) 17 | tasks.create("uploadTranslationAndMarkAsDeprecated", uploadTranslationAndMarkAsDeprecated::class.java) 18 | } 19 | } 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /MIT.LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Kentaro TakiguchI 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /plugin/src/test/java/com/cookpad/android/onesky/plugin/FilesTest.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | import org.junit.Test 5 | 6 | class FilesTest { 7 | @Test 8 | fun testLocalFromValuesDirName() { 9 | listOf( 10 | "values-ar" to "ar", 11 | "values-es" to "es", 12 | "values-in" to "id", 13 | "values-pt-rBR" to "pt-BR", 14 | "values-zh-rTW" to "zh-TW" 15 | ).forEach { 16 | val actual = localeFromValuesDirName(it.first) 17 | assertThat(actual).isEqualTo(it.second) 18 | } 19 | } 20 | 21 | @Test 22 | fun testValuesDirName() { 23 | listOf( 24 | "ar" to "values-ar", 25 | "es" to "values-es", 26 | "id" to "values-in", 27 | "pt-BR" to "values-pt-rBR", 28 | "zh-TW" to "values-zh-rTW" 29 | ).forEach { 30 | val actual = valuesDirNameFromLocale(it.first) 31 | assertThat(actual).isEqualTo(it.second) 32 | } 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Revision History of license-tools-plugin 2 | 3 | ## v0.1.1 4 | 5 | ### Breaking change 6 | - Changed the repository from `rejasupotaro` to `com.cookpad.android` 7 | - new: 8 | ```groovy 9 | // build.gradle 10 | buildscript { 11 | dependencies { 12 | classpath 'com.cookpad.android:onesky-gradle-plugin:' 13 | } 14 | } 15 | ``` 16 | 17 | ```groovy 18 | // app/build.gradle 19 | apply plugin: 'com.cookpad.android.onesky.plugin' 20 | onesky { 21 | // ... 22 | } 23 | ``` 24 | - before: 25 | 26 | ```groovy 27 | // build.gradle 28 | buildscript { 29 | dependencies { 30 | classpath 'rejasupotaro:onesky-gradle-plugin:' 31 | } 32 | } 33 | ``` 34 | 35 | ```groovy 36 | // app/build.gradle 37 | apply plugin: 'rejasupotaro.onesky.plugin' 38 | onesky { 39 | // ... 40 | } 41 | ``` 42 | 43 | ## Enhancement 44 | 45 | - Add uploadTranslationAndMarkAsDeprecated task [#11](https://github.com/cookpad/onesky-gradle-plugin/pull/11) 46 | 47 | ## v0.1.0 48 | 49 | initial release 50 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/tasks/UploadTranslationTask.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.tasks 2 | 3 | import com.cookpad.android.onesky.plugin.OneskyExtension 4 | import com.cookpad.android.onesky.plugin.client.Onesky 5 | import com.github.kittinunf.result.Result 6 | import org.gradle.api.DefaultTask 7 | import org.gradle.api.tasks.TaskAction 8 | import java.io.File 9 | 10 | open class UploadTranslationTask : DefaultTask() { 11 | private val oneskyClient by lazy { 12 | val oneskyExtension= project.extensions.findByType(OneskyExtension::class.java) 13 | val apiKey = oneskyExtension!!.apiKey 14 | val apiSecret = oneskyExtension.apiSecret 15 | val projectId = oneskyExtension.projectId 16 | Onesky(apiKey, apiSecret, projectId) 17 | } 18 | 19 | init { 20 | group = "Translation" 21 | description = "Upload the default translation file (values/strings.xml)" 22 | } 23 | 24 | @TaskAction 25 | fun uploadTranslation() { 26 | val file = File("${project.projectDir.absolutePath}/src/main/res/values/strings.xml") 27 | print("Uploading ${file.absolutePath} ... ") 28 | val result = oneskyClient.upload(file) 29 | when (result) { 30 | is Result.Success -> { 31 | println("Done!") 32 | } 33 | is Result.Failure -> { 34 | println("Failed!") 35 | throw result.error 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | maven { 7 | url uri("./repo") 8 | } 9 | maven { url 'https://repo.gradle.org/gradle/repo' } 10 | } 11 | dependencies { 12 | classpath 'com.cookpad.android:onesky-gradle-plugin:0.1.1' 13 | } 14 | } 15 | apply plugin: 'com.cookpad.android.onesky.plugin' 16 | 17 | android { 18 | compileSdkVersion 25 19 | buildToolsVersion '27.0.3' 20 | defaultConfig { 21 | applicationId "com.cookpad.android.onesky.app" 22 | minSdkVersion 17 23 | targetSdkVersion 25 24 | versionCode 1 25 | versionName "1.0" 26 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 27 | } 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation fileTree(dir: 'libs', include: ['*.jar']) 38 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 39 | exclude group: 'com.android.support', module: 'support-annotations' 40 | }) 41 | implementation 'com.android.support:appcompat-v7:25.3.1' 42 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 43 | testImplementation 'junit:junit:4.12' 44 | } 45 | 46 | onesky { 47 | apiKey oneskyApiKey 48 | apiSecret oneskyApiSecret 49 | projectId oneskyProjectId 50 | } 51 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/tasks/UploadTranslationAndMarkAsDeprecatedTask.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.tasks 2 | 3 | import com.cookpad.android.onesky.plugin.OneskyExtension 4 | import com.cookpad.android.onesky.plugin.client.Onesky 5 | import com.github.kittinunf.result.Result 6 | import org.gradle.api.DefaultTask 7 | import org.gradle.api.tasks.TaskAction 8 | import java.io.File 9 | 10 | open class uploadTranslationAndMarkAsDeprecated : DefaultTask() { 11 | private val oneskyClient by lazy { 12 | val oneskyExtension = project.extensions.findByType(OneskyExtension::class.java) 13 | val apiKey = oneskyExtension!!.apiKey 14 | val apiSecret = oneskyExtension.apiSecret 15 | val projectId = oneskyExtension.projectId 16 | Onesky(apiKey, apiSecret, projectId) 17 | } 18 | 19 | init { 20 | group = "Translation" 21 | description = "Upload the default translation file (values/strings.xml) and deprecate old translation" 22 | } 23 | 24 | @TaskAction 25 | fun uploadTranslationAndMarkAsDeprecated() { 26 | val file = File("${project.projectDir.absolutePath}/src/main/res/values/strings.xml") 27 | print("Uploading ${file.absolutePath} ... ") 28 | val result = oneskyClient.upload(file, isKeepingAllStrings = false) 29 | when (result) { 30 | is Result.Success -> { 31 | println("Done!") 32 | } 33 | is Result.Failure -> { 34 | println("Failed!") 35 | throw result.error 36 | } 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /plugin/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'kotlin' 3 | apply plugin: 'maven' 4 | apply plugin: 'bintray-release' 5 | 6 | sourceCompatibility = "1.7" 7 | targetCompatibility = "1.7" 8 | 9 | buildscript { 10 | configure([repositories, project.repositories]) { 11 | maven { url 'https://repo.gradle.org/gradle/repo' } 12 | } 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | repositories { 19 | jcenter() 20 | maven { 21 | url uri("../repo") 22 | } 23 | maven { url 'https://repo.gradle.org/gradle/repo' } 24 | } 25 | 26 | dependencies { 27 | compileOnly gradleApi() 28 | 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "com.github.kittinunf.fuel:fuel:2.3.1" 31 | implementation "commons-codec:commons-codec:1.10" 32 | implementation 'com.google.code.gson:gson:2.8.2' 33 | implementation 'com.jakewharton.fliptables:fliptables:1.0.2' 34 | implementation 'joda-time:joda-time:2.9.9' 35 | 36 | testImplementation 'junit:junit:4.12' 37 | testImplementation "org.assertj:assertj-core:2.1.0" 38 | testImplementation 'com.nhaarman:mockito-kotlin:1.6.0' 39 | } 40 | 41 | uploadArchives { 42 | repositories { 43 | mavenDeployer { 44 | repository(url: uri('../repo')) 45 | pom.groupId = 'com.cookpad.android' 46 | pom.artifactId = 'onesky-gradle-plugin' 47 | pom.version = '0.1.1-SNAPSHOT' 48 | } 49 | } 50 | } 51 | 52 | publish { 53 | userOrg = 'cookpad-inc' 54 | groupId = 'com.cookpad.android' 55 | artifactId = 'onesky-gradle-plugin' 56 | publishVersion = '0.1.1' 57 | desc = 'Gradle plugin for OneSky' 58 | website = 'https://github.com/cookpad/onesky-gradle-plugin' 59 | licences = ['MIT'] 60 | autoPublish = true 61 | } 62 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/client/Onesky.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.client 2 | 3 | import com.github.kittinunf.fuel.core.FuelError 4 | import com.github.kittinunf.result.Result 5 | import org.apache.commons.codec.binary.Hex 6 | import java.io.File 7 | import java.security.MessageDigest 8 | 9 | internal class Onesky(val apiKey: String, val apiSecret: String, val projectId: Int) { 10 | internal val endpoint = "https://platform.api.onesky.io" 11 | internal val version = 1 12 | internal val urlPrefix 13 | get() = "$endpoint/$version" 14 | internal var httpClient = HttpClient() 15 | 16 | fun download(locale: String): Result { 17 | val params = authParams() 18 | params.add("source_file_name" to "strings.xml") 19 | params.add("locale" to locale) 20 | 21 | return httpClient.get("$urlPrefix/projects/$projectId/translations", params) 22 | } 23 | 24 | fun upload(translationFile: File, isKeepingAllStrings : Boolean = true): Result { 25 | val params = authParams() 26 | params.add("file_format" to "ANDROID_XML") 27 | params.add("is_keeping_all_strings" to isKeepingAllStrings.toString()) 28 | 29 | return httpClient.post("$urlPrefix/projects/$projectId/files", params, translationFile) 30 | } 31 | 32 | fun languages(): Result { 33 | val params = authParams() 34 | return httpClient.get("$urlPrefix/projects/$projectId/languages", params) 35 | } 36 | 37 | fun authParams(): MutableList> { 38 | val md = MessageDigest.getInstance("MD5") 39 | val timestamp = (System.currentTimeMillis() / 1000L).toString() 40 | val devHash = Hex.encodeHexString(md.digest((timestamp + apiSecret).toByteArray())) 41 | 42 | return mutableListOf("api_key" to apiKey, 43 | "dev_hash" to devHash, 44 | "timestamp" to timestamp) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/tasks/DownloadTranslationTask.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.tasks 2 | 3 | import com.cookpad.android.onesky.plugin.OneskyExtension 4 | import com.cookpad.android.onesky.plugin.client.Onesky 5 | import com.cookpad.android.onesky.plugin.localeFromValuesDirName 6 | import com.cookpad.android.onesky.plugin.valuesDirNameFromLocale 7 | import com.github.kittinunf.result.Result 8 | import org.gradle.api.DefaultTask 9 | import org.gradle.api.tasks.TaskAction 10 | import java.io.File 11 | 12 | open class DownloadTranslationTask : DefaultTask() { 13 | private val oneskyExtension by lazy { 14 | project.extensions.findByType(OneskyExtension::class.java) 15 | } 16 | 17 | private val oneskyClient by lazy { 18 | val apiKey = oneskyExtension!!.apiKey 19 | val apiSecret = oneskyExtension!!.apiSecret 20 | val projectId = oneskyExtension!!.projectId 21 | Onesky(apiKey, apiSecret, projectId) 22 | } 23 | 24 | init { 25 | group = "Translation" 26 | description = "Download specified translation files (values-*/strings.xml)" 27 | } 28 | 29 | private val resDir by lazy { File("${project.projectDir.absolutePath}/src/main/res") } 30 | 31 | private val locales by lazy { 32 | if (oneskyExtension!!.locales.isEmpty()) { 33 | resDir.listFiles() 34 | .filter { it.name.startsWith("values-") } 35 | .filter { 36 | File("${it.absolutePath}/strings.xml").exists() 37 | } 38 | .map { localeFromValuesDirName(it.name) } 39 | } else { 40 | oneskyExtension!!.locales 41 | } 42 | } 43 | 44 | @TaskAction 45 | fun downloadTranslation() { 46 | if (locales.isEmpty()) { 47 | throw IllegalArgumentException("You should provide locales or values-* directories should be created before running this task") 48 | } 49 | 50 | locales.forEach { locale -> 51 | val file = targetStringsFile(locale) 52 | print("Downloading $locale translation into ${file.absolutePath} ... ") 53 | 54 | val result = oneskyClient.download(locale) 55 | when (result) { 56 | is Result.Success -> { 57 | file.writeText(result.value) 58 | println("Done!") 59 | } 60 | is Result.Failure -> { 61 | println("Failed!") 62 | throw result.error 63 | } 64 | } 65 | } 66 | } 67 | 68 | private fun targetStringsFile(locale: String): File { 69 | val valuesDir = File("${resDir.absolutePath}/${valuesDirNameFromLocale(locale)}") 70 | if (!valuesDir.exists()) { 71 | valuesDir.mkdir() 72 | } 73 | val stringsFile = File("${valuesDir.absolutePath}/strings.xml") 74 | if (!stringsFile.exists()) { 75 | stringsFile.createNewFile() 76 | } 77 | return stringsFile 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /plugin/src/main/java/com/cookpad/android/onesky/plugin/tasks/ShowTranslationProgressTask.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.tasks 2 | 3 | import com.cookpad.android.onesky.plugin.OneskyExtension 4 | import com.cookpad.android.onesky.plugin.client.Onesky 5 | import com.cookpad.android.onesky.plugin.gson 6 | import com.github.kittinunf.result.Result 7 | import com.google.gson.annotations.SerializedName 8 | import com.jakewharton.fliptables.FlipTable 9 | import org.gradle.api.DefaultTask 10 | import org.gradle.api.tasks.TaskAction 11 | import org.joda.time.DateTime 12 | import org.joda.time.format.DateTimeFormat 13 | 14 | open class ShowTranslationProgressTask : DefaultTask() { 15 | private val oneskyClient by lazy { 16 | val oneskyExtension= project.extensions.findByType(OneskyExtension::class.java) 17 | val apiKey = oneskyExtension!!.apiKey 18 | val apiSecret = oneskyExtension.apiSecret 19 | val projectId = oneskyExtension.projectId 20 | Onesky(apiKey, apiSecret, projectId) 21 | } 22 | 23 | init { 24 | group = "Translation" 25 | description = "Show translation progress" 26 | } 27 | 28 | @TaskAction 29 | fun showTranslationProgress() { 30 | val result = oneskyClient.languages() 31 | when (result) { 32 | is Result.Success -> { 33 | val translations = jsonToTranslations(result.value) 34 | printProgress(translations) 35 | } 36 | is Result.Failure -> { 37 | println("Failed!") 38 | throw result.error 39 | } 40 | } 41 | } 42 | 43 | private fun jsonToTranslations(json: String): List { 44 | val response = gson.fromJson(json, Response::class.java) 45 | return response.data.filterNot { 46 | it.isBaseLanguage 47 | }.filter { 48 | it.lastUpdatedAt != null 49 | }.sortedWith(compareBy( 50 | { -it.progress.replace("%", "").toFloat() }, 51 | { it.code }) 52 | ) 53 | } 54 | 55 | private fun printProgress(translations: List) { 56 | val headers = arrayOf("Locale", "Progress", "Last update at") 57 | val data = translations.map { 58 | val lastUpdatedAt = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm").print(it.lastUpdatedAt) 59 | arrayOf(it.code, it.progress, lastUpdatedAt) 60 | }.toTypedArray() 61 | println(FlipTable.of(headers, data)) 62 | } 63 | 64 | class Response { 65 | @SerializedName("data") val data = listOf() 66 | } 67 | 68 | class Translation { 69 | @SerializedName("code") val code = "" 70 | @SerializedName("locale") val locale = "" 71 | @SerializedName("region") val region = "" 72 | @SerializedName("is_base_language") val isBaseLanguage = false 73 | @SerializedName("translation_progress") val progress = "" 74 | @SerializedName("last_updated_at") val lastUpdatedAt: DateTime? = null 75 | @SerializedName("last_updated_at_timestamp") val lastUpdatedAtTimestamp: String? = "" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /plugin/src/test/java/com/cookpad/android/onesky/plugin/client/OneskyTest.kt: -------------------------------------------------------------------------------- 1 | package com.cookpad.android.onesky.plugin.client 2 | 3 | import com.github.kittinunf.fuel.core.FuelError 4 | import com.github.kittinunf.result.Result 5 | import com.nhaarman.mockito_kotlin.* 6 | import org.assertj.core.api.Assertions.assertThat 7 | import org.junit.Test 8 | import java.io.File 9 | 10 | 11 | class OneskyTest { 12 | internal val onesky: Onesky by lazy { 13 | val apiKey = "" 14 | val apiSecret = "" 15 | val projectId = 123456789 16 | Onesky(apiKey, apiSecret, projectId) 17 | } 18 | 19 | @Test 20 | fun testUrlPrefix() { 21 | assertThat(onesky.urlPrefix).isEqualTo("https://platform.api.onesky.io/1") 22 | } 23 | 24 | @Test 25 | fun testAuthParams() { 26 | val params = onesky.authParams() 27 | assertThat(params.map { it.first }).containsOnly("api_key", "dev_hash", "timestamp") 28 | } 29 | 30 | @Test 31 | fun testDownload() { 32 | val httpClient = mock { 33 | on { 34 | get(any(), any>>()) 35 | }.doReturn(mock> {}) 36 | } 37 | onesky.httpClient = httpClient 38 | 39 | onesky.download("es") 40 | 41 | val urlCaptor = argumentCaptor() 42 | val paramsCaptor = argumentCaptor>>() 43 | verify(httpClient).get( 44 | urlCaptor.capture(), 45 | paramsCaptor.capture()) 46 | assertThat(urlCaptor.firstValue).isEqualTo("https://platform.api.onesky.io/1/projects/123456789/translations") 47 | assertThat(paramsCaptor.firstValue.map { it.first }).containsOnly( 48 | "api_key", 49 | "dev_hash", 50 | "timestamp", 51 | "source_file_name", 52 | "locale") 53 | } 54 | 55 | @Test 56 | fun testUpload() { 57 | val file = mock() 58 | val httpClient = mock { 59 | on { 60 | post(any(), any>>(), any()) 61 | }.doReturn(mock> {}) 62 | } 63 | onesky.httpClient = httpClient 64 | 65 | onesky.upload(file) 66 | 67 | val urlCaptor = argumentCaptor() 68 | val paramsCaptor = argumentCaptor>>() 69 | verify(httpClient).post( 70 | urlCaptor.capture(), 71 | paramsCaptor.capture(), 72 | eq(file)) 73 | assertThat(urlCaptor.firstValue).isEqualTo("https://platform.api.onesky.io/1/projects/123456789/files") 74 | assertThat(paramsCaptor.firstValue.map { it.first }).containsOnly( 75 | "api_key", 76 | "dev_hash", 77 | "timestamp", 78 | "file_format", 79 | "is_keeping_all_strings") 80 | assertThat(paramsCaptor.firstValue.contains("is_keeping_all_strings" to "true")) 81 | } 82 | 83 | @Test 84 | fun testUploadAndMarkAsDeprecated() { 85 | val file = mock() 86 | val httpClient = mock { 87 | on { 88 | post(any(), any>>(), any()) 89 | }.doReturn(mock> {}) 90 | } 91 | onesky.httpClient = httpClient 92 | 93 | onesky.upload(file, false) 94 | 95 | val urlCaptor = argumentCaptor() 96 | val paramsCaptor = argumentCaptor>>() 97 | verify(httpClient).post( 98 | urlCaptor.capture(), 99 | paramsCaptor.capture(), 100 | eq(file)) 101 | assertThat(urlCaptor.firstValue).isEqualTo("https://platform.api.onesky.io/1/projects/123456789/files") 102 | assertThat(paramsCaptor.firstValue.map { it.first }).containsOnly( 103 | "api_key", 104 | "dev_hash", 105 | "timestamp", 106 | "file_format", 107 | "is_keeping_all_strings") 108 | assertThat(paramsCaptor.firstValue.contains("is_keeping_all_strings" to "false")) 109 | } 110 | 111 | @Test 112 | fun testLanguages() { 113 | val httpClient = mock { 114 | on { 115 | get(any(), any>>()) 116 | }.doReturn(mock> {}) 117 | } 118 | onesky.httpClient = httpClient 119 | 120 | onesky.languages() 121 | 122 | val urlCaptor = argumentCaptor() 123 | val paramsCaptor = argumentCaptor>>() 124 | verify(httpClient).get( 125 | urlCaptor.capture(), 126 | paramsCaptor.capture()) 127 | assertThat(urlCaptor.firstValue).isEqualTo("https://platform.api.onesky.io/1/projects/123456789/languages") 128 | assertThat(paramsCaptor.firstValue.map { it.first }).containsOnly( 129 | "api_key", 130 | "dev_hash", 131 | "timestamp") 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | --------------------------------------------------------------------------------