diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aea931c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,38 @@ +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=space +indent_size=4 + +[{*.sht,*.html,*.shtm,*.shtml,*.htm}] +indent_style=space +indent_size=2 + +[{*.mod,*.dtd,*.ent,*.elt}] +indent_style=space +indent_size=2 + +[{*.jhm,*.xslt,*.xul,*.tagx,*.rng,*.xsl,*.xsd,*.ant,*.tld,*.fxml,*.jrxml,*.jspx,*.xml,*.jnlp,*.wsdl,*.pom}] +indent_style=space +indent_size=2 + +[*.json] +indent_style=space +indent_size=2 + +[*.svg] +indent_style=space +indent_size=2 + +[{*.yml,*.yaml}] +indent_style=space +indent_size=2 + +[*.md] +indent_style = space +indent_size = 2 + +[{*.tsx, *.scss}] +indent_style = space +indent_size = 2 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..85590c8 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: malinskiy diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..4e845d6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behaviour: +1. Full configuration +2. Any additional information about the device provider (devices that were stuck, etc.) + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Logs and reports** +Add an execution log to help explain your problem. If possible, provide the report folder. + +**Devices (please complete the following information):** + - Device: [e.g. emulator/simulator/Nexus 5/etc] + - OS: [e.g. iOS8.1] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..4566abf --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. Are there any related issues already created? + +**Additional context** +Add any other context or code about the feature request here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..27198b5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: ci +on: [ push, pull_request ] +jobs: + ci: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + - name: test + run: | + chmod 0600 $GITHUB_WORKSPACE/vendor/vendor-apple/base/src/test/resources/fixtures/derived-data-manager/test_rsa + ./gradlew clean test jacocoTestReport integrationTest + bash <(curl -s https://codecov.io/bash) + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() + with: + report_paths: '**/build/test-results/test/TEST-*.xml' + - name: detekt + run: | + ./gradlew clean detektCheck || true + - name: validateGradlePlugins + run: | + ./gradlew validatePlugins + cd: + runs-on: ubuntu-22.04 + needs: ci + if: ${{ startsWith(github.ref, 'refs/tags/') }} + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + - uses: little-core-labs/get-git-tag@v3.0.2 + id: tag + if: ${{ startsWith(github.ref, 'refs/tags/') }} + - name: deliver gradle plugin + run: ./gradlew :marathon-gradle-plugin:publishPlugins -Pgradle.publish.key=$GRADLE_PUBLISH_KEY -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET -PreleaseMode=RELEASE + env: + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0df324 --- /dev/null +++ b/.gitignore @@ -0,0 +1,287 @@ +# Created by https://www.gitignore.io/api/node,java,macos,gradle,kotlin,intellij +# Edit at https://www.gitignore.io/?templates=node,java,macos,gradle,kotlin,intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf +.idea/modules +.idea/.name +.idea/compiler.xml +.idea/kotlinc.xml +.idea/misc.xml +.idea/modules.xml + + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +**/local.properties + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Kotlin ### +# Compiled class file + +# Log file + +# BlueJ files + +# Mobile Tools for Java (J2ME) + +# Package Files # + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +# End of https://www.gitignore.io/api/node,java,macos,gradle,kotlin,intellij + +# Custom +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +*.profraw +sample/ios-app/Marathondevices diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..70b1481 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @malinskiy diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e019194 --- /dev/null +++ b/README.md @@ -0,0 +1,166 @@ +

+ Marathon Logo +

+ +
+ +[![GitHub release][img-version-badge]][repo] [![Slack][img-slack-badge]][slack] [![Telegram][img-telegram-badge]][telegram] [![PRs Welcome][prs-badge]][prs] + +[Releases][release]   |   [Documentation][docs]    + +
+ +**Marathon** is a project that helps execute tests in the shortest time possible. Specifically it helps with **stability** of test execution adjusting for flakiness in the environment and in the tests and also achieves best **performance** using high parallelization + +## TL;DR +Marathon is a fast, platform-independent test runner focused on performance and stability. It offers easy to use platform implementations for Android and iOS as well as an API for use with custom hardware farms and more techstacks. + +Marathon implements multiple key concepts of test execution such as test **batching**, **device pools**, test **sharding**, test **sorting**, **preventive retries** as well as **post-factum retries**. By default, most of these are set to conservative defaults but custom configurations are encouraged for those who want to optimize performance and/or stability. + +Marathon's primary focus is on **full control over the balance between stability of test execution, testing performance and cost**. + +For more information see the [documentation][docs] + +### Overview +#### Performance +Marathon takes into account two key aspects of test execution: +* The duration of the test +* The probability of the test passing + +Test run can only finish as quickly as possible if we plan the execution of tests with regard to the expected duration of the test. On the other hand, we need to address the flakiness of the environment and of the test itself. One key indicator of flakiness is the *probability* of the test passing. + +Marathon takes a number of steps to ensure that each test run is as balanced as possible: +* The flakiness strategy queues up preventive retries for tests which are expected to fail during the test run according to the current real-time statistical data +* The sorting strategy forces long tests to be executed first so that if an unexpected retry attempt occurs it doesn't affect the test run significantly (e.g. at the end of execution) +* If all else fail we revert back to post-factum retries, but we try to limit their impact on the run with retry quotas + +### Configuration + +Create a basic **Marathonfile** in the root of your project with the following content: + +Android: +```yaml +name: "My application" +outputDir: "build/reports/marathon" +vendorConfiguration: + type: "Android" + applicationApk: "dist/app-debug.apk" + testApplicationApk: "dist/app-debug-androidTest.apk" +``` + +iOS: +```yaml +name: "My application" +outputDir: "derived-data/Marathon" +vendorConfiguration: + type: "iOS" + bundle: + application: "sample.app" + testApplication: "sampleUITests.xctest" + testType: xcuitest +``` + +Vendor section describes platform specific details. + +Since iOS doesn't have any way to discover remote execution devices you have to provide your simulators using the **Marathondevices** file: + +```yaml +workers: + - transport: + type: local + devices: + - type: simulator + udid: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" + - type: simulatorProfile + deviceType: com.apple.CoreSimulator.SimDeviceType.iPhone-13-mini +``` + +This **Marathondevices** file specifies a list of macOS instances and simulators for use. Marathon can use pre-provisioned simulators, but it can also provision new ones if needed. + +Example above uses the local instance where marathon is executed, but you can connect many more instance via SSH. + +> ℹ️ The instance where you run marathon is not limited to macOS: if you're using remote macOS instances then +you can easily start your marathon run from Linux for example. + +You can find more information on providing devices in the [workers documentation][docs-workers] + +The file structure for testing should look something like this: + +Android: +```shell-session +foo@bar $ tree . +. +├── Marathonfile +├── dist +│   ├── app-debug.apk +│   ├── app-debug-androidTest.apk +``` + +iOS: +```shell-session +foo@bar $ tree . +. +├── Marathondevices +├── Marathonfile +├── build +│   ├── my.app +│   ├── my.xctest + +``` + +### Execution + +Start the test runner in the root of your project +```bash +$ marathon +XXX [main] INFO com.malinskiy.marathon.cli.ApplicationView - Starting marathon +XXX [main] INFO com.malinskiy.marathon.cli.config.ConfigFactory - Checking Marathonfile config +... +``` + +### Requirements +Marathon requires Java Runtime Environment 8 or higher. + +## Move even faster with Marathon Cloud +

+ Marathon Logo +

+Marathon Cloud is a scalable testing-as-a-service product designed and developed by us, the creators of Marathon. It's got all the cloud testing infrastructure you need to run any number of tests in less than 15 minutes, +whether you're a startup or a large enterprise. + +[Learn more][marathon-cloud] + +## Contributing + +See [contributing docs][contributing] + +## License + +Marathon codebase is GPL 2.0 [LICENSE][LICENSE] with following optional components under specific licenses: +* [libxctest-parser][libxctest-parser-license] + + +[repo]:https://github.com/MarathonLabs/marathon + + +[img-version-badge]:https://img.shields.io/github/release/MarathonLabs/marathon.svg?style=for-the-badge +[img-slack-badge]:https://img.shields.io/badge/Chat-Slack-49c39e?style=for-the-badge +[img-telegram-badge]:https://img.shields.io/badge/Chat-Telegram-0088CC?style=for-the-badge + +[slack]:https://bit.ly/2LLghaW +[telegram]:https://t.me/marathontestrunner +[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJzdmcyIiB3aWR0aD0iNjQ1IiBoZWlnaHQ9IjU4NSIgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPiA8ZyBpZD0ibGF5ZXIxIj4gIDxwYXRoIGlkPSJwYXRoMjQxNyIgZD0ibTI5Ny4zIDU1MC44N2MtMTMuNzc1LTE1LjQzNi00OC4xNzEtNDUuNTMtNzYuNDM1LTY2Ljg3NC04My43NDQtNjMuMjQyLTk1LjE0Mi03Mi4zOTQtMTI5LjE0LTEwMy43LTYyLjY4NS01Ny43Mi04OS4zMDYtMTE1LjcxLTg5LjIxNC0xOTQuMzQgMC4wNDQ1MTItMzguMzg0IDIuNjYwOC01My4xNzIgMTMuNDEtNzUuNzk3IDE4LjIzNy0zOC4zODYgNDUuMS02Ni45MDkgNzkuNDQ1LTg0LjM1NSAyNC4zMjUtMTIuMzU2IDM2LjMyMy0xNy44NDUgNzYuOTQ0LTE4LjA3IDQyLjQ5My0wLjIzNDgzIDUxLjQzOSA0LjcxOTcgNzYuNDM1IDE4LjQ1MiAzMC40MjUgMTYuNzE0IDYxLjc0IDUyLjQzNiA2OC4yMTMgNzcuODExbDMuOTk4MSAxNS42NzIgOS44NTk2LTIxLjU4NWM1NS43MTYtMTIxLjk3IDIzMy42LTEyMC4xNSAyOTUuNSAzLjAzMTYgMTkuNjM4IDM5LjA3NiAyMS43OTQgMTIyLjUxIDQuMzgwMSAxNjkuNTEtMjIuNzE1IDYxLjMwOS02NS4zOCAxMDguMDUtMTY0LjAxIDE3OS42OC02NC42ODEgNDYuOTc0LTEzNy44OCAxMTguMDUtMTQyLjk4IDEyOC4wMy01LjkxNTUgMTEuNTg4LTAuMjgyMTYgMS44MTU5LTI2LjQwOC0yNy40NjF6IiBmaWxsPSIjZGQ1MDRmIi8%2BIDwvZz48L3N2Zz4%3D + +[release]:https://github.com/MarathonLabs/marathon/releases/latest "Latest Release (external link) ➶" +[docs]:https://docs.marathonlabs.io +[docs-workers]:https://docs.marathonlabs.io/ios/workers +[contributing]:https://docs.marathonlabs.io/intro/contribute +[prs]:http://makeapullrequest.com "Make a Pull Request (external link) ➶" +[LICENSE]:https://github.com/MarathonLabs/marathon/blob/-/LICENSE +[libxctest-parser-license]: https://github.com/MarathonLabs/marathon/blob/-/vendor/vendor-ios/src/main/resources/EULA.md + +[marathon-cloud]:https://marathonlabs.io diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..7730ab6 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,71 @@ +import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask +import io.gitlab.arturbosch.detekt.Detekt +import io.gitlab.arturbosch.detekt.extensions.DetektExtension + +buildscript { + repositories { + mavenCentral() + google() + } + dependencies { + classpath(BuildPlugins.kotlinPlugin) + classpath(BuildPlugins.junitGradle) + classpath(BuildPlugins.dokka) + } +} + + +plugins { + id("io.gitlab.arturbosch.detekt") version "1.23.4" + id("com.github.ben-manes.versions") version "0.51.0" +} + +configure { + debug = true + input = files( + rootProject.projectDir.absolutePath + ) + config = files("${rootProject.projectDir}/default-detekt-config.yml") + baseline = file("${rootProject.projectDir}/reports/baseline.xml") +} + +fun isNonStable(version: String): Boolean { + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } + val regex = "^[0-9,.v-]+(-r)?$".toRegex() + val isStable = stableKeyword || regex.matches(version) + return isStable.not() +} + +tasks.withType { + rejectVersionIf { + isNonStable(candidate.version) && !isNonStable(currentVersion) + } +} + +tasks.withType { + exclude(".*/resources/.*") + exclude(".*/build/.*") + exclude(".*/sample-app/.*") +} + +allprojects { + group = "com.malinskiy.marathon" + + repositories { + mavenLocal() + mavenCentral() + google() + } + + configurations.all { + resolutionStrategy { + eachDependency { + if (requested.group == "org.jetbrains.kotlin" + && (requested.name.startsWith("kotlin-stdlib") || requested.name.startsWith("kotlin-reflect")) + ) { + useVersion(Versions.kotlin) + } + } + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..4103031 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10") +} diff --git a/buildSrc/src/main/kotlin/ProjectExtensions.kt b/buildSrc/src/main/kotlin/ProjectExtensions.kt new file mode 100644 index 0000000..ecfb672 --- /dev/null +++ b/buildSrc/src/main/kotlin/ProjectExtensions.kt @@ -0,0 +1,33 @@ +import org.gradle.api.Project +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.withType +import org.gradle.testing.jacoco.tasks.JacocoReport +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +fun Project.setupKotlinCompiler(jvmTarget: String = "11") { + tasks.withType { + kotlinOptions.jvmTarget = jvmTarget + kotlinOptions.apiVersion = "1.5" + } + tasks.withType { + sourceCompatibility = jvmTarget + targetCompatibility = jvmTarget + } +} + +fun Project.setupTestTask(jacoco: Boolean = true) { + if (jacoco) { + tasks.named("jacocoTestReport").configure { + reports.xml.required.set(true) + reports.html.required.set(true) + dependsOn(tasks.named("test")) + } + } + + tasks.withType().all { + tasks.getByName("check").dependsOn(this) + useJUnitPlatform() + } +} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 0000000..776987e --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,41 @@ +object Versions { + val marathon = System.getenv("MARATHON_VERSION") ?: "0.10.1" + + val kotlin = "1.9.10" + + val kotlinLogging = "3.0.5" + + val junitGradle = "1.2.0" + val androidGradleVersion = "8.2.2" + val gradlePluginPublish = "1.2.1" + val gradlePluginShadow = "8.1.1" + val gradlePluginDownload = "5.6.0" + + val junit5 = "5.10.1" + + val gson = "2.10.1" + val apacheCommonsCodec = "1.15" + val jupiterEngine = junit5 + val dokka = "1.9.10" + val assertk = "0.28.0" +} + +object BuildPlugins { + val kotlinPlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" + val junitGradle = "org.junit.platform:junit-platform-gradle-plugin:${Versions.junitGradle}" + val androidGradle = "com.android.tools.build:gradle:${Versions.androidGradleVersion}" + val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}" +} + +object Libraries { + val configuration = "com.malinskiy.marathon:configuration:${Versions.marathon}" + val kotlinLogging = "io.github.microutils:kotlin-logging:${Versions.kotlinLogging}" + val gson = "com.google.code.gson:gson:${Versions.gson}" + val apacheCommonsCodec = "commons-codec:commons-codec:${Versions.apacheCommonsCodec}" +} + +object TestLibraries { + val junit5 = "org.junit.jupiter:junit-jupiter:${Versions.junit5}" + val jupiterEngine = "org.junit.jupiter:junit-jupiter-engine:${Versions.jupiterEngine}" + val assertk = "com.willowtreeapps.assertk:assertk:${Versions.assertk}" +} diff --git a/default-detekt-config.yml b/default-detekt-config.yml new file mode 100644 index 0000000..309e267 --- /dev/null +++ b/default-detekt-config.yml @@ -0,0 +1,379 @@ +autoCorrect: true +failFast: false + +test-pattern: # Configure exclusions for test sources + active: true + patterns: # Test file regexes + - '.*/test/.*' + - '.*Test.kt' + - '.*Spec.kt' + exclude-rule-sets: + - 'comments' + exclude-rules: + - 'NamingRules' + - 'WildcardImport' + - 'MagicNumber' + - 'MaxLineLength' + - 'LateinitUsage' + - 'StringLiteralDuplication' + - 'SpreadOperator' + - 'TooManyFunctions' + +build: + maxIssues: 20 + weights: + # complexity: 2 + # LongParameterList: 1 + # style: 1 + # comments: 1 + +processors: + active: true + exclude: + # - 'FunctionCountProcessor' + # - 'PropertyCountProcessor' + # - 'ClassCountProcessor' + # - 'PackageCountProcessor' + # - 'KtFileCountProcessor' + +console-reports: + active: true + exclude: + # - 'ProjectStatisticsReport' + # - 'ComplexityReport' + # - 'NotificationReport' + # - 'FindingsReport' + # - 'BuildFailureReport' + +output-reports: + active: true + exclude: + # - 'HtmlOutputReport' + # - 'PlainOutputReport' + # - 'XmlOutputReport' + +comments: + active: true + CommentOverPrivateFunction: + active: false + CommentOverPrivateProperty: + active: false + EndOfSentenceFormat: + active: false + endOfSentenceFormat: ([.?!][ \t\n\r\f<])|([.?!]$) + UndocumentedPublicClass: + active: false + searchInNestedClass: true + searchInInnerClass: true + searchInInnerObject: true + searchInInnerInterface: true + UndocumentedPublicFunction: + active: false + +complexity: + active: true + ComplexCondition: + active: true + threshold: 4 + ComplexInterface: + active: false + threshold: 10 + includeStaticDeclarations: false + ComplexMethod: + active: true + threshold: 10 + ignoreSingleWhenExpression: false + LabeledExpression: + active: false + LargeClass: + active: true + threshold: 150 + LongMethod: + active: true + threshold: 20 + LongParameterList: + active: true + threshold: 6 + ignoreDefaultParameters: false + MethodOverloading: + active: false + threshold: 6 + NestedBlockDepth: + active: true + threshold: 4 + StringLiteralDuplication: + active: false + threshold: 3 + ignoreAnnotation: true + excludeStringsWithLessThan5Characters: true + ignoreStringsRegex: '$^' + TooManyFunctions: + active: true + thresholdInFiles: 11 + thresholdInClasses: 11 + thresholdInInterfaces: 11 + thresholdInObjects: 11 + thresholdInEnums: 11 + +empty-blocks: + active: true + EmptyCatchBlock: + active: true + allowedExceptionNameRegex: "^(ignore|expected).*" + EmptyClassBlock: + active: true + EmptyDefaultConstructor: + active: true + EmptyDoWhileBlock: + active: true + EmptyElseBlock: + active: true + EmptyFinallyBlock: + active: true + EmptyForBlock: + active: true + EmptyFunctionBlock: + active: true + EmptyIfBlock: + active: true + EmptyInitBlock: + active: true + EmptyKtFile: + active: true + EmptySecondaryConstructor: + active: true + EmptyWhenBlock: + active: true + EmptyWhileBlock: + active: true + +exceptions: + active: true + ExceptionRaisedInUnexpectedLocation: + active: false + methodNames: 'toString,hashCode,equals,finalize' + InstanceOfCheckForException: + active: false + NotImplementedDeclaration: + active: false + PrintStackTrace: + active: false + RethrowCaughtException: + active: false + ReturnFromFinally: + active: false + SwallowedException: + active: false + ThrowingExceptionFromFinally: + active: false + ThrowingExceptionInMain: + active: false + ThrowingExceptionsWithoutMessageOrCause: + active: false + exceptions: 'IllegalArgumentException,IllegalStateException,IOException' + ThrowingNewInstanceOfSameException: + active: false + TooGenericExceptionCaught: + active: true + exceptionNames: + - ArrayIndexOutOfBoundsException + - Error + - Exception + - IllegalMonitorStateException + - NullPointerException + - IndexOutOfBoundsException + - RuntimeException + - Throwable + TooGenericExceptionThrown: + active: true + exceptionNames: + - Error + - Exception + - Throwable + - RuntimeException + +naming: + active: true + ClassNaming: + active: true + classPattern: '[A-Z$][a-zA-Z0-9$]*' + EnumNaming: + active: true + enumEntryPattern: '^[A-Z][_a-zA-Z0-9]*' + ForbiddenClassName: + active: false + forbiddenName: '' + FunctionMaxLength: + active: false + maximumFunctionNameLength: 30 + FunctionMinLength: + active: false + minimumFunctionNameLength: 3 + FunctionNaming: + active: true + functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' + excludeClassPattern: '$^' + MatchingDeclarationName: + active: true + MemberNameEqualsClassName: + active: false + ignoreOverriddenFunction: true + ObjectPropertyNaming: + active: true + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + PackageNaming: + active: true + packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' + TopLevelPropertyNaming: + active: true + constantPattern: '[A-Z][_A-Z0-9]*' + propertyPattern: '[a-z][A-Za-z\d]*' + privatePropertyPattern: '(_)?[a-z][A-Za-z0-9]*' + VariableMaxLength: + active: false + maximumVariableNameLength: 64 + VariableMinLength: + active: false + minimumVariableNameLength: 1 + VariableNaming: + active: true + variablePattern: '[a-z][A-Za-z0-9]*' + privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' + excludeClassPattern: '$^' + +performance: + active: true + ForEachOnRange: + active: true + SpreadOperator: + active: true + UnnecessaryTemporaryInstantiation: + active: true + +potential-bugs: + active: true + DuplicateCaseInWhenExpression: + active: true + EqualsAlwaysReturnsTrueOrFalse: + active: false + EqualsWithHashCodeExist: + active: true + ExplicitGarbageCollectionCall: + active: true + InvalidRange: + active: false + IteratorHasNextCallsNextMethod: + active: false + IteratorNotThrowingNoSuchElementException: + active: false + LateinitUsage: + active: false + excludeAnnotatedProperties: "" + ignoreOnClassesPattern: "" + UnconditionalJumpStatementInLoop: + active: false + UnreachableCode: + active: true + UnsafeCallOnNullableType: + active: false + UnsafeCast: + active: false + UselessPostfixExpression: + active: false + WrongEqualsTypeParameter: + active: false + +style: + active: true + CollapsibleIfStatements: + active: false + DataClassContainsFunctions: + active: false + conversionFunctionPrefix: 'to' + EqualsNullCall: + active: false + ExpressionBodySyntax: + active: false + ForbiddenComment: + active: true + values: 'TODO:,FIXME:,STOPSHIP:' + ForbiddenImport: + active: false + imports: '' + FunctionOnlyReturningConstant: + active: false + ignoreOverridableFunction: true + excludedFunctions: 'describeContents' + LoopWithTooManyJumpStatements: + active: false + maxJumpCount: 1 + MagicNumber: + active: true + ignoreNumbers: '-1,0,1,2' + ignoreHashCodeFunction: true + ignorePropertyDeclaration: false + ignoreConstantDeclaration: true + ignoreCompanionObjectPropertyDeclaration: true + ignoreAnnotation: false + ignoreNamedArgument: true + ignoreEnums: false + MaxLineLength: + active: true + maxLineLength: 150 + excludePackageStatements: false + excludeImportStatements: false + MayBeConst: + active: false + ModifierOrder: + active: true + NestedClassesVisibility: + active: false + NewLineAtEndOfFile: + active: true + NoTabs: + active: false + OptionalAbstractKeyword: + active: true + OptionalUnit: + active: false + OptionalWhenBraces: + active: false + ProtectedMemberInFinalClass: + active: false + RedundantVisibilityModifierRule: + active: false + ReturnCount: + active: true + max: 2 + excludedFunctions: "equals" + SafeCast: + active: true + SerialVersionUIDInSerializableClass: + active: false + SpacingBetweenPackageAndImports: + active: false + ThrowsCount: + active: true + max: 3 + TrailingWhitespace: + active: false + UnnecessaryAbstractClass: + active: false + UnnecessaryInheritance: + active: false + UnnecessaryParentheses: + active: false + UntilInsteadOfRangeTo: + active: false + UnusedImports: + active: true + UnusedPrivateMember: + active: false + UseDataClass: + active: false + excludeAnnotatedClasses: "" + UtilityClassWithPublicConstructor: + active: false + WildcardImport: + active: true + excludeImports: 'java.util.*,kotlinx.android.synthetic.*' diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/marathon-gradle-plugin/build.gradle.kts b/marathon-gradle-plugin/build.gradle.kts new file mode 100644 index 0000000..491c5cc --- /dev/null +++ b/marathon-gradle-plugin/build.gradle.kts @@ -0,0 +1,77 @@ +import de.undercouch.gradle.tasks.download.Download; + +plugins { + `kotlin-dsl` + id("org.jetbrains.dokka") + id("com.gradle.plugin-publish") version Versions.gradlePluginPublish + id("com.github.johnrengelman.shadow") version Versions.gradlePluginShadow + id("de.undercouch.download") version Versions.gradlePluginDownload +} + +project.version = Versions.marathon + +gradlePlugin { + website.set("https://docs.marathonlabs.io/") + vcsUrl.set("https://github.com/MarathonLabs/marathon") + plugins { + create("marathon-gradle-plugin") { + id = "com.malinskiy.marathon" + displayName = "Gradle plugin for Marathon test runner" + description = "Marathon is a fast and platform-independent test runner focused on performance and stability" + tags.set(listOf("marathon", "test", "runner", "android")) + implementationClass = "com.malinskiy.marathon.gradle.MarathonPlugin" + } + } +} + +setupKotlinCompiler() +//Tests are blackbox, no way to collect coverage anyway +setupTestTask(jacoco = false) + +dependencies { + shadow(gradleApi()) + shadow(localGroovy()) + + shadow(Libraries.kotlinLogging) + implementation(Libraries.configuration) + compileOnly(BuildPlugins.androidGradle) + shadow(Libraries.apacheCommonsCodec) + + testImplementation(gradleTestKit()) + testImplementation(TestLibraries.junit5) + testImplementation(TestLibraries.assertk) + testRuntimeOnly(TestLibraries.jupiterEngine) +} + +// needed to prevent inclusion of gradle-api into shadow JAR +afterEvaluate { + configurations["api"].dependencies.remove(dependencies.gradleApi()) + tasks.test.configure { + dependsOn(tasks.named("publishToMavenLocal")) + } +} + +val downloadCLI = tasks.create("downloadCLI", Download::class) { + src("https://github.com/MarathonLabs/marathon/releases/download/${Versions.marathon}/marathon-${Versions.marathon}.zip") + dest(layout.buildDirectory.file("marathon-cli.zip").get()) + onlyIfModified(true) +} + +tasks.processResources.configure { + from(downloadCLI) { + rename { + "marathon-cli.zip" + } + } + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + dependsOn(downloadCLI) +} + +tasks.shadowJar { + isZip64 = true + relocate( + "com.fasterxml.jackson", + "com.malinskiy.marathon.shadow.com.fasterxml.jackson" + ) + archiveClassifier.set("") +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/Const.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/Const.kt new file mode 100644 index 0000000..bc08a91 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/Const.kt @@ -0,0 +1,5 @@ +package com.malinskiy.marathon.gradle + +object Const { + const val GROUP = "marathon" +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/GradleAndroidTestBundle.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/GradleAndroidTestBundle.kt new file mode 100644 index 0000000..0fab40b --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/GradleAndroidTestBundle.kt @@ -0,0 +1,28 @@ +package com.malinskiy.marathon.gradle + +import com.android.build.api.variant.BuiltArtifactsLoader +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.Optional +import java.io.Serializable + +/** + * Can't just make the properties nullable, see https://github.com/gradle/gradle/issues/2016 + */ +sealed class GradleAndroidTestBundle : Serializable { + class ApplicationWithTest( + @InputDirectory val apkFolder: DirectoryProperty, + @Internal val artifactLoader: Property, + @InputDirectory val testApkFolder: DirectoryProperty, + @Internal val testArtifactLoader: Property, + ) : GradleAndroidTestBundle(), Serializable + + class TestOnly( + @InputDirectory val testApkFolder: DirectoryProperty, + @Internal val testArtifactLoader: Property, + ) : GradleAndroidTestBundle(), Serializable +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonExtension.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonExtension.kt new file mode 100644 index 0000000..e2addef --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonExtension.kt @@ -0,0 +1,572 @@ +package com.malinskiy.marathon.gradle + +import com.malinskiy.marathon.config.ScreenRecordingPolicy +import com.malinskiy.marathon.config.strategy.ExecutionStrategyConfiguration +import com.malinskiy.marathon.config.vendor.android.AdbEndpoint +import com.malinskiy.marathon.config.vendor.android.AllureConfiguration +import com.malinskiy.marathon.config.vendor.android.FileSyncConfiguration +import com.malinskiy.marathon.config.vendor.android.ScreenRecordConfiguration +import com.malinskiy.marathon.config.vendor.android.SerialStrategy +import com.malinskiy.marathon.config.vendor.android.TestAccessConfiguration +import com.malinskiy.marathon.config.vendor.android.TestParserConfiguration +import com.malinskiy.marathon.config.vendor.android.TimeoutConfiguration +import com.malinskiy.marathon.gradle.configuration.PoolingStrategyConfiguration +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil +import java.io.File + +open class MarathonExtension { + /** + * This string specifies the name of this test run configuration. It is used mainly in the generated test reports. + */ + var name: String = "Marathon" + + var analyticsConfiguration: AnalyticsConfig? = null + + /** + * Pooling strategy affects how devices are grouped together + */ + var poolingStrategy: PoolingStrategyConfiguration? = null + + /** + * Sharding is a mechanism that allows the marathon to affect the tests scheduled for execution inside each pool + */ + var shardingStrategy: ShardingStrategyConfiguration? = null + + /** + * In order to optimise the performance of test execution tests need to be sorted. This requires analytics backend enabled since we need + * historical data in order to anticipate tests behaviour like duration and success/failure rate + */ + var sortingStrategy: SortingStrategyConfiguration? = null + + /** + * Batching mechanism allows you to trade off stability for performance. A group of tests executed using one single run is called a batch. Most + * of the time, this means that between tests in the same batch you're sharing the device state so there is no clean-up. On the other hand you + * gain some performance improvements since the execution command usually is quite slow (up to 10 seconds for some platforms). + */ + var batchingStrategy: BatchingStrategyConfiguration? = null + + /** + * This is the main anticipation logic for marathon. Using the analytics backend we can understand the success rate and hence queue preventive + * retries to mitigate the flakiness of the tests and environment + */ + var flakinessStrategy: FlakinessStrategyConfiguration? = null + + /** + * This is the logic that kicks in if preventive logic failed to anticipate such high number of retries. This works after the tests were + * actually executed + */ + var retryStrategy: RetryStrategyConfiguration? = null + + /** + * In order to indicate to marathon which tests you want to execute you can use the allowlist and blocklist parameters. + * + * First allowlist is applied, then the blocklist. Each accepts a *TestFilter*: + * + * | YAML type | Gradle class | Description | + * | --------------------------------- |:-----------------------------------------------:| ------------------------------------------------------------------------------------------:| + * | "fully-qualified-test-name" | `FullyQualifiedTestnameFilterConfiguration` | Filters tests by their FQTN which is `$package.$class#$method`. The `#` sign is important! | + * | "fully-qualified-class-name" | `FullyQualifiedClassnameFilterConfiguration` | Filters tests by their FQCN which is `$package.$class` | + * | "simple-class-name" | `SimpleClassnameFilterConfiguration` | Filters tests by using only test class name, e.g. `MyTest` | + * | "simple-test-name" | `SimpleTestnameFilterConfiguration` | Filters tests by using only test class name with test method, e.g. `MyTest#mySimpleTest` | + * | "package" | `TestPackageFilterConfiguration` | Filters tests by using only test package, e.g. `com.example` | + * | "method" | `TestMethodFilterConfiguration` | Filters tests by using only test method, e.g. `myComplicatedTest` | + * | "annotation" | `AnnotationFilterConfiguration` | Filters tests by using only test annotation name, e.g. `androidx.test.filters.LargeTest` | + * + * All the filters can be used in allowlist and in blocklist block as well, for example the following will run only smoke tests: + * + * ```yaml + * allowlist: + * - type: "annotation" + * values: + * - "com.example.SmokeTest" + * ``` + * + * And the next snippet will execute everything, but the smoke tests: + * + * ```yaml + * blocklist: + * - type: "annotation" + * values: + * - "com.example.SmokeTest" + * ``` + * + * ### Filter parameters + * + * Each of the above filters expects **only one** of the following parameters: + * + * - A `regex` for matching + * - An array of `values` + * - A `file` that contains each value on a separate line (empty lines will be ignored) + * + * ### Regex filtering + * + * An example of `regex` filtering is executing any test for a particular package, e.g. for package: `com.example` and it's subpackages: + * + * ```yaml + * allowlist: + * - type: "package" + * regex: "com\.example.*" + * ``` + * + * ### Values filtering + * + * You could also specify each package separately via values: + * + * ```yaml + * allowlist: + * - type: "package" + * values: + * - "com.example" + * - "com.example.subpackage" + * ``` + * + * ### Values file filtering + * + * Or you can supply these packages via a file (be careful with the relative paths: they will be relative to the workdir of the process): + * + * ```yaml + * allowlist: + * - type: "package" + * file: "testing/myfilterfile" + * ``` + * + * Inside the `testing/myfilterfile` you should supply the values, each on a separate line: + * + * ``` + * com.example + * com.example.subpackage + * ``` + */ + var filteringConfiguration: FilteringPluginConfiguration? = null + + /** + * + * Directory path to use as the root folder for all the runner output (logs, reports, etc). + * + * For gradle, the output path will automatically be set to a `marathon` folder in your reports folder unless it's overridden. + * + */ + var baseOutputDir: String? = null + + + var outputConfiguration: OutputConfiguration? = null + fun outputConfiguration(action: Action) { + outputConfiguration = OutputConfiguration().also { action.execute(it) } + } + + fun outputConfiguration(closure: Closure) = outputConfiguration(ConfigureUtil.configureUsing(closure)) + + /** + * By default, the build fails if some tests failed. If you want to the build to succeed even if some tests failed use *true*. + */ + var ignoreFailures: Boolean? = null + + /** + * Depending on the vendor implementation code coverage may not be supported. By default, code coverage is disabled. If this option is enabled, + * code coverage will be collected and marathon assumes that code coverage generation will be setup by user (e.g. proper build flags, jacoco + * jar added to classpath, etc). + */ + var isCodeCoverageEnabled: Boolean? = null + + /** + * When executing tests with retries there are multiple trade-offs to be made. Two execution strategies are supported: any success or all success. + * By default, any success strategy is used with fast execution i.e. if one of the test retries succeeds then the test is considered successfully + * executed and all non-started retries are removed. + */ + var executionStrategy: ExecutionStrategyConfiguration? = null + + /** + * By default, tests that don't have any status reported after execution (for example a device disconnected during the execution) retry + * indefinitely. You can limit the number of total execution for such cases using this option. + */ + var uncompletedTestRetryQuota: Int? = null + + var includeSerialRegexes: Collection? = null + var excludeSerialRegexes: Collection? = null + + /** + * This parameter specifies the behaviour for the underlying test executor to timeout if the batch execution exceeded some duration. By + * default, this is set to 30 minutes. + */ + var testBatchTimeoutMillis: Long? = null + + /** + * This parameter specifies the behaviour for the underlying test executor to timeout if there is no output. By default, this is set to 5 + * minutes. + */ + var testOutputTimeoutMillis: Long? = null + + /** + * Enabled very verbose logging to stdout of all the marathon components. Very useful for debugging. + */ + var debug: Boolean? = null + + /** + * By default, screen recording will only be pulled for tests that failed (**ON_FAILURE** option). This is to save space and also to reduce the + * test duration time since we're not pulling additional files. If you need to save screen recording regardless of the test pass/failure please + * use the **ON_ANY** option + */ + var screenRecordingPolicy: ScreenRecordingPolicy? = null + + /** + * To better understand the use-cases that marathon is used for we're asking you to provide us with anonymised information about your usage. By + * default, this is enabled. Use **false** to disable. + */ + var analyticsTracking: Boolean = true + + /** + * Whether to report crashes to Bugsnag. By default, this is enabled. Use **false** to disable. + */ + var bugsnagReporting: Boolean = true + + /** + * When the test run starts device provider is expected to provide some devices. This should not take more than 3 minutes by default. If your + * setup requires this to be changed please override using this parameter + */ + var deviceInitializationTimeoutMillis: Long? = null + + /** + * By default, marathon does not clear state between test batch executions. To mitigate potential test side-effects, one could add an option to clear the package data between test runs. Keep in mind that test side-effects might be present. + * If you want to isolate tests even further, then you should consider reducing the batch size. + * + * Since `pm clear` resets the permissions of the package, the granting of permissions during installation is essentially overridden. Marathon doesn't grant the permissions again. + * If you need permissions to be granted and you need to clear the state, consider alternatives like [GrantPermissionRule](https://developer.android.com/reference/androidx/test/rule/GrantPermissionRule) + * + */ + var applicationPmClear: Boolean? = null + + /** + * By default, marathon does not clear state between test batch executions. To mitigate potential test side-effects, one could add an option to clear the package data between test runs. Keep in mind that test side-effects might be present. + * If you want to isolate tests even further, then you should consider reducing the batch size. + * + * Since `pm clear` resets the permissions of the package, the granting of permissions during installation is essentially overridden. Marathon doesn't grant the permissions again. + * If you need permissions to be granted and you need to clear the state, consider alternatives like [GrantPermissionRule](https://developer.android.com/reference/androidx/test/rule/GrantPermissionRule) + * + */ + var testApplicationPmClear: Boolean? = null + + /** + * This option will allow you to increase/decrease the default adb init timeout of 30 seconds. + */ + var adbInitTimeout: Int? = null + + /** + * By default, these will be ```-g -r``` (```-r``` prior to marshmallow). You can specify additional options to append to the default ones. + */ + var installOptions: String? = null + + /** + * This option allows to customise how marathon assigns a serial number to devices. + * + * Notes on the source of serial number: + * + * * ```marathon_property``` - Property name `marathon.serialno` + * * ```boot_property``` - Property name `ro.boot.serialno` + * * ```hostname``` - Property name `net.hostname` + * * ```ddms``` - Adb serial number(same as you see with `adb devices` command) + * * ```automatic``` - Sequentially checks all available options for first non-empty value. + * + * Priority order: + * Before 0.6: ```marathon_property``` -> ```boot_property``` -> ```hostname``` -> ```ddms``` -> UUID + * After 0.6: ```marathon_property``` -> ```ddms``` -> ```boot_property``` -> ```hostname``` -> UUID + */ + var serialStrategy: SerialStrategy? = null + + /** + * By default, device will record a 1280x720 1Mbps video of up to 180 seconds if it is supported. If on the other hand you want to force + * screenshots or configure the recording parameters you can override using this parameter + */ + var screenRecordConfiguration: ScreenRecordConfiguration? = null + + var waitForDevicesTimeoutMillis: Long? = null + + /** + * If you want to enable on-device collection of allure's reports, you can use this option + */ + var allureConfiguration: AllureConfiguration? = null + + /** + * With the introduction of [adam](https://github.com/Malinskiy/adam) we can precisely control the timeout of individual requests + */ + var timeoutConfiguration: TimeoutConfiguration? = null + + /** + * Sometimes you need to pull some folders from each device after the test execution. It may be screenshots or logs or other debug information. + * To help with this marathon supports pulling files from devices at the end of the test batch execution. + */ + var fileSyncConfiguration: FileSyncConfiguration? = null + + /** + * Test parsing (collecting a list of tests expected to execute) can be done using either a local test parser, which uses byte code analysis, + * or a remote test parser that uses an Android device to collect a list of tests expected to run. Both have pros and cons listed below: + * + * | YAML type | Gradle class | Pros | Const | + * | --------------|:---------------------:| ------------------------------------------------------------------------------------------------------------------ :| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- :| + * | "local" | `LocalTestParser` | Doesn't require a booted Android device | Doesn't support runtime-generated tests, e.g. named parameterized tests. Doesn't support parallelising parameterized tests | + * | "remote" | `RemoteTestParser` | Supports any runtime-generated tests, including parameterized, and allows marathon to parallelise their execution | Requires a booted Android device for parsing. If you need to use annotations for filtering purposes, requires test apk changes as well as attaching a test run listener for parser| + * + * Default test parser is local. If you need to parallelize the execution of parameterized tests or have complex runtime test generation + * (custom test runners, e.g. cucumber) - remote parser is your choice. + * + * For annotations parsing using remote test parser test run is triggered without running tests (using `-e log true` option). Annotations are + * expected to be reported as test metrics, e.g.: + * + * ```text + * INSTRUMENTATION_STATUS_CODE: 0 + * INSTRUMENTATION_STATUS: class=com.example.FailedAssumptionTest + * INSTRUMENTATION_STATUS: current=4 + * INSTRUMENTATION_STATUS: id=AndroidJUnitRunner + * INSTRUMENTATION_STATUS: numtests=39 + * INSTRUMENTATION_STATUS: stream= + * com.example.FailedAssumptionTest: + * INSTRUMENTATION_STATUS: test=ignoreTest + * INSTRUMENTATION_STATUS_CODE: 1 + * INSTRUMENTATION_STATUS: com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer.v2=[androidx.test.filters.SmallTest(), io.qameta.allure.kotlin.Severity(value=critical), io.qameta.allure.kotlin.Story(value=Slow), org.junit.Test(expected=class org.junit.Test$None:timeout=0), io.qameta.allure.kotlin.Owner(value=user2), io.qameta.allure.kotlin.Feature(value=Text on main screen), io.qameta.allure.kotlin.Epic(value=General), org.junit.runner.RunWith(value=class io.qameta.allure.android.runners.AllureAndroidJUnit4), kotlin.Metadata(bytecodeVersion=[I@bdf6b25:data1=[Ljava.lang.String;@46414fa:data2=[Ljava.lang.String;@5d4aab:extraInt=0:extraString=:kind=1:metadataVersion=[I@fbb1508:packageName=), io.qameta.allure.kotlin.Severity(value=critical), io.qameta.allure.kotlin.Story(value=Slow)] + * INSTRUMENTATION_STATUS_CODE: 2 + * INSTRUMENTATION_STATUS: class=com.example.FailedAssumptionTest + * INSTRUMENTATION_STATUS: current=4 + * INSTRUMENTATION_STATUS: id=AndroidJUnitRunner + * INSTRUMENTATION_STATUS: numtests=39 + * INSTRUMENTATION_STATUS: stream=. + * INSTRUMENTATION_STATUS: test=ignoreTest + * ``` + * + * To generate the above metrics you need to add a JUnit 4 listener to your dependencies: + * + * ```kotlin + * dependecies { + * androidTestImplementation("com.malinskiy.adam:android-junit4-test-annotation-producer:${LATEST_VERSION}") + * } + * ``` + * + * Then you need to attach it to the execution. One way to attach the listener is using `am instrument` parameters, e.g. + * `-e listener com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer`. + */ + var testParserConfiguration: TestParserConfiguration? = null + + /** + * This option will grant all runtime permissions during the installation of the + * application. This works like the option `-g` for ```adb install``` command. By default, it's set to **false**. + */ + var autoGrantPermission: Boolean? = null + + /** + * If you want to pass additional arguments to the `am instrument` command executed on the device + */ + var instrumentationArgs: MutableMap = mutableMapOf() + + /** + * Marathon supports adam's junit extensions which allow tests to gain access to adb on all devices and emulator's control + gRPC port. See the + * [docs](https://malinskiy.github.io/adam/extensions/1-android-junit/) as well as the [PR](https://github.com/Malinskiy/adam/pull/30) for + * description on how this works. + * + */ + var testAccessConfiguration: TestAccessConfiguration? = null + + /** + * Default configuration of marathon assumes that adb server is started locally and is available at `127.0.0.1:5037`. In some cases it may be + * desirable to connect multiple adb servers instead of connecting devices to a single adb server. An example of this is distributed execution + * of tests using test access (calling adb commands from tests). For such scenario all emulators should be connected via a local (in relation + * to the emulator) adb server. Default port for each host is 5037. + * + * In order to expose the adb server it should be started on all or public network interfaces using option `-a`. For example, if you want to + * expose the adb server and start it in foreground explicitly on port 5037: `adb nodaemon server -a -P 5037`. + * + */ + var adbServers: List? = null + + /** + * Install extra apk before running the tests if required, e.g. test-butler.apk + */ + var extraApplications: List? = null + + /** + * By default, instrumentation uses --no-window-animation flag. Use this option if you want to enable window animations + */ + var disableWindowAnimation: Boolean? = null + + /** + * Configuration of analytics backend to be used for storing and retrieving test metrics. This plays a major part in optimising + * performance and mitigating flakiness. + */ + fun analytics(action: Action) { + analyticsConfiguration = AnalyticsConfig().also { action.execute(it) } + } + + /** + * Batching mechanism allows you to trade off stability for performance. A group of tests executed using one single run is called a batch. Most + * of the time, this means that between tests in the same batch you're sharing the device state so there is no clean-up. On the other hand you + * gain some performance improvements since the execution command usually is quite slow (up to 10 seconds for some platforms). + */ + fun batchingStrategy(action: Action) { + batchingStrategy = BatchingStrategyConfiguration().also { action.execute(it) } + } + + /** + * This is the main anticipation logic for marathon. Using the analytics backend we can understand the success rate and hence queue preventive + * retries to mitigate the flakiness of the tests and environment + */ + fun flakinessStrategy(action: Action) { + flakinessStrategy = FlakinessStrategyConfiguration().also { action.execute(it) } + } + + /** + * Pooling strategy affects how devices are grouped together + */ + fun poolingStrategy(action: Action) { + poolingStrategy = PoolingStrategyConfiguration().also { action.execute(it) } + } + + /** + * This is the logic that kicks in if preventive logic failed to anticipate such high number of retries. This works after the tests were + * actually executed + */ + fun retryStrategy(action: Action) { + retryStrategy = RetryStrategyConfiguration().also { action.execute(it) } + } + + /** + * Sharding is a mechanism that allows the marathon to affect the tests scheduled for execution inside each pool + */ + fun shardingStrategy(action: Action) { + shardingStrategy = ShardingStrategyConfiguration().also { action.execute(it) } + } + + /** + * In order to optimise the performance of test execution tests need to be sorted. This requires analytics backend enabled since we need + * historical data in order to anticipate tests behaviour like duration and success/failure rate + */ + fun sortingStrategy(action: Action) { + sortingStrategy = SortingStrategyConfiguration().also { action.execute(it) } + } + + /** + * In order to indicate to marathon which tests you want to execute you can use the allowlist and blocklist parameters. + * + * First allowlist is applied, then the blocklist. Each accepts a *TestFilter*: + * + * | YAML type | Gradle class | Description | + * | --------------------------------- |:-----------------------------------------------:| ------------------------------------------------------------------------------------------:| + * | "fully-qualified-test-name" | `FullyQualifiedTestnameFilterConfiguration` | Filters tests by their FQTN which is `$package.$class#$method`. The `#` sign is important! | + * | "fully-qualified-class-name" | `FullyQualifiedClassnameFilterConfiguration` | Filters tests by their FQCN which is `$package.$class` | + * | "simple-class-name" | `SimpleClassnameFilterConfiguration` | Filters tests by using only test class name, e.g. `MyTest` | + * | "package" | `TestPackageFilterConfiguration` | Filters tests by using only test package, e.g. `com.example` | + * | "method" | `TestMethodFilterConfiguration` | Filters tests by using only test method, e.g. `myComplicatedTest` | + * | "annotation" | `AnnotationFilterConfiguration` | Filters tests by using only test annotation name, e.g. `androidx.test.filters.LargeTest` | + * + * All the filters can be used in allowlist and in blocklist block as well, for example the following will run only smoke tests: + * + * ```yaml + * allowlist: + * - type: "annotation" + * values: + * - "com.example.SmokeTest" + * ``` + * + * And the next snippet will execute everything, but the smoke tests: + * + * ```yaml + * blocklist: + * - type: "annotation" + * values: + * - "com.example.SmokeTest" + * ``` + * + * ### Filter parameters + * + * Each of the above filters expects **only one** of the following parameters: + * + * - A `regex` for matching + * - An array of `values` + * - A `file` that contains each value on a separate line (empty lines will be ignored) + * + * ### Regex filtering + * + * An example of `regex` filtering is executing any test for a particular package, e.g. for package: `com.example` and it's subpackages: + * + * ```yaml + * allowlist: + * - type: "package" + * regex: "com\.example.*" + * ``` + * + * ### Values filtering + * + * You could also specify each package separately via values: + * + * ```yaml + * allowlist: + * - type: "package" + * values: + * - "com.example" + * - "com.example.subpackage" + * ``` + * + * ### Values file filtering + * + * Or you can supply these packages via a file (be careful with the relative paths: they will be relative to the workdir of the process): + * + * ```yaml + * allowlist: + * - type: "package" + * file: "testing/myfilterfile" + * ``` + * + * Inside the `testing/myfilterfile` you should supply the values, each on a separate line: + * + * ``` + * com.example + * com.example.subpackage + * ``` + */ + fun filteringConfiguration(action: Action) { + filteringConfiguration = FilteringPluginConfiguration().also { action.execute(it) } + } + + /** + * If you want to pass additional arguments to the `am instrument` command executed on the device + */ + fun instrumentationArgs(action: Action>) { + instrumentationArgs = mutableMapOf().also { action.execute(it) } + } + + /** + * If you want to enable on-device collection of allure's reports, you can use this option + */ + fun allureConfiguration(action: Action) { + allureConfiguration = AllureConfiguration().also { action.execute(it) } + } + + /** + * With the introduction of [adam](https://github.com/Malinskiy/adam) we can precisely control the timeout of individual requests + */ + fun timeoutConfiguration(action: Action) { + timeoutConfiguration = TimeoutConfiguration().also { action.execute(it) } + } + + /** + * Sometimes you need to pull some folders from each device after the test execution. It may be screenshots or logs or other debug information. + * To help with this marathon supports pulling files from devices at the end of the test batch execution. + * + * Please pay attention to the path on the device: it's a relative path to the `Environment.getExternalStorageDirectory()` or + * the `EXTERNAL_STORAGE` envvar. In practice this means that if you have a folder like `/sdcard/my-folder` you should specify `/my-folder` as + * a relative path. + * + * Starting with Android 11 your test application will require MANAGE_EXTERNAL_STORAGE permission: + * + * ```xml + * + * + * + * ... + * + * ``` + * + * Marathon will automatically grant this permission before executing tests if you pull any files from devices. + */ + fun fileSyncConfiguration(action: Action) { + fileSyncConfiguration = FileSyncConfiguration().also { action.execute(it) } + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonPlugin.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonPlugin.kt new file mode 100644 index 0000000..81f73fb --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/MarathonPlugin.kt @@ -0,0 +1,277 @@ +package com.malinskiy.marathon.gradle + +import com.android.build.api.artifact.SingleArtifact +import com.android.build.api.variant.AndroidTest +import com.android.build.api.variant.ApplicationAndroidComponentsExtension +import com.android.build.api.variant.BuiltArtifactsLoader +import com.android.build.api.variant.LibraryAndroidComponentsExtension +import com.android.build.api.variant.TestAndroidComponentsExtension +import com.malinskiy.marathon.config.Configuration +import com.malinskiy.marathon.config.vendor.VendorConfiguration +import com.malinskiy.marathon.gradle.configuration.toStrategy +import com.malinskiy.marathon.gradle.service.JsonService +import com.malinskiy.marathon.gradle.task.GenerateMarathonfileTask +import com.malinskiy.marathon.gradle.task.MarathonRunTask +import com.malinskiy.marathon.gradle.task.MarathonUnpackTask +import org.apache.commons.codec.digest.DigestUtils +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.file.Directory +import org.gradle.api.file.RelativePath +import org.gradle.api.logging.Logger +import org.gradle.api.plugins.BasePlugin +import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.closureOf +import org.gradle.kotlin.dsl.findByType +import java.io.File + +class MarathonPlugin : Plugin { + + override fun apply(project: Project) { + val logger = project.logger + logger.info("Applying marathon plugin") + val marathonExtension = project.extensions.create("marathon", MarathonExtension::class.java) + + val rootProject = project.rootProject + val jsonServiceProvider = rootProject.gradle.sharedServices.registerIfAbsent("marathonJson", JsonService::class.java) {} + val wrapper: TaskProvider = rootProject.tasks.findByName(MarathonUnpackTask.NAME)?.let { + rootProject.tasks.named(MarathonUnpackTask.NAME, MarathonUnpackTask::class.java) + } ?: applyRoot(rootProject) + + val marathonTask: Task = project.task(TASK_PREFIX, closureOf { + group = JavaBasePlugin.VERIFICATION_GROUP + description = "Runs all the instrumentation test variations on all the connected devices" + }) + + val appExtension = project.extensions.findByType(ApplicationAndroidComponentsExtension::class.java) + val libraryExtension = project.extensions.findByType(LibraryAndroidComponentsExtension::class.java) + val testExtension = project.extensions.findByType(TestAndroidComponentsExtension::class.java) + val conf = + project.extensions.getByName("marathon") as? MarathonExtension ?: throw IllegalStateException("Android extension not found") + + when { + appExtension != null -> { + val sdkDirectory: Provider = appExtension.sdkComponents.sdkDirectory + appExtension.onVariants { applicationVariant -> + val androidTest = applicationVariant.androidTest + if (androidTest != null) { + logger.info("Applying marathon for ${applicationVariant.name}") + + val apkFolder: Provider = applicationVariant.artifacts.get(SingleArtifact.APK) + val artifactsLoader = applicationVariant.artifacts.getBuiltArtifactsLoader() + + val testApkFolder: Provider = androidTest.artifacts.get(SingleArtifact.APK) + val testArtifactsLoader = androidTest.artifacts.getBuiltArtifactsLoader() + + val bundle = GradleAndroidTestBundle.ApplicationWithTest( + apkFolder = project.objects.directoryProperty().apply { set(apkFolder) }, + artifactLoader = project.objects.property(BuiltArtifactsLoader::class.java) + .apply { set(artifactsLoader) }, + testApkFolder = project.objects.directoryProperty().apply { set(testApkFolder) }, + testArtifactLoader = project.objects.property(BuiltArtifactsLoader::class.java) + .apply { set(testArtifactsLoader) }, + ) + + val (generateMarathonfileTaskProvider, testTaskForVariantProvider) = createTasks( + logger, androidTest.name, bundle, project, conf, sdkDirectory, wrapper, jsonServiceProvider + ) + marathonTask.dependsOn(testTaskForVariantProvider) + } + } + } + + libraryExtension != null -> { + val sdkDirectory: Provider = libraryExtension.sdkComponents.sdkDirectory + libraryExtension.onVariants { libraryVariant -> + val androidTest = libraryVariant.androidTest + if (androidTest != null) { + logger.info("Applying marathon for ${libraryVariant.name}") + + val testApkFolder: Provider = androidTest.artifacts.get(SingleArtifact.APK) + val testArtifactsLoader = androidTest.artifacts.getBuiltArtifactsLoader() + + val bundle = GradleAndroidTestBundle.TestOnly( + testApkFolder = project.objects.directoryProperty().apply { set(testApkFolder) }, + testArtifactLoader = project.objects.property(BuiltArtifactsLoader::class.java) + .apply { set(testArtifactsLoader) }, + ) + + val (generateMarathonfileTask, testTaskForVariant) = createTasks( + logger, androidTest.name, bundle, project, conf, sdkDirectory, wrapper, jsonServiceProvider + ) + marathonTask.dependsOn(testTaskForVariant) + } + } + } + + testExtension != null -> { + val sdkDirectory: Provider = testExtension.sdkComponents.sdkDirectory + testExtension.onVariants { androidTest -> + logger.info("Applying marathon for ${androidTest.name}") + + val testApkFolder: Provider = androidTest.artifacts.get(SingleArtifact.APK) + val testArtifactsLoader = androidTest.artifacts.getBuiltArtifactsLoader() + + val bundle = GradleAndroidTestBundle.TestOnly( + testApkFolder = project.objects.directoryProperty().apply { set(testApkFolder) }, + testArtifactLoader = project.objects.property(BuiltArtifactsLoader::class.java) + .apply { set(testArtifactsLoader) }, + ) + + val (_, testTaskForVariant) = createTasks( + logger, androidTest.name, bundle, project, conf, sdkDirectory, wrapper, jsonServiceProvider + ) + marathonTask.dependsOn(testTaskForVariant) + + } + } + + else -> throw IllegalStateException("No AndroidComponentsExtensions found. Did you apply marathon plugin after applying the application/library plugin?") + } + } + + private fun applyRoot(rootProject: Project): TaskProvider { + val distZip = rootProject.objects.fileProperty() + distZip.set(rootProject.layout.buildDirectory.dir("marathon").map { it.file("marathon-cli.zip") }) + + val distZipTaskProvider = rootProject.tasks.register("marathonWrapperExtract", Copy::class.java) { + inputs.property("md5", DigestUtils.md5Hex(MarathonPlugin::class.java.getResourceAsStream(CLI_PATH))) + outputs.file(distZip).withPropertyName("distZip") + from(rootProject.zipTree(File(MarathonPlugin::class.java.protectionDomain.codeSource.location.toURI()).path)) + include("marathon-cli.zip") + into(rootProject.layout.buildDirectory.dir("marathon")) + } + + val wrapperTask = rootProject.tasks.register(MarathonUnpackTask.NAME, MarathonUnpackTask::class.java) { + inputs.file(distZipTaskProvider.map { File(it.destinationDir, "marathon-cli.zip") }) + .withPropertyName("distZip") + dist.set(rootProject.layout.buildDirectory.dir("marathon").map { it.dir("cli") }) + + from(rootProject.zipTree(distZip)) { + eachFile { + relativePath = RelativePath(true, *relativePath.segments.drop(1).toTypedArray()) + } + includeEmptyDirs = false + } + into(dist) + } + + val cleanTaskProvider = rootProject.tasks.register("cleanMarathonWrapper", Delete::class.java) { + group = Const.GROUP + setDelete(rootProject.layout.buildDirectory.dir("marathon")) + } + rootProject.plugins.withType(BasePlugin::class.java) { + rootProject.tasks.named(BasePlugin.CLEAN_TASK_NAME).configure { + dependsOn(cleanTaskProvider) + } + } + return wrapperTask + } + + companion object { + private fun createTasks( + logger: Logger, + variantName: String, + bundle: GradleAndroidTestBundle, + project: Project, + config: MarathonExtension, + sdkDirectory: Provider, + wrapper: TaskProvider, + jsonServiceProvider: Provider, + ): Pair, TaskProvider> { + val baseOutputDir = config.baseOutputDir?.let { File(it) } ?: File(project.buildDir, "reports/marathon") + val output = File(baseOutputDir, variantName) + + val configurationBuilder = Configuration.Builder(config.name, output).apply { + config.analyticsConfiguration?.toAnalyticsConfiguration()?.let { analyticsConfiguration = it } + config.poolingStrategy?.toStrategy()?.let { poolingStrategy = it } + config.shardingStrategy?.toStrategy()?.let { shardingStrategy = it } + config.sortingStrategy?.toStrategy()?.let { sortingStrategy = it } + config.batchingStrategy?.toStrategy()?.let { batchingStrategy = it } + config.flakinessStrategy?.toStrategy()?.let { flakinessStrategy = it } + config.retryStrategy?.toStrategy()?.let { retryStrategy = it } + config.filteringConfiguration?.toFilteringConfiguration()?.let { filteringConfiguration = it } + config.ignoreFailures?.let { ignoreFailures = it } + config.isCodeCoverageEnabled?.let { isCodeCoverageEnabled = it } + config.executionStrategy?.let { executionStrategy = it } + config.uncompletedTestRetryQuota?.let { uncompletedTestRetryQuota = it } + config.includeSerialRegexes?.map { it.toRegex() }?.let { includeSerialRegexes = it } + config.excludeSerialRegexes?.map { it.toRegex() }?.let { excludeSerialRegexes = it } + config.testBatchTimeoutMillis?.let { testBatchTimeoutMillis = it } + config.testOutputTimeoutMillis?.let { testOutputTimeoutMillis = it } + config.debug?.let { debug = it } + config.screenRecordingPolicy?.let { screenRecordingPolicy = it } + config.analyticsTracking?.let { analyticsTracking = it } + config.bugsnagReporting?.let { bugsnagReporting = it } + config.deviceInitializationTimeoutMillis?.let { + deviceInitializationTimeoutMillis = deviceInitializationTimeoutMillis + } + config.outputConfiguration?.toStrategy()?.let { outputConfiguration = it } + } + val vendorConfigurationBuilder = VendorConfiguration.AndroidConfigurationBuilder().apply { + config.autoGrantPermission?.let { autoGrantPermission = it } + instrumentationArgs = config.instrumentationArgs + config.applicationPmClear?.let { applicationPmClear = it } + config.testApplicationPmClear?.let { testApplicationPmClear = it } + config.adbInitTimeout?.let { adbInitTimeoutMillis = it } + config.installOptions?.let { installOptions = it } + config.screenRecordConfiguration?.let { screenRecordConfiguration = it } + config.serialStrategy?.let { serialStrategy = it } + config.waitForDevicesTimeoutMillis?.let { waitForDevicesTimeoutMillis = it } + config.allureConfiguration?.let { allureConfiguration = it } + config.fileSyncConfiguration?.let { fileSyncConfiguration = it } + config.testParserConfiguration?.let { testParserConfiguration = it } + config.testAccessConfiguration?.let { testAccessConfiguration = it } + config.timeoutConfiguration?.let { timeoutConfiguration = it } + config.adbServers?.let { adbServers = it } + config.disableWindowAnimation?.let { disableWindowAnimation = it } + } + + val jsonService = jsonServiceProvider.get() + val configurationJson = jsonService.serialize(configurationBuilder) + val vendorConfigurationJson = jsonService.serialize(vendorConfigurationBuilder) + + val generateMarathonfileTask = + project.tasks.register( + "$TASK_PREFIX${variantName.capitalize()}GenerateMarathonfile", + GenerateMarathonfileTask::class.java + ) { + group = Const.GROUP + description = "Generates Marathonfile for '${variantName}' variation" + flavorName.set(variantName) + applicationBundle.set(listOf(bundle)) + this.configurationBuilder.set(configurationJson) + this.vendorConfigurationBuilder.set(vendorConfigurationJson) + this.jsonService.set(jsonServiceProvider) + sdk.set(sdkDirectory) + marathonfile.set(project.layout.buildDirectory.dir("marathon").map { it.dir(variantName) } + .map { it.file("Marathonfile") }) + } + + val marathonTask = project.tasks.register("$TASK_PREFIX${variantName.capitalize()}", MarathonRunTask::class.java) { + group = JavaBasePlugin.VERIFICATION_GROUP + description = "Runs instrumentation tests on all the connected devices for '${variantName}' " + + "variation and generates a report with screenshots" + outputs.upToDateWhen { false } + dist.set(wrapper.flatMap { it.dist }) + marathonfile.set(generateMarathonfileTask.flatMap { it.marathonfile }) + } + + + return Pair(generateMarathonfileTask, marathonTask) + } + + + /** + * Task name prefix. + */ + private const val TASK_PREFIX = "marathon" + private const val CLI_PATH = "/marathon-cli.zip" + + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/AnalyticsConfig.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/AnalyticsConfig.kt new file mode 100644 index 0000000..b288818 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/AnalyticsConfig.kt @@ -0,0 +1,119 @@ +package com.malinskiy.marathon.gradle + +import com.malinskiy.marathon.config.AnalyticsConfiguration +import com.malinskiy.marathon.config.analytics.Defaults +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil + +class AnalyticsConfig { + var influx: InfluxConfig? = null + var graphite: GraphiteConfig? = null + var influx2: Influx2Config? = null + + fun influx(action: Action) { + influx = InfluxConfig().also { action.execute(it) } + } + + fun influx(closure: Closure) = influx(ConfigureUtil.configureUsing(closure)) + + fun graphite(action: Action) { + graphite = GraphiteConfig().also { action.execute(it) } + } + + fun graphite(closure: Closure) = graphite(ConfigureUtil.configureUsing(closure)) + + fun influx2(action: Action) { + influx2 = Influx2Config().also { action.execute(it) } + } + + fun influx2(closure: Closure) = influx2(ConfigureUtil.configureUsing(closure)) +} + +class InfluxConfig { + var url: String = "" + var user: String = "" + var password: String = "" + var dbName: String = "" + var retentionPolicy: RetentionPolicy? = null + var defaults: Defaults = Defaults() +} + +class Influx2Config { + var url: String = "" + var token: String = "" + var organization: String = "" + var bucket: String = "" + var retentionPolicy: Influx2RetentionPolicy? = null + var defaults: Defaults = Defaults() +} + +class Influx2RetentionPolicy { + var everySeconds: Int = 86400 * 30 + var shardGroupDurationSeconds: Long = 0L +} + +class RetentionPolicy { + var name: String = "rpMarathon" + var duration: String = "30d" + var shardDuration: String = "30m" + var replicationFactor: Int = 2 + var isDefault: Boolean = true +} + +class GraphiteConfig { + var host: String = "" + var port: String? = null + var prefix: String? = null + var defaults: Defaults = Defaults() +} + +fun AnalyticsConfig.toAnalyticsConfiguration(): AnalyticsConfiguration { + val influx = this.influx + val influx2 = this.influx2 + val graphite = this.graphite + return when { + influx2 != null -> AnalyticsConfiguration.InfluxDb2Configuration( + url = influx2.url, + token = influx2.token, + organization = influx2.organization, + bucket = influx2.bucket, + retentionPolicyConfiguration = influx2.retentionPolicy?.toRetentionPolicy() + ?: AnalyticsConfiguration.InfluxDb2Configuration.RetentionPolicyConfiguration.default, + defaults = influx2.defaults + ) + influx != null -> AnalyticsConfiguration.InfluxDbConfiguration( + dbName = influx.dbName, + user = influx.user, + password = influx.password, + url = influx.url, + retentionPolicyConfiguration = influx.retentionPolicy?.toRetentionPolicy() + ?: AnalyticsConfiguration.InfluxDbConfiguration.RetentionPolicyConfiguration.default, + defaults = influx.defaults + ) + graphite != null -> AnalyticsConfiguration.GraphiteConfiguration( + host = graphite.host, + port = graphite.port?.toIntOrNull(), + prefix = graphite.prefix, + defaults = graphite.defaults + ) + else -> AnalyticsConfiguration.DisabledAnalytics + } +} + +private fun Influx2RetentionPolicy.toRetentionPolicy(): AnalyticsConfiguration.InfluxDb2Configuration.RetentionPolicyConfiguration { + return AnalyticsConfiguration.InfluxDb2Configuration.RetentionPolicyConfiguration( + everySeconds = everySeconds, + shardGroupDurationSeconds = shardGroupDurationSeconds, + ) +} + +private fun RetentionPolicy.toRetentionPolicy(): AnalyticsConfiguration.InfluxDbConfiguration.RetentionPolicyConfiguration { + return AnalyticsConfiguration.InfluxDbConfiguration.RetentionPolicyConfiguration( + name, + duration, + shardDuration, + replicationFactor, + isDefault + ) +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/BatchingStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/BatchingStrategyConfiguration.kt new file mode 100644 index 0000000..69aa81f --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/BatchingStrategyConfiguration.kt @@ -0,0 +1,52 @@ +package com.malinskiy.marathon.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil +import java.time.Instant + +class BatchingStrategyConfiguration { + var fixedSize: FixedSizeBatchingStrategyConfiguration? = null + var className: ClassNameBatchingStrategyConfiguration? = null + + fun fixedSize(action: Action) { + fixedSize = FixedSizeBatchingStrategyConfiguration().also { action.execute(it) } + } + + fun fixedSize(closure: Closure) = fixedSize(ConfigureUtil.configureUsing(closure)) + + fun className(action: Action) { + className = ClassNameBatchingStrategyConfiguration + } + + fun className(closure: Closure) = className(ConfigureUtil.configureUsing(closure)) +} + +class FixedSizeBatchingStrategyConfiguration { + var size = 1 + var durationMillis: Long? = null + var percentile: Double? = null + var timeLimit: Instant? = null + var lastMileLength: Int = 0 +} + +object ClassNameBatchingStrategyConfiguration + +fun BatchingStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.BatchingStrategyConfiguration { + var batchingConfigurationCount = 0 + if (fixedSize != null) batchingConfigurationCount++ + if (className != null) batchingConfigurationCount++ + if (batchingConfigurationCount > 1) throw RuntimeException("Only one batching strategy can be selected") + + return fixedSize?.let { + com.malinskiy.marathon.config.strategy.BatchingStrategyConfiguration.FixedSizeBatchingStrategyConfiguration( + it.size, + it.durationMillis, + it.percentile, + it.timeLimit, + it.lastMileLength + ) + } + ?: className?.let { com.malinskiy.marathon.config.strategy.BatchingStrategyConfiguration.ClassNameBatchingStrategyConfiguration } + ?: com.malinskiy.marathon.config.strategy.BatchingStrategyConfiguration.IsolateBatchingStrategyConfiguration +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FilteringPluginConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FilteringPluginConfiguration.kt new file mode 100644 index 0000000..f92db3e --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FilteringPluginConfiguration.kt @@ -0,0 +1,106 @@ +package com.malinskiy.marathon.gradle + +import com.malinskiy.marathon.config.FilteringConfiguration +import com.malinskiy.marathon.config.TestFilterConfiguration +import groovy.lang.Closure + +open class FilteringPluginConfiguration { + //groovy + var groovyAllowList: Wrapper? = null + var groovyBlockList: Wrapper? = null + + fun allowlist(closure: Closure<*>) { + groovyAllowList = Wrapper() + closure.delegate = groovyAllowList + closure.call() + } + + fun blocklist(closure: Closure<*>) { + groovyBlockList = Wrapper() + closure.delegate = groovyBlockList + closure.call() + } + + //kts + var allowlist: MutableCollection = mutableListOf() + var blocklist: MutableCollection = mutableListOf() + fun allowlist(block: MutableCollection.() -> Unit) { + allowlist.also(block) + } + + fun blocklist(block: MutableCollection.() -> Unit) { + blocklist.also(block) + } +} + +open class Wrapper { + open var simpleClassNameFilter: ArrayList? = null + open var simpleTestNameFilter: ArrayList? = null + open var fullyQualifiedClassnameFilter: ArrayList? = null + open var fullyQualifiedTestnameFilter: ArrayList? = null + open var testPackageFilter: ArrayList? = null + open var testMethodFilter: ArrayList? = null + open var annotationFilter: ArrayList? = null + open var annotationDataFilter: ArrayList? = null + open var allureTestFilter: Boolean = false +} + +fun Wrapper.toList(): List { + val mutableList = mutableListOf() + when (annotationFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.AnnotationFilterConfiguration(annotationFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.AnnotationFilterConfiguration(values = annotationFilter)) + } + when (fullyQualifiedClassnameFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.FullyQualifiedClassnameFilterConfiguration(fullyQualifiedClassnameFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.FullyQualifiedClassnameFilterConfiguration(values = fullyQualifiedClassnameFilter)) + } + when (testPackageFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.TestPackageFilterConfiguration(testPackageFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.TestPackageFilterConfiguration(values = testPackageFilter)) + } + when (testMethodFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.TestMethodFilterConfiguration(testMethodFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.TestMethodFilterConfiguration(values = testMethodFilter)) + } + when (simpleClassNameFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.SimpleClassnameFilterConfiguration(simpleClassNameFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.SimpleClassnameFilterConfiguration(values = simpleClassNameFilter)) + } + when (simpleTestNameFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.SimpleTestnameFilterConfiguration(simpleTestNameFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.SimpleTestnameFilterConfiguration(values = simpleTestNameFilter)) + } + when (fullyQualifiedTestnameFilter?.size) { + null, 0 -> Unit + 1 -> mutableList.add(TestFilterConfiguration.FullyQualifiedTestnameFilterConfiguration(fullyQualifiedTestnameFilter?.first().orEmpty().toRegex())) + else -> mutableList.add(TestFilterConfiguration.FullyQualifiedTestnameFilterConfiguration(values = fullyQualifiedTestnameFilter)) + } + this.annotationDataFilter?.map { + val currentData = it.split(",") + TestFilterConfiguration.AnnotationDataFilterConfiguration(currentData.first().toRegex(), currentData[1].toRegex()) + }?.let { + mutableList.addAll(it) + } + if (allureTestFilter) { + mutableList.add(TestFilterConfiguration.AllureFilterConfiguration) + } + return mutableList +} + +fun FilteringPluginConfiguration.toFilteringConfiguration(): FilteringConfiguration { + if (groovyAllowList != null || groovyBlockList != null) { + val allow = groovyAllowList?.toList() ?: emptyList() + + val block = groovyBlockList?.toList() ?: emptyList() + return FilteringConfiguration(allow, block) + } + return FilteringConfiguration(allowlist, blocklist) +} + diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FlakinessStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FlakinessStrategyConfiguration.kt new file mode 100644 index 0000000..191f9cd --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/FlakinessStrategyConfiguration.kt @@ -0,0 +1,36 @@ +package com.malinskiy.marathon.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil +import java.time.Instant +import java.time.temporal.ChronoUnit + +class FlakinessStrategyConfiguration { + var probabilityBased: ProbabilityBasedFlakinessStrategyConfiguration? = null + + fun probabilityBased(action: Action) { + probabilityBased = ProbabilityBasedFlakinessStrategyConfiguration().also { action.execute(it) } + } + + fun probabilityBased(closure: Closure) = + probabilityBased(ConfigureUtil.configureUsing(closure)) +} + +private const val DEFAULT_MIN_SUCCESS_RATE = 0.8 +private const val DEFAULT_MAX_FLAKY_TESTS_COUNT = 3 + +class ProbabilityBasedFlakinessStrategyConfiguration { + var minSuccessRate: Double = DEFAULT_MIN_SUCCESS_RATE + var maxCount: Int = DEFAULT_MAX_FLAKY_TESTS_COUNT + var timeLimit: Instant = Instant.now().minus(DEFAULT_DAYS_COUNT, ChronoUnit.DAYS) +} + +fun FlakinessStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.FlakinessStrategyConfiguration = + probabilityBased?.let { + com.malinskiy.marathon.config.strategy.FlakinessStrategyConfiguration.ProbabilityBasedFlakinessStrategyConfiguration( + it.minSuccessRate, + it.maxCount, + it.timeLimit + ) + } ?: com.malinskiy.marathon.config.strategy.FlakinessStrategyConfiguration.IgnoreFlakinessStrategyConfiguration diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/OutputConfiugration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/OutputConfiugration.kt new file mode 100644 index 0000000..4b7bd0b --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/OutputConfiugration.kt @@ -0,0 +1,14 @@ +package com.malinskiy.marathon.gradle + +import com.malinskiy.marathon.config.OUTPUT_MAX_FILENAME +import com.malinskiy.marathon.config.OUTPUT_MAX_PATH +import com.malinskiy.marathon.config.OutputConfiguration + +open class OutputConfiguration { + fun toStrategy(): OutputConfiguration { + return OutputConfiguration(maxPath ?: OUTPUT_MAX_PATH, maxFilename ?: OUTPUT_MAX_FILENAME) + } + + var maxPath: Int? = null + var maxFilename: Int? = null +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/PoolingStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/PoolingStrategyConfiguration.kt new file mode 100644 index 0000000..e2fdbe2 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/PoolingStrategyConfiguration.kt @@ -0,0 +1,31 @@ +package com.malinskiy.marathon.gradle.configuration + +class PoolingStrategyConfiguration { + var operatingSystem: Boolean? = null + var abi: Boolean? = null + var manufacturer: Boolean? = null + var model: Boolean? = null +} + +fun PoolingStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration { + if (listOf(operatingSystem, abi, manufacturer, model).all { it == null || it == false }) { + return com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.OmniPoolingStrategyConfiguration + } else { + val strategies = mutableListOf() + when { + operatingSystem != null && operatingSystem == true -> { + strategies.add(com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.OperatingSystemVersionPoolingStrategyConfiguration) + } + abi != null && abi == true -> { + strategies.add(com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.AbiPoolingStrategyConfiguration) + } + manufacturer != null && manufacturer == true -> { + strategies.add(com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.ManufacturerPoolingStrategyConfiguration) + } + model != null && model == true -> { + strategies.add(com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.ModelPoolingStrategyConfiguration) + } + } + return com.malinskiy.marathon.config.strategy.PoolingStrategyConfiguration.ComboPoolingStrategyConfiguration(strategies) + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/RetryStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/RetryStrategyConfiguration.kt new file mode 100644 index 0000000..9c8405d --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/RetryStrategyConfiguration.kt @@ -0,0 +1,32 @@ +package com.malinskiy.marathon.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil + +open class RetryStrategyConfiguration { + var fixedQuota: FixedQuotaRetryStrategyConfiguration? = null + + fun fixedQuota(action: Action) { + fixedQuota = FixedQuotaRetryStrategyConfiguration().also { action.execute(it) } + } + + fun fixedQuota(closure: Closure) = fixedQuota(ConfigureUtil.configureUsing(closure)) +} + +private const val DEFAULT_TOTAL_ALLOWED_RETRY_QUOTA = 200 +private const val DEFAULT_RETRY_PER_TEST_QUOTA = 3 + +open class FixedQuotaRetryStrategyConfiguration { + var totalAllowedRetryQuota: Int = DEFAULT_TOTAL_ALLOWED_RETRY_QUOTA + var retryPerTestQuota: Int = DEFAULT_RETRY_PER_TEST_QUOTA +} + +fun RetryStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.RetryStrategyConfiguration { + return fixedQuota?.let { + com.malinskiy.marathon.config.strategy.RetryStrategyConfiguration.FixedQuotaRetryStrategyConfiguration( + it.totalAllowedRetryQuota, + it.retryPerTestQuota + ) + } ?: com.malinskiy.marathon.config.strategy.RetryStrategyConfiguration.NoRetryStrategyConfiguration +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/ShardingStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/ShardingStrategyConfiguration.kt new file mode 100644 index 0000000..f34b145 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/ShardingStrategyConfiguration.kt @@ -0,0 +1,23 @@ +package com.malinskiy.marathon.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil + +class ShardingStrategyConfiguration { + var countSharding: CountShardingStrategyConfiguration? = null + + fun countSharding(action: Action) { + countSharding = CountShardingStrategyConfiguration().also { action.execute(it) } + } + + fun countSharding(closure: Closure) = countSharding(ConfigureUtil.configureUsing(closure)) +} + +class CountShardingStrategyConfiguration { + var count = 1 +} + +fun ShardingStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.ShardingStrategyConfiguration = countSharding?.let { + com.malinskiy.marathon.config.strategy.ShardingStrategyConfiguration.CountShardingStrategyConfiguration(it.count) +} ?: com.malinskiy.marathon.config.strategy.ShardingStrategyConfiguration.ParallelShardingStrategyConfiguration diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/SortingStrategyConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/SortingStrategyConfiguration.kt new file mode 100644 index 0000000..a5bc852 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/configuration/SortingStrategyConfiguration.kt @@ -0,0 +1,59 @@ +package com.malinskiy.marathon.gradle + +import groovy.lang.Closure +import org.gradle.api.Action +import org.gradle.util.internal.ConfigureUtil +import java.time.Instant +import java.time.temporal.ChronoUnit +import java.util.Random + +class SortingStrategyConfiguration { + var executionTime: ExecutionTimeSortingStrategyConfiguration? = null + var randomOrder: RandomOrderStrategyConfiguration? = null + var successRate: SuccessRateSortingStrategyConfiguration? = null + + + fun executionTime(action: Action) { + executionTime = ExecutionTimeSortingStrategyConfiguration().also { action.execute(it) } + } + + fun executionTime(closure: Closure) = executionTime(ConfigureUtil.configureUsing(closure)) + + fun randomOrder(action: Action) { + randomOrder = RandomOrderStrategyConfiguration().also { action.execute(it) } + } + + fun randomOrder(closure: Closure) = randomOrder(ConfigureUtil.configureUsing(closure)) + + fun successRate(action: Action) { + successRate = SuccessRateSortingStrategyConfiguration().also { action.execute(it) } + } + + fun successRate(closure: Closure) = successRate(ConfigureUtil.configureUsing(closure)) +} + +private const val DEFAULT_PERCENTILE = 90.0 +const val DEFAULT_DAYS_COUNT = 30L + +class ExecutionTimeSortingStrategyConfiguration { + var percentile: Double = DEFAULT_PERCENTILE + var timeLimit: Instant = Instant.now().minus(DEFAULT_DAYS_COUNT, ChronoUnit.DAYS) +} + +class SuccessRateSortingStrategyConfiguration { + var limit: Instant = Instant.now().minus(DEFAULT_DAYS_COUNT, ChronoUnit.DAYS) + var ascending: Boolean = false +} + +class RandomOrderStrategyConfiguration {} + +fun SortingStrategyConfiguration.toStrategy(): com.malinskiy.marathon.config.strategy.SortingStrategyConfiguration = executionTime?.let { + com.malinskiy.marathon.config.strategy.SortingStrategyConfiguration.ExecutionTimeSortingStrategyConfiguration( + it.percentile, + it.timeLimit + ) +} ?: successRate?.let { + com.malinskiy.marathon.config.strategy.SortingStrategyConfiguration.SuccessRateSortingStrategyConfiguration(it.limit, it.ascending) +} ?: randomOrder?.let { + com.malinskiy.marathon.config.strategy.SortingStrategyConfiguration.RandomOrderStrategyConfiguration +} ?: com.malinskiy.marathon.config.strategy.SortingStrategyConfiguration.NoSortingStrategyConfiguration diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/service/JsonService.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/service/JsonService.kt new file mode 100644 index 0000000..60da4db --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/service/JsonService.kt @@ -0,0 +1,16 @@ +package com.malinskiy.marathon.gradle.service + +import com.malinskiy.marathon.config.Configuration +import com.malinskiy.marathon.config.serialization.MutableConfigurationFactory +import com.malinskiy.marathon.config.vendor.VendorConfiguration +import org.gradle.api.services.BuildService +import org.gradle.api.services.BuildServiceParameters + +abstract class JsonService : BuildService { + private val factory = MutableConfigurationFactory() + + fun serialize(configuration : Configuration.Builder) = factory.serialize(configuration) + fun serialize(configuration : VendorConfiguration.AndroidConfigurationBuilder) = factory.serialize(configuration) + fun parse(value: String) = factory.parse(value) + fun parseVendor(value: String) = factory.parseVendorAndroid(value) +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt new file mode 100644 index 0000000..c630960 --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt @@ -0,0 +1,133 @@ +package com.malinskiy.marathon.gradle.task + +import com.android.build.api.variant.BuiltArtifacts +import com.malinskiy.marathon.config.serialization.ConfigurationFactory +import com.malinskiy.marathon.config.vendor.android.AndroidTestBundleConfiguration +import com.malinskiy.marathon.gradle.GradleAndroidTestBundle +import com.malinskiy.marathon.gradle.Const +import com.malinskiy.marathon.gradle.service.JsonService +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.ListProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Nested +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.TaskAction +import org.gradle.kotlin.dsl.listProperty +import org.gradle.kotlin.dsl.property +import java.io.File +import javax.inject.Inject + +open class GenerateMarathonfileTask @Inject constructor(objects: ObjectFactory) : DefaultTask() { + init { + group = Const.GROUP + } + + @Input + val flavorName: Property = objects.property() + + @Input + val configurationBuilder: Property = objects.property() + + @Input + val vendorConfigurationBuilder: Property = objects.property() + + // Overrides for the configuration from the AGP + @Nested + val applicationBundle: ListProperty = objects.listProperty() + + @InputDirectory + @PathSensitive(PathSensitivity.NAME_ONLY) + val sdk: DirectoryProperty = objects.directoryProperty() + + @OutputFile + val marathonfile: RegularFileProperty = objects.fileProperty() + + @Internal + val jsonService: Property = objects.property() + + @TaskAction + fun write() { + val json = jsonService.get() + + // Override stuff coming from AGP + val androidConfiguration = vendorConfigurationBuilder.let { json.parseVendor(it.get()) }.apply { + androidSdk = sdk.get().asFile + outputs = mapAndroidOutputs(applicationBundle.get(), flavorName.get()) + }.build() + val cnf = configurationBuilder.let { json.parse(it.get()) }.apply { + vendorConfiguration = androidConfiguration + }.build() + + // Write a Marathonfile + val configurationFactory = ConfigurationFactory( + marathonfileDir = temporaryDir, + analyticsTracking = cnf.analyticsTracking, + bugsnagReporting = cnf.bugsnagReporting + ) + val yaml = configurationFactory.serialize(cnf) + marathonfile.get().asFile.writeText(yaml) + } + + private fun mapAndroidOutputs( + bundles: List, + flavorName: String + ): List { + return bundles.map { + when(it) { + is GradleAndroidTestBundle.ApplicationWithTest -> { + val artifactLoader = it.artifactLoader.get() + val artifacts: BuiltArtifacts = + artifactLoader.load(it.apkFolder.get()) ?: throw RuntimeException("No application artifact found") + when { + artifacts.elements.size > 1 -> throw UnsupportedOperationException( + "The Marathon plugin does not support abi splits for app APKs, " + + "but supports testing via a universal APK. " + + "Add the flag \"universalApk true\" in the android.splits.abi configuration." + ) + + artifacts.elements.isEmpty() -> throw UnsupportedOperationException("No artifacts for variant $flavorName") + } + val application = File(artifacts.elements.first().outputFile) + val testArtifactsLoader = it.testArtifactLoader.get() + val testArtifacts = + testArtifactsLoader.load(it.testApkFolder.get()) ?: throw RuntimeException("No test artifacts for variant $flavorName") + when { + testArtifacts.elements.size > 1 -> throw UnsupportedOperationException("The Marathon plugin does not support abi/density splits for test APKs") + testArtifacts.elements.isEmpty() -> throw UnsupportedOperationException("No test artifacts for variant $flavorName") + } + val testApplication = File(testArtifacts.elements.first().outputFile) + AndroidTestBundleConfiguration( + application = application, + testApplication = testApplication, + extraApplications = emptyList(), + splitApks = null, + ) + } + is GradleAndroidTestBundle.TestOnly -> { + val testArtifactsLoader = it.testArtifactLoader.get() + val testArtifacts = + testArtifactsLoader.load(it.testApkFolder.get()) ?: throw RuntimeException("No test artifacts for variant $flavorName") + when { + testArtifacts.elements.size > 1 -> throw UnsupportedOperationException("The Marathon plugin does not support abi/density splits for test APKs") + testArtifacts.elements.isEmpty() -> throw UnsupportedOperationException("No test artifacts for variant $flavorName") + } + val testApplication = File(testArtifacts.elements.first().outputFile) + AndroidTestBundleConfiguration( + application = null, + testApplication = testApplication, + extraApplications = emptyList(), + splitApks = null, + ) + } + } + } + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonRunTask.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonRunTask.kt new file mode 100644 index 0000000..f4bcf1b --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonRunTask.kt @@ -0,0 +1,61 @@ +package com.malinskiy.marathon.gradle.task + +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.api.tasks.AbstractExecTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.VerificationTask +import org.gradle.internal.os.OperatingSystem +import org.gradle.kotlin.dsl.property +import java.io.File +import java.nio.file.Files +import java.nio.file.Paths +import java.nio.file.attribute.PosixFilePermission +import javax.inject.Inject + +open class MarathonRunTask @Inject constructor(objects: ObjectFactory) : AbstractExecTask(MarathonRunTask::class.java), + VerificationTask { + + @InputFile + val marathonfile: RegularFileProperty = objects.fileProperty() + + @InputDirectory + val dist: DirectoryProperty = objects.directoryProperty() + + @OutputDirectory + val fakeLockingOutput = File(project.rootProject.buildDir, "fake-marathon-locking-output") + + private var ignoreFailure: Boolean = false + + override fun exec() { + setExecutable(getPlatformScript(dist.get().asFile)) + setArgs(listOf("-m", marathonfile.get().asFile.canonicalPath)) + + super.exec() + } + + override fun getIgnoreFailures(): Boolean = ignoreFailure + + override fun setIgnoreFailures(ignoreFailures: Boolean) { + ignoreFailure = ignoreFailures + } + + private fun getPlatformScript(marathonBuildDir: File) = when (OperatingSystem.current()) { + OperatingSystem.WINDOWS -> { + Paths.get(marathonBuildDir.canonicalPath, "bin", "marathon.bat").toFile() + } + + else -> { + val cliPath = Paths.get(marathonBuildDir.canonicalPath, "bin", "marathon") + cliPath.apply { + val permissions = Files.getPosixFilePermissions(this) + Files.setPosixFilePermissions(this, permissions + PosixFilePermission.OWNER_EXECUTE) + }.toFile() + } + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonUnpackTask.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonUnpackTask.kt new file mode 100644 index 0000000..05e14bc --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/MarathonUnpackTask.kt @@ -0,0 +1,21 @@ +package com.malinskiy.marathon.gradle.task + +import com.malinskiy.marathon.gradle.Const +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.model.ObjectFactory +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.Sync +import javax.inject.Inject + +open class MarathonUnpackTask @Inject constructor(objects: ObjectFactory) : Sync() { + init { + group = Const.GROUP + } + + @OutputDirectory + val dist: DirectoryProperty = objects.directoryProperty() + + companion object { + const val NAME = "marathonWrapper" + } +} diff --git a/marathon-gradle-plugin/src/test/kotlin/com/malinskiy/marathon/gradle/task/CachingTest.kt b/marathon-gradle-plugin/src/test/kotlin/com/malinskiy/marathon/gradle/task/CachingTest.kt new file mode 100644 index 0000000..11ccd4b --- /dev/null +++ b/marathon-gradle-plugin/src/test/kotlin/com/malinskiy/marathon/gradle/task/CachingTest.kt @@ -0,0 +1,80 @@ +package com.malinskiy.marathon.gradle.task + +import assertk.assertThat +import assertk.assertions.contains +import assertk.assertions.isEqualTo +import com.malinskiy.marathon.configuration.BuildConfig +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.io.TempDir +import java.io.File + + +class CachingTest { + val GRADLE_VERSION = "7.6.1" + + @Test + fun testUnpackingIsCached() { + val runner = GradleRunner.create() + .withGradleVersion(GRADLE_VERSION) + .withProjectDir(testProjectDir) + .withArguments(":marathonWrapper", "--build-cache", "--stacktrace") + var result = runner.build() + + assertThat(result.output).contains("BUILD SUCCESSFUL") + + result = runner + .withArguments(":marathonWrapper", "--build-cache", "--stacktrace", "--info") + .build() + + assertThat(result.task(":marathonWrapperExtract")!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + assertThat(result.task(":marathonWrapper")!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + } + + @Test + fun testMarathonfileGenerationIsCached() { + val runner = GradleRunner.create() + .withGradleVersion(GRADLE_VERSION) + .withProjectDir(testProjectDir) + .withArguments(":app:marathonDebugAndroidTestGenerateMarathonfile", "--build-cache", "--stacktrace") + var result = runner.build() + + assertThat(result.output).contains("BUILD SUCCESSFUL") + + result = runner + .withArguments(":app:marathonDebugAndroidTestGenerateMarathonfile", "--build-cache", "--stacktrace") + .build() + + assertThat(result.task(":app:marathonDebugAndroidTestGenerateMarathonfile")!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + } + + companion object { + @TempDir + lateinit var testProjectDir: File + @BeforeAll + @JvmStatic + internal fun setup() { + File(testProjectDir, "local.properties").writeText("sdk.dir=${androidHome()}") + val fixture = File(CachingTest::class.java.protectionDomain.classLoader.getResource("sample1").toURI()) + fixture.copyRecursively(overwrite = true, target = testProjectDir) + + val version = StringBuilder().apply { + append(BuildConfig.VERSION) + if (BuildConfig.RELEASE_MODE == "SNAPSHOT") { + append("-SNAPSHOT") + } + }.toString() + File(testProjectDir, "build.gradle").apply { + val content = readText() + writeText(content.replaceFirst("\${MARATHON_VERSION}", version)) + } + } + + private fun androidHome(): String { + return System.getenv("ANDROID_SDK_ROOT") ?: System.getenv("ANDROID_HOME") + ?: throw IllegalStateException("Missing Android SDK installation. Please specify 'ANDROID_SDK_ROOT'") + } + } +} diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/build.gradle b/marathon-gradle-plugin/src/test/resources/sample1/app/build.gradle new file mode 100644 index 0000000..7c41e3c --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/app/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'com.android.application' + id 'com.malinskiy.marathon' +} + +android { + compileSdkVersion 30 + defaultConfig { + applicationId "com.malinskiy.marathon.gradle.sample1" + minSdkVersion 23 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation("androidx.navigation:navigation-fragment-ktx:2.3.0") + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test:rules:1.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/src/androidTest/java/com/malinskiy/marathon/gradle/sample1/SampleTest.java b/marathon-gradle-plugin/src/test/resources/sample1/app/src/androidTest/java/com/malinskiy/marathon/gradle/sample1/SampleTest.java new file mode 100644 index 0000000..e69de29 diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/AndroidManifest.xml b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..db82cd1 --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/java/com/malinskiy/marathon/gradle/sample1/MainActivity.java b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/java/com/malinskiy/marathon/gradle/sample1/MainActivity.java new file mode 100644 index 0000000..5f5016a --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/java/com/malinskiy/marathon/gradle/sample1/MainActivity.java @@ -0,0 +1,13 @@ +package com.malinskiy.marathon.gradle.sample1; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; + +public class MainActivity extends AppCompatActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/layout/activity_main.xml b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..36e1986 --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/values/strings.xml b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..1ad8c29 --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Sample + diff --git a/marathon-gradle-plugin/src/test/resources/sample1/build.gradle b/marathon-gradle-plugin/src/test/resources/sample1/build.gradle new file mode 100644 index 0000000..be75904 --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/build.gradle @@ -0,0 +1,13 @@ +plugins { + id 'com.android.application' version '7.4.1' apply false + id 'com.android.library' version '7.4.1' apply false + id 'com.malinskiy.marathon' version '${MARATHON_VERSION}' apply false +} + +allprojects { + repositories { + mavenLocal() + mavenCentral() + google() + } +} diff --git a/marathon-gradle-plugin/src/test/resources/sample1/gradle.properties b/marathon-gradle-plugin/src/test/resources/sample1/gradle.properties new file mode 100644 index 0000000..5bac8ac --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/gradle.properties @@ -0,0 +1 @@ +android.useAndroidX=true diff --git a/marathon-gradle-plugin/src/test/resources/sample1/settings.gradle b/marathon-gradle-plugin/src/test/resources/sample1/settings.gradle new file mode 100644 index 0000000..5242526 --- /dev/null +++ b/marathon-gradle-plugin/src/test/resources/sample1/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + mavenLocal() + google() + gradlePluginPortal() + } +} + +include 'app' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..6ebf6d0 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + maven { url = uri("$rootDir/build/repository") } + gradlePluginPortal() + google() + } +} + +rootProject.name = "marathon-gradle-plugin" +include("marathon-gradle-plugin")