[
  {
    "path": ".github/stale.yml",
    "content": "# Number of days of inactivity before an issue becomes stale\ndaysUntilStale: 30\n# Number of days of inactivity before a stale issue is closed\ndaysUntilClose: 7\n# Issues with these labels will never be considered stale\nexemptLabels:\n  - bug\n  - enhancement\n  - help wanted\n# Label to use when marking an issue as stale\nstaleLabel: wontfix\n# Comment to post when marking an issue as stale. Set to `false` to disable\nmarkComment: >\n  This issue has been automatically marked as stale because it has not had\n  recent activity. It will be closed if no further activity occurs. Thank you\n  for your contributions.\n# Comment to post when closing a stale issue. Set to `false` to disable\ncloseComment: false\n"
  },
  {
    "path": ".gitignore",
    "content": "build/\n!autoplay/src/test/resources/sample-app/app/build/\n\ncaptures/\nout/\nuserHome/\n\n.idea/\n.gradle/\n.navigation/\n\n*.iml\n.DS_Store\n\nlocal.properties"
  },
  {
    "path": ".travis.yml",
    "content": "language: android\ninstall: true\n\njdk:\n  - oraclejdk8\n\nandroid:\n  components:\n  - tools\n  - platform-tools\n  - build-tools-27.0.3\n  - android-27\n  - extra-android-m2repository\n\nbefore_install:\n  - yes | sdkmanager \"platforms;android-27\"\n\nbefore_cache:\n  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock\n  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/\n\ncache:\n  directories:\n    - $HOME/.gradle/caches/\n    - $HOME/.gradle/wrapper/\n\nscript:\n  - ./gradlew clean build --stacktrace\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright 2018 Sergej Shafarenka, www.halfbit.de\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "[![Build Status](https://travis-ci.org/beworker/autoplay.svg?branch=master)](https://travis-ci.org/beworker/autoplay)\n[![Maven Central](http://img.shields.io/maven-central/v/de.halfbit/autoplay.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.halfbit%22%20a%3A%22autoplay%22)\n[![Gradle](https://img.shields.io/badge/gradle-5.0-blue.svg)](https://gradle.org/)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n\nArchived in favor of https://github.com/Triple-T/gradle-play-publisher\n\n<img src=\"https://github.com/beworker/autoplay/blob/master/publishing/autoplay-logo.png\" alt=\"autoplay\" width=200 />\n\n# Autoplay\nGradle plugin for publishing Android artifacts to Google Play.\n\n# Features\n\n- Autoplay is optimized for CI/CD usage:\n  - it does **not** trigger assembly task automatically - you can reuse build artifacts from previous build steps;\n  - it accepts JSON key as **base64-encoded string** from external secure variables.\n  \n- Autoplay is developer friendly:\n  - it does **not** require storing any dummy keys in source control;\n  - it has a single publish task for uploading artifacts (apk or app bundle) and release notes.\n  \n- Autoplay is reliable and future-proof:\n  - it has clean and concise implementation, which is easy to understand, extend and fix;\n  - it's covered by unit tests;\n  - it's built using latest tools and API's.\n \n# Usage\n\nIn the main `build.gradle`\n\n```gradle\nbuildscript {\n  repositories {\n    google()\n    mavenCentral()\n  }\n  dependencies {\n    classpath \"de.halfbit:autoplay:<version>\"\n  }\n}\n```\n\nLatest published version can be found at [![Maven central](http://img.shields.io/maven-central/v/de.halfbit/autoplay.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.halfbit%22%20a%3A%22autoplay%22)\n\n## Gradle compatibility\n\nAutoplay Version | Gradle Version | AGP Version\n-----------|-----------|---------------\n| 1.3.x | 4.8.x |  |\n| 2.3.x | 4.10.x |  |\n| 3.0.x | 5.x, 6.x, 7.x | 3.x |\n| 4.0.x | 6.x | 4.0.x, 4.1.x |\n\n## Publishing apk\n\nIn the application module's `build.gradle`\n\n```gradle\napply plugin: 'com.android.application'\napply plugin: 'android-autoplay'\n\nautoplay {\n    track \"internal\"\n    secretJsonBase64 project.hasProperty('SECRET_JSON') ? project.property('SECRET_JSON') : ''\n}\n```\n\nExecute `./gradlew tasks` and you will see a new publishing task `publishApk<BuildVariant>` in the list. Autoplay adds this task for each build variant of `release` type. For a project without custom build flavors the task is named `publishApkRelease`.\n\n## Publishing app bundle\n\nIn the application module's `build.gradle`\n\n```gradle\napply plugin: 'com.android.application'\napply plugin: 'android-autoplay'\n\nautoplay {\n    track \"internal\"\n    artifactType \"bundle\"\n    secretJsonBase64 project.hasProperty('SECRET_JSON') ? project.property('SECRET_JSON') : ''\n}\n```\n\nExecute `./gradlew tasks` and you will see a new publishing task `publishBundle<BuildVariant>` in the list. Autoplay adds this task for each build variant of `release` type. For a project without custom build flavors the task is named `publishBundleRelease`.\n\n## Central build\n\nNow you can call this task from a central build script. Here is an example of how to use it with Gitlab CI.\n\n```yml\nstages:\n  - assemble\n  - release\n\nassemble:\n  stage: assemble\n  only:\n    - master\n  script:\n    - ./gradlew clean bundleRelease -PSTORE_PASS=${STORE_PASS} -PKEY_PASS=${KEY_PASS}\n  artifacts:\n    paths:\n      - app/build/outputs/\n\nrelease:\n  stage: release\n  dependencies:\n    - assemble\n  only:\n    - master\n  script:\n    - ./gradlew publishBundleRelease -PSECRET_JSON=${SECRET_JSON}\n```\n\nYou can encode JSON key file into base64 string using following shell command (linux, mac)\n\n```shell\nbase64 -i secret.json -o -\n```\n\nand provide the value to the build script using a [protected variable](https://docs.gitlab.com/ee/ci/variables/#variables).\n\n## Publishing Release Notes\n\nAutoplay takes apk and obfuscation mapping files (or app bundle file, if `artifactType \"bundle\"` is set) for uploading from the default build output directories. Release notes are to be stored under `src/main/autoplay/release-notes` directory in accordance to the structure shown down below.\n\n```\nsrc\n  +- main\n       +- java\n       +- autoplay\n            +- release-notes\n                 +- <track>           e.g. internal\n                     +- <locale>.txt  e.g. en-US.txt\n```\n\n## Properties\nAutoplay supports following `gradle.properties`\n\nName | Default | Description\n-----|---------|-----\n| `autoplay.connectTimeout` | 120000ms | Connection establishment timeout in milliseconds. |\n| `autoplay.readTimeout` | 120000ms | Connection reading timeout in milliseconds. |\n\nHappy continuous integration!\n\n# License\n```\nCopyright 2018-2021 Sergej Shafarenka, www.halfbit.de\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n"
  },
  {
    "path": "autoplay/build.gradle.kts",
    "content": "plugins {\n    `kotlin-dsl`\n    `maven-publish`\n    id(\"org.gradle.signing\")\n    id(\"org.jetbrains.dokka\") version \"0.9.17\"\n    kotlin(\"jvm\").version(embeddedKotlinVersion).apply(false)\n}\n\ndependencies {\n    compileOnly(\"com.android.tools.build:gradle:4.1.3\") {\n        exclude(group = \"org.jetbrains.kotlin\")\n    }\n    implementation(\"com.google.apis:google-api-services-androidpublisher:v3-rev142-1.25.0\")\n\n    testImplementation(\"junit:junit:4.12\")\n    testImplementation(\"com.google.truth:truth:0.40\")\n    testImplementation(\"com.android.tools.build:gradle:4.1.3\") {\n        exclude(group = \"org.jetbrains.kotlin\")\n    }\n}\n\ngradlePlugin {\n    isAutomatedPublishing = false\n    plugins {\n        create(\"android-autoplay\") {\n            id = \"android-autoplay\"\n            implementationClass = \"de.halfbit.tools.autoplay.PlayPublisherPlugin\"\n        }\n    }\n}\n\ngroup = \"de.halfbit\"\nversion = \"4.0.0\"\n\npublishing {\n\n    repositories {\n        maven {\n            name = \"local\"\n            url = uri(\"$buildDir/repository\")\n        }\n        maven {\n            name = \"central\"\n            url = uri(\"https://oss.sonatype.org/service/local/staging/deploy/maven2\")\n            credentials {\n                username = project.getPropertyOrEmptyString(\"NEXUS_USERNAME\")\n                password = project.getPropertyOrEmptyString(\"NEXUS_PASSWORD\")\n            }\n        }\n    }\n\n    val dokka by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class) {\n        outputFormat = \"javadoc\"\n        outputDirectory = \"$buildDir/javadoc\"\n    }\n\n    val sourcesJar by tasks.creating(Jar::class) {\n        classifier = \"sources\"\n        from(sourceSets[\"main\"].allSource)\n    }\n\n    val javadocJar by tasks.creating(Jar::class) {\n        classifier = \"javadoc\"\n        from(dokka)\n    }\n\n    publications {\n        create(\"Autoplay\", MavenPublication::class) {\n            from(components[\"java\"])\n            artifact(sourcesJar)\n            artifact(javadocJar)\n            pom {\n                name.set(\"Gradle plugin for publishing Android artifacts to Google Play.\")\n                description.set(\"Gradle plugin for publishing Android artifacts to Google Play.\")\n                url.set(\"http://www.halfbit.de\")\n                licenses {\n                    license {\n                        name.set(\"The Apache License, Version 2.0\")\n                        url.set(\"http://www.apache.org/licenses/LICENSE-2.0.txt\")\n                    }\n                }\n                developers {\n                    developer {\n                        id.set(\"beworker\")\n                        name.set(\"Sergej Shafarenka\")\n                        email.set(\"info@halfbit.de\")\n                    }\n                }\n                scm {\n                    connection.set(\"scm:git:git@github.com:beworker/autoplay.git\")\n                    developerConnection.set(\"scm:git:ssh://github.com:beworker/autoplay.git\")\n                    url.set(\"http://www.halfbit.de\")\n                }\n            }\n        }\n    }\n\n}\n\nif (project.hasProperty(\"signing.keyId\")) {\n    signing {\n        sign(publishing.publications[\"Autoplay\"])\n    }\n}\n\nfun Project.getPropertyOrEmptyString(name: String): String =\n    if (hasProperty(name)) property(name) as String? ?: \"\"\n    else \"\"\n\ntasks.withType<Test> {\n    addTestListener(object : TestListener {\n        override fun beforeSuite(suite: TestDescriptor) {}\n        override fun afterSuite(suite: TestDescriptor, result: TestResult) {}\n        override fun beforeTest(testDescriptor: TestDescriptor) {}\n        override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {\n            if (result.resultType == TestResult.ResultType.FAILURE) {\n                result.exception?.printStackTrace()\n            }\n        }\n    })\n}\n"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/AutoplayPublisherExtension.kt",
    "content": "/*\n * Copyright (C) 2018-2019 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay\n\nimport de.halfbit.tools.autoplay.publisher.ArtifactType\nimport de.halfbit.tools.autoplay.publisher.ReleaseStatus\n\ninternal const val RELEASE_NOTES_PATH = \"src/main/autoplay/release-notes\"\ninternal const val UNINITIALIZED = \"\"\n\nopen class AutoplayPublisherExtension {\n\n    var track: String = UNINITIALIZED\n    var userFraction: Double = 1.0\n    var status: String = ReleaseStatus.Completed.name\n    var secretJsonBase64: String? = null\n    var secretJsonPath: String? = null\n    var releaseNotesPath: String = RELEASE_NOTES_PATH\n    var artifactType = ArtifactType.Apk.name\n\n}\n"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/AutoplayPublisherPlugin.kt",
    "content": "/*\n * Copyright (C) 2018-2021 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay\n\nimport com.android.Version\nimport com.android.build.gradle.AppExtension\nimport com.android.build.gradle.api.ApkVariantOutput\nimport com.android.build.gradle.api.ApplicationVariant\nimport de.halfbit.tools.autoplay.publisher.ArtifactType\nimport de.halfbit.tools.autoplay.publisher.Credentials\nimport de.halfbit.tools.autoplay.publisher.ReleaseNotes\nimport de.halfbit.tools.autoplay.publisher.ReleaseStatus\nimport de.halfbit.tools.autoplay.publisher.ReleaseTrack\nimport de.halfbit.tools.autoplay.publisher.TRACK_ROLLOUT\nimport org.gradle.api.Plugin\nimport org.gradle.api.Project\nimport org.gradle.kotlin.dsl.invoke\nimport org.gradle.kotlin.dsl.register\nimport java.io.File\nimport java.util.*\n\ninternal const val TASK_GROUP = \"Publishing\"\ninternal const val PLUGIN_ID = \"android-autoplay\"\ninternal const val EXTENSION_NAME = \"autoplay\"\n\ninternal class PlayPublisherPlugin : Plugin<Project> {\n\n    override fun apply(project: Project) {\n\n        val extension = project.extensions\n            .create(EXTENSION_NAME, AutoplayPublisherExtension::class.java)\n\n        val androidAppExtension = project.requireAndroidAppExtension()\n        androidAppExtension.applicationVariants.whenObjectAdded {\n            if (buildType.isDebuggable) return@whenObjectAdded\n\n            val appVariant = this\n            val variantName = appVariant.name.capitalize()\n\n            when (extension.artifactType) {\n                ArtifactType.Apk.name -> {\n                    project.tasks {\n                        register<PublishTask>(\"publishApk$variantName\") {\n                            description =\n                                \"Publish $variantName apk, mapping and release-notes to Google Play.\"\n                            group = TASK_GROUP\n\n                            applicationId = appVariant.applicationId\n                            artifactType = ArtifactType.Apk\n                            artifacts = appVariant.collectArtifacts(ArtifactType.Apk, project)\n                            obfuscationMappingFile = appVariant.getObfuscationMappingFile()\n                            releaseTrack = extension.getReleaseTrack()\n                            releaseStatus = extension.getReleaseStatus()\n                            releaseNotes = extension.getReleaseNotes(project.projectDir)\n                            credentials = extension.getCredentials()\n                        }\n                    }\n                }\n\n                ArtifactType.Bundle.name -> {\n                    project.tasks {\n                        register<PublishTask>(\"publishBundle$variantName\") {\n                            description =\n                                \"Publish $variantName bundle and release-notes to Google Play.\"\n                            group = TASK_GROUP\n\n                            applicationId = appVariant.applicationId\n                            artifactType = ArtifactType.Bundle\n                            artifacts = appVariant.collectArtifacts(ArtifactType.Bundle, project)\n                            releaseTrack = extension.getReleaseTrack()\n                            releaseStatus = extension.getReleaseStatus()\n                            releaseNotes = extension.getReleaseNotes(project.projectDir)\n                            credentials = extension.getCredentials()\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    companion object {\n\n        private const val MINIMAL_ANDROID_PLUGIN_VERSION = \"3.0.1\"\n\n        private fun ApplicationVariant.collectArtifacts(\n            artifactType: ArtifactType, project: Project\n        ): List<File> {\n\n            return when (artifactType) {\n                ArtifactType.Apk -> this.outputs\n                    .filterIsInstance<ApkVariantOutput>()\n                    .map { it.outputFile }\n\n                ArtifactType.Bundle -> {\n                    val archivesBaseName = project.properties[\"archivesBaseName\"] as String\n                    listOf(File(project.buildDir, \"outputs/bundle/$name/$archivesBaseName.aab\"))\n                }\n            }\n        }\n\n        private fun ApplicationVariant.getObfuscationMappingFile(): File? {\n            val mapping = mappingFile\n            if (mapping == null || mapping.length() == 0L) {\n                return null\n            }\n            return mapping\n        }\n\n        private fun AutoplayPublisherExtension.getReleaseTrack(): ReleaseTrack {\n            return when (track) {\n                UNINITIALIZED -> error(\"$EXTENSION_NAME { track } property is required.\")\n                ReleaseTrack.Internal.name -> ReleaseTrack.Internal\n                ReleaseTrack.Alpha.name -> ReleaseTrack.Alpha\n                ReleaseTrack.Beta.name -> ReleaseTrack.Beta\n                TRACK_ROLLOUT -> ReleaseTrack.Rollout(userFraction)\n                ReleaseTrack.Production.name -> ReleaseTrack.Production\n                else -> error(\"Unsupported track: $track\")\n            }\n        }\n\n        private fun AutoplayPublisherExtension.getReleaseStatus(): ReleaseStatus {\n            return when (status) {\n                ReleaseStatus.Completed.name -> ReleaseStatus.Completed\n                ReleaseStatus.Draft.name -> ReleaseStatus.Draft\n                ReleaseStatus.Halted.name -> ReleaseStatus.Halted\n                ReleaseStatus.InProgress.name -> ReleaseStatus.InProgress\n                else -> error(\"Unsupported status: $status\")\n            }\n        }\n\n        private fun AutoplayPublisherExtension.getReleaseNotes(rootDir: File): List<ReleaseNotes> {\n            val trackDirectory = File(rootDir, \"$releaseNotesPath/$track\")\n            if (!trackDirectory.exists()) return emptyList()\n            val directoryFiles = trackDirectory.listFiles() ?: return emptyList()\n            return directoryFiles\n                .filter { it.isFile }\n                .mapNotNull { localizedFile ->\n                    if (localizedFile.exists()) localizedFile else null\n                }\n                .map { releaseNoteFile ->\n                    ReleaseNotes(\n                        releaseNoteFile.getLocale(),\n                        releaseNoteFile\n                    )\n                }\n        }\n\n        private fun AutoplayPublisherExtension.getCredentials(): Credentials {\n            val secretJson = if (secretJsonBase64 != null) {\n                Base64.getDecoder().decode(secretJsonBase64).toString(Charsets.UTF_8)\n            } else {\n                null\n            }\n            return Credentials(secretJson, secretJsonPath)\n        }\n\n        private fun Project.requireAndroidAppExtension(): AppExtension {\n            val current = Version.ANDROID_GRADLE_PLUGIN_VERSION\n            val expected = MINIMAL_ANDROID_PLUGIN_VERSION\n            if (current < expected) {\n                error(\n                    \"Plugin '$PLUGIN_ID' requires 'com.android.application' plugin version $expected or higher,\" +\n                        \" while yours is $current. Update android gradle plugin and try again.\"\n                )\n            }\n            return project.extensions.findByType(AppExtension::class.java)\n                ?: error(\"Required 'com.android.application' plugin must be added prior '$PLUGIN_ID' plugin.\")\n        }\n\n        private fun File.getLocale(): String {\n            if (name.length < 5 || name.substring(2, 3) != \"-\") {\n                error(\n                    \"Release notes must be named using the following format:\" +\n                        \" <language>-<COUNTRY>.txt, e.g. en-US.txt. Found name: $this\"\n                )\n            }\n            return name.substring(0, 5)\n        }\n\n    }\n\n}"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/PublishTask.kt",
    "content": "/*\n * Copyright (C) 2018-2021 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay\n\nimport de.halfbit.tools.autoplay.publisher.ArtifactType\nimport de.halfbit.tools.autoplay.publisher.Configuration\nimport de.halfbit.tools.autoplay.publisher.Credentials\nimport de.halfbit.tools.autoplay.publisher.ReleaseArtifact\nimport de.halfbit.tools.autoplay.publisher.ReleaseData\nimport de.halfbit.tools.autoplay.publisher.ReleaseNotes\nimport de.halfbit.tools.autoplay.publisher.ReleaseStatus\nimport de.halfbit.tools.autoplay.publisher.ReleaseTrack\nimport de.halfbit.tools.autoplay.publisher.v3.V3GooglePlayPublisher\nimport org.gradle.api.DefaultTask\nimport org.gradle.api.Project\nimport org.gradle.api.tasks.Input\nimport org.gradle.api.tasks.InputFile\nimport org.gradle.api.tasks.InputFiles\nimport org.gradle.api.tasks.Optional\nimport org.gradle.api.tasks.PathSensitive\nimport org.gradle.api.tasks.PathSensitivity\nimport org.gradle.api.tasks.TaskAction\nimport org.gradle.work.InputChanges\nimport java.io.File\n\ninternal open class PublishTask : DefaultTask() {\n\n    @get:Input\n    lateinit var artifactType: ArtifactType\n\n    @get:InputFiles\n    @get:PathSensitive(PathSensitivity.ABSOLUTE)\n    lateinit var artifacts: List<File>\n\n    @get:Optional\n    @get:InputFile\n    var obfuscationMappingFile: File? = null\n\n    @get:Input\n    lateinit var releaseNotes: List<ReleaseNotes>\n\n    @get:Input\n    lateinit var applicationId: String\n\n    @get:Input\n    lateinit var credentials: Credentials\n\n    @get:Input\n    lateinit var releaseTrack: ReleaseTrack\n\n    @get:Input\n    var releaseStatus: ReleaseStatus = ReleaseStatus.Completed\n\n    @TaskAction\n    @Suppress(\"UNUSED_PARAMETER\", \"unused\")\n    fun execute(inputChanges: InputChanges) {\n        credentials.validate()\n\n        val configuration = Configuration(\n            readTimeout = project.getIntProperty(\"readTimeout\", 120_000),\n            connectTimeout = project.getIntProperty(\"connectTimeout\", 120_000)\n        )\n\n        V3GooglePlayPublisher\n            .getGooglePlayPublisher(credentials, applicationId, configuration)\n            .publish(\n                ReleaseData(\n                    applicationId,\n                    artifacts.map { it.toReleaseArtifact(artifactType) },\n                    obfuscationMappingFile,\n                    releaseNotes,\n                    releaseStatus,\n                    releaseTrack\n                )\n            )\n    }\n\n}\n\nprivate fun Project.getIntProperty(propertyName: String, default: Int): Int =\n    (project.properties[\"autoplay.$propertyName\"] as? String)?.toInt() ?: default\n\nprivate fun File.toReleaseArtifact(artifactType: ArtifactType): ReleaseArtifact =\n    when (artifactType) {\n        ArtifactType.Apk -> ReleaseArtifact.Apk(this)\n        ArtifactType.Bundle -> ReleaseArtifact.Bundle(this)\n    }\n\nprivate fun Credentials.validate() {\n    if (!secretJson.isNullOrEmpty() && !secretJsonPath.isNullOrEmpty()) {\n        error(\n            \"Either $EXTENSION_NAME { secretJsonBase64 } or\" +\n                \" $EXTENSION_NAME { secretJsonPath } must be specified, never both.\"\n        )\n    }\n}\n\n"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/publisher/GooglePlayPublisher.kt",
    "content": "/*\n * Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay.publisher\n\nimport java.io.File\nimport java.io.Serializable\n\ninternal const val TRACK_ROLLOUT = \"rollout\"\n\ninternal interface GooglePlayPublisher {\n    fun publish(data: ReleaseData)\n}\n\ninternal class ReleaseData(\n    val applicationId: String,\n    val artifacts: List<ReleaseArtifact>,\n    val obfuscationMappingFile: File?,\n    val releaseNotes: List<ReleaseNotes>,\n    val releaseStatus: ReleaseStatus,\n    val releaseTrack: ReleaseTrack\n)\n\ninternal class ReleaseNotes(\n    val locale: String,\n    val file: File\n) : Serializable\n\ninternal sealed class ReleaseTrack(val name: String) : Serializable {\n    object Internal : ReleaseTrack(\"internal\")\n    object Alpha : ReleaseTrack(\"alpha\")\n    object Beta : ReleaseTrack(\"beta\")\n    class Rollout(val userFraction: Double) : ReleaseTrack(TRACK_ROLLOUT)\n    object Production : ReleaseTrack(\"production\")\n}\n\ninternal sealed class ReleaseArtifact(val file: File) {\n    class Apk(file: File) : ReleaseArtifact(file)\n    class Bundle(file: File) : ReleaseArtifact(file)\n}\n\ninternal sealed class ArtifactType(val name: String) : Serializable {\n    object Apk : ArtifactType(\"apk\")\n    object Bundle : ArtifactType(\"bundle\")\n}\n\ninternal sealed class ReleaseStatus(val name: String) : Serializable {\n    object Completed : ReleaseStatus(\"completed\")\n    object Draft : ReleaseStatus(\"draft\")\n    object Halted : ReleaseStatus(\"halted\")\n    object InProgress : ReleaseStatus(\"inProgress\")\n}\n\ninternal class Credentials(\n    val secretJson: String?,\n    val secretJsonPath: String?\n) : Serializable\n\ninternal class Configuration(\n    val readTimeout: Int,\n    val connectTimeout: Int\n)"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/publisher/common/FileExt.kt",
    "content": "/*\n * Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay.publisher.common\n\nimport java.io.File\n\ninternal fun File.readTextLines(maxLength: Long): String {\n    if (!exists()) error(\"File must exist: $this\")\n    if (length() == 0L) error(\"File must not be empty: $this\")\n\n    var complete = false\n    val text = StringBuilder()\n    forEachLine { line ->\n        if (complete) return@forEachLine\n\n        if (text.length + line.length < maxLength) {\n            text.append(line.trim()).append(\"\\n\")\n        } else {\n            complete = true\n        }\n    }\n\n    return text.toString()\n}"
  },
  {
    "path": "autoplay/src/main/kotlin/de/halfbit/tools/autoplay/publisher/v3/V3GooglePlayPublisher.kt",
    "content": "/*\n * Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay.publisher.v3\n\nimport com.google.api.client.googleapis.auth.oauth2.GoogleCredential\nimport com.google.api.client.googleapis.javanet.GoogleNetHttpTransport\nimport com.google.api.client.http.FileContent\nimport com.google.api.client.json.jackson2.JacksonFactory\nimport com.google.api.services.androidpublisher.AndroidPublisher\nimport com.google.api.services.androidpublisher.AndroidPublisherScopes\nimport com.google.api.services.androidpublisher.model.AppEdit\nimport com.google.api.services.androidpublisher.model.LocalizedText\nimport com.google.api.services.androidpublisher.model.Track\nimport com.google.api.services.androidpublisher.model.TrackRelease\nimport de.halfbit.tools.autoplay.EXTENSION_NAME\nimport de.halfbit.tools.autoplay.publisher.*\nimport de.halfbit.tools.autoplay.publisher.common.readTextLines\nimport java.io.File\n\ninternal const val MIME_TYPE_APK = \"application/vnd.android.package-archive\"\ninternal const val MIME_TYPE_STREAM = \"application/octet-stream\"\ninternal const val TYPE_PROGUARD = \"proguard\"\n\ninternal class V3GooglePlayPublisher(\n    private val androidPublisher: AndroidPublisher\n) : GooglePlayPublisher {\n\n    override fun publish(data: ReleaseData) {\n\n        data.validate()\n\n        val edits = androidPublisher.edits()\n        val appEdit = edits.insert(data.applicationId, null).execute()\n\n        val artifactVersionCodes = data.artifacts.map {\n            val artifactVersionCode = when (it) {\n                is ReleaseArtifact.Apk -> it.uploadApk(edits, data, appEdit)\n                is ReleaseArtifact.Bundle -> it.uploadBundle(edits, data, appEdit)\n            }\n            artifactVersionCode.toLong()\n        }\n\n        edits.tracks()\n            .update(\n                data.applicationId,\n                appEdit.id,\n                data.releaseTrack.name,\n                data.createTrackUpdate(artifactVersionCodes)\n            )\n            .execute()\n\n        edits.commit(data.applicationId, appEdit.id).execute()\n\n    }\n\n    companion object {\n\n        private val jsonFactory = JacksonFactory.getDefaultInstance()\n        private val httpTransport = GoogleNetHttpTransport.newTrustedTransport()\n        private var publisher: GooglePlayPublisher? = null\n\n        private fun createAndroidPublisher(\n            secretJson: String, applicationName: String, configuration: Configuration\n        ): AndroidPublisher {\n            val credentials = GoogleCredential\n                .fromStream(secretJson.byteInputStream(), httpTransport, jsonFactory)\n                .createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER))\n\n            return AndroidPublisher\n                .Builder(httpTransport, jsonFactory) { httpRequest ->\n                    credentials.initialize(\n                        httpRequest.apply {\n                            readTimeout = configuration.readTimeout\n                            connectTimeout = configuration.connectTimeout\n                        }\n                    )\n                }\n                .setApplicationName(applicationName)\n                .build()\n        }\n\n        private fun ReleaseData.createTrackUpdate(apkVersionCodes: List<Long>): Track {\n            return Track().apply {\n                releases = listOf(\n                    TrackRelease().apply {\n                        versionCodes = apkVersionCodes\n                        status = releaseStatus.name\n                        if (releaseTrack is ReleaseTrack.Rollout) {\n                            userFraction = releaseTrack.userFraction\n                        }\n                        releaseNotes = this@createTrackUpdate.releaseNotes.map { releaseNotes ->\n                            LocalizedText().apply {\n                                language = releaseNotes.locale\n                                text = releaseNotes.file.readTextLines(maxLength = 500)\n                            }\n                        }\n                    }\n                )\n            }\n        }\n\n        private fun ReleaseData.validate() {\n            if (artifacts.isEmpty()) {\n                error(\"No artifacts found for publishing.\")\n            }\n            artifacts.forEach {\n                if (!it.file.exists()) error(\"Artifact does not exist: ${it.file}\")\n                if (it.file.length() == 0L) error(\"Artifact must not be empty: ${it.file}\")\n            }\n        }\n\n        fun getGooglePlayPublisher(\n            credentials: Credentials, applicationName: String, configuration: Configuration\n        ): GooglePlayPublisher {\n            var instance = publisher\n            if (instance == null) {\n                val androidPublisher = createAndroidPublisher(\n                    credentials.getSecretJson(), applicationName, configuration\n                )\n                instance = V3GooglePlayPublisher(androidPublisher)\n                publisher = instance\n            }\n            return instance\n        }\n\n        private fun Credentials.getSecretJson(): String {\n            if (secretJson != null) {\n                if (secretJson.isEmpty()) {\n                    error(\"$EXTENSION_NAME { secretJsonBase64 } must not be empty.\")\n                }\n                return secretJson\n            }\n            if (secretJsonPath == null) {\n                error(\"Either $EXTENSION_NAME { secretJsonBase64 } or $EXTENSION_NAME { secretJsonPath } must be specified.\")\n            }\n            val file = File(secretJsonPath)\n            if (!file.exists()) {\n                error(\"SecretJson file cannot be found: $file\")\n            }\n            if (file.length() == 0L) {\n                error(\"SecretJson file must not be empty: $file\")\n            }\n            return file.readText()\n        }\n    }\n\n}\n\nprivate fun ReleaseArtifact.Apk.uploadApk(\n    edits: AndroidPublisher.Edits, data: ReleaseData, appEdit: AppEdit\n): Int {\n\n    val apkVersionCode = edits.apks()\n        .upload(\n            data.applicationId,\n            appEdit.id,\n            FileContent(MIME_TYPE_APK, file)\n        )\n        .execute()\n        .versionCode\n\n    data.obfuscationMappingFile?.let { obfuscationMappingFile ->\n        edits.deobfuscationfiles()\n            .upload(\n                data.applicationId,\n                appEdit.id,\n                apkVersionCode,\n                TYPE_PROGUARD,\n                FileContent(MIME_TYPE_STREAM, obfuscationMappingFile)\n            )\n            .execute()\n    }\n\n    return apkVersionCode\n}\n\nprivate fun ReleaseArtifact.Bundle.uploadBundle(\n    edits: AndroidPublisher.Edits, data: ReleaseData, appEdit: AppEdit\n): Int {\n    return edits.bundles()\n        .upload(\n            data.applicationId,\n            appEdit.id,\n            FileContent(MIME_TYPE_STREAM, file)\n        )\n        .execute()\n        .versionCode\n}\n"
  },
  {
    "path": "autoplay/src/test/kotlin/de/halfbit/tools/autoplay/PlayPublisherPluginTest.kt",
    "content": "/*\n * Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay\n\nimport com.google.common.truth.Truth.assertThat\nimport de.halfbit.tools.autoplay.publisher.ReleaseStatus\nimport de.halfbit.tools.autoplay.publisher.ReleaseTrack\nimport org.gradle.api.GradleException\nimport org.gradle.api.Project\nimport org.gradle.kotlin.dsl.withGroovyBuilder\nimport org.gradle.testfixtures.ProjectBuilder\nimport org.hamcrest.core.IsEqual.equalTo\nimport org.junit.Before\nimport org.junit.Rule\nimport org.junit.Test\nimport org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage\nimport org.junit.rules.ExpectedException\nimport java.io.File\n\nprivate const val EXPECTED_EXTENSION_NAME = \"autoplay\"\n\n@Suppress(\"RemoveSingleExpressionStringTemplate\")\ninternal class PlayPublisherPluginTest {\n\n    @Rule\n    @JvmField\n    var thrown: ExpectedException = ExpectedException.none()\n\n    private lateinit var project: Project\n\n    @Before\n    fun before() {\n        project = ProjectBuilder.builder()\n            .withName(\"sample-app\")\n            .withProjectDir(File(\"src/test/resources/sample-app/app\"))\n            .build()\n\n        project.pluginManager.apply(\"com.android.application\")\n        project.pluginManager.apply(PlayPublisherPlugin::class.java)\n    }\n\n    @Test\n    fun `PlayPublisherPlugin, valid Apk configuration`() {\n\n        project.withGroovyBuilder {\n\n            \"android\" {\n                \"compileSdkVersion\"(27)\n            }\n\n            \"$EXPECTED_EXTENSION_NAME\" {\n                \"track\"(\"internal\")\n                \"status\"(\"inProgress\")\n                \"userFraction\"(0.5)\n                \"secretJsonBase64\"(\"c2VjcmV0\")\n            }\n\n            \"evaluate\"()\n        }\n\n        val tasks = project.getTasksByName(\"publishApkRelease\", false)\n        assertThat(tasks).hasSize(1)\n\n        val task = tasks.first()\n        assertThat(task).isNotNull()\n        assertThat(task).isInstanceOf(PublishTask::class.java)\n\n        val publishApkRelease = task as PublishTask\n        assertThat(publishApkRelease.artifacts).hasSize(1)\n\n        val artifact = publishApkRelease.artifacts.first()\n        assertThat(artifact).isNotNull()\n        assertThat(artifact.path).endsWith(\"sample-app-release-unsigned.apk\")\n        assertThat(File(artifact.path).exists()).isTrue()\n\n        assertThat(publishApkRelease.releaseNotes).hasSize(1)\n\n        val releaseNotes = publishApkRelease.releaseNotes.first()\n        assertThat(releaseNotes).isNotNull()\n        assertThat(releaseNotes.locale).isEqualTo(\"en-US\")\n        assertThat(releaseNotes.file.path).endsWith(\"release-notes/internal/en-US.txt\")\n\n        assertThat(publishApkRelease.credentials).isNotNull()\n        assertThat(publishApkRelease.credentials.secretJson).isEqualTo(\"secret\")\n        assertThat(publishApkRelease.credentials.secretJsonPath).isNull()\n\n        assertThat(publishApkRelease.obfuscationMappingFile).isNull()\n        assertThat(publishApkRelease.applicationId).isEqualTo(\"de.halfbit.tools.autoplay.sample\")\n        assertThat(publishApkRelease.releaseTrack).isEqualTo(ReleaseTrack.Internal)\n        assertThat(publishApkRelease.releaseStatus).isEqualTo(ReleaseStatus.InProgress)\n\n    }\n\n    @Test\n    fun `PlayPublisherPlugin, valid Bundle configuration`() {\n\n        project.withGroovyBuilder {\n\n            \"android\" {\n                \"compileSdkVersion\"(27)\n            }\n\n            \"$EXPECTED_EXTENSION_NAME\" {\n                \"track\"(\"internal\")\n                \"status\"(\"inProgress\")\n                \"userFraction\"(0.5)\n                \"artifactType\"(\"bundle\")\n                \"secretJsonBase64\"(\"c2VjcmV0\")\n            }\n\n            \"evaluate\"()\n        }\n\n        val tasks = project.getTasksByName(\"publishBundleRelease\", false)\n        assertThat(tasks).hasSize(1)\n\n        val task = tasks.first()\n        assertThat(task).isNotNull()\n        assertThat(task).isInstanceOf(PublishTask::class.java)\n\n        val publishApkRelease = task as PublishTask\n        assertThat(publishApkRelease.artifacts).hasSize(1)\n\n        val artifact = publishApkRelease.artifacts.first()\n        assertThat(artifact).isNotNull()\n        assertThat(artifact.path).endsWith(\"sample-app.aab\")\n        assertThat(File(artifact.path).exists()).isTrue()\n\n        assertThat(publishApkRelease.releaseNotes).hasSize(1)\n\n        val releaseNotes = publishApkRelease.releaseNotes.first()\n        assertThat(releaseNotes).isNotNull()\n        assertThat(releaseNotes.locale).isEqualTo(\"en-US\")\n        assertThat(releaseNotes.file.path).endsWith(\"release-notes/internal/en-US.txt\")\n\n        assertThat(publishApkRelease.credentials).isNotNull()\n        assertThat(publishApkRelease.credentials.secretJson).isEqualTo(\"secret\")\n        assertThat(publishApkRelease.credentials.secretJsonPath).isNull()\n\n        assertThat(publishApkRelease.obfuscationMappingFile).isNull()\n        assertThat(publishApkRelease.applicationId).isEqualTo(\"de.halfbit.tools.autoplay.sample\")\n        assertThat(publishApkRelease.releaseTrack).isEqualTo(ReleaseTrack.Internal)\n        assertThat(publishApkRelease.releaseStatus).isEqualTo(ReleaseStatus.InProgress)\n\n    }\n\n    @Test\n    fun `PublishApkTask, missing 'track'`() {\n\n        thrown.expect(GradleException::class.java)\n        thrown.expectCause(hasMessage(equalTo(\"$EXPECTED_EXTENSION_NAME { track } property is required.\")))\n\n        project.withGroovyBuilder {\n            \"android\" {\n                \"compileSdkVersion\"(27)\n            }\n            \"autoplay\" {\n            }\n            \"evaluate\"()\n        }\n\n        project.getTasksByName(\"publishApkRelease\", false)\n    }\n\n    @Test\n    fun `PublishBundleTask, missing 'track'`() {\n\n        thrown.expect(GradleException::class.java)\n        thrown.expectCause(hasMessage(equalTo(\"$EXPECTED_EXTENSION_NAME { track } property is required.\")))\n\n        project.withGroovyBuilder {\n            \"android\" {\n                \"compileSdkVersion\"(27)\n            }\n            \"autoplay\" {\n                \"artifactType\"(\"bundle\")\n            }\n            \"evaluate\"()\n        }\n\n        project.getTasksByName(\"publishBundleRelease\", false)\n    }\n\n}"
  },
  {
    "path": "autoplay/src/test/kotlin/de/halfbit/tools/autoplay/publisher/common/FileExtTest.kt",
    "content": "/*\n * Copyright (C) 2018 Sergej Shafarenka, www.halfbit.de\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage de.halfbit.tools.autoplay.publisher.common\n\nimport com.google.common.truth.Truth.assertThat\nimport org.junit.Test\nimport java.io.File\n\nclass FileExtTest {\n\n    @Test\n    fun testReadingShortFile() {\n        val file = getResourceFile(\"release-notes-short.txt\")\n        val text = file.readTextLines(maxLength = 500)\n\n        assertThat(text).startsWith(\"v 2.15.0\")\n        assertThat(text).hasLength(206)\n        assertThat(text).endsWith(\"* New: feature three\\n\")\n    }\n\n    @Test\n    fun testReadingLongFile() {\n        val file = getResourceFile(\"release-notes-long.txt\")\n        val text = file.readTextLines(maxLength = 500)\n\n        assertThat(text).startsWith(\"v 2.15.0\")\n        assertThat(text.length).isAtMost(500)\n        assertThat(text).endsWith(\"v 2.7.0\\n\")\n    }\n\n    companion object {\n\n        fun getResourceFile(name: String): File {\n            val path = FileExtTest::class.java.getResource(\n                File.separator + \"LinesFileReader\" + File.separator + name).file\n            return File(path)\n        }\n\n    }\n\n}"
  },
  {
    "path": "autoplay/src/test/resources/LinesFileReader/release-notes-long.txt",
    "content": "v 2.15.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.13.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.12.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.11.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.10.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.9.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.8.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.7.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.6.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.5.0\n* New: feature one\n* New: feature two\n* New: feature three"
  },
  {
    "path": "autoplay/src/test/resources/LinesFileReader/release-notes-short.txt",
    "content": "v 2.15.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.13.0\n* New: feature one\n* New: feature two\n* New: feature three\n\nv 2.12.0\n* New: feature one\n* New: feature two\n* New: feature three\n"
  },
  {
    "path": "autoplay/src/test/resources/sample-app/app/build/outputs/apk/release/sample-app-release-unsigned.apk",
    "content": "sample apk"
  },
  {
    "path": "autoplay/src/test/resources/sample-app/app/build/outputs/bundle/release/sample-app.aab",
    "content": "sample apk"
  },
  {
    "path": "autoplay/src/test/resources/sample-app/app/src/main/AndroidManifest.xml",
    "content": "<manifest package=\"de.halfbit.tools.autoplay.sample\">\n    <application/>\n</manifest>\n"
  },
  {
    "path": "autoplay/src/test/resources/sample-app/app/src/main/autoplay/release-notes/internal/en-US.txt",
    "content": "* New awesome feature added"
  },
  {
    "path": "build.gradle.kts",
    "content": "buildscript {\n    repositories {\n        google()\n        mavenCentral()\n        jcenter()\n    }\n}\n\ntasks.withType<Wrapper>().configureEach {\n    distributionType = Wrapper.DistributionType.ALL\n}\n\nallprojects {\n    repositories {\n        google()\n        jcenter()\n    }\n    configurations {\n        all {\n            resolutionStrategy {\n                force(\"com.google.guava:guava:28.1-jre\")\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.7.1-bin.zip\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\n"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env sh\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >/dev/null\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >/dev/null\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS='\"-Xmx64m\"'\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn () {\n    echo \"$*\"\n}\n\ndie () {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\nnonstop=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\n  NONSTOP* )\n    nonstop=true\n    ;;\nesac\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" -a \"$nonstop\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n    JAVACMD=`cygpath --unix \"$JAVACMD\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Escape application args\nsave () {\n    for i do printf %s\\\\n \"$i\" | sed \"s/'/'\\\\\\\\''/g;1s/^/'/;\\$s/\\$/' \\\\\\\\/\" ; done\n    echo \" \"\n}\nAPP_ARGS=$(save \"$@\")\n\n# Collect all arguments for the java command, following the shell quoting and substitution rules\neval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS \"\\\"-Dorg.gradle.appname=$APP_BASE_NAME\\\"\" -classpath \"\\\"$CLASSPATH\\\"\" org.gradle.wrapper.GradleWrapperMain \"$APP_ARGS\"\n\n# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong\nif [ \"$(uname)\" = \"Darwin\" ] && [ \"$HOME\" = \"$PWD\" ]; then\n  cd \"$(dirname \"$0\")\"\nfi\n\nexec \"$JAVACMD\" \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\"-Xmx64m\"\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif \"%ERRORLEVEL%\" == \"0\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto init\r\n\r\necho.\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r\necho.\r\necho Please set the JAVA_HOME variable in your environment to match the\r\necho location of your Java installation.\r\n\r\ngoto fail\r\n\r\n:init\r\n@rem Get command-line arguments, handling Windows variants\r\n\r\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\r\n\r\n:win9xME_args\r\n@rem Slurp the command line arguments.\r\nset CMD_LINE_ARGS=\r\nset _SKIP=2\r\n\r\n:win9xME_args_slurp\r\nif \"x%~1\" == \"x\" goto execute\r\n\r\nset CMD_LINE_ARGS=%*\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\r\nexit /b 1\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "settings.gradle.kts",
    "content": "include(\":autoplay\")"
  }
]